var div=$("<div class='changs'></div>");
var ids=0;
var ins=0;
var flag=0;
var rem=0;
var flags=0;
$(window).blur(function () {
	  clearInterval(ids);
	  flag=0;
	  flags=1;
});
$(window).focus(function () {
	if(flags==1)
		setTimeout('xunhuan()',2000);
	flags=0;
});
function changePics(index) {
	if (flag==0) {
		clearInterval(ids);
		setTimeout('xunhuan()',8000);
		flag=1;
	}
	changePic(index);
}
function xunhuan() {
	ins=rem;
	ids=setInterval(actions,8000);
	flag=1;
}
function changePic(index) {	
	rem=index;
	if (index==4) {
		$(".changs").css("left",459+23*index);
	}
	else if(index==3||index==2){
		$(".changs").css("left",458+23*index);
	}
	else {
		$(".changs").css("left",457+23*index);
	}
	var i=index;
	$("#m_pic_"+index).css("z-index","3");
	i++;
	$("#m_pic_"+i%5).css("z-index","2");
	i++;
	$("#m_pic_"+i%5).css("z-index","1");
	i++;
	$("#m_pic_"+i%5).css("z-index","1");
	i++;
	$("#m_pic_"+i%5).css("z-index","2");
	$("#m_pic_"+index).animate({	
	"top":"64.5px",
	"width": "635px",
	"height":"311px",
	"left":"198px"},"fast");
	index++;
	$("#m_pic_"+index%5).animate({
	"top":"95px",
	"width":"372px",
	"height":"258px",
	"left":"144px"},"fast");
	index++;
	$("#m_pic_"+index%5).animate({
	"top":"117.5px",
	"width":"409.5px",
	"height":"212px",
	"left":"104px"},"fast");
	index++;
	$("#m_pic_"+index%5).animate({
	"top":"118.5px",
	"width":"409.5px",
	"height":"212px",
	"left":"518.5px"},"fast");
	index++;
	$("#m_pic_"+index%5).animate({
	"top":"95px",
	"width":"372px",
	"height":"258px",
	"left":"514px"},"fast");
}
function actions()
{
	flag=0;
	++ins;
	changePic(ins%5);
	if(ins>4)
		ins=0;
}
$(document).ready(function(){
	$(div).appendTo("div[id='m_pic']");
	ids=setInterval(actions,8000);
});
$("div[onClick]").each(
function(index)
{
	$(this).hover(
		function () {
			$(this).css("cursor","pointer");
			if((index<1) || index > 4)
				return;
			$("#head_home").find("img").each(function (index) {
					$(this).css("z-index",""+((index+1)%2));
				}); 
			$(this).find("img").each(function (index) {
					$(this).css("z-index",""+((index+1)%2));
				});  
		},
		function () {
			if((index<1) || index > 4)
				return;
			$("#head_home").find("img").each(function (index) {
					$(this).css("z-index",""+index);
				});
			$(this).find("img").each(function (index) {
					$(this).css("z-index",""+index);
				});  
		});
});

