var currentSubnavigationID = '';
var currentThirdnavigationID = '';
var imagedivLeft = 0;
var currentElementNumber = 0;
var imagesForPrecaching = new Array();

var activeNavigationElements = new Array();


function eId(elementId){
	if(element = document.getElementById(elementId)){
		return element;
	} else {
		return false;
	}
}

function setImagesForPrecaching(imageUrl){
	imagesForPrecaching.push(imageUrl);
}

function preCacheImages(){
	backgroundDiv = eId('main_product_image_container');
	for(i=0;i<imagesForPrecaching.length;i++)
	{
		if(backgroundDiv){
			backgroundDiv.style.backgroundImage = "url("+imagesForPrecaching[i]+")";
			backgroundDiv.style.backgroundRepeat = "no-repeat";
		}
	}
}

function setActiveNavigationElement(elementNr){
	activeNavigationElements.push(elementNr);
	listElement = eId(elementNr);
	if (listElement){
		var childs = listElement.getElementsByTagName('img');

		element = "";

		for (i=0;i<=childs.length;i++){
			if (childs[i] && childs[i].className == "navigationimage"){
				element = childs[i];
				break;
			}
		}


		if (element != ""){
			if (element.src.substring((element.src.length-10)) == "_aktiv.png"){
				element.src = element.src.replace("_aktiv.png",".png");
			}
			else{
				element.src = element.src.replace(".png","_aktiv.png");
			}
		}
	}

}





function activatePreviewImage(nr){
	$('.white_teaser_image_row_image_active').each(function(){
		$(this).removeClass("white_teaser_image_row_image_active").addClass("white_teaser_image_row_image");
		variable1 = $(this).height();
	})

	$('.image_link_container_overlay').each(function(){
		$(this).css('display', 'none')
	})
	img = eId('preview_image_'+nr);
	if (img){
		img.className = 'white_teaser_image_row_image_active';
		overlayDiv = eId('preview_image_overlay_'+nr);
		if(overlayDiv){
			overlayDiv.style.height = $('#preview_image_'+nr).height()-2+"px";
			overlayDiv.style.width = $('#preview_image_'+nr).width()-2+"px";

			imgY = getElementY(img);
			overlayY = getElementY(overlayDiv);

			// IE7 HACK ;-)
			if (overlayY > 0){
				overlayDiv.style.top = (($('#preview_image_'+nr).height()*-1)-3)+"px";
				overlayDiv.style.height = $('#preview_image_'+nr).height()+"px";
				overlayDiv.style.width = $('#preview_image_'+nr).width()-1+"px";

			}
			if(!checkBrowserName('msie 7')){
				overlayDiv.style.top = "0px";
			}


			$('#preview_image_overlay_'+nr).css('display', 'block');


		}
	}
}

function switchNavigationElement(listElement){
	var childs = listElement.getElementsByTagName('img');

	if (listElement.id && activeNavigationElements.length > 0){
		for(i=0;i<activeNavigationElements.length;i++)
		{
			if (activeNavigationElements[i] == listElement.id){
				return false;
			}
		}
	}
	element = "";
	for (i=0;i<=childs.length;i++){
		if (childs[i] && childs[i].className == "navigationimage"){
			element = childs[i];
			break;
		}
	}
	if (element != ""){
		if (element.src.substring((element.src.length-10)) == "_aktiv.png"){
			element.src = element.src.replace("_aktiv.png",".png");
		}
		else{
			element.src = element.src.replace(".png","_aktiv.png");
		}
	}
}

function showSubnavigation(cID){
	container = eId('subnavigation_container');
	if (container){
		container.style.display='block';
		subnavigation = eId(cID);
		if (subnavigation){
			subnavigation.style.display='block';
			currentSubnavigationID = cID;
		}
	}
}

function hideSubnavigation(cID){
	container = eId('subnavigation_container');
	if (container){
		container.style.display='none';
		if (currentSubnavigationID != ''){
			subnavigation = eId(currentSubnavigationID);
			if (subnavigation){
				subnavigation.style.display='none';

			}
		}
	}
}


