// JavaScript Document
function nav(nav,secNav,on){
	var $first = $(nav);
	var $second = $(secNav);
	var time,curIndex = -1;
	$first.each(function(index){
		$("a",this).hover(function(){
			var cur = this;
			//clearTimeout(time);
			$(this).addClass(on);
			$($second[index]).show();
			
			$($second[index]).hover(function(){
				$($second[index]).show();
				$(cur).addClass(on);
				clearTimeout(time);
				curIndex = index;
			},function(){
				$($second[index]).hide();
				$(cur).removeClass(on);
			});
			
		},function(){
			$($second[index]).hide();
			$("a",$($first[index])).removeClass(on);
		});					 
	});
}

function shade(nav,shade,obj,closePop){
	var $screen = $(nav);
	var $shade = $(shade);
	var height = document.documentElement.scrollHeight;
	var screenHeight = document.documentElement.clientHeight;
	$screen.height(height);
	
	$(obj).click(function(){			  
		if( screenHeight < $shade.height() ){
			if( screenHeight + $(window).scrollTop() < height ){
				$shade.css("top",$(window).scrollTop());
			}else{
				$shade.css("top",height - $shade.height() );	
			}
		}else{
			$shade.css("top",(screenHeight-$shade.height())/2+$(window).scrollTop());
		}
		$screen.show();
		$shade.show();
	});
	$(closePop).click(function(){					   
		$screen.hide();
		$shade.hide();
	});
}

function shade02(nav,shade,closePop,popList){
	var $screen = $(nav);
	var $shade = $(shade);
	var $popList = $(popList);
	var height = document.documentElement.scrollHeight;
	var screenHeight = document.documentElement.clientHeight;
	$screen.height(height);
	
	$popList.each(function(index){
		$($popList[index]).click(function(){			  
			if( screenHeight < $($shade[index]).height() ){
				if( screenHeight + $(window).scrollTop() < height ){
					$($shade[index]).css("top",$(window).scrollTop());
				}else{
					$($shade[index]).css("top",height - $shade.height() );	
				}
			}else{
				$($shade[index]).css("top",(screenHeight-$shade.height())/2+$(window).scrollTop());
			}
			$screen.show();
			$($shade[index]).show();
		});
		$(closePop).click(function(){					   
			$screen.hide();
			$($shade[index]).hide();
		});
	});	
}

function scrollBar (nav,list,leftBtn,rightBtn,pos){
	var $listBox = $(nav);
	var $list = $(list);
	var $leftBtn = $(leftBtn);
	var $rightBtn = $(rightBtn);
	var cur = 0,len = $list.length;
	
	var play = function(i){
		$listBox.animate({left:-pos*i+"px"},500);
	}
	
	var autoplay = function(i){
		setInterval(function(){$listBox.animate({left:-pos*i+"px"},500);if( i < len-1 ){i++;}else{i=0;}},2000);
		
	}
	
	this.init = function(){
		autoplay(cur);
		$leftBtn.click(function(e){
			
			if( cur < len-1 ){
				cur++;	
			}
			play( cur );
			e.preventDefault();
		});
		$rightBtn.click(function(e){
			if( cur > 0 ){
				cur--;	
			}
			play( cur );
			e.preventDefault();
		});
	}
}

function scrollBar(list, innerview, speed) {
    if (speed <= 0)
        speed = 5; 
    var $list = $(list)[0];
    var $innerview1 = $(innerview)[0];
    //var $innerview1 = $(innerview1);
    var $innerview2 = $(innerview)[1];
    //var $innerview2 = $(innerview2);
    $innerview2.innerHTML = $innerview1.innerHTML;
    function Marquee() {
        if ($innerview2.offsetWidth - $list.scrollLeft <= 0)
            $list.scrollLeft -= $innerview1.offsetWidth
        else {
            $list.scrollLeft++;
        }
    }
    var MyMar = setInterval(Marquee, speed);
    $list.onmouseover = function() { clearInterval(MyMar) };
    $list.onmouseout = function() { MyMar = setInterval(Marquee, speed) };
}

function tab( list01,list02,on ){
	var $list01 = $(list01);
	var $list02 = $(list02);
	var cur = 0,len = $list01.length;
	
	$list01.each(function(index){
		$(this).click(function(){
			if(!!on){
				if(cur != len-1){$($list01[cur]).removeClass(on);}
				$($list01[index]).addClass(on);
			}
			$($list02[cur]).hide();
			$($list02[index]).show();
			cur = index;
		});					  
	});
}

function change(){
	var $list01 = $(".picList02 .big");
	var $list02 = $(".picList02 .smallpiclist li");
	$list02.each(function(i){
		$(this).click(function(){
			$list01.animate({top:-268*i+"px"},500);   
		});					  
	});
}

function tabchange(){
	var list01 = $("#inner li");
	var list02 = $(".inn");
	
	list01.each(function(i){
		$(this).hover(function(){
			list01.removeClass("on");
			list02.addClass("hide");
			$(list01[i]).addClass("on");
			$(list02[i]).removeClass("hide");	   
		},function(){})
	});
}

function ppw(){
	var obj = $(".mmp");
	var showObj = $(".smallmap");
	var prev = 0;
	
	obj.each(function(index){
		$(this).click(function(e){
			$(showObj[prev]).hide();
			$(showObj[index]).show();
			e.preventDefault();
			$(showObj[index]).click(function(){
				$(this).hide();								 
			});
			prev = index;
		});				  
	});
}

function horse(){
	var list = $(".hourse");
	var whe = $(".where");
	var last = 0;
	
	list.each(function(index){
		$(this).click(function(e){
			$(whe[last]).hide();
			$(whe[index]).show();
			e.preventDefault();
			$(whe[index]).click(function(){
				$(this).hide();							  
			});
			last = index;
		});				  
	});
}

function school(){
	var $littleSchool = $(".school");
	var $scholl = $(".schoolPic");
	var i = 0;
	
	$littleSchool.each(function(index){
		$(this).hover(function(){
			if( index != i ){
				$(".arrowup").removeClass("arrowUp"+i).addClass("arrowUp"+index);
				$($scholl[i]).hide();
				$($scholl[index]).show();
				i = index;
			}
		},function(){});							
	});
}

$(function(){
	nav("#header .nav li","#header .secondNav","on");
	ppw();
	horse();
	school();
});
