/** @Name		PxO Ink
 ** @URI		http://www.pxoink.net/
 ** @Author		PxO Ink
 ** @AuthorURI	http://www.pxoink.net/
 ** @License	Proprietary
 ** @Copyright	© 2011 PxO Ink
 **/

//Preload background images.
jQuery(document).ready(function(){
	var	home		=	new Image();
	var	portfolio	=	new Image();
	var	contact		=	new Image();
	
	home.src		=	"images/homehover.png";	
	portfolio.src	=	"images/porthover.png";
	contact.src		=	"images/contacthover.png";
});

//Function to create the icebox effect.
function icebox(obj) {
	//Declare variables.
	var	ID		=	jQuery(obj).attr('name');
	var	src		=	jQuery(ID).attr('alt');
	var	title	=	jQuery(ID).attr('title');
	var	markup	=	new Array();
	
	//Create new element.
	markup.push(
		'<div id="icebox">',
			'	<a href="' + ID + '" onclick="closeElement()">Close</a>',
			'	<img id="icebox-loading" src="images/loading.gif" alt="loading" title="One moment please..." />',
			'	<img id="icebox-img" src="IceCMS/serve-image.php?image=' + src + '&amp;w=850&amp;h=0&amp;r=true" alt="' + src + '" title="' + title + '" />',
			'	<a href="IceCMS/serve-image.php?image=' + src + '">Full-Size</a>',
		'</div>'
	);
	
	//Implement the new element.
	jQuery('body').append(markup.join(''));
	
	//Hide the image.
	jQuery('#icebox-img').hide();
	
	//Position the element in the center.
	centerElement('#icebox');
	
	//When the image is loaded.
	jQuery('#icebox-img').load(function() {
		//When the other image has faded out.
		jQuery('#icebox-loading').fadeOut('medium', function() {
			//Fade the new image in.
			jQuery('#icebox-img').fadeIn('medium');
			
			//Position the element in the center.
			centerElement('#icebox');	
		});
	});
	
	//Fade the new element in.
	jQuery('#icebox').fadeIn('medium');
	
	//Stop the default action.
	return false;
}

//Function to destroy the icebox element.
function closeElement() {
	//Fade and close the element.
	jQuery('#icebox').fadeOut('medium', function() {
		jQuery('#icebox').remove();
	});
}

//Set the element to be positioned in the center.
function centerElement(ID) {
	jQuery(ID).css("top", (((jQuery(window).height() - jQuery(ID).outerHeight()) / 2) + jQuery(window).scrollTop()));
	jQuery(ID).css("left", (((jQuery(window).width() - jQuery(ID).outerWidth()) / 2) + jQuery(window).scrollLeft()));
}

//Google Analytics
var _gaq = _gaq || [];
_gaq.push(['_setAccount', 'UA-23711723-1']);
_gaq.push(['_setDomainName', 'pxoink.net']);
_gaq.push(['_setAllowHash', 'false']);
_gaq.push(['_trackPageview']);

(function() {
	var ga = document.createElement('script'); ga.type = 'text/javascript'; ga.async = true;
	ga.src = ('https:' == document.location.protocol ? 'https://ssl' : 'http://www') + '.google-analytics.com/ga.js';
	var s = document.getElementsByTagName('script')[0]; s.parentNode.insertBefore(ga, s);
})();
