function hoverIn(oCurrentHoverObj){
	if(oCurrentHoverObj.className != 'hotels_overview_stars_price_hoverdiv_active'){
		var aDivChilds = getChildsByTagName(oCurrentHoverObj.parentNode, 'DIV');
		for(var i in aDivChilds){
			if(aDivChilds[i].className == 'hotels_overview_stars_price_outerdiv_hover'){
				aDivChilds[i].style.display = 'block';
				oCurrentHoverObj.className = 'hotels_overview_stars_price_hoverdiv_active';
				return;
			}
		}
	}
}

function hoverOut(oCurrentHoverObj){
	if(oCurrentHoverObj.className != 'hotels_overview_stars_price_hoverdiv_inactive'){
		var aDivChilds = getChildsByTagName(oCurrentHoverObj.parentNode, 'DIV');
		for(var i in aDivChilds){
			if(aDivChilds[i].className == 'hotels_overview_stars_price_outerdiv_hover'){
				aDivChilds[i].style.display = 'none';
				oCurrentHoverObj.className = 'hotels_overview_stars_price_hoverdiv_inactive';
				return;
			}
		}
	}
}


YAHOO.util.Event.onDOMReady(function() {
	doMenuInit();
});
function doMenuInit() {
	// this avoids errors in ie and onDomReady if opened in a frame
	if(document.getElementById('header_menu_sub_outerdiv')==null) {
		window.setTimeout('doMenuInit()', 500);	
		return;	
	}	
	//PNG Fix
	if (document.all && YAHOO.env.ua.ie<7) {
			var aImages = document.getElementsByTagName('img');
			for(var i = 0; i < aImages.length; i++){
				startFixImageForIE(aImages[i]);
			}
	}
	loadMenuAnimations();
	
	aStarOuterDivs = YAHOO.util.Dom.getElementsByClassName('hotels_overview_stars_price_outerdiv');
	if(aStarOuterDivs.length == 0){
		aStarOuterDivs = YAHOO.util.Dom.getElementsByClassName('offers_overview_stars_price_outerdiv');
	}

}


var aIEImageFixImages = new Array();
function startFixImageForIE(oImage){
	aIEImageFixImages[aIEImageFixImages.length] = oImage;
	fixImageForIE((aIEImageFixImages.length - 1));
}

function fixImageForIE(iImage){
	if(aIEImageFixImages[iImage].complete){
		if(aIEImageFixImages[iImage].width > 0 && aIEImageFixImages[iImage].height > 0){
			aIEImageFixImages[iImage].width = aIEImageFixImages[iImage].width;
			aIEImageFixImages[iImage].height = aIEImageFixImages[iImage].height;
			aIEImageFixImages[iImage].style.behavior = "url(/totoya/cache/core/clib/lib/iepngfix/iepngfix.htc)";
		}
	}else{
		window.setTimeout('fixImageForIE('+iImage+')', 500);
	}
}


function sendRingbackRequest(){
	if(_('contact_firstname').value.length > 0 && _('contact_lastname').value.length > 0 && _('contact_phonenumber').value.length > 0 && _('contact_email').value.length > 0){
		var oInfos = new Object();
		oInfos['sFirstname'] = _('contact_firstname').value;
		oInfos['sLastname'] = _('contact_lastname').value;
		oInfos['sPhonenumber'] = _('contact_phonenumber').value;
		oInfos['sEmail'] = _('contact_email').value;
		if(_('contact_desireddate').value.length > 0){
			oInfos['sDesireddate'] = _('contact_desireddate').value;
		}
		if(_('contact_notes').value.length > 0){
			oInfos['sNotes'] = _('contact_notes').value;
		}
		oInfos['sType'] = 'contact'
		
		yuiAjaxRequest('cFormulars', 'ajaxSave', oInfos, {success: sendRingBackSuccess, failure: sendRingBackFailure});
	
	}else{
		alert('Die benoetigen Daten wurden leider nicht eingetragen.');
	}
}