function replaceImageSource(elementId, source){
	if(element = eId(elementId)){
		element.src = source;
	}
}

function showDiv(elementId){
	if(element = eId(elementId)){
		element.style.display="block";
	}
}

function hideDiv(elementId){
	if(element = eId(elementId)){
		element.style.display="none";
	}
}

function showDivAnimated(elementId){
	/*if(element = eId(elementId)){
			$('#'+elementId).fadeIn(300, function(){});
			element.style.display="block";

	}*/

	$('#'+elementId).fadeIn(300, function(){});
}

function hideDivAnimated(elementId){
	/*if(element = eId(elementId)){
		if(element.style.display != "none"){
			$('#'+elementId).delay(100).fadeOut(300, function(){});
		}
	}*/

	$('#'+elementId).fadeOut(300, function(){});
}

function resizeImageContainer(){
	if (element = eId("header_images_container")){
		element.style.height = "10px";
	}


}

function showLandingPageDiv(elementNumber){
	currentElementNumber = elementNumber;
	hideAllLandingpageDivsExcludeOne(elementNumber);
	element1 = eId("header_images_container_div_"+elementNumber);
	element2 = eId("header_image_container_link_overlay_div_"+elementNumber);
	currentElementNumber = elementNumber;
	if (element1 && element2){
		element2.style.height = element1.offsetHeight+"px";
		$('#header_image_container_link_overlay_div_'+elementNumber).fadeIn(200, function() {

      	});


	}


}

function hideLandingPageDiv(elementNumber){
	element2 = eId("header_image_container_link_overlay_div_"+elementNumber);

	if (element2){
		element2.style.display = "";
	}


}

function hideAllLandingpageDivs(){
	for(i=1;i<=10;i++){
		element2 = eId("header_image_container_link_overlay_div_"+i);
		if (element2){

			//element2.style.display = "";
			$('#header_image_container_link_overlay_div_'+i).fadeOut(200, function() {
			//animation complete
      		});
		}
	}
}

function resetQueue(elementNumber){
	for(i=1;i<=10;i++){
		element2 = eId("header_image_container_link_overlay_div_"+i);
		if(elementNumber != i && currentElementNumber != i){
			if (element2){
				$('#header_image_container_link_overlay_div_'+i).fadeOut(function (){});
			}
		}
	}

}

function hideAllLandingpageDivsExcludeOne(elementNumber){
	for(i=1;i<=10;i++){
		if (elementNumber != i){
			element2 = eId("header_image_container_link_overlay_div_"+i);
			if (element2){
				$('#header_image_container_link_overlay_div_'+i).fadeOut(200, function() {


				});
				//element2.style.display = "";
			}
		}
	}
}

function setCurrentElementNumber(value){
	currentElementNumber = value;
}

function setNewSrc(elementId, newsource){

	$('#main_product_image_container').css("height",$('#'+elementId).height()+"px");
	backgroundDiv = eId('main_product_image_container');
	tmpImOb = eId(elementId);
	if(backgroundDiv){
		backgroundDiv.style.backgroundImage = "url("+tmpImOb.src+")";
		backgroundDiv.style.backgroundRepeat = "no-repeat";
	}
	$('.content_container_full_over_image').css("top", "-59px");
	$('#'+elementId).fadeOut(1, function() {

	$(this).attr({'src':newsource});




		$(this).fadeIn(1000);



	});

}



function showProductGroup(groupcontainerId, groupArrowOpenId, groupArrowClosedId){
	if(elememt = eId(groupcontainerId)){
		elememt.style.display = "block";
	}
	if(elememt = eId(groupArrowOpenId)){
		elememt.style.display = "none";
	}
	if(elememt = eId(groupArrowClosedId)){
		elememt.style.display = "block";
	}
}

