function swap_tab5(n){
	for(var i=1;i<=2;i++){
		var curC=document.getElementById("tab5_"+i);
		var curB=document.getElementById("tab5_t"+i);
		if(n==i){
			curC.style.display="block";
			curB.className="active"
		}else{
			curC.style.display="none";
			curB.className="normal"
		}
	}
}
function swap_tab4(n){
	for(var i=1;i<=2;i++){
		var curC=document.getElementById("tab4_"+i);
		var curB=document.getElementById("tab4_t"+i);
		if(n==i){
			curC.style.display="block";
			curB.className="active1"
		}else{
			curC.style.display="none";
			curB.className="normal1"
		}
	}
}  

//滚动插件
(function($){
$.fn.extend({
        Scroll:function(opt,callback){
                //参数初始化
                if(!opt) var opt={};
                var _this=this.eq(0).find("ul:first");
                var        lineH=_this.find("li:first").height(), //获取行高
                        line=opt.line?parseInt(opt.line,10):parseInt(this.height()/lineH,10), //每次滚动的行数，默认为一屏，即父容器高度
                        speed=opt.speed?parseInt(opt.speed,10):800, //卷动速度，数值越大，速度越慢（毫秒）
                        timer=opt.timer?parseInt(opt.timer,10):1000; //滚动的时间间隔（毫秒）
                if(line==0) line=1;
                var upHeight=0-line*lineH;
                //滚动函数
                scrollUp=function(){
                        _this.animate({
                                marginTop:upHeight
                        },speed,function(){
                                for(i=1;i<=line;i++){
                                        _this.find("li:first").appendTo(_this);
                                }
                                _this.css({marginTop:0});
                        });
                }
                //鼠标事件绑定
                _this.hover(function(){
                        clearInterval(timerID);
                },function(){
                        timerID=setInterval("scrollUp()",timer);
                }).mouseout();
        }        
})
})(jQuery);

$(document).ready(function(){
        $("#scrollDiv").Scroll({line:4,speed:800,timer:6000});
});


//菜单效果
var menu2Height = "190";
var menu3Height = "100";
var menu1Array = {"menu101" : "220", "menu102" : "210" , "menu103" : "190", "menu104" : "170"};
var inMenu_event = false, menu301_li_event = false;

function showMenu(id){
	var height = (id == "menu301") ? menu3Height : menu2Height;
	var duration = (height - jQuery("#" + id).height())/height * 400;
	jQuery("#" + id).stop().animate({
		height: height.toString() + "px"
		}, duration, function() {
	});
	
		if(id == "menu2"){
		if(! inMenu_event){
			inMenu_event = true;
			$("#inMenu").mouseover(function(){
				showMenu("menu2");
			}).mouseout(function(){
				hideMenu("menu2");
			});
		}
		for(menu in menu1Array){
			if(! jQuery("#" + menu).data("width")){
				jQuery("#" + menu).data("width", jQuery("#" + menu).width());
			}
			jQuery("#" + menu).stop().animate({
				width: menu1Array[menu] + "px"
				}, duration, function() {
			});
		}
	} else if(! menu301_li_event){
		menu301_li_event = true;
		$("#menu301_li").mouseover(function(){
			showMenu("menu301");
		}).mouseout(function(){
			hideMenu("menu301");
		});
	}
		
}
function hideMenu(id){
	var height = (id == "menu301") ? menu3Height : menu2Height;
	var duration = (jQuery("#" + id).height())/height * 400;
	jQuery("#" + id).stop().animate({
		height: 0
		}, duration, function() {
		$("#inMenu").unbind("mouseouver").unbind("mouseout");
		$("#menu301_li").unbind("mouseouver").unbind("mouseout");
		inMenu_event = false;
		menu301_li_event = false;
	});
	
		if(id == "menu2"){
		for(menu in menu1Array){
			jQuery("#" + menu).stop().animate({
				width: jQuery("#" + menu).data("width") + "px"
				}, duration, function() {
			});
		}
	}
	}

$(document).ready(function() {

	jQuery("#menu201, #menu202, #menu203, #menu204").mouseover(function(){
		clearTimeout($(this).data("hover"));
		$(this).data("hover", setTimeout("$('#" + this.id + "').addClass('hover')", 50));
	}).mouseout(function(){
		clearTimeout($(this).data("hover"));
		$(this).data("hover", setTimeout("$('#" + this.id + "').removeClass('hover')", 50));
	});
});


//弹出联系方式
$(document).ready(function(){
						   		   
	//When you click on a link with class of poplight and the href starts with a # 
	$('a.poplight[href^=#]').click(function() {
		var popID = $(this).attr('rel'); //Get Popup Name
		var popURL = $(this).attr('href'); //Get Popup href to define size
				
		//Pull Query & Variables from href URL
		var query= popURL.split('?');
		var dim= query[1].split('&');
		var popWidth = dim[0].split('=')[1]; //Gets the first query string value

		//Fade in the Popup and add close button
		$('#' + popID).fadeIn().css({ 'width': Number( popWidth ) }).prepend('<a href="#" class="close"><img src="img/close_pop.png" class="btn_close" title="Close Window" alt="Close" /></a>');
		
		//Define margin for center alignment (vertical + horizontal) - we add 80 to the height/width to accomodate for the padding + border width defined in the css
		var popMargTop = ($('#' + popID).height() + 80) / 2;
		var popMargLeft = ($('#' + popID).width() + 80) / 2;
		
		//Apply Margin to Popup
		$('#' + popID).css({ 
			'margin-top' : -popMargTop,
			'margin-left' : -popMargLeft
		});
		
		//Fade in Background
		$('body').append('<div id="fade"></div>'); //Add the fade layer to bottom of the body tag.
		$('#fade').css({'filter' : 'alpha(opacity=80)'}).fadeIn(); //Fade in the fade layer 
		
		return false;
	});
	
	
	//Close Popups and Fade Layer
	$('a.close, #fade').live('click', function() { //When clicking on the close or fade layer...
	  	$('#fade , .popup_block').fadeOut(function() {
			$('#fade, a.close').remove();  
	}); //fade them both out
		
		return false;
	});

	
});
