

$(document).ready(function(){
	if(window.location.hash != ""){
		window.location.href = base_url1+"main/index/"+window.location.hash.replace("#", "");
	}
	$("#showhide").click(function(){
		var el = $(this);
		var pg = "";
		if(!$(this).hasClass("open")){
			pg = "more";
			$("#entrance").stop(1,1).slideUp(500, function(){
				$("#page").slideDown(700);
				$(el).addClass("open");
				var txt=$(el).find("span").text();
				$(el).html("<span>"+$(el).find("input").val()+"</span><input type='hidden' value='"+txt+"'/>");
			});
			$("#menu ul li:first").addClass("active");
			$("#main_flash").fadeOut(200);
		}
		else{
			$("#page").stop(1,1).slideUp(700, function(){
				$("#entrance").slideDown(400);
				$(el).removeClass("open");
				var txt=$(el).find("span").text();
				$(el).html("<span>"+$(el).find("input").val()+"</span><input type='hidden' value='"+txt+"'/>");
			});
			$("#menu ul li:first").removeClass("active");
			$("#main_flash").fadeIn(200);
		}
		if(!$.browser.msie){
			history.pushState({foo: "bar"}, "1", base_url1+"main/index/"+pg);
		}
		else{
			window.location.hash = pg;
		}
	});
	$(".stripe").mouseenter(function(){
		$(this).stop().animate({width: 496, left: $(this).index()*44}, 498, function(){
			if($.browser.msie && parseInt(jQuery.browser.version) == 7){
				$(this).children(".pic").css({"filter": "alpha(opacity=100)"});
				$(this).children(".open").css({display: "block"});
				$(this).children(".sign").css({display: "none"});
			}
		});
		if($.browser.msie && parseInt(jQuery.browser.version) == 7){
			$(this).children(".pic").css({"filter": "alpha(opacity=100)"});
			$(this).children(".open").css({display: "block"});
			$(this).children(".sign").css({display: "none"});
		}
		else{
			$(this).children(".pic").stop().animate({opacity: 1});
			$(this).children(".open").stop(1,1).fadeIn(300);
			$(this).children(".sign").stop(1,1).fadeOut(300);
		}
		var cur = $(this).index()+1;
		for(var i=1; i < cur; i++){
			$("#str_"+i).stop().animate({width: 42, left: (i-1)*44}, 498);
			if($.browser.msie && parseInt(jQuery.browser.version) == 7){
				$("#str_"+i).children(".open").css({display: "none"});
				$("#str_"+i).children(".sign").css({display: "block"});
				$("#str_"+i).children(".pic").css({"filter": "alpha(opacity=40)"});
			}
			else{
				$("#str_"+i).children(".open").stop(1,1).fadeOut(100);
				$("#str_"+i).children(".sign").stop(1,1).fadeIn(300);
				$("#str_"+i).children(".pic").stop().animate({opacity: 0.4});
			}
		}
		for(i = cur+1; i <= $(".stripe").length; i++){
			$("#str_"+i).stop().animate({width: 42, left: (i-2)*44+498}, 498);
			if($.browser.msie && parseInt(jQuery.browser.version) == 7){
				$("#str_"+i).children(".open").css({display: "none"});
				$("#str_"+i).children(".sign").css({display: "block"});
				$("#str_"+i).children(".pic").css({"filter": "alpha(opacity=40)"});
			}
			else{
				$("#str_"+i).children(".open").stop(1,1).fadeOut(100);
				$("#str_"+i).children(".sign").stop(1,1).fadeIn(300);
				$("#str_"+i).children(".pic").stop().animate({opacity: 0.4});
			}
		}
	});
	$(".stripe").click(function(){
		if(!$(this).hasClass("close")){
			if(!$(this).hasClass("fd_active")){
				$(this).stop(1,1)
				var el = $(this);
				var id = $(this).children("input").val();
				var lft = $(this).offset().left-6;
				$("#loader").fadeIn(300);
				var hgt = $(window).height() - $(this).offset().top-$(this).height()-100;
				$.ajax({
					type: "POST",
					async: false,
					data: "id="+id+"&hgt="+hgt,
					url: base_url1+"main/get_case_txt",
					success: function(text){
						$("#loader").fadeOut(300);
						$(el).css({zIndex:10});
						$("<div class='whitebg'></div>").appendTo("body");
						if(!$.browser.msie){
							$(".whitebg").fadeIn(700, function(){
								$("#content_page").after(text);
								$("#pop_text").css({left: lft});
								$(".scroll_box").tinyscrollbar_update();
								$("#pop_text").fadeIn(700,function(){
										$(".scroll_box").tinyscrollbar_update();
										var t=setTimeout('$(".scroll_box").tinyscrollbar_update()',100);	
									});
							});
						}
						else{
							if(parseInt(jQuery.browser.version) == 7){
								$("#content_page").after(text);
								$("#pop_text").css({left: lft});
								$("#pop_text").css({display: "block"});
								$(".whitebg").css({display: "block"});
								$(".scroll_box").tinyscrollbar_update();
							}
							else{
								$(".whitebg").fadeIn(700, function(){
									$("#content_page").after(text);
									$("#pop_text").css({left: lft});
									
									$("#pop_text").fadeIn(700,function(){
										$(".scroll_box").tinyscrollbar_update();
										var t=setTimeout('$(".scroll_box").tinyscrollbar_update()',100);	
									});
								});
							}
						}
						$(el).addClass("fd_active");
						//$(".scroll_box").tinyscrollbar_update();
					}
				});
				$('<div class="close_popup"></div>').prependTo(el);
				if(!$.browser.msie){
					history.pushState({foo: "bar"}, "1", base_url1+"main/index/more/"+id);
					//$(".scroll_box").tinyscrollbar_update();
				}
				else{
					//$(".scroll_box").tinyscrollbar_update();
					$("#content_subpage").find(".whiten").css({"opacity": "0.7"});
					window.location.hash = "more/"+id;
				}
				
			}
			return false;
		}
	});
	
	$(".close_popup").live("mouseenter",function(){
		$(this).parent().addClass('close');
	})
	$(".close_popup").live("mouseleave",function(){
		$(this).parent().removeClass('close');
	});
	
	$(".close_popup, .whitebg, .stripe.close").live("click", function(){
		$(".stripe.fd_active").css({zIndex:5});
		$(".stripe.fd_active").removeClass("fd_active").removeClass('close');
		if(!$.browser.msie){
			$(".whitebg").fadeOut(400, function(){
				$(this).remove();
			});
			$("#pop_text").fadeOut(250, function(){
				$(this).remove();
			});
		}
		else{
			if(parseInt(jQuery.browser.version) == 7){
				$(".whitebg").remove();
				$("#pop_text").remove();
			}
			else{
				$(".whitebg").fadeOut(400, function(){
					$(this).remove();
				});
				$("#pop_text").fadeOut(250, function(){
					$(this).remove();
				});
			}
		}
		$.post(base_url+"main/get_title", function(data){
			$("title").html(data);
		});
		if(!$.browser.msie){
			history.pushState({foo: "bar"}, "1", base_url1+"main/index/more");
		}
		else{
			$("#content_subpage").find(".whiten").css({"opacity": "0"});
			window.location.hash = "more";
		}
		$(".close_popup").remove();
		return false;
	});
	$("#auth").submit(function(){
		var d_id = $("#d_id").val();
		if(d_id != ""){
			$.ajax({
				type: "POST",
				async: false,
				data: "d_id="+d_id,
				url: base_url1+"main/auth",
				success: function(){
					window.location.href = window.location.href;
				}
			});
		}
		return false;
	});
});
