
/* 
 * Application for LDR STUDIOS 
 * Copyright 2010, All Rights Reserved.
 */


/* Style Code */
jQuery.fn.styleCode = function(){
	return this.each(function(){ 
	var b = jQuery(this).find(".entry pre");
		b.data("isStyled") != true && b.wrap('<div class="codebg"><div class="codetop"></div></div>').data("isStyled",true)
	}
)}; // End Function 


/* Collapse */
jQuery.fn.collapse = function(){
	return this.each(function(){ 
		jQuery(this).stop().animate({
			opacity:0,
			width:0,
			marginRight:0,
			padding:0},350)
	}
)}; // End Function 


/* Expand */
jQuery.fn.expand = function(b){ 
	return this.each(function(){ 
		jQuery(this).stop().animate({
			opacity:1,
			width:b,
			marginRight:"18px",
			padding:"0 1px"},350)
	}
)}; // End Function 


$(function(){
	
	
	function b(){ 
		$("#about a").parent().parent().addClass("aboutactive");
		$("#fullscreen").css("display","block").animate({opacity:0.5},200);
		$("#aboutview").slideDown(550,function(){
			$(this).find(".closeabout").fadeIn(200)
		});
		$("#header").animate({marginTop:"320px"},550)
	} // End Function 
		
	
	function e(a){
		if(a < 1)a = h;
		else if(a > h)a = 1;
		$("#focusarea").find("li:visible").fadeOut("slow").end().find("li:nth-child(" + a + ")").fadeIn("slow");
		$markers.find("a.active").removeClass("active").end().find("li:nth-child(" + a + ") a").addClass("active")
	} // End Function 
	
	
	function i(){ 
		var a = 2 + $markers.find("a.active").parent().index();
		e(a);
		f = setTimeout(i,j)
	} // End Function 
	
	
	function k(a){
		a = a.toLowerCase();
		a == "all" ? $("#thumbnails li").expand(l) : $("#thumbnails li").not("." + a).collapse().end().filter("." + a).expand(l)
	} // End Function 
	
	
	var m = [];
	$.preLoadImages = function(){
		for(var a = arguments.length; a--;){
			var d = document.createElement("img");
			d.src = arguments[a];
			m.push(d)
		}
	}; // End Function 	
	$.preLoadImages("includes/images/earth.jpg","includes/images/photo.jpg");
	
	
	$("#contact a").mouseenter(function(){
		$("#contactinfo").text($(this).text()).fadeIn("fast");
		$(this).stop().parent().stop().animate({paddingTop:"7px"},150).end().animate({opacity:1},100)}).mouseleave(function(){$(this).stop().parent().stop().animate({paddingTop:"10px"},150).end().animate({opacity:0.5},100)
	});
	
	
	$("#contact").mouseleave(function(){
		$("#contactinfo").fadeOut("fast")
	});
	
	
	$("#fullscreen").css("opacity",0);
	
	
	$("#about a").click(function(a){
		a.preventDefault();
		b()
	});
	
	
	$("#sabout").click(function(a){
		a.preventDefault();
		$("html,body").animate({scrollTop:0},550);
		b()
	});
	
	
	$("#fullscreen, #aboutview .closeabout").click(function(a){
		a.preventDefault();
		$("#menu").removeClass("aboutactive");
		$("#fullscreen").delay(200).fadeOut("slow");
		$("#aboutview").slideUp(550).find(".closeabout").fadeOut(200);
		$("#header").animate({marginTop:"0px"},550)
	});
	
	
	$("#focusarea").find("li").hide().end().find("li:first").show();
	$markers = $("#feature ul.markers");
	var h = $("#focusarea").children().length,j = 7E3,f = setTimeout(i,j);
	$("#focusnext, #focusprev").click(function(a){
		a.preventDefault();
		clearTimeout(f);
		a = 2 * $(this).hasClass("nextslide") + $markers.find("a.active").parent().index();
		e(a)
	});
	
	
	$markers.delegate("a","click",function(a){
		a.preventDefault();
		clearTimeout(f);
		e($(this).parent().index() + 1)
	});
	
	
	$("#thumbnails li").mouseenter(function(){
		$(this).find("img").stop().animate({opacity:0.8},300).end().find(".viewcasestudy").fadeIn("fast")}).mouseleave(function(){
		$(this).find("img").stop().animate({opacity:1},150).end().find(".viewcasestudy").fadeOut("fast")
	});
	
	
	$("#filter a").click(function(a){
		a.preventDefault();
		$(this).parent().parent().find("li a").removeClass("active").end().end().end().addClass("active");	
		window.location.hash = "/" + $(this).text().replace(" ","-");
		k($(this).text().replace(" ","-"))
	});
	
	
	var l = $("#thumbnails li:first").width(),c = window.location.hash;
	if(c != ""){
		c = c.split("/");
		k(c[1]);
		$("#filter").find(".active").removeClass("active").end().find(".f" + c[1].toLowerCase()).addClass("active")
	}
	
	
	$("#content").styleCode();
	
	
	$("div.tag-video").click(function(){
		$(this).find("span.date").fadeOut("slow")
	});
	
	
	var n = $("#content").children().length - 1,g = $("#content").children().length - 1;
	
	
	$("#loadmoreposts").click(function(a){
		a.preventDefault();
		$.ajax({
	   		method: "get",
	   		url: "../content/get_articles.php",
	   		data: "posts=" + n + "&offset=" + g,
	   		beforeSend: function(){},
	   		complete: function(){},
	   		success: function(d){ 
				g += $("#content").append(d).styleCode().find(".moreposts:last").slideDown(600).find(".categoryicon").delay(600).fadeIn("fast").end().children().length;
				g >= totalPosts && $("#loadmoreposts").fadeOut("fast");
				navigator.platform == "iPad" && $("#content .post.tag-video").hide().filter(".tag-youtube").show()
			}
		}) // End Ajax
	}); 
	
	navigator.platform == "iPad" && $("#content .post.tag-video").hide().filter(".tag-youtube").show()
	
});