function sendRingBackSuccess(o){
	_('form_outerdiv').innerHTML = "<p>Vielen Dank f&uuml;r Ihre Anfrage. Wir werden uns bei Ihnen melden.</p>";
}

function sendRingBackFailure(o){
	alert('Ein Problem ist aufgetreten.')
}

function sendNewsletterRequest(){
	if(_('contact_firstname').value.length > 0 && _('contact_lastname').value.length > 0 && _('contact_email').value.length > 0){
		var oInfos = new Object();
		oInfos['sFirstname'] = _('contact_firstname').value;
		oInfos['sLastname'] = _('contact_lastname').value;
		oInfos['sEmail'] = _('contact_email').value;
		oInfos['sOrder'] = _('contact_order').options[_('contact_order').selectedIndex].value
		oInfos['sType'] = 'newsletter'
		
		yuiAjaxRequest('cFormulars', 'ajaxSave', oInfos, {success: sendNewsletterSuccess, failure: sendNewsletterFailure});
	
	}else{
		alert('Die benoetigen Daten wurden leider nicht eingetragen.');
	}
}

function sendNewsletterSuccess(o){
	_('form_outerdiv').innerHTML = "<p>Die &Auml;nderungen wurden erfolgreich gespeichert.</p>";
}

function sendNewsletterFailure(o){
	alert('Ein Problem ist aufgetreten.')
}

			

var aStarOuterDivs;
function slidePrice(){
	for(var i = 0; i<aStarOuterDivs.length; i++){
	
		var parentDiv = aStarOuterDivs[i];
		var aChildNodes = parentDiv.childNodes;
		for(var j = 0; j < aChildNodes.length; j++ ){
			if(!aChildNodes[j].tagName){
				parentDiv.removeChild(aChildNodes[j]);
			}
		}
		if(parentDiv.lastChild.getElementsByTagName('td')[0].innerHTML == 0){
			parentDiv.lastChild.getElementsByTagName('td')[0].innerHTML = parentDiv.firstChild.getElementsByTagName('td')[0].innerHTML
		}
		
		
		
		parentDiv.insertBefore(parentDiv.lastChild, parentDiv.firstChild);
		
	}
	window.setTimeout('slidePrice()', 3000);
}

function getStyleClass (className) {
	for (var s = 0; s < document.styleSheets.length; s++)
	{
		if(document.styleSheets[s].rules) 
		{
			for (var r = 0; r < document.styleSheets[s].rules.length; r++)
			{
				if (document.styleSheets[s].rules[r].selectorText == '.' + className)
				{
					return document.styleSheets[s].rules[r];
				}
			}
		}
		else if(document.styleSheets[s].cssRules)
		{
			for (var r = 0; r < document.styleSheets[s].cssRules.length; r++)
			{
				if (document.styleSheets[s].cssRules[r].selectorText == '.' + className)
					return document.styleSheets[s].cssRules[r];
			}
		}
	}
	
	return null;
}

function showSoutafricaMapRegion(iActiveRegion){
	for(var i = 1; i < 11; i++){
		if(iActiveRegion == i){
			document.getElementById('soutafrica_text_region_'+i).style.color = "#FA9731";
			document.getElementById('soutafrica_map_region_'+i).style.zIndex = 60;
		}else{
			document.getElementById('soutafrica_text_region_'+i).style.color = "#33190C";
			document.getElementById('soutafrica_map_region_'+i).style.zIndex = 20;
		}
	}
}

function getChildsByTagName(oNode, sTagName){
	if(oNode){
		var aResult = new Array();
		
		for(var i = 0; i < oNode.childNodes.length; i++){
			if(oNode.childNodes[i].tagName == sTagName){
				aResult[aResult.length] = oNode.childNodes[i];
			}
		}
		return aResult;
	}else{
		return false;
	}
}

