
$(function() {
	// When we click the about arrows
	$('.about-forward').click(function(){
				
		// Fetch the maximum amount
		var maximum = (($('#totalImages').val()-8)*82)*-1;
		// Get left
		var left = parseFloat($('.about_thumbs').css('left'));
				
		// if we are above the maximum (working in negatives my head hurts)
		if(left > maximum)
		{
			// Animate
			$('.about_thumbs').animate({"left": "-=82px"}, "normal");
		}
		else
		{
			// Don't animate and reset to full distance
			$('.about_thumbs').css({"left": maximum + "px"});
		}
				
				
	});
	
	
			
	$('.about-back').click(function(){
				
		// Get the value of left and parse it into a number (remove the px)
		var left = parseFloat($('.about_thumbs').css('left'));
		
		// If it is less than 0 then we can animate it
		if(left < 0)
		{
			$('.about_thumbs').animate({"left": "+=82px"}, "normal");
		}
		
		else
		{
			$('.about_thumbs').css({"left": "0px"});
		}	
			
	});


});

$(function(){
	// Turn off the top right link 
	$.Lightbox.construct({"show_linkback":false});
	
	// Activate the gallery lightbox
	$('.hewittImages a, .icon a').lightbox({fixedNavigation:true});
	zIndexHandler();
	
});

// On page load
$(function(){
	// Supersleight the system so PNGs work
	$('body').supersleight({shim: '/images/blank.gif'});
	// Apply a main pull down to the top nav
	$('.depMain').pullDown('300');
	$('.depSub, subSub').subNav('0');

});

$(function(){
	// When we click a thumbnail
	$('a.jsThumbnail').click(function(){
		// get the href
		var img	= $(this).attr('href');
		
		$('#jsLargeImage').attr('src',img);
		
		return false;
	});
	
	// When we click the forward arrow
	$('.forward_arrow').click(function(){
		// Fetch the maximum amount from our input field
		var maximum = (($('#totalImages').val()-8)*82)*-1;
		// Get left
		var left = parseFloat($('.product_list').css('left'));
		
		// if we are above the maximum (working in negatives my head hurts)
		if(left > maximum){
			// Animate
			$('.product_list').animate({"left": "-=82px"}, "normal");
		}else{
			// Don't animate and reset to full distance
			$('.product_list').css({"left": maximum + "px"});
		}
		
		
	});
	
	$('.back_arrow').click(function(){
		
		// Get the value of left and parse it into a number (remove the px)
		var left = parseFloat($('.product_list').css('left'));
		
		// If it is less than 0 then we can animate it
		if(left < 0){
			$('.product_list').animate({"left": "+=82px"}, "normal");
		}else{
			$('.product_list').css({"left": "0px"});
		}
	});
	
});

$(function(){
	aboutImages();
});

function aboutImages(){
	// When click on thumbnail
	$('.jsThumbnail').click(function(){
		//select src as variable
		var src = $(this).attr("src");
		//remove src thumbnail string
		src = src.replace("/thumbs","");
		//replace target attribute with thumbnail src
		$("#target").attr("src",src);
		return false;
	});
}
$(function() {
	zIndexHandler();
});

function zIndexHandler(){
	var zIndexNumber = 10000;
	$('ul#topnav, li.depMain').each(function() {
		$(this).css('zIndex', zIndexNumber);
		zIndexNumber -= 10;
	});
}

/**
 * Email validator
 * LEAVE THIS ALONE!!
 * @param str
 * @return
 */
function validateEmail(str) 
{
	var at="@";
	var dot=".";
	var lat=str.indexOf(at);
	var lstr=str.length;
	var ldot=str.indexOf(dot);
	if(str.indexOf(at)==-1 || str.indexOf(at)==0 || str.indexOf(at)==lstr){
		return false;
	}
	if(str.indexOf(dot)==-1 || str.indexOf(dot)==0 || str.indexOf(dot)==lstr){
		return false;
	}
	if(str.indexOf(at,(lat+1))!=-1){
		return false;
	}
	if(str.substring(lat-1,lat)==dot || str.substring(lat+1,lat+2)==dot){
		return false;
	}
	if(str.indexOf(dot,(lat+2))==-1){
		return false;
	}
	if(str.indexOf(" ")!=-1){
		return false;
	}
	return true;		
}
