//animate the opening of the branch (span.grower jQueryElement)
function openBranch(jQueryElement, noAnimation) {
		jQueryElement.addClass('OPEN').removeClass('CLOSE');
		if(noAnimation)
			jQueryElement.parent().find('ul:first').show();
		else
			jQueryElement.parent().find('ul:first').show();
}
//animate the closing of the branch (span.grower jQueryElement)
function closeBranch(jQueryElement, noAnimation) {
	jQueryElement.addClass('CLOSE').removeClass('OPEN');
	if(noAnimation)
		jQueryElement.parent().find('ul:first').hide();
	else
		jQueryElement.parent().find('ul:first').hide();
}

//animate the closing or opening of the branch (ul jQueryElement)
function toggleBranch(jQueryElement, noAnimation) {
	if(jQueryElement.hasClass('OPEN'))
		closeBranch(jQueryElement, noAnimation);
	else
		openBranch(jQueryElement, noAnimation);
}

function get_GET_params() {
   var GET = new Array();
   if(location.search.length > 0) {
      var get_param_str = location.search.substring(1, location.search.length);
      var get_params = get_param_str.split("&");
      for(i = 0; i < get_params.length; i++) {
         var key_value = get_params[i].split("=");
         if(key_value.length == 2) {
            var key = key_value[0];
            var value = key_value[1];
            GET[key] = value;
         }
      }
   }
   return(GET);
}
 
function get_GET_param(key) {
   var get_params = get_GET_params();
   if(get_params[key])
      return(get_params[key]);
   else
      return false;
}

$(document).ready(function() 
{	
	/*
		CLICK EVENTS ON DIVS ACTIVATING INNER A CLICK
	*/
	$(".menu_item").click(function()
	{		
		document.location = $(this).find('a').attr('href');				
	});	
	
	
	$("#categories_block_left .tree li").click(function()
	{
		var href = $(this).find('a').attr('href');
		if(href == '#') 
		{
			//Grower is clicked, we have to expand the tree		
			toggleBranch($(this));			
			
			/*if($('#categories_block_left .tree li.accessoires').css('margin-top') == '87px')
			{
				$('#categories_block_left .tree li.accessoires').css('margin-top','0px');
				$('ul.tree :first-child ul').css('display','none');
			}
			else{
			*/
				$('#categories_block_left .tree li.accessoires').css('margin-top','87px');
				$('ul.tree :first-child ul').css('display','block');
				$('ul.tree :first-child ul').css('margin-top','4px');
			//}
		}
		else
		{
			/*toggleBranch($(this)).clearQueue();
			$('#categories_block_left .tree li.accessoires').css('margin-top','88px');
			$('ul.tree :first-child ul').css('display','block');
			$('ul.tree :first-child ul').css('margin-top','4px');*/
			document.location = href;				
		}				
	});
	
	//add a fonction on clicks on growers
	$('ul.tree.dhtml a.grower').click(function(){
			toggleBranch($(this));			
			if($('#categories_block_left .tree li.accessoires').css('margin-top') == '87px')
			{
				$('#categories_block_left .tree li.accessoires').css('margin-top','0px');
				$('ul.tree :first-child ul').css('display','none');
			}
			else{
				$('#categories_block_left .tree li.accessoires').css('margin-top','87px');
				$('ul.tree :first-child ul').css('display','block');
				$('ul.tree :first-child ul').css('margin-top','4px');
			}
	});
	
	$(".submenu_magazin ul li.mag").click(function()
	{		
		document.location = $(this).find('a').attr('href');				
	});
	/* END OF CLICKING MANIA */
	
	
	$(".menu_item.non_active").mouseover(function()
	{					
		$(this).css("background", "url('img/magazin-hover.png') repeat scroll 0 0 transparent");				
	});	
	$(".menu_item.non_active").mouseout(function()
	{					
		$(this).css("background", "none");				
	});
	$(".magazin.non_active").mouseover(function()
	{					
		$(this).css("background", "url('img/magazin-hover.png') repeat scroll 0 0 transparent");	
		$(".submenu_magazin").css("display", "block");		
	});	
	$(".magazin.non_active").mouseout(function()
	{					
		$(this).css("background", "none");	
		$(".submenu_magazin").css("display", "none");		
	});
	$(".magazin").mouseover(function()
	{					
		$(this).css("background", "url('img/magazin-hover.png') repeat scroll 0 0 transparent");	
		$(".submenu_magazin").css("display", "block");		
	});	
	$(".magazin").mouseout(function()
	{					
		$(".submenu_magazin").css("display", "none");		
	});
	$(".submenu_magazin").mouseover(function()
	{					
		$(".submenu_magazin").css("display", "block");	
		$(".magazin.non_active").css("background", "url('img/magazin-hover.png') repeat scroll 0 0 transparent");		
		$(".magazin").css("background", "url('img/magazin-hover.png') repeat scroll 0 0 transparent");		
	});	
	$(".submenu_magazin").mouseout(function()
	{					
		$(".submenu_magazin").css("display", "none");	
		$(".magazin.non_active").css("background", "none");		
	});
	
	$(".tee.non_active").mouseover(function()
	{					
		$(this).css("background", "url('img/tee-tester-hover.png') repeat scroll 0 0 transparent");				
	});	
	$(".tee.non_active").mouseout(function()
	{					
		$(this).css("background", "none");				
	});	
	$(".vip.non_active").mouseover(function()
	{					
		$(this).css("background", "url('img/vip-club-hover.png') repeat scroll 0 0 transparent");				
	});	
	$(".vip.non_active").mouseout(function()
	{					
		$(this).css("background", "none");				
	});	
	$(".news.non_active").mouseover(function()
	{					
		$(this).css("background", "url('img/newsletter-hover.png') repeat scroll 0 0 transparent");				
	});	
	$(".news.non_active").mouseout(function()
	{					
		$(this).css("background", "none");				
	});	
	$(".submenu_magazin").css("display", "none");
	$(".overlay").colorbox({width:"520px", height:"945px", iframe:true});
	$(".overlay_passwort").colorbox({width:"520px", height:"400px", iframe:true});
	$(".overlay_datachange").colorbox({width:"520px", height:"610px", iframe:true});
	$(".overlay_datachangepass").colorbox({width:"520px", height:"410px", iframe:true});
	$(".overlay_tee_tester").colorbox({width:"520px", height:"450px", iframe:true});
	$(".overlay_gewinnspiel").colorbox({width:"520px", height:"560px", iframe:true});
	$(".overlay_nl_abmelden").colorbox({width:"520px", height:"400px", iframe:true});
	
	var sPath = window.location.pathname;
	var sPage = sPath.substring(sPath.lastIndexOf('/') + 1);
	//alert(sPage);
	if(sPage == "cms.php"){
		$("#left_column").css("top", "423px");
	}
	else if(sPage == "order.php"){
		$("#left_column").css("top", "222px");
	}
	
	
	
	
	//GET PARAMETER FOR THE AGB IN SHOP
	if(get_GET_param("content_only")==1)
	{
		$(".vip_teaser").css("display", "none");
		$(".breadcrumb").css("display", "none");
		$(".teekanne_mann").css("display", "none");
		$(".special_cms div").css("padding-left", "0px");
		$(".special_cms div").css("margin-top", "10px");
	}
	//$('#quantity_wanted_p').css('display','block');
	//$('#add_to_cart').css('display','block');
	
	
});
