//document.write("<style type=\"text/css\"> .jqpreload img { display:none; } #category-list ul li { display:none; } #jewels-item { height:560; } </style>");

 	$(function(){
		
		if($("#news-item").length){
			if($("#next-prev-previous").length){
				var title = $("#next-prev-previous a").attr("title");
				$("#next-prev-previous a").removeAttr('title');
				$("#next-prev").append("<div id=\"np-prev-title\">"+title+"<img src=\"/images/ticdown.png\" width=\"9\" height=\"4\" /></div>");
			}
			if($("#next-prev-next").length){
				var title = $("#next-prev-next a").attr("title");
				$("#next-prev-next a").removeAttr('title');
				$("#next-prev").append("<div id=\"np-next-title\">"+title+"<img src=\"/images/ticdown.png\" width=\"9\" height=\"4\" /></div>");
			}			
			
			$("#next-prev-previous").hover(function(){ $("#np-prev-title").fadeIn("fast"); }, function(){ $("#np-prev-title").fadeOut("fast"); });
			$("#next-prev-next").hover(function(){ $("#np-next-title").fadeIn("fast"); }, function(){ $("#np-next-title").fadeOut("fast"); });
		}

		if($("#press-item").length){		
			$("#prevlink").hover(function(){ 
				var thumbpos = $("#prevlink").position().top-61;
				$("#prevthumb").css({left:($("#prevlink").position().left)+"px", top:thumbpos + "px"}).fadeIn("fast"); 
			}, function(){ $("#prevthumb").fadeOut("fast"); });
			
			$("#nextlink").hover(function(){ 
				var thumbpos = $("#nextlink").position().top-61;
				$("#nextthumb").css({left:($("#nextlink").position().left+$("#nextlink").width()-50)+"px", top:thumbpos + "px"}).fadeIn("fast");
			}, function(){ $("#nextthumb").fadeOut("fast"); });
		}
			
		/*
			Build category item list

		if($("#category-list ul li").length){
			$("#category-list ul").height(483);

			items = $("#category-list ul li");
			$(items).hide();
		
			$(items).each(function(){
				var img = $(this).find("img").clone();

				var a = $(this).find("a");

				var linktext = $(a).text();
				$(a).empty().text(linktext).wrap('<div></div>');
				
				$(this).prepend(img);
			});
			
			var match = self.location.href.match(/#\/page\/([0-9]+)\/$/);
			currentpage = (match) ? Number(match[1]) : 1;	

			if(items.length % 9){
				var newlength = items.length;
				for(var i = 0; i < (9 - items.length % 9); i++){
					newlength ++;
					var li = $("<li class=\"blank\">&nbsp;</li>").hide();
					if(newlength%3 == 0) $(li).addClass("third");
					$("#category-list ul").append(li);
				}
				items = $("#category-list ul li");
			}

			if(items.length > 9){
				$("#category-prevnext-nav").show();
				$("#category-prevnext-nav #category-next").click(nextPage);
				$("#category-prevnext-nav #category-previous").click(previousPage);
			
				totalpages = Math.floor(items.length / 9);
				if( items.length % 9 ) totalpages ++;
			}
		
			$(items).height(160);
		
			showPage();

			$("#category-list ul li:not('.blank')").hover(function(){
				var div = $(this).find("div");
				div.fadeIn("fast");
				window.status = $(div).text();
			},
			function(){
				$(this).find("div").fadeOut("fast");
				window.status = "";
			});
			$("#category-list ul li:not('.blank')").click(function(e){
				e.preventDefault();
				window.location = $(this).find("a").attr("href");
			});
		}
		*/
	});
	
	function changeSelectedImage(changeTo){
		var med = "/images/"+changeTo+"-medium.jpg";
		var full = "/images/"+changeTo+"-full.jpg";
		
		$("#item-medium-image img").hide().attr("src",med).fadeIn("fast");
		$("#item-zoom img").attr("src",full);
	}
	
	function nextPage(){
		if(currentpage < totalpages) showPage( currentpage + 1 );
	}
	function previousPage(){
		if(currentpage > 1) showPage( currentpage - 1);
	}
	function showPage(page){
		$("#category-prevnext-nav #category-previous a, #category-prevnext-nav #category-next a, #category-prevnext-nav #category-filter").hide();
		if(page){
			hidePage();
			currentpage=page;
		}

		itemOnStart = (currentpage-1) * 9;
		
		showItems();		
	}
	function hidePage(){
		$("#category-list ul li").hide();
	}
	
	var itemOnStart = null;
	var itemOnCount = null;
	
	function showItems(){
		if(!itemOnCount) itemOnCount = itemOnStart;

		if(itemOnCount < itemOnStart + 9){
			$(items[itemOnCount]).fadeIn(300, function(){ itemOnCount ++; showItems(); });
    }
		else{
			itemOnCount = null;
			showNextPrev();
		}
	}
	
	function showNextPrev(){
		if(currentpage < totalpages) $("#category-prevnext-nav #category-next a").attr("href","#/page/" + (currentpage + 1) + "/").fadeIn("fast");
		if(currentpage > 1) $("#category-prevnext-nav #category-previous a").attr("href","#/page/" + (currentpage - 1) + "/").fadeIn("fast");	
		if($("#category-filter").length) $("#category-filter, #category-filter a").fadeIn("fast");
	}
	
function debug(msg){
	if (window.console && window.console.log)
      window.console.log(msg);	
}
