function stripeTables () {
	$('tr:nth-child(odd)').addClass("odd");
}

function galleryButtons () {
	$('#detail-photos li a.previous').click(function() {
		var currentPhoto = parseInt($('#media-item img').attr('title'));
		
		if (currentPhoto > 0) {
			$('#detail-photos li').eq(currentPhoto+1).removeClass("active-img");
			$('#detail-photos li').eq(currentPhoto).children(":first").click();
			$($('#detail-photos li').eq(currentPhoto)[0]).addClass("active-img");
		}
	});
	
	$('#detail-photos li a.next').click(function() {
		
		var currentPhoto = parseInt($('#media-item img').attr('title'));
		var length = $('#detail-photos li').length-3;
		if (currentPhoto < length ) {
			$('#detail-photos li').eq(currentPhoto+1).removeClass("active-img");
			$('#detail-photos li').eq(currentPhoto+2).children(":first").click();
			$($('#detail-photos li').eq(currentPhoto+2)[0]).addClass("active-img");
		}
	});
	
	$('#detail-photos li a:not(.previous, .next)').click(function() {
		$('#detail-photos li').each(function() {
			$(this).removeClass("active-img");
		});
		$(this).parent().addClass("active-img");
	});
}

/* = CURRENT LOCATION USING A:PATH
-------------------------------------------------
	Macthes a links URL with the window.location.
	Works on ancesters of links and children
	activating all in current path with specified
	class.
-------------------------------------------------*/

//function activeMenu () {
//	$('#main-nav a:path').parent().addClass("active");
//	$('#main-nav a:path').addClass('active');
//}

/* = MAIN NAVIGATION PREP
-------------------------------------------------
	Preps the main mavigation for all mouse /
	keyboard events needed.
-------------------------------------------------*/

function prepMainNav(elementId) {
	if(!document.getElementById || !document.getElementById("main-nav")) return false;
	
	var main_nav = document.getElementById("main-nav");
	
	var main_nav_li = main_nav.getElementsByTagName("LI");
	
	for(var i = 0; i < main_nav_li.length; i++) {

		if(main_nav_li[i].className.match("active") || main_nav_li[i].parentNode != main_nav) continue;
		
		main_nav_li[i].onmouseover = function() {
			if(this.className.match("hover")) return 0;
			
			addHover(this);
			return 0;
		};
		main_nav_li[i].onmouseout = function() {
			removeHover(this);
		};
	}
}

function addHover(element) {
	if(!element || !document.createElement || !document.getElementById("main-menu")) return false;
	
	var main_menu = document.getElementById("main-menu");
	
	var main_nav_li = element;
	
	$(main_nav_li).addClass("hover");
	
	if(document.getElementById("mn-top-shadow") && document.getElementById("mn-bot-shadow")) {
		
		var top_shadow = document.getElementById("mn-top-shadow");
		var bot_shadow = document.getElementById("mn-bot-shadow");
		
		
		if(top_shadow.parentNode != bot_shadow.parentNode || top_shadow.parentNode != main_nav_li) {
			main_nav_li.appendChild(top_shadow.parentNode.removeChild(top_shadow));
			main_nav_li.appendChild(bot_shadow.parentNode.removeChild(bot_shadow));
		}

		top_shadow.style.display = "block";
		bot_shadow.style.display = "block";

	}
	else 
	{
			
		if(!document.getElementById("mn-top-shadow"))
		{
			var top_shadow = document.createElement("IMG");
			top_shadow.setAttribute("src", "/images/blank.gif");
			top_shadow.setAttribute("id", "mn-top-shadow");
			top_shadow.setAttribute("alt", "");
			main_nav_li.appendChild(top_shadow);
		}
		
		if(!document.getElementById("mn-bot-shadow"))
		{
			var bot_shadow = document.createElement("IMG");
			bot_shadow.setAttribute("src", "/images/blank.gif");
			bot_shadow.setAttribute("id", "mn-bot-shadow");
			bot_shadow.setAttribute("alt", "");
			main_nav_li.appendChild(bot_shadow);
		}
	}
	
	return 0;
}

function removeHover(element) {
	if(!element || !document.getElementById("mn-top-shadow") || !document.getElementById("mn-bot-shadow")) return false;
	
	var main_nav_li = element;
	
	var top_shadow = document.getElementById("mn-top-shadow");
	var bot_shadow = document.getElementById("mn-bot-shadow");
	
	$(main_nav_li).removeClass("hover");
	
	top_shadow.style.display = "none";
	bot_shadow.style.display = "none";
	
	return 0;
}


this.tooltip = function(){	
	/* CONFIG */		
		xOffset = 10;
		yOffset = 20;		
		// these 2 variable determine popup's distance from the cursor
		// you might want to adjust to get the right result		
	/* END CONFIG */
			
	$("a.tooltip, area.tooltip").hover(function(e){											  
		this.t = this.title;
		this.title = "";									  
		$("body").append("<p id='tooltip'>"+ this.t +"</p>");
		$("#tooltip")
			.css("top",(e.pageY - xOffset) + "px")
			.css("left",(e.pageX + yOffset) + "px")
			.fadeIn("fast");		
    },
	function(){
		this.title = this.t;		
		$("#tooltip").remove();
    });	
	$("a.tooltip, area.tooltip").mousemove(function(e){
		$("#tooltip")
			.css("top",(e.pageY - xOffset) + "px")
			.css("left",(e.pageX + yOffset) + "px");
	});			
};

$(document).ready(function() {

	$.path.ignoreFiles = ['index.htm'];
	//activeMenu();

	stripeTables();
	galleryButtons();
	prepMainNav('main-nav');

	tooltip();
});

