/* Setup*/
motionDuration = 1500; /* Set transition speed */
currentHero = "#heroPCWrapper"; /* Specify inital banner to display */


$(function() {
	screenWidth = window.innerWidth;
		$('#heroPrintingWrapper').css("right", screenWidth);
		$('#heroGraphicDesignWrapper').css("right", screenWidth);
		$('#heroDesignOnlineWrapper').css("right", screenWidth);
});



$(function() {
		$("#bigNavPrinting").hover(function(){
				navHover = "#bigNavPrinting";
				whichBanner();
		});
});


$(function() {
		$("#bigNavDesign").hover(function(){
				if(currentHero != "#heroDesignOnlineWrapper"){swapBanner("#heroDesignOnlineWrapper");}			
		});
});

$(function() {
		$("#bigNavGraphic").hover(function(){
				if(currentHero != "#heroGraphicDesignWrapper"){swapBanner("#heroGraphicDesignWrapper");}			
		});
});


/* Identify banner currently hovered */

function whichBanner() {
				delay(1000);
				if(navHover = "#bigNavPrinting"){
					alert("delay still hover")
					if(currentHero != "#heroPrintingWrapper"){swapBanner("#heroPrintingWrapper");}			
				}			
}



/* Swap banner function */

function swapBanner(newHero) {
			screenWidth = window.innerWidth;
			$(currentHero).animate({ left: screenWidth }, {duration: motionDuration, easing: 'easeInBack'});
			$(newHero).delay(motionDuration).animate({ left: 0 }, {duration: motionDuration, easing: 'easeOutBack'});
			currentHero = newHero;
}


/* Open in new window for links with class new-window specified*/
$(function(){
    $('a.new-window').click(function(){
        window.open(this.href);
        return false;
    });
});




/* Menu Drop Down Function */

$(function() {
			   $('.topNav ul li').hover(  
				function () {  
					//show its submenu  
					$('ul', this).fadeIn(300);  
				},   
				function () {  
					//hide its submenu  
					$('ul', this).fadeOut(300);           
				}  
			);  
			  
}); 




function imageLoader(imageSource,divID,templateName)

{
        var img = new Image();

        $(img).load(function () {
            //$(this).css('display', 'none'); // .hide() doesn't work in Safari when the element isn't on the DOM already
            $(this).hide();
            $(divID).removeClass('loading').append(this);

		var height = img.height;
		var width = img.width;
		var cellWidth = "380";
		var cellHeight = "270";
		
	 
						 

		if (width>height)
			{
			var xyRatio = height/width;
			var cellHeight = cellWidth*xyRatio;
			$(this).width(cellWidth);
			$(this).height(cellHeight);
			}
			else
			{
			var xyRatio = width/height;
			var cellWidth = cellHeight*xyRatio;
			$(this).width(cellWidth);
			$(this).height(cellHeight);
			}


		//Centre in box
				var containerWidth = $(this).parent().width();
				var containerHeight = $(this).parent().height();
				var elementWidth = $(this).width();
				var elementHeight = $(this).height();
				var newLeft = (containerWidth - elementWidth)/2	;
				var newTop = (containerHeight - elementHeight)/2;
				$(this).css("left", newLeft);
				$(this).css("top", newTop);


            $(this).fadeIn();
        }).error(function () {
            // notify the user that the image could not be loaded
        //}).attr('src', imageSource);
		}).attr({
			src: imageSource,
			title: templateName,
			alt: templateName
		});
			
			
}


function loginButton(firstName)
{
	
		if (firstName != "")
			{
				document.write('<li class="padLeft"><a href="#">WELCOME ' + firstName + '</a></li>');
				document.write('<li class="padLeft"><a href="login.asp?red=www.printcentral.co.nz/live">LOGOUT</a></li>');
			}
			else
			{
				document.write('<li id="loginButton" class="padLeft"><a href="LoginWindow.htm">LOGIN</a></li>');
			}
}


$(function() {
	$("li#loginButton a").fancybox({
		'type'	: 'iframe',
		'padding' : 10,
		'width' : 424,
		'height' : 224
		//'onClosed' : function() { window.location = "cart.asp"; }
	});
});

$(function() {
	$("a.fancyBoxOn").fancybox({
		'type'	: 'iframe',
		'padding' : 10,
		'width' : 504,
		'height' : 389
	});
});


$(function() {
	$("a.fancyBoxPopup").fancybox({
		'type'	: 'iframe',
		'padding' : 10,
		'width' : 650,
		'height' : 500
	});
});







