var dateUrl = 'http://i.com/canshi/_getDate.php';
var topShowloopTime = 4 ; // s

$(function(){
	landscapeLoop('#top > div.show li');
	//$('#serverDate').load(dateUrl);
	moviesPhoto();
	setTimeout(function(){zoomPhoto();},2500);
	adShow('#adShow .show li','#adShow .order li');
	
	$('#shiPinZaiXian a').click(function(){
		hs.htmlExpand(this, { objectType: 'iframe', width :480,align:'center' } );
		return false;
	});
	
	$('.beautyImg').corner('6px');
	
	
	
});

function landscapeLoop(obj){
	var $landscapeLi = $(obj);
	var len  = $landscapeLi.length , index = 1;	
	$landscapeLi.eq(0).animate({opacity:'show'},1200);
	if( len == 1 ) return false;
	setInterval(function(){
		showImg( index , $landscapeLi );
		index++;
		if(index==len){index=0;}		
	},topShowloopTime * 1000);
};

function showImg( iShow , obj ){
	obj.each(function(i){
		if( i!= iShow)
			$(this).animate({opacity:'hide'},1200);
		else
			$(this).animate({opacity:'show'},1200);
	});
};


function adShow(obj,objOrder){
	var $landscapeLi = $(obj);
	var len  = $landscapeLi.length , index = 1;	
	$landscapeLi.eq(0).animate({opacity:'show'},1200);
	setInterval(function(){
		showImg( index , $landscapeLi );
		index++;
		if(index==len){index=0;}		
	},topShowloopTime * 1000);
};

$(function(){
	var index = 0;
	var $node = $("#gongZuoShowSlide li");
	var $nodeParent =  $("#gongZuoShowSlide ul");
	var len   = $node.length;
	var orderHtml = '';
	for(var i=1; i <= len ; i++){
		orderHtml += '<a>'+ i +'</a>';
	}	
	var $order = $('#gongZuoShowSlide .order').html(orderHtml);
	
	showSlideImg($nodeParent,index);
	index++;
	
	$order.find('a').click(function(){
		index = $order.find('a').index(this);
		showSlideImg($nodeParent,index);
	});
	
	
	
	var MyTime = setInterval(function(){
		showSlideImg($nodeParent,index);
		index++;
		if(index==len) index=0;
	} ,4000);
	$node.mouseover(function(){
		index = $node.index(this);
		showSlideImg($nodeParent,index);
	});
	$('#idTransformView').hover(function(){
		if(MyTime){ clearInterval(MyTime); }
	},function(){
		MyTime = setInterval(function(){ showSlideImg($nodeParent,index); index++; if(index==len){index=0;}  } , 2000); 
	});	
});
function showSlideImg(node,i){
	//$(node).stop(true,false).animate({left : -300*i},'slow'); 
	$(node).find('li').each(function(ii){
		if( ii != i  )
			$(this).animate({'opacity':'hide'},'normal');
		else
			$(this).animate({'opacity':'show'},'normal')
	}); 
	$('#gongZuoShowSlide .order a').removeClass("action").eq(i).addClass("action");
}

function moviesPhoto(){
	var $moviesPhoto = $('#mingJiaShuHua');
	var $node = $moviesPhoto.find('ul');
	var $li = $moviesPhoto.find('li');
	var len = $li.length ;
	var liWidth = 0;
	for(var i=0; i < len ; i++ ){
		liWidth += $li.eq(i).width();
	}
	var width = liWidth - $moviesPhoto.find('div.photos').width();
	var left = 0;
	var way ;
	var liTime = setInterval(function(){movePhotos();},30); 
	$moviesPhoto.hover(function(){if(liTime) clearInterval(liTime); },function(){liTime = setInterval(function(){movePhotos();},20);});
	function movePhotos(){
		if( Math.abs(left) >= width  ) way = 'right';
		else if( left >= 0 ) way = 'left'; 		
		if( 'right' == way  ) left ++;
		else left--;
		$node.css('left', left);
	};
};

function zoomPhoto(){
	$('#mingJiaShuHua img').each(function(){
		var width = $(this).width();
		var height = $(this).height();
		var paddingTop = parseInt($(this).css('padding-top'));
		$(this).hover(function(){
			$(this).parent().addClass('action');
			$(this).animate({ width : width * 1.2,height : height * 1.2,paddingTop:paddingTop / 4},'fast');
		},function(){
			$(this).parent().removeClass('action');
			$(this).animate({ width : width ,height : height ,paddingTop:paddingTop},'normal');
		});
	});
	
	
	
	
}

