/***** START: Special Dropdownlist for mobile devices *****/

toggleLists = '';

other_toggleList = function(){
	var toggleLists = $$('.toggle_list').concat($$('.toggle_list *'));

	if(toggleLists){
		toggleLists.invoke('observe', global.pointHandler(), 
			function(event){
				toggleList_init(this,event);	
			});
	}
}

toggleList_init = function(list, event){
	
	var listItemFinder = event.element();
	
	if( typeof(listItemFinder) == 'undefined' ) {
		return;
	}
	
	if( !listItemFinder.hasClassName('option'))
	{
		listItemFinder = Event.findElement(event,'.option');
	};
	
	if( listItemFinder == document || listItemFinder.hasClassName('toggle_list') ) {
		Event.stop(event);
		return false;
	}
	
	var listItem = listItemFinder;
	
	if( !list.hasClassName('toggle_list') ) {
		
		listFinder = null;

		list.ancestors().each(function(pe){
			if( listFinder == null && pe.hasClassName('toggle_list') ) {
				listFinder = pe;
			}
		});

		if( listFinder != null ) {
			list = listFinder;
		}
		
	}
	
	list.select('.option').each(function(el){el.removeClassName('selected');});
	listItem.addClassName('selected');
	
	var newValue = '';
	
	if( typeof(list.select('input[type="hidden"]')[0]) == 'undefined') {
		elmt = Event.findElement(event,'input');

		if( typeof(elmt) != 'undefined' && elmt != document ) {
			elmt.value = listItem.className.match(/value_([^ ]+)/i)[1];
			newValue = elmt.value;
		}
	} else {
		if( Element.childElements(listItem).size() > 0 ) {
			list.select('input[type="hidden"]')[0].value = listItem.className.match(/value_([^ ]+)/i)[1];
		} else {
			list.select('input[type="hidden"]')[0].value = listItem.innerHTML;
		}
		newValue = list.select('input[type="hidden"]')[0].value;
	}
	
	if( newValue != '' && typeof(show_elv_input) != 'undefined' ) {
		show_elv_input((newValue == 'elv' ? true : false));
	}
	
	Event.stop(event);
	
}

function baseToggleClass(el, add, cl)
{
	if(add)
	{
		Element.addClassName(el, cl);
	}
	else
	{
		Element.removeClassName(el, cl);
	}
}

/***** END: Special Dropdownlist for mobile devices *****/


footerMenuTimeout = new Array();
function company_hover(pBool) {	
	if (pBool) 
	{
		//IE Fix
		if(typeof(footerMenuTimeout) != 'undefined')
		{
			window.clearTimeout(footerMenuTimeout['footermenu']);
			window.clearTimeout(footerMenuTimeout['footermenu_underline']);
		}
		document.getElementById('company_menu').style.display = 'block';
		$('company_footer_field_inline').addClassName('company_footer_hover');
		
		
	} else
	{
		
		//document.getElementById('company_menu').style.display = 'none';
		//$('company_footer_field_inline').removeClassName('company_footer_hover');
		// IE Fix
		footerMenuTimeout['footermenu'] = window.setTimeout("document.getElementById('company_menu').style.display = 'none'");
		footerMenuTimeout['footermenu_underline'] = window.setTimeout("$('company_footer_field_inline').removeClassName('company_footer_hover')");
	}
		
	
}

function company_field_hover(el,pBool) {
	if (pBool)
	{
		Element.addClassName(el, 'company_menu_field_hover');		
		
	} else
	{
		Element.removeClassName(el, 'company_menu_field_hover');
	}
}

function press_field_hover(el,pBool) {
	if (pBool)
	{
		Element.addClassName(el, 'company_menu_field_hover');
		$('press_img').src = '/images/layout/info/arrow_right_hover.jpg';
		$('press_menu').style.display = 'block';
	} else
	{

		Element.removeClassName(el, 'company_menu_field_hover');
		$('press_img').src = '/images/layout/info/arrow_right.gif';
		$('press_menu').style.display = 'none';
	}
}

function kidsshoes_field_hover(el,pBool) {
	if (pBool)
	{
		Element.addClassName(el, 'company_menu_field_hover');
		$('kids_img').src = '/images/layout/info/arrow_right_hover.jpg';
		$('kids_menu').style.display = 'block';
	} else
	{

		Element.removeClassName(el, 'company_menu_field_hover');
		$('kids_img').src = '/images/layout/info/arrow_right.gif';
		$('kids_menu').style.display = 'none';
	}
}

function kidsweb_field_hover(el,pBool) {
	if (pBool)
	{
		Element.addClassName(el, 'company_menu_field_hover');
		$('kidsweb_img').src = '/images/layout/info/arrow_right_hover.jpg';
		$('kidsweb_menu').style.display = 'block';
	} else
	{

		Element.removeClassName(el, 'company_menu_field_hover');
		$('kidsweb_img').src = '/images/layout/info/arrow_right.gif';
		$('kidsweb_menu').style.display = 'none';
	}
}


