$(window).ready(function(){
	imgPreLoad();
});

$(window).load(function(){
	imgRollOver();
	scrollToTop();
});

/*--------------
  scrollToTop 
 ---------------*/
function scrollToTop(){
	$('.pageToTop').click(function(){								
		$('html, body').animate({ scrollTop : $('#container').offset().top,easing: 'swing'},1000);
	});
}

/*--------------
  imgRollOver  
 ---------------*/
var $g = {
	selector : 'imgOver',
	suffix : '_o',
	ftype:'',
	preloadImg : new Array(),
	imgTag : document.getElementsByTagName('img'),
	imgOverSrc:'',
	swapImgSrc:''
};

function imgPreLoad(){
	for(var i=0;i<$g.imgTag.length;i++){ 		
  		if($g.imgTag[i].className.match($g.selector)){
			if(!($g.imgTag[i].src.match('_s'))){
				$g.ftype = $g.imgTag[i].src.substring($g.imgTag[i].src.lastIndexOf('.'), $g.imgTag[i].src.length);
				$g.preloadImg[i] = new Image();
				$g.preloadImg[i].src = $g.imgTag[i].src.replace( $g.ftype , $g.suffix + $g.ftype);
			}
		}
  	}
};

function imgRollOver(){
  for(var i=0;i<$g.imgTag.length;i++){ 
  	if($g.imgTag[i].className.match($g.selector)){		

		$g.imgTag[i].onmouseover = function() {
			$g.imgOverSrc = this.src;
			$g.swapImgSrc = $g.imgOverSrc.replace( $g.ftype , $g.suffix + $g.ftype);
			if(!($g.imgOverSrc.match('_s'))){
				this.src = $g.swapImgSrc;
			}
		}			
		$g.imgTag[i].onmouseout = function() {	
			if($g.imgOverSrc){
				this.src = $g.imgOverSrc;
			}
		}
	}
  }
};

/*--------------
  glovalNavi 
 ---------------*/
$(document).ready(function(){
	glovalNavi();
});

function glovalNavi(){
	var timerId01;
	var timerId02;
	var currentLeftNext=0;
	var currentWidthNext=0;
	var currentLeftDef;
	var currentWidthDef;
	var currentLineObj = '<div id="currentLine"></div>';
	
	$('#globalNav').children().before(currentLineObj);

	currentLeftDef = $('#currentLine').position().left;	
	currentWidthDef = $('#currentLine').width();
	
	//$('#gNav > li:not(#gNav06)').not('#gNav > li:#gNav05').hover(
	$('#gNav > li:not(#gNav06)').hover(
		function(){
			clearTimeout(timerId02);
			timerId01 = setTimeout(next,200);
			currentLeftNext = $(this).position().left;
			currentWidthNext = $(this).width();
			function next(){
				$('#currentLine').animate({'left': currentLeftNext + 'px','width': currentWidthNext-1+'px'});
			}
		},
		function(){
			clearTimeout(timerId01);
			timerId02 = setTimeout(prev,200);
			function prev(){
				$('#currentLine').animate({'left': currentLeftDef + 'px','width': currentWidthDef+'px'});
			}

		}
	);
};

