$(function(){
	var url = window.location.href;
	var loc = url.split("#");
	
	if(loc.length == 2){
		if(loc[1] == "news"){
			$.scrollTo( {top:'532px', left:'0px'}, 1000 );	
		}else if(loc[1] == "work"){
			$.scrollTo( {top:'787px', left:'0px'}, 1000 );	
		}else{};
	}else{};
	
	$("#header, .navContainer").css({ opacity: .98 });//transparence for header
	$(".navigation").css({ opacity: .92 });//transparence for navigation
	
	//for feature(banner) photo gallery
	var qEle = $('.scrollTo').length - 1;
	var cEle = 1;
		
	$('.dot').click(function(){
		var n = $('.dot').index(this);
		$('#big').scrollTo( '.scrollTo:eq('+n+')', 1000, {axis:'x'} );
		$(this).parent().children().css('background-position','top');
		$(this).css('background-position','bottom');
		cEle = n;
		$('.img_content:eq('+cEle+')').parent().children('.img_content').hide();
		$('.img_content:eq('+cEle+')').fadeIn("slow");
	});
	
	var hoverData = 1;
	function rotate(){
		if(hoverData == 1){
			$('#big').scrollTo( '.scrollTo:eq('+cEle+')', 1000, {axis:'x'} );
			$('.dot:eq('+cEle+')').parent().children().css('background-position','top');
			$('.dot:eq('+cEle+')').css('background-position','bottom');
			$('.img_content:eq('+cEle+')').parent().children('.img_content').hide();
			$('.img_content:eq('+cEle+')').fadeIn("slow");
			if(cEle < qEle){
				cEle ++;
			}else{
				cEle = 0;
			};
		}else{};
	};
	
	setInterval(rotate,5000);
	//end for feature(banner) photo gallery	
	
	$('#news_sections').//Drag Scrollable function for News section
		dragscrollable({acceptPropagatedEvent: true});
	
	$('#work_sections').//Drag Scrollable function for Work section
		dragscrollableWork({acceptPropagatedEvent: true});
		
	report();//fix the position of banner navigation and padding-bottom of #footer
	
		
	$('.nav a').click(function(){//change the color of a in header when click
		$('.nav').children().css("color","#666");
		$(this).css("color","#fff");
	});
	
	$('#about_a, #about_close').click(function(){// animate for the content of About
		$('#contactUs').hide();
		if($('#about').css("display") == "none"){
			$('#about').animate({
				height: 'show'
			}, 'slow');	
		}else{
			$('#about_a').css("color","#666");
			$('#about').animate({
				height: 'hide'
			}, 'slow');			
		}
	});
	
	$('#contactUs_a, #contactUs_close').click(function(){// animate for the content of contactUs
		$('#about').hide();
		if($('#contactUs').css("display") == "none"){
			$('#contactUs').animate({
				height: 'show'
			}, 'slow');			
		}else{
			$('#contactUs_a').css("color","#666");
			$('#contactUs').animate({
				height: 'hide'
			}, 'slow');			
		}
	});
	
	
	//click function for Banner(Feature) News and Work
	$('#banner_a').click(function(){
		$('#about, #contactUs').animate({
			height: 'hide'
		}, 'slow');	
		$.scrollTo( {top:'0px', left:'0px'}, 1000 );
		$('.nav').children().css("color","#666");
	});
	
	$('#news_a').click(function(){
		$('#contactUs, #about').animate({
				height: 'hide'
			}, 'slow');	
		$.scrollTo( {top:'532px', left:'0px'}, 1000 );
	});
	
	$('#work_a').click(function(){
		$('#contactUs, #about').animate({
				height: 'hide'
			}, 'slow');	
		$.scrollTo( {top:'787px', left:'0px'}, 1000 );
	});
	//click function for Banner(Feature) News and Work
	
	$('.banner').hover(function(){//banner hover function
		hoverData = 0;
		if(($('#about').css("display") == "none") && ($('#contactUs').css("display") == "none")){
			$('.navigation').animate({
				height: 'show'
			}, 'slow');	
			
			var imgConNum = $('.img_content').length;//make writeup on the banner to be abit more centralised to the height
			for(var i = 0; i < imgConNum; i ++){
				var hei = $('.img_content').eq(i);
				var alt = (240 - hei.height())/2;
				hei.css("top",alt);
			};
		}else{};	
	},function(){
		hoverData = 1;
		$('.navigation').animate({
			height: 'hide'
		}, 'slow');	
	});	
	
//	$('#sub_screen').serialScroll({//serialScroll function
//		target:'#sub_sections',
//		items:'li', 
//		prev:'img.prev',
//		next:'img.next',
//		axis:'x',
//		navigation:'.sub_navigation li a',
//		offset:0, 
//		queue:false,
//		duration:600,
//		force:true, 
//		cycle:false,
//		jump:true, 
//		interval:false,
//		constant:true,
//		onBefore:function( e, elem, $pane, $items, pos ){
//			/**
//			 * 'this' is the triggered element 
//			 * e is the event object
//			 * elem is the element we'll be scrolling to
//			 * $pane is the element being scrolled
//			 * $items is the items collection at this moment
//			 * pos is the position of elem in the collection
//			 * if it returns false, the event will be ignored
//			 */
//			 //those arguments with a $ are jqueryfied, elem isn't.
//			e.preventDefault();
//			if( this.blur )
//				this.blur();
//		},
//		onAfter:function( elem ){
//			//'this' is the element being scrolled ($pane) not jqueryfied
//		}
//	});
		
});

//function imgContent(num,index){//banner navigation change
//	for(var i = 1; i <= num; i ++){
//		document.getElementById('img_content_' + i).className = "img_content";
//		document.getElementById('nav_a_' + i).className = "";
//	};	
//	document.getElementById('img_content_' + index).className = "img_content_current";
//	document.getElementById('nav_a_' + index).className = "a_current";
//};

//function aChange(num,index){//news and work navigation change
//	for(var i = 1; i <= num; i ++){
//		document.getElementById('tank_a_' + i).className = "";
//	};	
//	document.getElementById('tank_a_' + index).className = "a_current";
//};

//function aWorkChange(num,index){//news and work navigation change
//	for(var i = 1; i <= num; i ++){
//		document.getElementById('w_tank_a_' + i).className = "";
//	};	
//	document.getElementById('w_tank_a_' + index).className = "a_current";
//};

function report(){//fix the position of banner navigation and padding-bottom of #footer
	var screenHeight = document.documentElement.clientHeight;
	var bottomData = screenHeight - 710;
	
	$('.navigation').css("bottom",bottomData);//fix the position of banner navigation
	
	if(navigator.userAgent.indexOf("MSIE 7.0")>0){//fix the padding-bottom of #footer in especial IE7
		$('#footer').css("padding-bottom",screenHeight - 477);		
	}else{
		$('#footer').css("padding-bottom",screenHeight - 480);	
	};
};




