document.write('<link rel="StyleSheet" href="/inc/js.css" type="text/css" media="screen">');


google.setOnLoadCallback(function() {
	$(document).ready(function() {	
		imageLoader();
		newWindowLinks();
		defaultText();
		clickable();
		//subnav();	
		gallery();	
	});	
});

function subnav() {
	$("#nav li").hover(
		function(){
			$("ul",this).show();
		},
		function(){
			$("ul",this).hide();
		}
	)
}

/* Gallery */
function gallery() {
	$("#gallery a").click(function(){
		$("#gallery a").removeClass("selected");
		$(this).addClass("selected");
		var newImg = $(this).attr("href");
		$("#galleryLargeImage").fadeOut(1000,function(){			
			newImage = new Image();
			newImage.onload = function() {
				$("#galleryLargeImage").attr("src",newImg)
				$("#galleryImageWrapper b").css({"margin-top":"-"+(this.height/2)+"px","margin-left":"-"+(this.width/2)+"px"})
				$("#galleryLargeImage").fadeIn(1000);
			}
			newImage.src = newImg;
		})
		return false;
	});
	$(".galleryThumbs a").click(function(){
		$(".galleryThumbs a").removeClass("selected");
		$(this).addClass("selected");
		var newImg = $(this).attr("href");
		var galleryWrapperObj 	= $(this).closest(".galleryWrapper");
		var galleryImageB 		= $(".left b",galleryWrapperObj);
		var targetImageObj 		= $(".left img",galleryWrapperObj);
		targetImageObj.fadeOut(200,function(){			
			newImage = new Image();
			newImage.onload = function() {
				targetImageObj.attr("src",newImg);
				
				// Calculate how long this animation should take based on largest difference in dimensions
				var ydiff 		= galleryImageB.height() - this.height;
					ydiff		= ydiff<0 ? ydiff*-1 : ydiff;
				var xdiff 		= galleryImageB.width() - this.width;
					xdiff		= xdiff<0 ? xdiff*-1 : xdiff;					
				var difference 	= xdiff>ydiff ? xdiff : ydiff;				
				
				galleryImageB.animate({height:this.height+"px",width:this.width+"px"},difference*2,function(){
					targetImageObj.fadeIn(1000);
				});				
			}
			newImage.src = newImg;
		})
		return false;
	})
	
}

var iLoad = new Array();
function imageLoader() {
	$(".ldr img, #gallery img, .galleryThumbs img").each(function(i) {
		iLoad[i] = new Image();
		iLoad[i].onload = function() {
			$('img[src='+iLoad[i].src+']').hide().css({visibility:"visible"}).fadeIn(1000)
		}
		iLoad[i].src = $(this).attr("src")
	})
}

/**	
 * Target new windows
 */
function newWindowLinks(){
	$('a.pop').unbind('click').click(function(){
		window.open($(this).attr('href'));
		return false;
	});
}


/* Remove default value and replace */
function defaultText() {
	$(".defaultText").unbind("focus,blur").focus(function () {		
		if ($(this).val() == $(this)[0].defaultValue) {
        	$(this).val("");
        }
	 }).blur(function() {
        if ($(this).val() == "") {
        	$(this).val($(this)[0].defaultValue);
     	}
	 });
}

/* Make a whole box clickable */
function clickable() {
	$(".clickable:has(a)").css({"cursor":"pointer"}).unbind("click").click(function() {
		var link = $("a",this).eq(0).attr("href");
		window.location = link;
	}).hover(function(){
		$(this).addClass("hover");
	},function(){
		$(this).removeClass("hover");
	})
}

/* Un-obfuscate email */
function fnE(inarr,text) {
	inarr = inarr.split(",");
	var out = "";
	for(i=inarr.length-1;i>=0;i--) {
		out += inarr[i];
	}
	if(text==false || text=="" || text==undefined) {
		text = out;
	}
	document.write('<a href="mailto:'+out+'">'+text+'</a>');	
}