
/*
 * Javascript to initialise the document
 */

$(document).ready(function() {
	
	// email addresses
	$('.email').each(function(index) {
		$(this).html($(this).html().replace('[at]', '@') );
		$(this).html('<a href="mailto:' + $(this).html() + '?subject=Web Enquiry">' + $(this).html() + '</a>');
	});
	
	// newsletter form
	// FORM FIELDS
	$('input').focus(function()
	{
		if (this.value == this.defaultValue) this.select();
	}).blur(function() {
		if (this.value == '') this.value = this.defaultValue;
	}).mouseup(function(event) {
		event.preventDefault();
	});
	
	
	// products
	
	var totWidth = 0;
	var positions = new Array();
	
	// Traverse through all the slides and store their accumulative widths in totWidth
	$('#gallery #slides .slide').each(function(index)
	{
		// The positions array contains each slide's commulutative offset from the left part of the container
		positions[index] = totWidth;
		totWidth += $(this).width();
		
		if(!$(this).width())
		{
			alert("Please, fill in width & height for all your images!");
			return false;
		}
	});
	
	// Change the cotnainer div's width to the exact width of all the slides combined
	$('#slides').width(totWidth);

	// Traverse through all the descriptions and hide them
	$('#products #descriptions .description').each(function(index)
	{
		if (index != 0)
		{
			$(this).css({display: 'none'});
		}
	});
	
	// On a thumbnail click
	$('#galleryMenu ul li a, #products ul#sidenav li a').click(function(event)
	{
		// $('li.menuItem').removeClass('act').addClass('inact');
		// $(this).parent().addClass('act');
		
		var pos = $(this).parent().prevAll('li').length;
		
		// Start the sliding animation
		$('#slides').stop().animate({marginLeft:-positions[pos]+'px'}, 'slow');
		
		// Show the new text
		$('#products #descriptions .description').css({display: 'none'});
		$('#products #descriptions .description:eq('+ pos +')').fadeIn('fast');
		
		// Prevent the default action of the link
		event.preventDefault();
	});
	
	// On page load, mark the first thumbnail as active */
	// $('#menu ul li.menuItem:first').addClass('act').siblings().addClass('inact');
	
	
});
