$(document).ready ( function () 
{

	$("#topNavigation").gradient (
	{ 
		from: 'FFFFFF', 
		to: 'AAAAAA'
	});
	
	$("#topNavigation .active").gradient (
	{ 
		from: 'a6a6a6', 
		to: '6f6f6f'
	});
	
	$("#searchBox").gradient (
	{ 
		from: 'b3b3b3', 
		to: '7d7d7d'
	});

	$(".boxBtn").gradient ({ from: 'b2b2b2', to: '7d7d7d' });

	if (!$.browser.msie || ($.browser.version >= 7))
	{
			
		$("#searchBox").corner ('6px');
		
		$("a.pageNavigation").corner ('4px');
	
		$(".contentBox").corner ('6px');
		
		$("#singleHeadline").corner ('6px');
		
		$(".newsTeaserImage").corner ('6px');
		
		/*$("#mainContainer").dropShadow ({
			left: 0,
			top: 0,
			opacity: 0.4
		});*/
		
		$("#mainContainer").corner ('bl 7px');
		$("#mainContainer").corner ('br 7px');
		
		/*$("#top").dropShadow ({
			left: 0,
			top: 2,
			opacity: 0.3
		});*/
	
		/*$("#searchBox h1.boxHeadline").dropShadow ({
			left: -9,
			top: -3,
			opacity: 0.3
		});*/
		
		/*$(".contentBox h1.boxHeadline").dropShadow ({
			left: -9,
			top: -1,
			opacity: 0.3
		});*/	
	
		$("#topNavigation").corner ('bl 4px');
		$("#topNavigation").corner ('br 4px');
		$(".boxBtn").corner ('6px');
		
		/*$(".textShadow").dropShadow ({
			left: -6,
			top: 1,
			opacity: 0.3
		});*/
		
		/*if ($.browser.safari)
		{
			$(".boxBtn .textShadow").removeShadow ();
			$(".boxBtn .textShadow").dropShadow ({
				left: 5,
				top: 2,
				opacity: 0.3
			});
		}*/
		
		/*$("#singleHeadline h1").dropShadow ({
			left: -10,
			top: 2,
			opacity: 0.3
		});*/
	}
	
	
	$('#alertWindow').hide();
	
	$('.mainNavigation').hover(function () 
	{
		if (!$(this).hasClass ("active"))
		{
			if ($(this).find (".gradient").size () < 1)
			{
				$(this).addClass ("hover");
				$(this).gradient (
				{ 
					from: 'a6a6a6', 
					to: '6f6f6f'
				});
			}
		}
    }, 
    function () 
	{
		if (!$(this).hasClass ("active"))
		{
	   		$(this).removeClass("hover");
			//alert($(this).html());
			$(this).find (".gradient").remove();
		}
    });
	
	
	$('#productSearchInput').focus ( function () 
								   {
									   var val = $(this).val();
									   
									   if (val == "Suche")
									   {
										   $(this).val ("");
									   }
								   });	

	$('#productSearchInput').blur ( function () 
								   {
									   var val = $(this).val();
									   
									   if (val == "")
									   {
										   $(this).val ("Suche");
									   }
								   });	
	
	
	
	$('.productItem img').load ( function () 
								{
									var imageHeight = $(this).height ();
									if (imageHeight < 40)
									{	
										$(this).css ("margin-top", "50px");
									}
								} );

});




/* navigation */



function menu(elem)
{
	var mainOffset = $('#mainContainer').offset();
	var offset = $('#href_' + elem).offset();

	var menu_pos = offset.left-mainOffset.left-7;
		
	
	$('#menu_' + elem).css('left',menu_pos + "px");
	

	var show = $('#menu_' + elem).css('display');
	
	$('#topNavigation > a ').removeAttr('class');
	$('#href_' + elem).attr('class', 'active');
	
	for(var i=1;i<=5;i++)
	{
		hideMenu(i);
	
		$('#href_' + i + " .gradient").remove();
	}
		
	
	if(show == 'none')
	{
		showMenu(elem);
	} 
	else
	{
		hideMenu(elem);		
		$('#href_' + elem).removeAttr('class');
		$('#href_' + elem + " .gradient").remove();
	}
}
	
function hideMenu(elem) 
{
	$('#menu_' + elem).hide ();	
	$('#menu_' + elem).removeShadow ();
	$('#href_' + elem).removeAttr ('class');
}

function showMenu(elem)
{
	$('#menu_' + elem).show ();
	//setMenuShadow ('#menu_' + elem);	----------------- HERE -----------------
	
	if (!$.browser.msie || ($.browser.version >= 7))
	{			
		$('#menu_' + elem).corner ('bl 6px').corner ('br 6px');
	}
	
	$("#topNavigation #href_" + elem).gradient (
	{ 
		from: 'a6a6a6', 
		to: '6f6f6f'
	});
	$('#href_' + elem).attr('class', 'active');
}

