$(function()
{
	

	$('a.gallery').lightBox();
	opaqueBackgrounds();
	
	
	// add lightbox stylesheet
	$('head').append('<' + 'lin' + 'k href="css/jquery.lightbox-0.5.css" rel="stylesheet" type="text/css" />');

	
	
	
	// 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;
		
	});

	

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

	
	
	
	
	// ie 6 fix index box
	if ( $.browser.msie && $.browser.version == 6 )
	{
		$('.indexBox .panelText').css({'hasLayout':'1', 'zoom':'1', 'position':'relative', 'background':'#333 !important'});
	}
	
	
	// mac firefox fix index boxes
	if ( $.client.os == 'Mac' && $.browser.mozilla )
	{
		$('.indexBox').css('margin', '-30px 0 0 0');
	}
	
	
});

