$(document).ready(function(){
	$(".header_thi .here").mouseover(function(){
		$(".header_thi .pop1").css("display","block");
		$(".header_thi .pop2").css("display","block");	
	});

	$(".header_thi .pop2").mouseover(function(){
		$(".header_thi .pop1").css("display","block");
		$(".header_thi .pop2").css("display","block");
	});

	$(".header_thi .pop1").mouseout(function(){
		$(".header_thi .pop1").css("display","none");
		$(".header_thi .pop2").css("display","none");
	});

	$("ol.pop2").mouseout(function(){
		$(".header_thi .pop1").css("display","none");
		$(".header_thi .pop2").css("display","none");
	});

	$(".my_sell").mouseover(function(){
		$(this).addClass("hover");
		$(".menu_sell").css("display","block");
		$(".menu_sell .pop2").css("display","block");
		$(".blue_col").css("background-color","#ffffff");
	}).mouseout(function(){
		$(this).removeClass("hover");
		$(".menu_sell").css("display","none");
		$(".menu_sell .pop2").css("display","none");
		$(".blue_col").css("background-color","transparent");
	});
	
	$(".help").mouseover(function(){
		$(this).addClass("hover");
		$(".menu_help").css("display","block");
		$(".menu_help .pop4").css("display","block");
		$(".help_a").css("background-color","#ffffff");
	}).mouseout(function(){
		$(this).removeClass("hover");
		$(".menu_help").css("display","none");
		$(".menu_help .pop4").css("display","none");
		$(".help_a").css("background-color","transparent");
	});

	if($('#eduTopNav').length > 0){
        $('#eduTopNav .topNavList ul li').mouseover(function(){
            if($(this).hasClass('current')){return;}
            $('#eduTopNav .current').removeClass('current');
            $('#eduTopNav .cLink').removeClass('cLink');
            $(this).addClass('current');
            $('a:first',this).addClass('cLink');
        });

        $('#eduTopNav .default').trigger('mouseover');
    }

	$.fn.rolling = function (offset) {
		return this.each(function(){
			var wapper = $(this);
			var controller = $(wapper.next('.turn_page'));

			$('li:first',controller).click(function(){rollingDown(wapper,controller,offset)});
			$('li:last',controller).click(function(){rollingUp(wapper,controller,offset)});
			$("a[title=1]",controller).click(function(){rollingTurn(wapper,controller,1,offset)});
			$("a[title=2]",controller).click(function(){rollingTurn(wapper,controller,2,offset)});
			$("a[title=3]",controller).click(function(){rollingTurn(wapper,controller,3,offset)});
		});
	};

	function rollingUp (wapper,controller,offset){

		var nowtop = wapper.find("li:first").css("marginTop");
		var turn = nowtop.split("px")[0] - offset;

		if(turn == 0 || turn == -offset || turn == -offset*2){
			wapper.find("li:first").animate({marginTop:turn},1000);
		}

		if(turn == -offset){
			$("a[title=2]",controller).removeClass();
			$("a[title=2]",controller).addClass("current");
			$("a[title=1]",controller).removeClass();
			$("a[title=3]",controller).removeClass(); 
			$("a[title=1]",controller).addClass("pageNum");
			$("a[title=3]",controller).addClass("pageNum");
		}

		if(turn == -offset*2){
			$("a[title=3]",controller).removeClass();
			$("a[title=3]",controller).addClass("current");
			$("a[title=2]",controller).removeClass(); 
			$("a[title=1]",controller).removeClass(); 
			$("a[title=2]",controller).addClass("pageNum");
			$("a[title=1]",controller).addClass("pageNum");
		}
	}

	function rollingDown (wapper,controller,offset){
		var nowtop = wapper.find("li:first").css("marginTop");
		var turn = parseInt(nowtop.split("px")[0])+ offset;

		if(turn == 0 || turn == -offset || turn == -offset*2 ){
			wapper.find("li:first").animate({marginTop:turn},1000);
		}

		if(turn==-180){
			$("a[title=2]",controller).removeClass();
			$("a[title=2]",controller).addClass("current");
			$("a[title=1]",controller).removeClass();
			$("a[title=3]",controller).removeClass(); 
			$("a[title=1]",controller).addClass("pageNum");
			$("a[title=3]",controller).addClass("pageNum");
		}

		if(turn==0){
			$("a[title=1]",controller).removeClass();
			$("a[title=1]",controller).addClass("current");
			$("a[title=2]",controller).removeClass(); 
			$("a[title=3]",controller).removeClass(); 
			$("a[title=2]",controller).addClass("pageNum");
			$("a[title=3]",controller).addClass("pageNum");
		}
	}

	function rollingTurn (wapper,controller,num,offset){
		var tempnum =-(num-1)* offset;
		wapper.find("li:first").animate({marginTop:tempnum},1000);
		for(i=1;i<=3;i++){
			$("a[title="+i+"]",controller).removeClass();
			if(i==num){  
				$("a[title="+i+"]",controller).addClass("current");
			}else{
				$("a[title="+i+"]",controller).addClass("pageNum");
			}
		}
	}

	$('.rolling176').rolling(176);
	$('.rolling163').rolling(163);
   	$('.rolling445').rolling(445);
});