function hideProductGroup(groupcontainerId, groupArrowOpenId, groupArrowClosedId){
	if(elememt = eId(groupcontainerId)){
		elememt.style.display = "none";
	}
	if(elememt = eId(groupArrowOpenId)){
		elememt.style.display = "block";
	}
	if(elememt = eId(groupArrowClosedId)){
		elememt.style.display = "none";
	}
}

function showSingleProduct(productId, openLink, closeLink, productHeadline, productPrice){
	if(elememt = eId(productId)){
		elememt.style.display = "block";
	}
	if(elememt = eId(openLink)){
		elememt.style.display = "none";
	}
	if(elememt = eId(closeLink)){
		elememt.style.display = "block";
	}
	if(elememt = eId(productHeadline)){
		$('#'+productHeadline).removeClass("shopitem_color_closed");
		$('#'+productHeadline).addClass("shopitem_color_open");
	}
	if(elememt = eId(productPrice)){
		$('#'+productPrice).removeClass("shopitem_color_closed");
		$('#'+productPrice).addClass("shopitem_color_open");
	}
}

function hideSingleProduct(productId, openLink, closeLink, productHeadline, productPrice){
	if(elememt = eId(productId)){
		elememt.style.display = "none";
	}
	if(elememt = eId(openLink)){
		elememt.style.display = "block";
	}
	if(elememt = eId(closeLink)){
		elememt.style.display = "none";
	}
	if(elememt = eId(productHeadline)){
		$('#'+productHeadline).removeClass("shopitem_color_open");
		$('#'+productHeadline).addClass("shopitem_color_closed");
	}
	if(elememt = eId(productPrice)){
		$('#'+productPrice).removeClass("shopitem_color_open");
		$('#'+productPrice).addClass("shopitem_color_closed");
	}
}

function showPopup(elementNumber){
	element1 = eId("header_navigation_link_white_"+elementNumber);
	element2 = eId("startsite_popup_div-"+elementNumber);
	hideaction = false;
	mainDivHeight = 0;
	popupHeight = 200;


	$.each($('div[id|=startsite_popup_div]'), function() {
	  	currentId = this.id.split('-');
	  	currentId = currentId[1];

		if(this.style.display != "none"){
			hidePopup(currentId);
			hideaction =true;
			setTimeout("showPopup("+elementNumber+")", 600);
		}

	});

	if(hideaction == false){
		if(element2 && element2.style.display != "none"){
			setTimeout("showPopup("+elementNumber+")", 600);
		} else {
			currentX = getElementX(element1);

			tmpMainDiv = eId('header_images_container');
			if (tmpMainDiv){
				mainDivHeight = tmpMainDiv.offsetHeight;
				if (mainDivHeight > 400){
					mainDivHeight = 400;
				}
			}

			newX=currentX-getElementX('header_container');
			newX = newX - 97;
			if(newX > 544){
				newX = 544;
			}
			if(newX < 25){
				newX = 25;
			}
			if(element2){
				element2.style.left=newX+"px";
				element2.style.display='block';
				popupHeight = element2.offsetHeight;
				element2.style.display='none';

				newY = 0;
				if (mainDivHeight - popupHeight > 0){
					newY = (mainDivHeight - popupHeight) / 2;
					element2.style.top =newY+"px";
				}
			}

			$('#startsite_popup_div-'+elementNumber).fadeIn(500, function() {
			});


			//element2.style.display = "block";
		}
	}



}

function doNothing(){

}

function hidePopup(elementNumber){

	element2 = eId("startsite_popup_div-"+elementNumber);
	$('#startsite_popup_div-'+elementNumber).fadeOut(500, function() {

	});
	//element2.style.display = "none";
}

function hideAllPopups(){
	for (i=0;i<=10;i++){
		element2 = eId("startsite_popup_div-"+i);
		$('div[id|=startsite_popup_div]').fadeOut(500, function() {
		});
	}
	//element2.style.display = "none";
}

/* Absolute Position von links
 *
 */
