
// When DOM is loaded
$(document).ready(function(){
	
	// Hopefully protect e-mail from spammers
	protectedMail();
		
	// Center description & btn_next vertically based on image
	var description_margin = (400 - $("#description").height()) / 2;
	$("#description").css('margin-top', description_margin);	
	
	// Push footer down to bottom of screen
	footerPush("#page");
	
	// Color switching animations
	if ($("html").hasClass("switch_to_w")) {
		$("html").animate({backgroundColor: '#E1E1E1'}, 500);
	};
	
	if ($("html").hasClass("switch_to_b")) {
		$("html").animate({backgroundColor: '#2C2C2C'}, 500);
	};
	
	// Image preloader
	
	var img = new Image();
	var cat_name = $("#image").attr("cat_name");
	var item_name = $("#image").attr("item_name");
	
	$(img).load(function () {
		$(this).hide();
		
		$('#image').removeClass('loading').append(this);
		
		if ($("html").hasClass("switch_to_w") || $("html").hasClass("switch_to_b")) {	
			$(this).delay(500).fadeIn(400);
		} else {
			$(this).delay(200).fadeIn(400);
		}
	}).attr('src', '/snobbydesign/portfolio/' + cat_name + '/images/' + item_name + '.jpg');
	
});

// Global functions
function protectedMail() {  
	if (!document.getElementById("protectedMail")) return false;
	var spanobject = document.getElementById("protectedMail");
	var anchr = document.createElement("a");
	var roger = "howdy";
	var wilco = "snobbydesign.com";
	var fuzz = "mailto:" + roger + "@" + wilco;
	anchr.setAttribute("href",fuzz);
	spanobject.appendChild(anchr);
	var final = document.createTextNode("Send me an e-mail");
	anchr.appendChild(final);
	return true;
}

function footerPush (bodyElement) {
	if ($("#image").hasClass("detail")) {
		var content_fix = 0;
	} else {
		var content_fix = -20;
	}
	
    if ( $.browser.opera ) {     //If Opera
        if ( window.innerHeight > $(document.body).height() ) {
            $(bodyElement).height( $(bodyElement).height() + ( window.innerHeight - $(document.body).height()) + content_fix );
        };
    } else if ( $.browser.msie ) {     //If IE
        if ( $(window).height() > $(document.body).height() ) {
            $(bodyElement).height( $(bodyElement).height() + ( $(window).height() - $(document.body).height()) - 20 );
        };
    } else if ( $(window).height() > $(document.body).height() ) {
		$(bodyElement).height( $(bodyElement).height() + ( $(window).height() - $(document.body).height()) + content_fix );
    };
	
	$("#footer").css('visibility','visible');
};