var iActivePriceBox;
function showPriceDivs(iId, bShow){
	return;
	var oPriceOuterDiv = document.getElementById('offers_offer_pricediv_'+iId);
	var oPriceAllOuterDiv = document.getElementById('offers_offer_pricealldiv_'+iId);
	
	
	if(oPriceOuterDiv){	
		if(!oPriceAllOuterDiv && bShow == true){
			oPriceAllOuterDiv = oPriceOuterDiv.cloneNode(true);
			oPriceAllOuterDiv.id = 'offers_offer_pricealldiv_'+iId;
			//oPriceAllOuterDiv.className = "";
			oPriceAllOuterDiv.style.overflow = "visible";
			oPriceAllOuterDiv.style.zIndex = 9;
			oPriceAllOuterDiv.style.backgroundColor = '#FFFEF5';
			oPriceAllOuterDiv.style.bottom = '15px';
			oPriceAllOuterDiv.style.marginTop = '0px';
			
			oPriceOuterDiv.parentNode.appendChild(oPriceAllOuterDiv);
			
			var iHeight = 0;
			var aChildNodes = oPriceAllOuterDiv.childNodes;
			var aInnerHTMLTemp = new Array();
			for(var i = 0; i<aChildNodes.length; i++){
				if(aChildNodes[i].tagName && aChildNodes[i].tagName.toLowerCase() == 'div'){
					var bExists = false;
					for(var j in aInnerHTMLTemp){
						if(aInnerHTMLTemp[j] == aChildNodes[i].getElementsByTagName('td')[0].innerHTML){
							oPriceAllOuterDiv.removeChild(aChildNodes[i]);
							bExists = true;
						}
					}
					if(!bExists){
						aInnerHTMLTemp[aInnerHTMLTemp.length] = aChildNodes[i].getElementsByTagName('td')[0].innerHTML;
						var aChild = new YAHOO.util.Region.getRegion(aChildNodes[i]);
						iHeight += (aChild.bottom-aChild.top);
					}
					
				}
			}
			
			oPriceAllOuterDiv.style.height = iHeight+'px';
			setTimeout('checkMouseInPriceBox('+iId+')', 50);
			showPriceDivs(iActivePriceBox, false);
			iActivePriceBox = iId;
		}else{
			if(bShow == false){
				if(oPriceAllOuterDiv && oPriceAllOuterDiv.parentNode){
				oPriceAllOuterDiv.parentNode.removeChild(oPriceAllOuterDiv);
				iActivePriceBox = NaN;
				}
			}
		}
	}
}


function checkMouseInPriceBox(iId){
	var oCurrentPoint = new YAHOO.util.Point(iMouseXPosition, iMouseYPosition);
	var oRegion = new YAHOO.util.Region.getRegion('offers_offer_pricealldiv_'+iId);
	if(oRegion.contains(oCurrentPoint)){
		setTimeout('checkMouseInPriceBox('+iId+')', 50);
	}else{
		showPriceDivs(iId, false)
	}
}

// Island-subnavi generated on the fly
// TODO: parent.parent^5 is dangerous, better put some classes or ids in menu sourcecode
$(document).ready(function(){
	//log($(".menu_content_link_active").html());
	var sHtml = $(".menu_content_link_active").html();
	if(typeof sHtml == 'string' && sHtml.toLowerCase() == "hotels" && ! (document.location.href.indexOf("/v/")>0 || document.location.href.indexOf("/sudafrika/sudafrika/")>0)) {
		//log('!');
		var i 			= 0;
		var sSubMenu	= "";
		$("h2").each(function(){
			//log($(this).html());
			i++;
			sSubMenu += "<a href='#headline_"+i+"'><strong>"+$(this).html().substr(0,$(this).html().length-1)+"</strong></a><br />\n";
			$(this).prepend("<a name='headline_"+i+"'></a>");
		});
		$(".menu_content_link_active")
			.parent().parent().parent().parent().parent()
			.append(sSubMenu)
			.css("height",28+i*16+"px")
			.css("white-space","nowrap")
			.css("overflow","hidden");
	}
	//log('?');
	
	
});
