/*
	## init
*/
var tld = window.location.hostname;
tld = 'http://' + tld;

var publicPhp = tld + '/public/php/';



/*
	## handle basket: actions 1=add, 2=subtract, 3=clearProduct, 4=clearBasket
*/
function handleBasket_f ( idLabuyla, action, updateBasket )
{	
	//requestUrl	= publicPhp + 'shop_insertToBasket.php.php?idLabuyla='+idLabuyla;
	act			= action;
	id			= idLabuyla;
	requestUrl	= publicPhp + 'shop_basket.php.php?idLabuyla='+ id + '&action=' + act;
	kind		= 4;
	
	// unteren part des sidebar.basket ein/ausblenden
	if( act == 4 )
	{
		// wenn 'basket leeren' dann unteren part ausblenden
		if( window.location != tld + "/shop/basket.html" )
		{
			// wenn auf modul basket, dann wird reload ausgefuehrt
			tween_f ('shopBasketBottom', 0);
		}		
		
	}
	else if( act == 1 )
	{	
		// sobald basket mindestens ein produkt enthaelt dann unteren part einblenden
		tween_f ('shopBasketBottom', 70);
			
	}
	
	request_f ( requestUrl, kind, id, updateBasket );
}


/*
	## produkte neu laden
*/
function loadProducts_f ( ids )
{
	
	ids = ids + '_';


	arr_ids 	= ids.split('_');
	
	var cat_id = 0;
	if ( arr_ids[0] )
	{
		cat_id		= arr_ids[0];
	}
	
	var catSub_id = 0;
	if ( arr_ids[1] )
	{
		catSub_id	= arr_ids[1];
	}
	
	var catGroup_id = 0;
	if ( arr_ids[2] )
	{
		catGroup_id	= arr_ids[2];
	}
	
	
	requestUrl	= publicPhp + 'shop_loadProduct.php.php?catid=' + cat_id + '&catSubId=' + catSub_id + '&catGroupId=' + catGroup_id;
	kind		= 3;
	id			= 'shopContent';
	
	request_f ( requestUrl, kind, id );
	
	

}


/*
	## menu
*/
var catActive			= "ieSevenMenuLinkTitleActive";
var catInActive			= "ieSevenMenuLinkTitle";

var catSubActive		= "ieSevenMenuLinkActive";
var catSubInActive		= "ieSevenMenuLink";

var catGroupActive		= "endingSortimentActive";
var catGroupInActive	= "endingSortiment";


