(function() {
	var oScript = document.createElement('script'); oScript.type = 'text/javascript'; oScript.async = true;
	oScript.src = ('https:' == document.location.protocol ? 'https://' : 'http://') + 'ajax.googleapis.com/ajax/libs/jquery/1.6.2/jquery.min.js';
	var s = document.getElementsByTagName('script')[0]; s.parentNode.insertBefore(oScript, s);
	oScript.onreadystatechange = function() {
		if ((this.readyState == 'complete') || (this.readyState == 'loaded')) {
			jQuery(document).ready(function() {
				addSlideEvent();
				productsFn();
			});
		}
	}
	oScript.onload = function() {
		jQuery(document).ready(function() {
			addSlideEvent();
			productsFn();
		});
	};

})();



function addSlideEvent()
{ 
	
	jQuery("#v_slideout").click(function(e) {
	    e.preventDefault();
	    jQuery("#vertical_slide").slideUp("slow")
	    jQuery("#buttonDiscover").show();    
	    jQuery("#buttonHide").hide();
	});
	
	
	jQuery("#v_slidein").click(function(e) {
	    e.preventDefault();
	    jQuery("#vertical_slide").slideDown("slow");
	    jQuery("#buttonDiscover").hide();    
	    jQuery("#buttonHide").show();
	
	});

}


function productsFn() {
	// Google chrome browser detection
	var userAgent = navigator.userAgent.toLowerCase(); 
	$.browser.chrome = /chrome/.test(navigator.userAgent.toLowerCase());
	
	// Accordion menu
	$('li:not(.accordContent)', '.accordion').click(function() {
		var $$ = $(this), $n = $$.next();
		
		$n.slideToggle(function() {
			$$.toggleClass('active');
		});
	});
	
	// Product images full size
	$('#productImages').click(function(e) {
		e.preventDefault();
		
		// Create the overlay element
		$('<div />', {id : 'imageOverlay'})
			.css({opacity : 0.7, height : $(document).height()})
			.prependTo('body');
		
		// Add an onclick for the overLay
		$("#imageOverlay").live('click', function(e) {
			e.preventDefault();
			$('#imageOverlay, #imageFullSize').hide().remove();
		});
		
		// Create a new wrapper element to house the image popup
		$('<div />', {id : 'imageFullSize'}).append(
			$('<img />', {src : this.href.replace(/gif/, 'jpg'), alt : '', height : 800, width : 530}).after(
				$('<a />', {href: '#', title : 'Close this window'}).html('X')
			)
		).prependTo('body');
		
		// Work out the ratio of height to width of the image
		// We'll use this to work out how big the image should be when / if we resize it
		var ratio = 1 / (530 / 800);
		
		// Because some screens are smaller then others we need to ensure
		// when we get to a certain size that the modal window resizes
		if ($(window).height() <= 850) {
		
			var $$ = $('#imageFullSize'),
				newHeight = $(window).height() - 60,
				newWidth  = 530 - ($$.find('img').height() - newHeight),
				newBoxHeight = Math.round(newWidth * ratio);
			
			$$.css({
				height     : newBoxHeight,
				marginLeft : '-' + (newWidth / 2) + 'px',
				marginTop  : '-' + (newBoxHeight / 2) + 'px',
				width      : newWidth
			}).find('img')
			  .css({
				  width  : newWidth,
				  height : newBoxHeight
			  });
			
			/*var newRatio = 1 / (newWidth / newHeight);
			console.debug("ratio:", newRatio);
			console.debug("newHeight:", newWidth * ratio, newHeight, newWidth);*/
		}
		
		/*
		
		// Because some screens are smaller then others we need to ensure
		// when we get to a certain size that the modal window resizes
		if ($(window).height() <= 850) {
			var $$ = $('#imageFullSize'),
				newHeight = $(window).height() - 60,
				newWidth  = 530 - ($$.find('img').height() - newHeight);
			
			$$.css({
				height     : newHeight,
				marginLeft : '-' + (newWidth / 2) + 'px',
				marginTop  : '-' + (newBoxHeight / 2) + 'px',
				width      : newWidth
			}).find('img')
			  .css({
				  height : newHeight,
				  width  : newWidth
			  })
			  
		}*/
		
		$('#imageOverlay, #imageFullSize').show();
	});
	
	$('a', '#imageFullSize').live('click', function(e) {
		e.preventDefault();
		$('#imageOverlay, #imageFullSize').hide().remove();
	});
	
	// Internet Explorer 6 & 7 have some slight bugs so to fix them we
	// need to add a class to the body element
	if ($.browser.msie && ($.browser.version === '6.0' || $.browser.version === '7.0')) {
		$('body').addClass('ie');
	}
	
	// IE6 specific fixes
	if ($.browser.msie && $.browser.version === '6.0') {
		// :first-child fix for the information boxes
		$('li:first-child', '.infoBox').css('margin-left', 0);
		
		// :hover fix for the accordion menu
		$('li:not(.accordContent)', '.accordion').hover(function() {
			$('span', this).addClass('active');
		}, function() {
			$('span', this).removeClass('active');
		});
	}
	
	// Global IE fixes
	if ($.browser.msie) {
		$('li.accordContent:last-child', '.accordion').css('border-bottom', '1px solid #d2cfcf');
	}
	
	// Multi browser fixes
	if ($.browser.msie || $.browser.chrome) {
		// table margin fix
		$('table', '.accordContent').after(
			$('<div />').css({height : 1, width : 'auto'})
		);
	}
}