function press_field_hover_bottom(el,pBool) {
	if (pBool)
	{
		Element.addClassName(el, 'company_menu_field_hover');
		$('press_img').src = '/images/layout/info/arrow_right_hover.jpg';
		$('press_menu_bottom').style.display = 'block';
	} else
	{

		Element.removeClassName(el, 'company_menu_field_hover');
		$('press_img').src = '/images/layout/info/arrow_right.gif';
		$('press_menu_bottom').style.display = 'none';
	}
}
function engagement_field_hover(el,pBool) {
	if (pBool)
	{
		Element.addClassName(el, 'company_menu_field_hover');
		$('engagement_img').src = '/images/layout/info/arrow_right_hover.jpg';
		$('engagement_menu_bottom').style.display = 'block';
	} else
	{
		Element.removeClassName(el, 'company_menu_field_hover');
		$('engagement_img').src = '/images/layout/info/arrow_right.gif';
		$('engagement_menu_bottom').style.display = 'none';
	}
}

function engagement_field_hover(el,pBool) {
	if (pBool)
	{
		Element.addClassName(el, 'company_menu_field_hover');
		$('engagement_img').src = '/images/layout/info/arrow_right_hover.jpg';
		$('engagement_menu_bottom').style.display = 'block';
	} else
	{

		Element.removeClassName(el, 'company_menu_field_hover');
		$('engagement_img').src = '/images/layout/info/arrow_right.gif';
		$('engagement_menu_bottom').style.display = 'none';
	}
}

function franchise_field_hover(el,pBool) {
	if (pBool)
	{
		Element.addClassName(el, 'company_menu_field_hover');
		$('fran_img').src = '/images/layout/info/arrow_right_hover.jpg';
		$('fran_menu').style.display = 'block';
	} else
	{
		Element.removeClassName(el, 'company_menu_field_hover');
		$('fran_img').src = '/images/layout/info/arrow_right.gif';
		$('fran_menu').style.display = 'none';
	}
}

function footer_field_hover(el,pBool) {
	var $test = el.id;
	if (pBool) {
		$($test).addClassName('company_footer_hover');
	} else
	{
		$($test).removeClassName('company_footer_hover');
	}
}

function info_hover(pImg,pDiv,pBool)
{
	if (pBool)
	{
		$(pImg).style.display = 'none';
		$(pImg+'_hover').style.display = 'block';
		if (pDiv)
		$(pImg+'_div').style.display = 'block';
	} else
	{
		$(pImg+'_hover').style.display = 'none';
		$(pImg).style.display = 'block';	
		if (pDiv)
		$(pImg+'_div').style.display = 'none';
	}
	
}
function mouseX(evt) 
{
	if (evt.pageX) return evt.pageX;
	else if (evt.clientX)
	   return evt.clientX + (document.documentElement.scrollLeft ?
	   document.documentElement.scrollLeft :
	   document.body.scrollLeft);
	else return null;
	}
function mouseY(evt) 
{
	if (evt.pageY) return evt.pageY;
	else if (evt.clientY)
	   return evt.clientY + (document.documentElement.scrollTop ?
	   document.documentElement.scrollTop :
	   document.body.scrollTop);
	else return null;
}

/**
 * Zeigt den "Loadinghint" an. Fadet die Seite auf Hellgelb
 * und aktiviert die "Ladekringel" Grafik. Wird momentan
 * nur bei den mobile devices eingesetzt und passiert fast
 * ausschliesslich bei einem click oder touch event auf einen
 * button
 */
function applyLoadingHint(evt)
{
	// Ist gerade eine reload der seite geplant? anhalten
	if( typeof(global.timeoutForReload) != 'undefined' ) {
		window.clearTimeout(global.timeoutForReload);
	}
	
	// Tastatur auch verstecken, wenn da
	if( typeof(TerminalControl) != 'undefined' && TerminalControl.isKeyboardVisible() ) {
		TerminalControl.keyboardHide();
	}
	
	// Ladekringel anzeigen
	if( $('loadingHintGrafic') != null ) {
		$('loadingHintGrafic').show();	
	}
	
	// LightboxOverlay starten (Die Seite mit einem transparenten
	// layer überlagern)
	if( typeof(LightboxOverlay) != 'undefined' ) {
		if( evt == 'no_fading' ) {
			LightboxOverlay.activate(0);
		} else {
			LightboxOverlay.activate();
		}
	}
	
	// Nach 60 Sekunden den ganzen Kram wieder deaktivieren.
	// Dient als fallback, falls irgendetwas abgestürzt ist
	window.setTimeout("removeLoadingHint()",60000);
	
}

/**
 * Schaltet den "Loadinghint" wieder aus (s.o.)
 */
