var imgArr = new Array('switch1','switch2','switch3','switch4','switch5','switch1');
var hrefArr = new Array('#','#','#','#','#','#');
var imgNow = 0;
var lef = rig = 0;
var lenable = false;
var renable = true;
var speed = 500;

$(document).ready(function(){
	$("#menuBswitch a").each(function(index){
		$(this).bind("mouseenter",function(){
			$("#bswitchBar").stop();
			var step = 0;
			if(index > imgNow){
				step = index-imgNow;
				for(var i=0; i<step; i++){
					speed = 500/step;
					rightPic();
				}
			}else{
				step = imgNow-index;
				if(step ==  0){
					 moveLight();
				}else{
					for(var i=0; i<step; i++){
						speed = 500/step;
						leftPic();
					}
				}
			}
		});
	});
	
	var pics = "";
	for(i=0; i<6; i++){
		pics += '<a href="'+hrefArr[i]+'"><img src="images/switchs/'+imgArr[i]+'.png" /></a>';
	}
	$("#bswitchBar").html(pics);
	
	/*$("#bswitchLeft").hide();
	$("#bswitchRight").css("opacity","0.7");
	$("#bswitchRight").click(function(){
		$("#bswitchBar").stop();
		speed = 500;
		rightPic();
	}).mouseover(function(){
		if(renable){
			$("#bswitchRight").show();
			$(this).css("opacity","1");
		}
	}).mouseout(function(){
		if(renable){
			$("#bswitchRight").show();
			$(this).css("opacity","0.7");
		}
	});
	$("#bswitchLeft").click(function(){
		$("#bswitchBar").stop();
		speed = 500;
		leftPic();
	}).mouseover(function(){
		if(lenable){
			$("#bswitchLeft").show();
			$(this).css("opacity","1");
		}
	}).mouseout(function(){
		if(lenable){
			$("#bswitchLeft").show();
			$(this).css("opacity","0.7");
		}
	});*/
	
	$("#module .module-part-pic").each(function(index){
		$(this).mouseover(function(){
			$(this).children(".modPic1").hide();
			$(this).children(".modPic2").show();
		}).mouseout(function(){
			$(this).children(".modPic2").hide();
			$(this).children(".modPic1").show();
		});
	});
	
	$("#startVideo").click(function(){
		var ftop = $(document).scrollTop() + getBrowserHeight()/2 - 272;
		$("#flashLayout").css("top",ftop);
		
		$("#flashFloat").show();	
	});
	$("#flashClose").click(function(){
		$("body").css("overflow-y","auto");
		$("#flashFloat").hide();
	});
	$("#menuBswitch .current").mouseenter();
});
function getBrowserHeight() {
    if ($.browser.msie) {
        return document.compatMode == "CSS1Compat" ? document.documentElement.clientHeight :
                document.body.clientHeight;
    } else {
        return self.innerHeight;
    }
}

function rightPic(){
	if(lef > -910*5){
		imgNow++;
		lef -= 910;
		if(lef <= -910*5){
			$("#bswitchRight").hide();
			renable = false;
		}
		$("#bswitchBar").animate({left: lef+'px'}, speed);
		/*$("#bswitchLeft").show();
		$("#bswitchLeft").css("opacity","0.7");
		lenable = true;*/
		moveLight()
	}
}
function leftPic(){
	if(lef <0){
		imgNow--;
		lef += 910;
		if(lef >= 0 ){
			$("#bswitchLeft").hide();
			lenable = false;
		}
		$("#bswitchBar").animate({left: lef+'px'}, speed);
		/*$("#bswitchRight").show();
		$("#bswitchRight").css("opacity","0.7");
		renable = true;*/
		moveLight()
	}
}
function resetBar(){
	$("#menuBswitch a").each(function(index){
		if(index == 0){
			or = 0;
		} else if(index == 1){
			or = -17;
		} else if(index == 2){
			or = -35;
		} else if(index == 3){
			or = -53;
		} else if(index == 4){
			or = -70;
		} else if(index == 5){
			or = -88;
		}
		$(this).children("span").css("background-position","0 "+or+"px");
	});
}

function moveLight(){
	var lef1 = imgNow * 151;
	$("#lightBswitch").animate({left: lef1+'px'}, 100);
	resetBar();
	if(imgNow == 0){
		or = 0;
	} else if(imgNow == 1){
		or = -17;
	} else if(imgNow == 2){
		or = -35;
	} else if(imgNow == 3){
		or = -53;
	} else if(imgNow == 4){
		or = -70;
	} else if(imgNow == 5){
		or = -88;
	}
	$("#menuBswitch a").eq(imgNow).children("span").css("background-position","-177px "+or+"px");
}