function getElementX(el){
 if (typeof(el) != "object"){
  el = eId(el);
 }

 x = el.offsetLeft;
 if (!el.offsetParent) return x;
 else return (x+getElementX(el.offsetParent));
}

/**
 * Absolute Position von oben
 *
 */
function getElementY(el) {
 if (typeof(el) != "object"){
  el = eId(el);
 }

 y = el.offsetTop;
 if (!el.offsetParent) return y;
 else return (y+getElementY(el.offsetParent));
}

function showContactTab(elementNumber){
	element1 = eId("contact_1");
	element2 = eId("contact_2");
	tabElement1 = eId("contactTab1");
	tabElement2 = eId("contactTab2");
	if(element1 && element2 && tabElement1 && tabElement2){
		if(elementNumber == 1){
			element1.style.display="block";
			element2.style.display="none";
			tabElement1.className = "contact_tab_active";
			tabElement2.className = "contact_tab";
		}
		if(elementNumber == 2){
			element1.style.display="none";
			element2.style.display="block";
			tabElement1.className = "contact_tab";
			tabElement2.className = "contact_tab_active";
		}
	}
}

function initializeGoogleMap() {

	var latlng = new google.maps.LatLng(50.94659, 6.95702);
    var myOptions = {
      zoom: 15,
      center: latlng,
      mapTypeControl: false,
      mapTypeId: google.maps.MapTypeId.ROADMAP
    };
	var map = new google.maps.Map(document.getElementById("contact_google_map"), myOptions);

	var marker = new google.maps.Marker({
      position: latlng,
      map: map,
      title:"SAVOY Hotel Cologne"
  	});
}

function openGoogleDirections(){
	element = eId('google_directions_input');
	if (element.value != 'Ihre Adresse hier eingeben' && element.value != 'Please insert your address'){
		window.open('http://maps.google.de/maps?f=d&source=s_d&saddr='+element.value+'&daddr=Turiner+Str.+6,+50668+Köln+(SAVOY+Hotel)');
	}
}

function openWYSIWYGEditor(editorName){
	if (document.getElementById(editorName)){
		CKEDITOR.replace( editorName, {
			toolbar :
					[
						[ 'Bold','Italic','Underline', '-', 'Table', 'NumberedList', 'BulletedList', '-', 'Link', 'Unlink', '-','FontSize','-','Cut','Copy','Paste','PasteText','PasteFromWord', '-', 'Source' ]
					],
			fontSize_sizes : 'klein/10px;mittel/11px;Standard/12px;',
			language : 'de',
			imagesPath: CKEDITOR.getUrl( '../images/editor/'),
			enterMode: CKEDITOR.ENTER_P,
			ShiftEnterMode: CKEDITOR.ENTER_BR
		} );
	}
}