/*function setMenuShadow (elem)
{
	$(elem).dropShadow ({
		left: 0,
		top: 2,
		opacity: 0.3
	});
	
	$(elem + ' submenu').slideDown(); 
}*/



function goto (url)
{
	window.location = url;
}

function submitProductForm ()
{
	$('#productForm').submit();
}

function productImageLoaded ()
{
	if (!$.browser.msie || ($.browser.version >= 7))
	{
		$('#productDetailWindow').corner ('#575757 10px');
	}

	var productContentHeight = $("#productDetailContent").height ()+2;
	var productImageHeight = $("#productDetailImage").height ()+2;
	
	if (productImageHeight > productContentHeight)
	{
		$("#productDetailWindow").css ("height", productImageHeight + "px");
		$("#productDetailContent").css ("height", productImageHeight + "px");
	}
	else
	{
		$("#productDetailWindow").css ("height", productContentHeight + "px");
	}

	$("#productDetailWindow").css ("left", (($(document).width() - $("#productDetailWindow").width()) / 2) + "px");
	$("#productDetailWindow").css ("top", Math.max (10, ($(window).height() - $("#productDetailWindow").height()) / 2 ) + "px");

	$('a.overlayClose').click ( closeProductDetail );
	$("a.overlayClose").corner ('3px');
		
	$("#productDetailWindow .boxBtn").gradient ({ from: 'b2b2b2', to: '7d7d7d' });
	$("#productDetailWindow .boxBtn").corner ('6px');
	$('#productDetailWindow .boxBtn').click ( submitProductForm );

	$('#overlayBackground').click ( closeProductDetail );	
	$('#loadingAnimation').remove();
	
	var verticalPosition = Math.round ((productContentHeight/2)-(productImageHeight/2));
	
	if (verticalPosition > 1)
	{	
		$("#productDetailImage").css ("margin-top", verticalPosition);
	}	
	
	$("#productDetailWindow").animate({ opacity: 1 }, 100 );
		
}

function productDataLoaded (html)
{
	$("body").append (html);

	$('#productDetailImage').load ( productImageLoaded );
}

function closeProductDetail ()
{
	$('#overlayBackground').remove();
	$('#loadingAnimation').remove();
	$("#productDetailWindow").remove();

}

function openProductDetail (category, id)
{
	var screenWidth = $(document).width();
	var screenHeight = $(document).height();

	$("body").append ('<div id="overlayBackground" class="overlayBackground"></div>');
	var background = $('#overlayBackground');
	background.width ( screenWidth );
	background.height ( screenHeight );

	$("body").append ('<div id="loadingAnimation" class="loadingAnimation"><img src="../img/loading.gif" /><br><br>Lade Produktinformationen</div>');
	var loading = $('#loadingAnimation');
	loading.css ("left", ((screenWidth - loading.width()) / 2) + "px");
	loading.css ("top", (( $(window).height() - loading.height()) / 2) + "px");

	background.animate({ opacity: 0.9 }, 100 );
	loading.animate({ opacity: 0.9 }, 100 );
	
	$.ajax ({
	  type: "POST",
	  url: "product_detail.php",
	  data: { area: category, product: id },
	  dataType: "html",
	  success: productDataLoaded
	});
}

function _alert (headline, text, btn)
{
	var screenWidth = $(document).width();
	var screenHeight = $(document).height();
	
	$("#alertHeadline").append (headline);
	$("#alertText").append (text);
	$("#alertOkBtn").append (btn);

	$("body").append ('<div id="overlayBackground" class="overlayBackground"></div>');
	var background = $('#overlayBackground');
	background.width ( screenWidth );
	background.height ( screenHeight );
	background.animate({ opacity: 0.9 }, 100 );
	
	var alertWindow = $('#alertWindow');
	alertWindow.css ("left", ((screenWidth - alertWindow.width()) / 2) + "px");
	alertWindow.css ("top", (( $(window).height() - alertWindow.height()) / 2) + "px");
	$("#alertWindow").fadeIn();
	
	if (!$.browser.msie || ($.browser.version >= 7))
	{
		$('#alertWindow').corner ('#575757 10px');
	}	
}

function closeAlert ()
{
	$('#overlayBackground').remove();
	$("#alertWindow").fadeOut();
}


/*
left    : integer (default = 4)
top     : integer (default = 4)
blur    : integer (default = 2)
opacity : decimal (default = 0.5)
color   : string (default = "black")
swap    : boolean (default = false)
*/