// JavaScript Document

$.preloadImages = function()
{
  for(var i = 0; i<arguments.length; i++)
  {
    jQuery("<img>").attr("src", arguments[i]);
  }
}

function altItem(p,c,e) {
	// p: jQuery selector statement for container of altItems; ie. "table"
	// c: jQuery selector statement of altItems via .find() prototype; ie. "tr"
	// e: Determines if altItems are odd or even; ie. ("odd" | "even") optional
	e = (!e ? "odd" : e);
	$(p).each(function() {
		$(this).find(c).removeClass("altItem").filter(":visible:"+e).addClass("altItem");
	});
}

function infoTabs(containerId) {
	var infoContainer = $("#"+ containerId);
	var navLinks = $("#"+ containerId + " .nav li");

	navLinks.each(function() {
		$(this).hover(function() {
			$("#"+ containerId + " .nav li").removeClass("active");
			$(this).addClass("active").siblings().each(function() {
				$(this).children("img").attr("src").replace("-o.gif", ".gif");
				$(this).removeClass("active");
			});
		 });
   });

}

function activeTab(imgJqueryObj) {
	$(".ui-tabs-nav a img").each(function(){
			var thisSrc = $(this).attr("src").replace("-o.gif", ".gif");
			$(this).attr("src", thisSrc);	
	});
	var curImg = $(imgJqueryObj);
	var origSrc = curImg.attr("src").replace("-o.gif", ".gif");
	var newSrc = origSrc.replace(".gif", "-o.gif");
    curImg.attr("src", newSrc);	
}


$(function() {		   
	
	 $("#infoTabs img").each(function() {
        var origSrc = $(this).attr("src");
        var overSrc = origSrc.replace(".gif", "-o.gif");
        $.preloadImages(overSrc);
        $(this).hover(function() {
           	$(this).attr("src", overSrc);
        });
        $(this).mouseout(function() {
			if(!$(this).closest("li").hasClass("ui-state-active")) {
            	$(this).attr("src", origSrc);
			}
        });
    });
	 
	$("#infoTabs").tabs();
	$("#infoTabs").bind('tabsselect', function(event, ui) {
		activeTab($(ui.tab).find("img"));
	});
	activeTab($("#infoTabs .ui-state-active").find("img"));
	
	$("#infoTabs ul li:first").addClass("first");
	 
	altItem("#featuredEvents", ".event", "even");

});