function urlConformField(value,field,focus){
	if(!focus){
		focus = false;
	}
	if (typeof(field) != "object"){
		field = eId(field);
	}
	caretP = doGetCaretPosition(field);

	v = value;
	v = v.replace(/[^-_a-zA-Z 0-9äÄüÜöÖß]+/g,'');
	/** default Chars **/
	v = v.replace(/ /g,"-");
	v = v.replace(/'/g,"");
	v = v.replace(/"/g,"");

	/** general / de / Chars **/

	v = v.replace(/ä/g,"ae");
	v = v.replace(/ü/g,"ue");
	v = v.replace(/ö/g,"oe");
	v = v.replace(/Ä/g,"Ae");
	v = v.replace(/Ü/g,"Ue");
	v = v.replace(/Ö/g,"Oe");
	v = v.replace(/ß/g,"ss");



	/*v = v.replace(.*(,|#|'|;|:|.)/g,"");*/

	if (field.value.substr(field.value.length-1) != "_" && v.substr(v.length-1) == '_'){
		v = v.substr(0,v.length-1);
	}
	field.value = v;
	if(focus){
		field.focus();
		doSetCaretPosition(field,caretP);
	}
}


function doGetCaretPosition (oField) {
	// Initialize
	var iCaretPos = 0;

	// IE Support
	if (document.selection) {

		// Set focus on the element
		oField.focus ();

		// To get cursor position, get empty selection range
		var oSel = document.selection.createRange ();

		// Move selection start to 0 position
		oSel.moveStart ('character', -oField.value.length);

		// The caret position is selection length
		iCaretPos = oSel.text.length;
	}
	// Firefox support
	else if (oField.selectionStart || oField.selectionStart == '0')
	iCaretPos = oField.selectionStart;

	// Return results
	return (iCaretPos);
}

function doSetCaretPosition (oField, iCaretPos) {

	// IE Support
	if (document.selection) {

		// Set focus on the element
		oField.focus ();

		// Create empty selection range
		var oSel = document.selection.createRange ();

		// Move selection start and end to 0 position
		oSel.moveStart ('character', -oField.value.length);

		// Move selection start and end to desired position
		oSel.moveStart ('character', iCaretPos);
		oSel.moveEnd ('character', 0);
		oSel.select ();
	}
	// Firefox support
	else if (oField.selectionStart || oField.selectionStart == '0') {
		oField.selectionStart = iCaretPos;
		oField.selectionEnd = iCaretPos;
		oField.focus ();
	}
}


function showVideoContainer(swfThumb, swfMovie){

	containerElement = eId('videolist_view_container');
	contentElement = eId('videolist_view_container_content');
	if (containerElement && contentElement){

		var dataForPost = new Object();
		dataForPost['swfThumb'] = swfThumb;
		dataForPost['swfMovie'] = swfMovie;

		var url = "/show_video_container/";

		$.ajax({
			url: url,
			type: 'POST',
			data: dataForPost,
			complete: function(XMLHttpRequest, textStatus) {
				contentElement.innerHTML = XMLHttpRequest.responseText;
				$("#videolist_view_container").toggle();
				$("#videolist_view_container_content").fadeIn(500);
				centerDiv(contentElement);
			}
		});
	}
}

function closeVideoContainer(){
	$("#videolist_view_container_content").fadeOut(1000);
	$("#videolist_view_container").fadeOut(500);
}


function centerDiv(node) {
	var x,y;

	if(window.innerWidth) {
		x = (window.pageXOffset+window.innerWidth);
		y = (window.pageYOffset+window.innerHeight);
	}
	else {
		x = (document.body.scrollLeft+document.body.offsetWidth);
		y = (document.body.scrollTop+document.body.offsetHeight)-450;
	}

	node.style.top = ((y-node.offsetHeight)/2)+'px';
	node.style.left = ((x-node.offsetWidth)/2)+'px';
}

$("select[id^=navigation_]").each(function() {
	$(this).mouseover(function() {
		switchNavigationElement(this);
	});
	$(this).mouseout(function() {
		switchNavigationElement(this);
	});
});

function checkBrowserName(name){
	var agent = navigator.userAgent.toLowerCase();
	if (agent.indexOf(name.toLowerCase())>-1) {
    	return true;
    }
    return false;
}

function showDropdown(elementId){
	element = eId(elementId);
	if(element){
		if(element.style.display == "none"){
			$('#'+elementId).slideDown(100);
		} else {
			$('#'+elementId).slideUp(100);
		}
	}
}

function setDropdownValue(elementId, elementValue, contentId, dropdownId){
	$('#'+elementId).val(elementValue);
	$('#'+contentId).html(elementValue);
	showDropdown(dropdownId);
}

function toggleMoreGuests()
{
	if ($('#hiddenGuests').is(':hidden'))
	{
		showMoreGuests();
	}
	else 
	{
		showLessGuests();
	}
}

function showMoreGuests()
{
	$('#hiddenGuests').slideDown('slow');
	$('a.guestToggle').html( $('#label_show_less').attr('value'));
}

function showLessGuests()
{
	$('#hiddenGuests').slideUp('slow');
	$('a.guestToggle').html( $('#label_show_more').attr('value'));
}
