jQuery.extend({
	
	//content
	firstLoad: function(id) {
		if(!location.hash) {
			$.sendRequest(id);
		}
	},
	
	contentTarget: undefined,
	
	latestLoad: undefined,
	
	sendRequest: function(id) {
		if(id == jQuery.latestLoad) return;
		if(id.search("tag-") < 0) jQuery.contentLoad(id);
		else jQuery.tagClick(id);
	},
	
	contentLoad: function(id) {
		$(".entry-text").removeClass("link-active");
		$("#entry-"+id+" .entry-text").addClass("link-active");
		
		jQuery.contentTarget.animate({"opacity":0},200);
		
		$.ajax({
			type: "POST",
			url: "core/functions/get_entry.php",
			data: "id="+id,
			success: function(data){
				$('html').animate({scrollTop:0}, 200);
				jQuery.latestLoad = id;
				jQuery.contentInsert(data);
			}
		});
	},
	
	contentInsert: function(data) {
		var id = jQuery.contentTarget.attr("id");
		jQuery.contentTarget.html(data);
		
		$("#close-entry").click(function(){
			$(".entry-text").removeClass("link-active");
			jQuery.latestLoad = "";
			$(this).parent().html("");
		});
		Cufon.refresh();
		jQuery.contentTarget.animate({"opacity":1},200);
	},
	
	//tags
	tagArray: undefined,
	
	tagClick: function(id) {
		id = id.replace(/tag-/,'');
		var text,tag,arr,ex;
					 
		$(".tag-link").each(function() {
			text = $(this).html();
			if(id == text) {
				$(this).addClass("link-active");
				tag = $(this).attr("id").replace(/-/,'');
			} else {			
				$(this).removeClass("link-active");
			}
		});
			
		arr = (jQuery.tagArray[tag]);
		
		$(".entry-link").each(function() {
			ex = false;
			for (var i = 0;i<arr.length;i++){
				var e_id = $(this).attr("id").replace(/entry-/,'');
				if( e_id == arr[i] ) ex = true;
			}
			
			
			if(ex) $(this).fadeTo(200,1.0);
			else $(this).fadeTo(200,0.25);
		});
	},
	
	tagAll: function() {
		$(".link-active").each(function() {
			$(this).removeClass("link-active");
		});
									 
		$(".entry-link").each(function() {
			$(this).fadeTo(200,1.0);
		});
	}
});

