var navArr;
var contentArr;
var objNum;

function eventInfoInit()
{
	
	currTheme = $("#pageTheme").html();
	/* Event Info Summary Display */
	$("h3").filter(".titleHide").hide();
	$("caption").filter(".titleHide").hide();
	
	navArr = $("#eventInfoNav").children("dd").children();
	contentArr = $("div").filter(".eventInfoContent");
				
	$("#eventInfoNav_0").addClass("active");
				
	navArr.mousedown(toggleEventInfo);
	
	
	/* Calender slide */
	if (document.getElementById("calendar_Event"))
	{
		$("#calendar").children("table").children("tbody").children("tr").children("td").children("a").click(function(){
			activeDay = $("#calendar").children("table").children("tbody").children("tr").children("td").children("a");
			activeDay.removeClass("active");
			for (i=0; i < activeDay.length; i++)
			{
				if (activeDay[i].innerHTML == this.innerHTML)
				{
					$(activeDay[i]).addClass("active");
					toggleDay(i);
				}
			}
		});
		
		$("#calendar_Event").children(".btn-arrow-r").hide();
		$("#calendar_Event").hide();
	}
	
	/* Image Hover in Nav */
	$("#eventInfoNav").children("dd").children("a").click(toggleImgNav);
	
	$("img").filter(".navhover").hover(function(){
		if (this.className != "active") this.src = hoverURL(this.src);
	}, function(){ 
		if (this.className != "active") this.src = hoverURL(this.src);
	});
	
	resetImgNav();
	
	$("div").filter(".eventInfoContent").each(function(i){
		if (i == 0)
		{
			$(this).show();
		}
		else
		{
			$(this).hide();
		}
	});
	
	var months = new Array('January','February','March','April','May','June','July','August','September','October','November','December');
	
	$("div").filter(".eventdate").css("display","inline");
	
	$("div").filter(".eventdate").each(function(i){
		monthno = $(this).children("span").html().split("-")[1];
		dayno	= $(this).children("span").html().split("-")[2];
		
		if (monthno.charAt(0) == '0')
		{
			monthno = monthno.split("0")[1];
		}
		
		$(this).children("span").html(dayno+" "+months[monthno-1]);
	});
	
    fromDate = $("div").filter(".eventdate")[0];
    if ( $("div").filter(".eventdate").length > 1 )$(fromDate).append("&#160;-&#160;");
}

function resetImgNav()
{
	$("img").filter(".navhover").attr("src", function(){
		currSrc = this.src;
		newSrc = currSrc.split("img/")[0] + "App_Themes/" + currTheme + "/img/" + currSrc.split("img/")[1];
		return newSrc;
	});
}

function toggleImgNav()
{
	$("#eventInfoNav").children("dd").children("a").children("img").attr("class", "navhover");
	$("#eventInfoNav").children("dd").children("a").children("img").attr("src", function(){
		var newSrc = this.src;
		if (newSrc.indexOf("App_Themes") == -1)	newSrc = this.src.split("img/")[0] + "App_Themes/" + currTheme + "/img/" + this.src.split("img/")[1];
		return newSrc;
	});
	
	$(this).children("img").attr("class","active");
	$(this).children("img").attr("src", function(){
		currSrc = this.src;
		this.src = currSrc.split('App_Themes/')[0]  + 'img/' + currSrc.split('img/')[1];
	});
}

function toggleDay(sessions)
{
	activeSession = $("#calendar_Event").children("div");
	for (i=0; i < activeSession.length; i++)
	{
		if (i == parseInt(sessions))
		{
			if (!sessionBG) 
			{
				$("#calendar_Event").fadeIn("slow");
				$(activeSession[i]).slideDown("slow", function(){ $("#calendar_Event").children(".btn-arrow-r").fadeIn("slow");});
				sessionBG = true;
			}
			else
			{
				$(activeSession[i]).fadeIn("slow");
			}
			
		}
		else
		{
			$(activeSession[i]).hide();
		}
	}
}

function toggleEventInfo()
{
	$("#eventInfoContent").children("div").children("h3").hide();
	$("#eventInfoContent").children("table").children("caption").hide();
	
	navArr.removeClass("active");
	objNum = parseInt($(this).attr("id").split("_")[1]);
	
	$("div").filter(".eventInfoContent").hide();
	$("#eventInfoContent_"+[objNum]).fadeIn("fast");
//	for (var i=0; i < contentArr.length; i++)
//	{
//		//contentArr[i].style.display = (objNum == i) ? 'block' : 'none';
//		if(objNum == i)
//		{
//			$("#eventInfoContent_"+[i]).fadeIn("fast");
//		}
//		else
//		{
//			$("#eventInfoContent_"+[i]).hide();
//		}
//	}
	
	$(this).attr("href","javascript://");
	$(this).addClass("active");
}

$(document).ready(eventInfoInit);