$(function()
{
	

	// set up a reusable dialog...
	$('<div id="dialog"></div>').dialog(
	{
		autoOpen: false,
		modal: true, 
		height: 200,
		width: 500, 
		title: 'Information'
	});
	
	
	
	
	setRequiredFields();
	
	
	$('#madeToMeasure, #wallStickers').click(function(){
									   
		window.location.href = $('a',this).attr('href');
									   
	});
	
	
	
	
	
	
	
	
	// product position select dropdown
	// show input box if they choose 'other' from the select
	$('#productPositionSelect').change(function()
	{
		if ( $(this).val() == 'other' )
		{
			$(this).after('<input style="margin:0px 3px 0 0;" type="text" id="position_other" name="product[data][position]" value="" />');
		}
		else
		{
			$('#position_other').remove();
		}
	});
	
	
	
	
	
	
	$('#productTabs a').click(function(){
	
		$('#productTabs td').removeClass('current');
		$(this).closest('td').addClass('current');
	
		var id = $(this).attr('id').replace('link_','');
	
		$('div.information').hide();
		$('#'+id).show();
	
		return false;
	});

	
	
	
	
	// product detail - click thumb, change src of larger one
	$('#mainProductThumbs img').click(function()
	{
		var l = $(this).attr('src').replace(/_sqr/, '_l');
		$('#mainProductImage img').attr('src', l);
		
		var xl = $(this).attr('src').replace(/_sqr/, '_xl');
		$('#mainProductImage_LinkClickForLarger').attr('href', xl);
		
		
	});

	
	
	
	// product detail page - faq
	$('dl.toggleMyBits dt').toggle(
	function()
	{
		$(this).next().show();
	}, 
	function()
	{
		$(this).next().hide();
	}
	);

	
	
	// assign lightbox to product image.
	if ( $('.lightboxMe').length )
	{
		$('.lightboxMe').lightBox();
	}
	
	
	// hover product main image, shows link to see larger one...
	$('#mainProductImageWrap')
	.mouseover(function()
	{
		$('#mainProductImage_LinkClickForLarger').stop().show();
	})
	.mouseout(function()
	{
		$('#mainProductImage_LinkClickForLarger').stop().hide();
	});

	
	
	
	
	
	// alt table rows - basket
	$('table.stripes > tbody > tr:even').addClass('even');
	
	
	
	
	// checkout / admin create order 
	$('.checkoutBlockHead').click(function()
	{
		$('.checkoutBlockHead').removeClass('currentTab');
		$(this).addClass('currentTab');
		$('.checkoutBlock').hide();
		$( '#' + $(this).attr('id').replace(/head/, 'checkout')).show();
	});
	
	$('input, select').bind('keyup click change', function()
	{
		checkRequiredFields();
	});
	
	checkRequiredFields();
	
	
	
	
	
	
	
	// order display screen - image size toggle
	$('#toggleImageSizesLink').toggle(
	function()
	{
		$('td.imageCell').width('90px');
		$('td.imageCell img').width('90px');
	}, 
	function()
	{
		$('td.imageCell').width('45px');
		$('td.imageCell img').width('45px');
	});

	
	

	
	
	
	
	// category page - product list
	// rollowver images
	$('.swapImagesInMe')
	.mouseover(function()
	{
		var current = $('img', $(this)).attr('src');
		var swap 	= $('img', $(this)).attr('swap');
		if ( swap == '' )
		{
			return;
		}
		$('img', $(this)).attr('src', swap);
		$('img', $(this)).attr('swap', current);
	})
	.mouseout(function()
	{
		var current = $('img', $(this)).attr('src');
		var swap 	= $('img', $(this)).attr('swap');
		if ( swap == '' )
		{
			return;
		}
		$('img', $(this)).attr('src', swap);
		$('img', $(this)).attr('swap', current);
	});
	
	
	
	
	
	
	
	
	
	
	

});
