jQuery.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) {
		
		if (id == "Info")
		{
			$.latestLoad = "";
			$(".entry-link").each(function() {
			$(this).fadeTo(200,1.0);
			});
			
			$(".link-active").each(function() {
				$(this).removeClass("link-active");
			}); 
			
			$(".tag-all").css("color","#c3c4bf");
		}
		$(".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");
		
	

		if (Number(id))
		{
			if (document.getElementById("thumb"+id).style.opacity == 0.25)
			{
				$.latestLoad = "";
				$(".link-active").each(function() {
					$(this).removeClass("link-active");
				});
									 
				$(".entry-link").each(function() {
					$(this).fadeTo(200,1.0);
				});
			}
		}
		jQuery.contentTarget.animate({"opacity":0},200);
		
   if (id == "Info")
		{
  			 var leftVal=(220)+"px";
			 var topVal=(128)+"px";
	
			 var relativeX = leftVal;
			 var relativeY = topVal;
			 //alert(relativeX + " " + relativeY);
			 
			 $("#core-loader").css("top",relativeY);
			 $("#core-loader").css("left",relativeX);		
   		}
		else
		{
			var p = $("#thumb"+id);
			var pos = p.position();
			
			var height = pos.top;
			var width = pos.left;
			//alert(height + " " + width);
			var leftVal=(width+220+76)+"px";
			var topVal=(height+128+80)+"px";
	
			 var relativeX = leftVal;
			 var relativeY = topVal;
			 //alert(relativeX + " " + relativeY);
			 
			 $("#core-loader").css("top",relativeY);
			 $("#core-loader").css("left",relativeX);
		}
		$.ajax({
			type: "POST",
			url: "core/functions/get_entry.php",
			data: "id="+id,
			success: function(data){
				
				if($.browser.safari){ 
				$("body").animate({scrollTop:0},"slow");
				}
				else
				{
				$('html').animate({scrollTop:0}, "slow");
				}
				$("#load-content").show();
				jQuery.latestLoad = id;
				jQuery.contentInsert(data);
			}
		});
		
				
		
	},
	
	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").html("");
			$("#load-content").hide();
			$(".tag-all").css("color","#a6b61c");
			
			
		});
		
		jQuery.contentTarget.animate({"opacity":1},200);
	},
	
	//tags
	tagArray: undefined,
	
	tagClick: function(id) {
		var tag,arr,ex;
		
		$(".tag-link.link-active").each(function(){
			$(this).removeClass("link-active");								 
		});
		
		$(".tag-link[href='#"+id+"']").each(function(){
			$(this).addClass("link-active");
			tag = $(this).attr("name");
			$(".link-text, .page-link").removeClass("link-active");
			$("#load-content").hide();
			$.latestLoad = "";
			$(".tag-all").css("color","#a6b61c");
			
		});
		
		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);
			}
		});
	
		if($.browser.safari){ 
				$("body").animate({scrollTop:0}, 'slow');
				}
				else
				{
				$('html').animate({scrollTop:0}, 'slow');
				}
	},
	
	tagAll: function() {
		
		$("#load-content").hide();
		$.latestLoad = "";
		$(".link-active").each(function() {
			$(this).removeClass("link-active");
		});
									 
		$(".entry-link").each(function() {
			$(this).fadeTo(200,1.0);
		});
		$(".tag-all").css("color","#a6b61c");
	}
});