function menu_f ( kind, id, idToOpen, idToOpenHeight )
{
	/* cat */
	if ( kind == 1 )
	{
		/* timeout definition */
		timeOutCat	= 0;
	
		/* welche kategorie ist grad offen */
		catSubIdIsOpen = innerHtml_f ( 2, 'catIdOpen', '' );
		
		/* es kommt als catId_x */
		arr_catSubIdIsOpen 	= catSubIdIsOpen.split('_');
		catSubIdIsOpenInt 		= arr_catSubIdIsOpen[1]; // reine id als int
		
		if ( catSubIdIsOpenInt )
		{
		
/*subnavi*/		
			/* welche gruppe ist grad offen */
			catGroupIdIsOpen = innerHtml_f ( 2, 'catSubId', '' );
		
			/* es kommt als catId_x */
			arr_catGroupIdIsOpen 	= catGroupIdIsOpen.split('_');
			catGroupIdIsOpenInt 		= arr_catGroupIdIsOpen[1]; // reine id als int
		
			if ( catGroupIdIsOpenInt )
			{
				/* schliesst das alte fenster */
				tween_f ('catGroupHolder_' + catGroupIdIsOpenInt, 0);
			
				/* setzte die Klasse zurueck */
				changeClass_f ( catSubActive, catSubInActive, catGroupIdIsOpen );
			}
/*subnavi ENDE*/			
		
			timeOut_cur = 400;
			/* schliesst das alte fenster */
			if ( catSubIdIsOpen != id ) 
			{ 
				tween_f ('catSubHolder_' + catSubIdIsOpenInt, 0); 
				timeOut_cur = 600;
			}
			
			/* setzte die Klasse zurueck */
			changeClass_f ( catActive, catInActive, catSubIdIsOpen );
			
			/* warten bis es auf geht */
			timeOutCat = timeOut_cur;
		}
		
		/* welche id soll ich oeffnen es kommt als catId_x */
		arr_catIdToOpen 	= idToOpen.split('_');
		catIdToOpen 		= arr_catIdToOpen[1];	// reine id als int
		
		/* offnet die neue Kategorie */
		//tween_f ('catSubHolder_'+catIdToOpen, idToOpenHeight);
		window.setTimeout("tween_f('catSubHolder_"+catIdToOpen+"','"+idToOpenHeight+"')", timeOutCat);
		
		/* setzte eine neue klasse */	
		changeClass_f ( catInActive, catActive, id )
		
		/* merkt sich das diese id nun geoeffnet ist */
		innerHtml_f ( 1, 'catIdOpen', id );
		
	}
	
	
	/* group */
	if ( kind == 2 )
	{
		/* welche gruppe ist grad offen */
		groupIdIsOpen = document.getElementById("catGroupId_act").value;
		
		if ( ( groupIdIsOpen ) && (groupIdIsOpen != 0 ) )
		{
			/* setzte die Klasse zurueck */
			changeClass_f ( catGroupActive, catGroupInActive, groupIdIsOpen); 
			document.getElementById("catGroupId_act").value = 0;
		} 
		
		
		/* timeout definition */
		timeOutGroup	= 0;	
		
		/* welche gruppe ist grad offen */
		catGroupIdIsOpen = innerHtml_f ( 2, 'catSubId', '' ); 
		//catGroupIdIsOpen = document.getElementById("catSubId_act").value;
		
		/* es kommt als catId_x */
		arr_catGroupIdIsOpen 	= catGroupIdIsOpen.split('_'); 
		catGroupIdIsOpenInt 		= arr_catGroupIdIsOpen[1]; // reine id als int
		
		if ( catGroupIdIsOpenInt )
		{
			/* schliesst das alte fenster */ 
			if ( catGroupIdIsOpen != id ) 
			{ 
				tween_f ('catGroupHolder_' + catGroupIdIsOpenInt, 0); 
			} 
			
			/* setzte die Klasse zurueck */
			changeClass_f ( catSubActive, catSubInActive, catGroupIdIsOpen );
			
			/* warten bis es auf geht */
			timeOutGroup = 400; 
		}
		
/*cat*/		
		
		/* welche kategorie ist grad offen */
		catSubIdIsOpen = innerHtml_f ( 2, 'catIdOpen', '' );
		/* es kommt als catId_x */
		arr_catSubIdIsOpen 	= catSubIdIsOpen.split('_');
		catSubHeightxxxx 	= arr_catSubIdIsOpen[1];
		catSubHeight 		= arr_catSubIdIsOpen[2]; // reine id als int
		
		catSubNewHeight = parseInt(catSubHeight) + parseInt(idToOpenHeight);
		tween_f ('catSubHolder_' + catSubHeightxxxx, catSubNewHeight);
/*cat ENDE*/			
		
		
		/* welche id soll ich oeffnen es kommt als catId_x */
		arr_catSubIdToOpen 	= idToOpen.split('_');
		catSubIdToOpen 		= arr_catSubIdToOpen[1];	// reine id als int

		/* offnet die neue gruppe */
		//tween_f ('catGroupHolder_'+catSubIdToOpen, idToOpenHeight);
		window.setTimeout("tween_f('catGroupHolder_"+catSubIdToOpen+"','"+idToOpenHeight+"')", timeOutGroup);
	
		/* setzte eine neue klasse */	
		changeClass_f ( catSubInActive, catSubActive, id )
		
		/* merkt sich das diese id nun geoeffnet ist */
		innerHtml_f ( 1, 'catSubId', id );
	}
	
	/* group faerben */
	if ( kind == 3 )
	{
		/* welche gruppe ist grad offen */
		groupIdIsOpen = innerHtml_f ( 2, 'catGroupId', '' );
		
		if ( ( groupIdIsOpen ) && (groupIdIsOpen != 0 ) )
		{
			/* setzte die Klasse zurueck */
			changeClass_f ( catGroupActive, catGroupInActive, groupIdIsOpen);

		}
		
		/* setzte die Klasse zurueck */
		changeClass_f ( catGroupInActive, catGroupActive, id);
		
		/* merkt sich das diese id nun geoeffnet ist */
		innerHtml_f ( 1, 'catGroupId', id );
	}
}

