// JavaScript Document

$(document).ready(function(){
$(window).bind( 'hashchange', function(){
	loadStuff()
})
	$(window).resize(function(){	
		var w = $(window).width();
		var h = $(window).height();
		var cheight = (h - 80)
		$(".jScrollPaneContainer").animate({"height" : cheight, "width" : w}, 0)
		$("#scrollme").jScrollPane({showArrows:false, scrollbarWidth:18, scrollbarMargin:'-5px'});
		
	})
	$(".mnvla").live('click', function(){
		return false;
	})
	$(".drop").live('click', function(){
		return false;
	})
	$(".mnvl").live('click', function(){
		var has = $(this).attr('get')
		var hah = has.split(":")
		$(location).attr("hash", "!s=" +  hah[1]);
		return false;
	})
	$(".pmr").live('click', function(){
		//$(".spinner").fadeIn(100)
		var sit = $(this).attr('id')
		var set = sit.split("-")
		if($(".postbd").hasClass("act")){
			$(".act").slideUp(300)
			$(".act").removeClass("act")
			var old = $(".pmo").attr('id')
			var ole = old.split("-")
			$(".pmo").attr('id', "m-" + ole[1] + "-" + set[2])
			$(".pmo").text(ole[2])
			$(".pmo").addClass("pmr")
			$(".pmo").removeClass("pmo")
		}
		$("#t-" + set[1]).slideDown(300, function(){
			$("#t-" + set[1]).addClass("act")
			var sat = $("#" + sit).text()
			$("#" + sit).text(set[2])
			$("#" + sit).addClass("pmo")
			$("#" + sit).removeClass("pmr")
			$("#" + sit).attr('id', "m-" + set[1] + "-" + sat)
			$("#scrollme").jScrollPane({showArrows:false, scrollbarWidth:18, scrollbarMargin:'-5px'});
			//$(location).attr('hash', "y=hello&set=blogpost:" + set[1])
			//$(".spinner").fadeOut(100)
			return false;
		})
		
	})
	$(".pmo").live('click', function(){
		//$(".spinner").fadeIn(100)
		var sit = $(this).attr('id')
		var set = sit.split("-")
		var sat = $(this).text()
		$("#t-" + set[1]).slideUp(300,function(){
			$("#scrollme").jScrollPane({showArrows:false, scrollbarWidth:18, scrollbarMargin:'-5px'});
			$("#t-" + set[1]).removeClass("act")
		})
		$(this).text(set[2])
		$(this).addClass("pmr")
		$(this).removeClass("pmo")
		$(this).attr('id', "m-" + set[1] + "-" + sat)
		//$(location).attr('hash', "y=hello&set=blog")
		//$(".spinner").fadeOut(100)
	})
	$(".hnav").live('click', function(){
		var sit = $(this).attr('id')
		var set = sit.split("-")
		$(location).attr('hash', "!y=" + set[1] + "&set=" + set[2])
		
	})
	$(".pc").live('click', function(){
		var set = $(this).attr('id')
		$(".thedrop").load("System/Modules/com.3drei.box.php?set=" + set, function(){
			$(".thedrop").slideDown(200, "easeOutExpo")
		})
		$(".ac").addClass("pc")
		$(".ac").removeClass("ac")
		$(this).addClass("ac")
		$(this).removeClass("pc")
	})
	$(".ac").live('click', function(){
		$(".thedrop").slideUp(200, "easeOutExpo", function(){
			$(".thedrop").empty();
											})
		$(this).removeClass("ac")
		$(this).addClass("pc")
	})
	$(".thebackground").live('click', function(){
		$(".thedrop").slideUp(200, "easeOutExpo", function(){
			$(".thedrop").empty();
											})
		$(".ac").addClass("pc")
		$(".ac").removeClass("ac")
		$(".b").addClass("pc")
		$(".b").removeClass("b")
		
	})
	$(".subnav").live('click', function(){
		return false;
										})
	
	$(".thumb").live('click', function(){
		flipClass("thumb", "thumba", this)
		var sit = $(this).attr("id")
		var set = sit.split("-")
		$(".galimg").fadeOut(100, function(){
			$(this).html('<img src="Content/Uploads/Images/p' + set[1] + '.jpg"  />')
			$(this).oneTime(100, function(){
				$(this).fadeIn(100)
			})
		})
	})
	$(".pp").live('click', function(){
		$(".ap").animate({"width":160 + "px"}, 200, "easeOutBack")
		$(".ap").addClass("pp")
		$(".ap").removeClass("ap")
		$(this).animate({"width":350 + "px"}, 200, "easeOutBack", function(){
			$("#scrollme").jScrollPane({showArrows:false, scrollbarWidth:18, scrollbarMargin:'-5px'});
		})
		$(this).addClass("ap")
		$(this).removeClass("pp")
	})
	$(".ap").live('click', function(){
		$(this).animate({"width":160 + "px"}, 200, "easeOutBack", function(){
			$("#scrollme").jScrollPane({showArrows:false, scrollbarWidth:18, scrollbarMargin:'-5px'});
		})
		$(this).addClass("pp")
		$(this).removeClass("ap")
	})
})

/* Global Functions */
function flipClass(newClass, oldClass, selNew){
	$("." + oldClass).addClass(newClass)
	$("." + oldClass).removeClass(oldClass)
	$(selNew).addClass(oldClass)
	$(selNew).removeClass(newClass)
}

function loadStuff(){
	//$("#spinner").fadeIn(100)
	if($(location).attr('hash')){
		var hasa = $(location).attr('hash')
		if( hasa.indexOf( "&" ) !== -1 ){
			var haha = hasa.replace("#!", "")
			var heyu = haha.split("&")
			var heya = heyu[1].split("=")
			var heyo = heyu[0].split("=")
			var heyy = heyo[1] + "&set=" + heya[1]
		}else{
			var haha = hasa.replace("#!", "")
			var heyo = haha.split("=")
			var heyy = heyo[1]
		}
		var curn = $("#nv-" + heyo[1])
		flipClass("mnvl", "mnvla", curn)
		$("#nv-" + heyo[1]).oneTime(10, function(){
			var off = $(this).offset().left
			var pss = ($(this).width() / 2)
			var pos = Math.floor(off + pss - 5)
			$("#indi").animate({"left": pos + "px"}, 200, "easeOutBack")
			
		})
		$(".cright").load("System/Modules/com.3drei.cright.php?drei=" + heyy, {"ajax": "yep"}, function(){
			var w = $(window).width();
			var h = $(window).height();
			var cheight = (h - 80)
			$(".jScrollPaneContainer").animate({"height" : cheight, "width" : w}, 0)
			$("#scrollme").oneTime(100, function(){
				$(this).jScrollPane({showArrows:false, scrollbarWidth:18, scrollbarMargin:'-5px'});
			})
			
		})
		$(".cleft").load("System/Modules/com.3drei.cleft.php?drei=" + heyy, {"ajax": "yep"}, function(){
			$(".cleft").load("System/Modules/com.3drei.cleft.php?drei=" + heyy, {"ajax": "yep"})
		})
	}else{
		$(".nfirst").oneTime(0, function(){
		  var off = $(".nfirst").offset().left
		  var pss = ($(".nfirst").width() / 2)
		  var pos = Math.floor(off + pss - 20)
		  $("#indi").animate({"left": pos + "px"}, 0)
		  $("#scrollme").oneTime(150, function(){
			$("#scrollme").jScrollPane({showArrows:false, scrollbarWidth:18, scrollbarMargin:'-5px'});
		})
	  })
	}
	//$("#spinner").fadeOut(100)
}
