$(function()
{
	
	

	
	// external links
	$('a.external').click(function()
	{
		$(this).attr('target', '_blank');
	});
	


	// go through each form assigning a handler to save buttons
	// making sure that all labels 
	var errorAlert = '<div id="errorAlert" class="message error"><p style="margin:0;">\
						<strong>Error</strong><br/>\
						Please fill in all required fields (marked with a <img src="/img/forms/required.gif" style="background:#fff;padding:3px;" />) before submitting the form.\
						</p></div>';

	$('form').submit(function()
	{
		var ret = true;
		var f = $(this).parent();
		var errorText = '<p><strong>Please fix the following errors:</strong><br/>';

		$('label[class="required"]', $(this)).each(function()
		{
			var lf = $(this).attr('for');
			var e = $('*[name="' + lf + '"]', f);
			var v = e.val();
			if ( v == '' )
			{
				e.addClass('errorInput').effect("pulsate", { times: 3 }, 150);
				$('#errorAlert').remove();
				$('p.message').after(errorAlert);
				$('#errorAlert').show();
				errorText += '<span style="width:30%;float:left;">' + lf.replace(/_/g, ' ').replace('cust', '').replace('del', 'Delivery') + '</span>';

				ret = false;
			}
			else
			{
				$('#errorAlert').hide();
				e.removeClass('errorInput');
				// ret = true;
			}
		});

		if ( ret === false )
		{
			$('#errorAlert').remove();
		
			errorText + '</p>';
			$(this).before(errorAlert);
			window.location.href += '#';
		}
		
		return ret;
		
	});

	

	
	
	$('.image_cycle').cycle();

	
	
	
	
	$('#brandScroller').jCarouselLite(
	{
	    auto: 4000,
	    scroll: 5, 
	    speed: 2000, 
	    circular: true, 
	    visible: 8
	});

	
	
	if ( !$.browser.msie && !$.browser.version == 6 )
	{
		$('.mini').css({'opacity':'0.7'});
	}
	else // is IE Shix
	{
		$('#basketTableWrap').css('hasLayout', '1');
	}
	
	
	$('#selGroupId').change(function(){
		
		if($('#hire_flag').val()==1){
			var url = '/p/populate.variations.php?g='+$(this).val()+'&hire';
		}else{
			var url = '/p/populate.variations.php?g='+$(this).val();
		}
		
		$('#variation_wrap').load(url,function(){
			$(this).show();
		});
	});
	
	
});

