var time;
function tri_init()
{
	var link, title;
	jQuery(".lnk",this).click(function(event)
	{
		event.preventDefault();
		link = this.href + "&triajax=1";
		if(link != lastlink)
		{
			jQuery(".sidebar").load(link);
			lastlink = link;
		}
	});
	jQuery(".hovernav > ul > li",this).hover(function(event)
	{
		timer(false);
		title = jQuery("a", this).attr("title").substr(0,4);
		jQuery("#featured").hide();
		jQuery("#" + title).fadeIn();
	},function(event)
	{
		jQuery(".hovernav > div").hide();
		jQuery("#featured").show();
		timer(true);
	}
	);
	jQuery("#galnails > a",this).hover(
		function(event)
		{
			lastlink = jQuery("#galnails > .current").attr("href") + "&triajax=1";
			link = jQuery(this).attr("href") + "&triajax=1";
			if(link != lastlink)
			{
				jQuery("#galnails > a").removeClass("current");
				jQuery("#galimg").load(link,tri_init);
				lastlink = link;
				jQuery(this).addClass("current");
			}
		}, 
		function(event){}
	);
	jQuery("a[rel^='lightbox']").slimbox({/* opts */}, null, function(el) {
		return (this == el) || ((this.rel.length > 8) && (this.rel == el.rel));
	});
}
function timer(start)
{
	if(jQuery("#featured").length > 0)
	{
		if(start)
		{ 
			time = setInterval(function()
			{
				jQuery("#featured").fadeOut();
				jQuery.get("?triajax=1" + Math.random() + "&trid=" + jQuery("#featured").attr("class"),function(data){
					jQuery("#featured").replaceWith(data);
					jQuery("#featured").fadeIn('slow');
					tri_init();
				});
				
			},5000);
		}
		else
		{
			clearInterval(time);
		}
	}
}
jQuery(function($)
{	
	var title, link;
	jQuery(".menu > li > ul").css("display","block");
	jQuery(".menu > li > ul").hide();
	jQuery(".hide").css("display", "none");
	jQuery("#map").click(function(event)
	{
		event.preventDefault();
		jQuery(".hide").css("display", "inline");
	});
	jQuery(".menu > li").hover(
		function(event){jQuery("ul",this).slideDown("fast");}, 
		function(event){jQuery("ul",this).fadeOut("fast");}
	);
	jQuery.each(jQuery(".hovernav > ul > li"),function(){
		title = jQuery("a", this).attr("title").substr(0,4);
		link = "?roll=" + title + "&triajax=1";
		if(jQuery("img", "#" + title).length < 1)
		{
			jQuery(".hovernav ul").after("<div id='" + title + "'><img width='438' height='438'/></div>");
			jQuery("#" + title).hide();
			jQuery("#" + title).load(link,tri_init);
		}
	});
	// Removed for TRI by JDH
	//timer(true);
});
jQuery(document).ready(tri_init);