$(document).ready(function(){
	$("nav a").hover(
		// over
		function(){
			var theImg = $(this).find('img:first');
			// store the original image src
			theImg.data( "originalsrc" , theImg.attr("src") );
			
			// add -over to the image unless it is already -over
			if (!theImg.attr("src").match(/-over/) ) {
				theImg.attr( "src", theImg.attr("src").replace(/\./, "-over.") );
			}
			
		},
		
		// out
		function(){
			var theImg = $(this).find('img:first');
			// replace the original src
			if (theImg.data("originalsrc")) {
				theImg.attr("src", theImg.data("originalsrc"));
			}
		}
	);
	

	$(".tabLinks a").click(function(e){
		e.preventDefault;
		var $this = $(this);
		var $parent = $this.closest(".tabs");
		$parent.find(".tabLinks a").removeClass("selected");
		$this.addClass("selected");
		$parent.find(".tabPanel").hide();
		$($this.attr("href")).show();
		return false;
	});


	$("#portfolioMainLink").lightBox({
		imageLoading: '/images/lightbox/ico-loading.gif',
		imageBtnClose: '/images/lightbox/btn-close.gif',
		imageBtnPrev: '/images/lightbox/btn-prev.gif',
		imageBtnNext: '/images/lightbox/btn-next.gif',
		imageBlank: '/images/lightbox/blank.gif'
	 });



	$("#thumbs a").click(function(e){
		e.preventDefault;
		// image
		var image = $(this).attr('href');
	
		$("#thumbs a").removeClass('selected');
		$(this).addClass('selected');
		
		$("#portfolioMain").attr('src', '/images/thumb.php?src=' + image + '&w=600&h=445&zc=1');
		$("#portfolioMainLink").attr('href', image);
			
		// lightbox
		$("#portfolioMainLink").lightBox({
			imageLoading: '/images/lightbox/ico-loading.gif',
			imageBtnClose: '/images/lightbox/btn-close.gif',
			imageBtnPrev: '/images/lightbox/btn-prev.gif',
			imageBtnNext: '/images/lightbox/btn-next.gif',
			imageBlank: '/images/lightbox/blank.gif'
		 });
		 
		 return false;
	});
	
	
});



window.onload = function() {
		// preload
		$("nav a img").each(
			function() {
				if (!$(this).attr("src").match(/-over/) && !$(this).attr("src").match(/-active/) ) {
					$("<img>").attr( "src", $(this).attr("src").replace(/\./, "-over.") );
				}
			}
		);
}



