$(function()
{
	
	
	
	$('a.external').click(function()
	{
		$(this).attr('target', '_blank');
	});
	
	
	
	$('.mini').css({'opacity':'0.7'});
	
	
	
	
	// product nav hovers
	$('#productNavigation ul li:not(".groupli")')
	.mouseover(function()
	{
		$(this).css({'background': 'url(/img/common/navigation/sideNavBullet2.png) no-repeat left 4px'});
	})
	.mouseout(function()
	{
		$(this).css({'background': 'url(/img/common/navigation/sideNavBullet.png) no-repeat left 4px'});
	});
	
	


	
	$('#copyAddressToDeliveryButton').click(function()
	{
		copyAddressToDelivery();
	});
	
	
	
	
	
	// go through each form assigning a handler to save buttons
	// making sure that all labels 
	var errorAlert = '<div id="errorAlert">\
						<strong>Error</strong><br/>\
						Please fill in all required fields (marked with a <img src="/admin/img/icons/bullet_red.png" />) before submitting the form.\
						</div>';

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

		$('label[class="required"]').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.adminDescription').after(errorAlert);
				$('#errorAlert').show();
				errorText += '<p style="width:30%;float:left;">' + lf.replace(/_/g, ' ').replace('cust', '').replace('del', 'Delivery') + '</p>';

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

		$('#errorWrapper').html(errorText + '<div class="clear"></div>');

		return ret;

	});
	
	
	
	
	
	
	// center and vertically align:middle the images for cats, subs and groups.
	setTimeout("centerCenterImage()", 500);
	
	
	
	
	// ie7 fixes
	if ( $.browser.msie && $.browser.version <= 7 )
	{
		$('#builderLeft').css({'width': '520px'});
		$('#builderRight').css({'width': '382px', 'float':'right'});
	}
	
	
	// ie6 fixes
	if ( $.browser.msie && $.browser.version <= 7 )
	{
		$('#navigationWrap').css({'background': 'black'});
		$('#navigationWrap img').css({'display': 'none'});
	}
	
	
	$('#navigation li').mouseover(function(){
		
		$(this).css('position','relative');
		
		if($('ul',this).length){
			$('ul',this).show();
		}
	}).mouseout(function(){
		
		if($('ul',this).length){
			$('ul',this).hide();
		}
	});
	
	
});
