$.extend({
	
	//content
	firstLoad: function(id) {
		if(!location.hash && id) {
			$.sendRequest(id);
		}
	},
	
	contentTarget: undefined,
	
	latestLoad: undefined,
	
	sendRequest: function(id) {
		if(!id) return;
		id = decodeURIComponent(id);
		if(id == jQuery.latestLoad) return;
		if(id.search("tag-") < 0) jQuery.contentLoad(id);
		else jQuery.tagClick(id);
	},
	
	contentLoad: function(id) {
		$(".link-text, .page-link").removeClass("link-active");
		$(".page-link[href='#"+id+"']").addClass("link-active");
		$("#thumb"+id+" .link-text,#list"+id+" .link-text").addClass("link-active");
		//$("#thumb"+id+"").addClass("link-active");
		
		$.ajax({
			type: "POST",
			url: "core/functions/get_entry.php",
			data: "id="+id,
			success: function(data){
				$("#load-content").show();
				$("#load-content").animate({"opacity":0},0);
				jQuery.contentTarget.animate({"opacity":0},200,function(){
					$('html, body').animate({scrollTop:$('#top').offset().top}, 500, "easeInOutCubic");
					jQuery.latestLoad = id;
					jQuery.contentInsert(data);
					$("#content").grid(settings);
					$("#load-content").animate({"opacity":0},200);
				});
				
			}
		});
	},
	
	contentInsert: function(data) {
		var id = jQuery.contentTarget.attr("id");
		jQuery.contentTarget.html(data);
		
		$("#close-entry").click(function(){
			$(".link-text, .page-link").removeClass("link-active");
			jQuery.latestLoad = "";
			$("#load-content").animate({"opacity": "toggle"}, 30, function() {
				$("#load-content").html("");
				$("#content").grid(settings);
				$("#load-content").hide();
			});
		});
	},
	
	//tags
	tagArray: undefined,
	
	tagClick: function(id) {
		var tag,arr,ex;
		
		$(".tag-link.link-active").each(function(){
			$(this).removeClass("link-active");								 
		});
		
		$(".tag-all").each(function(){
			$(this).removeClass("link-active");
		});
		
		$(".tag-link[href='#"+id+"']").each(function(){
			$(this).addClass("link-active");
			tag = $(this).attr("name");
		});
		
		arr = jQuery.tagArray[tag];
		if(!arr) arr = [];
		
		$(".entry-link").each(function() {
			ex = false;
			
			for (var i = 0;i<arr.length;i++){
				var e_id = $(this).attr("id").replace(/list/,'').replace(/thumb/,'');
				if( e_id == arr[i] ) ex = true;
			}
			
			if(ex) $(this).fadeTo(200,1.0);
			else $(this).fadeTo(200,0.25);
		});
	},
	
	tagAll: function() {
		jQuery.latestLoad = "";
		$("#load-content").animate({"opacity": "toggle"}, 30, function() {
			$("#load-content").html("");
			$("#content").grid(settings);
			$("#load-content").hide();
		});
		$(".link-active").each(function() {
			$(this).removeClass("link-active");
		});
		$(".tag-all").each(function(){
			$(this).addClass("link-active");
		});
									 
		$(".entry-link").each(function() {
			$(this).fadeTo(200,1.0);
		});
	}
});

//Loader follow mouse
$(document).mousemove(function(e){
	$("#loader").css({
		top: (e.pageY + 15) + "px",
		left: (e.pageX + 15) + "px"
	});
});


//RollOver animation
$("#logo").live("mouseenter", function(){
	$(this).fadeTo(150, 0.7);
}).live("mouseleave", function(){
	$(this).fadeTo(150, 1);
});

$(".thumb").live("mouseenter", function(){
	$(this).find(".overlay").fadeTo(200, 0.8);
	$(this).find(".postDesc").fadeTo(200, 0.9);
}).live("mouseleave", function(){
	$(this).find(".overlay").fadeTo(200, 0);
	$(this).find(".postDesc").fadeTo(200, 0);
});


//Grid-a-Licious configuration
$(function () {
    var resizeTimer = null;
    $(window).bind('resize', function () {
        if (resizeTimer) clearTimeout(resizeTimer);
        resizeTimer = setTimeout(function () {
            $("#content").grid(settings);
        }, 100);
    });
    
    // disable animation at start
    settings.animateUpdate = false;
    $("#content").grid(settings, '', false, true);
    // enable animation
    settings.animateUpdate = true;
});

settings = {
	min_cols: 2,
    gap: 0,
    width: 250,
    easing: 'easeInOutQuart',
    animateUpdate: false,
    duration: 300,
    speed: 30
};
