jQuery.timer = function (interval, callback)
{
	var interval = interval || 100;
	if (!callback)
		return false;
	_timer = function (interval, callback) {
		this.stop = function () {
			clearInterval(self.id);
		};
		this.internalCallback = function () {
			callback(self);
		};
		this.reset = function (val) {
			if (self.id)
				clearInterval(self.id);
			var val = val || 100;
			this.id = setInterval(this.internalCallback, val);
		};
		this.interval = interval;
		this.id = setInterval(this.internalCallback, this.interval);
		var self = this;
	};
	return new _timer(interval, callback);
};


$(function(){
	//==\\scroll to top\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\
	$("a[rel='gotop']").click(function () {
		$('html, body').animate({scrollTop:0}, 'normal');
		return false;
	});
	
	//==\\office photo slideshow\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\
	$('.fadein img:gt(0)').hide();
	setInterval(function(){$('.fadein :first-child').fadeOut().next('img').fadeIn().end().appendTo('.fadein');}, 3000);

	//==\\service sidebar hover\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\
	$(".svsiderow a").hover(
	  function () {
		$(this).parent().prev().css("background-position","top");
	  },
	  function () {
		$(this).parent().prev().css("background-position","bottom");
	  }
	);
	
	//==\\Floating layer in portfolio\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\
	$(window).scroll(function(){
		$winheight = $(window).height();
		$fltheight = $('.pf_float').height();
		if($fltheight<=$winheight){
			maxheight=$(".col_wrap").height()-$(".pf_float").height();
			h_space=$(".pf_float").attr('rel')
			scrollheight=$(window).scrollTop()-h_space;
			//console.log(maxheight);
			myscroll=(scrollheight>maxheight)?maxheight:scrollheight;
			if($(window).scrollTop()>h_space){
				$('.pf_float').animate({top:myscroll+"px" },{queue: false, duration: 500});  
			}else{
				$('.pf_float').animate({top:0 },{queue: false, duration: 500});  
			}
		}
	});

	
	//==\\portfolio hover\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\
	$(".home_work").hover(
	  function () {
		$(this).find(".home_work_title").slideDown('fast');
	  },
	  function () {
		$(this).find(".home_work_title").slideUp('slow');
	  }
	);
	
 	$('.col_left_menu a').hover(
		function(){
			//$(this).css({"backgroundColor":"#F7F7F7"});
			$(this).css("backgroundColor","#F7F7F7").animate({textIndent:"20px"},200);
		},
		function(){
			$(this).css("backgroundColor","#FFFFFF").animate({textIndent:"15px"},200);
		}
	); 
	
	$('.col_left_menu a').click(
		function(){
			
			$('.col_left_content dd').animate({top:$(this).attr('rel')},300);
			return false;
		
		}
	); 
	
	
	//career form
	$('#career_btn').click(function(){
		var ifempty=true;
		$("#career_form .require").each(function(){
			if($(this).val()==""){
				ifempty=false;
			}
		});	
			if(ifempty){
				$('#career_msg').html('<img src="/images/loading.gif" />').parent('form').ajaxSubmit(function(data){$('#career_msg').html(data)});
			}else{
				$('#career_msg .alert_msg').text('请完整填写您的信息')
			}			
		
	});
	
	
	
	//contact form
	$('#contact_btn').click(function(){
		var ifempty=true;
		$("#contact_form .require").each(function(){
			if($(this).val()==""){
				ifempty=false;
			}
		});	
			if(ifempty){
				$('#contact_msg').html('<img src="/images/loading.gif" />').parent('form').ajaxSubmit(function(data){$('#contact_msg').html(data)});
			}else{
				$('#contact_msg .alert_msg').text('请完整填写您的信息')
			}			
		
	});	
	
	
	//portfolio slideshow
	function showImg(i){
		$('.focus dl').stop();
		var posx=-720*i+"px";
		$('.focus dl').animate({left:posx},300);
		$('.focusnum a').eq(i).addClass('on').siblings().removeClass('on');
	}
	
	var index01 = 0;
	var tm = false;
	var ads;
	var lens = $('.focus dl dd').length;
	var dlwidth = 720*lens+"px";
	$('.focus dl').css("width",dlwidth);
	
	$.timer(0, function (timer) {
		$('.focusnum a').hover(
			function(){
				timer.stop();
				index01 = $('.focusnum a').index(this);
				showImg(index01);
			},
			function(){
				timer.reset(3000);
			}		
		);
		if(!tm){timer.reset(3000);tm=true;}
		showImg(index01);
		index01++;
		if(index01==lens){index01=0}
	});
	

	
	
	
});