/* beim laden gestartete funktionen etc. */
window.addEvent('domready', function() 
{
	/*
		## menu
	*/
	$$('.ieSevenMenuLinkTitle').addEvent('click', function(e)
	{
		var id				= this.id;
		var idToOpen 		= this.id;
		var idToOpenHeight 	= this.getAttribute('hoehe');
		
		menu_f ( 1, id, idToOpen, idToOpenHeight );
		
		var ids 	= this.getAttribute('ids');
		loadProducts_f (ids);
	});
	
	$$('.ieSevenMenuLink').addEvent('click', function(e)
	{	
		var id				= this.id;
		var idToOpen 		= this.id;
		var idToOpenHeight 	= this.getAttribute('hoehe'); 
		
		document.getElementById("catSubId_act").value=id; 
		
		var catGroupId_act = document.getElementById("catGroupId_act").value; 
		//document.getElementById("catGroupId_act").value = '';
		
		menu_f ( 2, id, idToOpen, idToOpenHeight );
		
		var ids 	= this.getAttribute('ids');
		loadProducts_f (ids);
	});
	
	$$('.endingSortiment').addEvent('click', function(e)
	{	
		var id				= this.id;
		var idToOpen 		= this.id;
		var idToOpenHeight 	= 0; 
		
		document.getElementById("catGroupId_act").value=id;  
		
		menu_f ( 3, id, idToOpen, idToOpenHeight );
		
		var ids 	= this.getAttribute('ids');
		loadProducts_f (ids);
		//var catSubIDcur = document.getElementById("catSubId_act").value;  
		//changeClass_f ( catSubActive, catSubInActive, catSubIDcur )
	});
	
	
	$$('.ieSevenMenuLinkTitleActive').addEvent('click', function(e)
	{
		var id				= this.id;
		var idToOpen 		= this.id;
		var idToOpenHeight 	= this.getAttribute('hoehe');
		
		menu_f ( 1, id, idToOpen, idToOpenHeight );
		
		var ids 	= this.getAttribute('ids');
		loadProducts_f (ids);
	});
	
	$$('.ieSevenMenuLinkActive').addEvent('click', function(e)
	{	
		var id				= this.id;
		var idToOpen 		= this.id;
		var idToOpenHeight 	= this.getAttribute('hoehe');
		
		document.getElementById("catSubId_act").value=id;  
		
		var catGroupId_act = document.getElementById("catGroupId_act").value; 
		//document.getElementById("catGroupId_act").value = '';
		
		menu_f ( 2, id, idToOpen, idToOpenHeight );
		
		var ids 	= this.getAttribute('ids');
		loadProducts_f (ids);
	}); 
	
	$$('.endingSortimentActive').addEvent('click', function(e)
	{	
		var id				= this.id;
		var idToOpen 		= this.id;
		var idToOpenHeight 	= 0; 
		
		document.getElementById("catGroupId_act").value=id;  
		
		menu_f ( 3, id, idToOpen, idToOpenHeight );
		
		var ids 	= this.getAttribute('ids');
		loadProducts_f (ids);
		//var catSubIDcur = document.getElementById("catSubId_act").value;  
		//changeClass_f ( catSubActive, catSubInActive, catSubIDcur )
	});
		//document.getElementById("catGroupId_act").value=id;  
		//document.getElementById("catSubId_act").value=id; 
	
	
});
	