function removeLoadingHint()
{
	// Transparenten Layer ausschalten
	if( typeof(LightboxOverlay) != 'undefined' ) {
		LightboxOverlay.deactivate();
	}

	// Ladekringel weg
	if( $('loadingHintGrafic') != null ) {
		$('loadingHintGrafic').hide();
	}
	
	// Wenn wir uns auf einem iPad befinden automatischen
	// "Screensaver" wieder einschalten (falls man längere
	// Zeit auf einer Seite ist, wieder zur Startseite wechseln,
	// da das Gerät wohl gerade nicht benutzt wird ...)
	// Im Shop nach 4 Minuten, im Checkout nach 15 Minuten
	if( global.client == 'ipad' ) {
	
		global.timeoutForReload = window.setTimeout(
			'window.location.href="' + getMobileStartUrl() + '";', 
			( global.size=='checkout' ? 900 : 240 ) * 1000
		);
	}
	
}
function sizeSearchChangeSelect(event,cat) 
{
	//dom-object des angeklickten elementes
	var activeMenu = event.element(event);

	//auswahl in div-container markieren
	//bei allen die klasse fuer markierung/hintergrund entfernen
	$$('div#filterSsCatListContainerInner a').invoke('removeClassName', 'filter_active');
	$(activeMenu.id).addClassName('filter_active');
	
	//groessen-container leeren
	$('filterSsSizeListContainerInner').update();
	
	//lies den inhalt der groessen ein
	var ssSizesListId	= 'ssSizesList' + activeMenu.id;
	var sizesInhalt		= $(ssSizesListId).innerHTML;
	
	//inhalt aus div einbauen
	$('filterSsSizeListContainerInner').update(sizesInhalt);
	
	//allen a-tags eine css-klasse hinzufuegen
	$$('div#filterSsSizeListContainerInner a').invoke('addClassName', 'spanFilterListSsSize');
	
	//aktiviere groessencontainer
	$('filterSsSizeContainer').style.display = 'block';

	//aktiviere size-Container
	$('klappLinkSsSize').className  			 = 'klappLinkWithList';
	$('filterSsSizeListContainer').style.display = 'block';
	
	vScroll(null , 'SsSize');
	
	// schliesse kategorien wieder und packe die ausgewaehlte kategorie in das feld oben
	$('filterSsCatListContainer').style.display = 'none';
	$('klappLinkSsCat').className 				= 'klappLink';
	var inhaltCat 								= $(activeMenu.id).innerHTML;
	$('catHeadline').update(inhaltCat);
}

function closeCatList(selectedId,catContainer) 
{
	// schliesse cat-container
	$('filterSsCatListContainer').style.display = 'none';
	$('klappLinkSsCat').className 				= 'klappLink';

	// hole die bezeichnung der angewaehlten division, um diese in den kopf zu hauen
	var mctDivName	= $(selectedId).innerHTML;

	$('catHeadline').update(mctDivName);
}


/**
 * Liefert die Startseiten URL für die mobile devices
 * Option "with_popup" Zeigt auf der nächsten Seite das
 * "Ihre persönlichen Daten wurden gelöscht" Popup an
 * 
 * @param Array option=[null|"with_popup"|"without_cookie_delete"]
 */
 
function getMobileStartUrl(option)
{
	// Startseitenlink holen
	var destUrl = $("top_right").select("a")[0].href;
	// naechsten delimiter rausfinden
	var delim = ( destUrl.match(/\?/) ? '&' : '?' );
	// beim iPad automatische Adress und Locationauswahl einbauen
	// (im Cookie steht, in welchem Store und welcher Abteilung das iPad gerade ist)
	var addonForIpad = ( getCookie('ipad') == '1' ? '&setMobileLocationId='+getCookie('mobileLocationId')+'&setMobileAddressId='+getCookie('mobileAddressId') : '' );
	// Falls das "Daten gelöscht" Popup angefordert wird, auch diese Option anhängen
	var addonForPopup = ( typeof(option) != "undefined" && option == "with_popup" ? '&show_cookie_popup=true' : '' );
	var addonForCookieDelete = ( typeof(option) != "undefined" && option == "without_cookie_delete" ? "" : 'force_cookie_delete=1' );
	return destUrl + delim + addonForCookieDelete + addonForIpad + addonForPopup;

}



function getUrlVars()
{
    var vars = {};
    var parts = window.location.href.replace(/[?&]+([^=&]+)=([^&]*)/gi, function(m,key,value) {
                vars[key] = value;
                });
    return vars;
}



Event.observe(window, 'load', function(){
	
	// Initialisiert die Togglelists (ersetzt auf den mobile devices radiobuttons)
	other_toggleList();
	var f=$$('.themebutton');
	f.each( function(e) {
		if( e == null ) return;
		Event.observe(e, 'mouseover', function() {
			Element.addClassName(e, 'hover');
		});
		Event.observe(e, 'mouseout', function() {
			Element.removeClassName(e, 'hover');
		});
		// bei den mobile devices den ladekringel an den click oder touch hängen
		if( global.style == 'mobile' && !e.className.match(/loadingHintImmune/) ) {
			Event.observe(e,global.pointHandler(),applyLoadingHint);
		}
	});
	// groessensuche
	if($('filterSsCatListContainerInner') != null) 
	{
		$$('a.ssDivision').invoke('observe','click', sizeSearchChangeSelect.bindAsEventListener(this, $$('ssSizesList')));
	}
});
