var gWindowHref='';
var gCurrentPage='';
var iwidth=0;
var gIsClick=0;
var gDf_id='';
$(function(){
	Shadowbox.init();
	plusToggle();
	addClick();
	gWindowHref=document.location.hash;
	iwidth=eval(0-$(".move_block")[0].offsetWidth);
	$('.current_page').css('width',Math.abs(iwidth));
	$('.hidden_page').css('width',Math.abs(iwidth));
	idInterval=setInterval(testWindowHref,1000);
	if(gWindowHref!=''){
		var pageHref=gWindowHref.split("#");
		sliding(pageHref[1]);
	}else{
		gCurrentPage='home';
	}
	window.onresize=resizeCurrentPage;
})

function testWindowHref(){
	var windowHref=document.location.hash;
	if(gWindowHref!=windowHref){
		gWindowHref=windowHref;
		var pageHref=windowHref.split("#");
		sliding(pageHref[1]);
	}
}
function sliding(variable){
	
	if(typeof(variable)=='object'){var pageHref=$(this).attr('id').replace('menu_','')}else{var pageHref=variable};
	if(gCurrentPage!=pageHref){
//		if(gCurrentPage=='' && pageHref=='home'){
//		}else{
			gCurrentPage=pageHref;
			$('.href').removeClass('selected');
			$('#menu_'+pageHref).addClass('selected');
			iwidth=eval(0-$(".move_block")[0].offsetWidth);
			var iheight=$(".move")[0].offsetHeight;
			if(typeof(variable)=='object'){
				$.getJSON('page.html',{pageHref:pageHref},function(json){
					$(".hidden_page").html(json.page);
					$(".hidden_page").show();
					iheight=$(".hidden_page")[0].offsetHeight;
					$(".move").animate({'left': eval(iwidth-80), 'height': iheight}, 500, null, function(){
						$(".current_page").remove();
						$(".move").css('left',0);
						$(".hidden_page").attr('class','current_page');
						$(".current_page").css('width',Math.abs(iwidth));
						$(".current_page").after('<div class="hidden_page" style="width:' + Math.abs(iwidth) + 'px;"></div>');
						dfToggle();
						addClick();
						resizeCurrentPage();
						Shadowbox.clearCache();
						Shadowbox.setup();
						plusToggle();
					});
				});
			}else{
				$(".current_page").html('');
//				$("#load").show();
				$('.current_page').css('width',Math.abs(iwidth));
				$('.hidden_page').css('width',Math.abs(iwidth));
				$.getJSON('page.html',{pageHref:pageHref},function(json){
					$(".hidden_page").html(json.page);
					iheight=$(".hidden_page")[0].offsetHeight;
					$(".hidden_page").html('');
					$(".current_page").html(json.page);
//					$("#load").hide();
					$(".move").animate({
						'left': 0,
						'height': iheight
					}, 500);
					dfToggle();
					addClick();
					resizeCurrentPage();
					Shadowbox.clearCache();
					Shadowbox.setup();
					plusToggle();
				});
			}
//		}
	}
}
function addClick(){
	$('.href').each(function(){
		$(this).click(sliding);
	});
}
function dfToggle(){
	$('.df_title_click', '.current_page').toggle(
		function(){
			gDf_id=$(this).attr('id');
			gDf_id=gDf_id.replace('df_title_','');
			$('#df_hid_'+gDf_id).show();
			$('span','#df_title_'+gDf_id).css('color','#ABABAB');
			$('span','#df_title_'+gDf_id).css('border-bottom','1px dashed #ABABAB');
			$('.move').css('height','auto');
			resizeCurrentPage();
		},
		function(){
			gDf_id=$(this).attr('id');
			gDf_id=gDf_id.replace('df_title_','');
			$('#df_hid_'+gDf_id).hide();
			$('span','#df_title_'+gDf_id).css('color','#C534B1');
			$('span','#df_title_'+gDf_id).css('border-bottom','1px dashed #C534B1');
			$('.move').css('height','auto');
			resizeCurrentPage();
		}
	);
}
function resizeCurrentPage(){
	iwidth=eval(0-$(".move_block")[0].offsetWidth);
	$('.current_page').css('width',Math.abs(iwidth));
}
function plusToggle(){
	$('a.option').hover(
		function () {
			$('.plus',this).show();
		},
		function () {
			$('.plus',this).hide();
		}
	);
}