var ajaxCache = true;
if (!teaserOut) {
	var teaserOut;      
}
jQuery(document).ready(function(){
	
	
	checkSuperBanner();
		
	//jQuery('input:submit').button();
    
	if (teaserOut) {
		jQuery.get('index.php?eID=mg_skiresort&action=teaserOut',teaserOut);
	}

	// Beim Browser zurück bleibt der alte wert stehen, damit nicht mehr:
	jQuery('.mapcontainer select[name=sort] option[selected=selected]').attr("selected", true);  

	jQuery('#cse-search-box').submit(function(){
		showLoading();   
	});   

	// Karte in Listen nach unten scrollen

	if (jQuery('.mapcontent .listcontainer').length > 0 && defaultMapOffset > 0) {
		jQuery('.mapcontent .listcontainer').scrollTop(defaultMapOffset);
	}



	var pid = jQuery('#resortListFilterForm input[name="pid"]').val() ;
	hideLoading();



	jQuery('#resortListFilterForm input[name="tx_mgskiresort_pi1[resortlist][specialfilter][open]"]').live('click',function(){
		showLoading();

		chk = 0;
		if (jQuery(this).is(':checked')) {
			chk = 1;
		}

		url = jQuery('#resortListFilterForm input[name="filterHref"]').val() + '&type=997';
		setResortlist(url,pid);
		jQuery.ajax({
			type: "GET",
			url: url,
			cache: ajaxCache,
			dataType: "html",

			success: function(response,textStatus){
				var html=jQuery('#resortList',response).html(); 
				jQuery('#resortList').html(html);
				updateContentAferAjaxInList(response);
				hideLoading();
			}
		});

	});




	// *********************************************************



	jQuery('.sortfields a').live('click',function(){
		//return true;
		showLoading(); 
		var clickedElement = this;

		jQuery('.sortfields a').each(function(index){
			if (clickedElement != this) {
				jQuery(this).addClass('init');
			} else {
				jQuery(this).removeClass('init');
			}
		})  ;

		var sort =  jQuery(clickedElement).attr('href');
		var sortDir =  jQuery(clickedElement).attr('class');
		var filter = jQuery('#resortListFilterForm').serialize();
		if (sortDir == 'desc') {
			jQuery(clickedElement).attr("class","asc");
		} else {
			jQuery(clickedElement).attr("class","desc");
		}
		url = jQuery(this).attr('href') + '&type=997';
		setResortlist(url,pid);

		jQuery.ajax({
			type: "GET",
			url: url,
			cache: ajaxCache,
			dataType: "html",
			success: function(response,textStatus){
				var html=jQuery('#resortList',response).html(); 
				jQuery('#resortList').html(html);
				updateContentAferAjaxInList(response);
				hideLoading();
			}
		});
		return false;
	});

	// *********************************************************
	// Vor/Zurück in Resortliste

	jQuery('.pagebrowser a').live('click',function(){
		showLoading();
		return true;
	});




	jQuery.extend({
		searchResort: function(){
			showLoading(); 
			var sword = jQuery('#resortListSearch input[name="tx_mgskiresort_pi1[resortlist][sword]"]').val();

			//jQuery.get('ajax');
			ajaxURL = jQuery('#resortListSearch input[name="searchformaction"]').val() + '?&type=997&tx_mgskiresort_pi1[action]=getSearchURL&tx_mgskiresort_pi1[resortlist][sword]='+encodeURIComponent(sword) + '&tx_mgskiresort_pi1[resortlist][sword_h]='+encodeURIComponent(sword);
			jQuery.get(ajaxURL,function(data){
				window.location = data;
			});




		},
		updateSearchInput: function(e) {
            /*
			if (e.val() != searchDefaultVal ) {
				jQuery('#resortListSearch input[name="tx_mgskiresort_pi1[resortlist][sword]"]').val(e.val());
			}
			if (e.val() == ''){
				e.val(searchDefaultVal);
				jQuery('#resortListSearch input[name="tx_mgskiresort_pi1[resortlist][sword]"]').val('');
			}*/
			jQuery('#resortListSearch input[name="tx_mgskiresort_pi1[resortlist][sword]"]').val(e.val());  
			return true;  
		}
	});

	var regionSubmit;
	jQuery.extend({
		regionTheatreClick:  function(e,dbl) {
			regionSubmit = 0;
			jQuery('#theatreSelect div.buttons').html('');
			jQuery('#countrySelect div.buttons').html('');
			jQuery('#countrySelect select').html('');
			
			jQuery('#regionSelect div.buttons').html('');
			jQuery('#regionSelect select').html('');
			
			jQuery('#localregionSelect div.buttons').html('');
			jQuery('#localregionSelect select').html('');
			
			
			url = ajaxURL + '&tx_mgskiresort_pi1[action]=location&tx_mgskiresort_pi1[location][theatre]=' + e.val() + '&tx_mgskiresort_pi1[piVars]=' + jQuery('#regionSelectForm input[name="pivars"]').val();
			jQuery.ajax({
				type: "POST",
				url: url,
				cache: false,
				dataType: "html",
				success: function(response,textStatus){
					formAction = jQuery(response).find('#regionSelectForm').attr('action');
					if (dbl) {
						location.href= formAction;
					} else {
						html = jQuery(response).find('#countrySelect').html();
						regionSubmit = 1;
						jQuery('#countrySelect').html(html);
						
						button = jQuery(response).find('#theatreSelect div.buttons').html();
						jQuery('#theatreSelect div.buttons').html(button);
						
						     
						
					}

				}
			});
		},
		regionCountryClick:  function(e,dbl) {
			regionSubmit = 0;
			jQuery('#countrySelect div.buttons').html('');
			
			jQuery('#regionSelect div.buttons').html('');
			jQuery('#regionSelect select').html('');
			
			jQuery('#localregionSelect div.buttons').html('');
			jQuery('#localregionSelect select').html('');
			
			var theatre = jQuery('#headerregioncontent select[name="tx_mgskiresort_pi1[location][theatre]"]').val();
			url = ajaxURL + '&tx_mgskiresort_pi1[action]=location&tx_mgskiresort_pi1[location][country]=' + e.val() + '&tx_mgskiresort_pi1[location][theatre]=' + theatre + '&tx_mgskiresort_pi1[piVars]=' + jQuery('#regionSelectForm input[name="pivars"]').val();
			jQuery.ajax({
				type: "POST",
				url: url,
				cache: false,
				dataType: "html",
				success: function(response,textStatus){
					formAction = jQuery(response).find('#regionSelectForm').attr('action');

					
					html = jQuery(response).find('#regionSelect').html();
					jQuery('#regionSelect').html(html);
					button = jQuery(response).find('#countrySelect div.buttons').html();
					jQuery('#countrySelect div.buttons').html(button);
					
					regionSubmit = 1;
					

					if (html == "") {
						jQuery('#headerregioncontent .regionshow').hide();
						jQuery('#headerregioncontent .regions').hide() ;                             
					} else {
						jQuery('#headerregioncontent .regionshow').show();
						jQuery('#headerregioncontent .regions').hide() ;
					} 

				}
			});    
		},
		regionRegionClick: function(e,dbl){
			regionSubmit = 0;
			jQuery('#regionSelect div.buttons').html(''); 
			
			
			jQuery('#localregionSelect div.buttons').html('');
			jQuery('#localregionSelect select').html('');
			
			var theatre = jQuery('#headerregioncontent select[name="tx_mgskiresort_pi1[location][theatre]"]').val();
			var country = jQuery('#headerregioncontent select[name="tx_mgskiresort_pi1[location][country]"]').val();
			url = ajaxURL + '&tx_mgskiresort_pi1[action]=location&tx_mgskiresort_pi1[location][region]=' + e.val() + '&tx_mgskiresort_pi1[location][theatre]=' + theatre + '&tx_mgskiresort_pi1[location][country]=' + country + '&tx_mgskiresort_pi1[piVars]=' + jQuery('#regionSelectForm input[name="pivars"]').val();
			jQuery.ajax({
				type: "POST",
				url: url,
				cache: false,
				dataType: "html",
				success: function(response,textStatus){
					formAction = jQuery(response).find('#regionSelectForm').attr('action');
                    html = jQuery(response).find('#localregionSelect select').html();
                    jQuery('#localregionSelect select').html(html);     
					button = jQuery(response).find('#regionSelect div.buttons').html();
					jQuery('#regionSelect div.buttons').html(button);
                    regionSubmit = 1; 
					
				}
			});     
		},
		localregionRegionClick: function(e,dbl){
			regionSubmit = 0;
			
			jQuery('#localregionSelect div.buttons').html(''); 
			var theatre = jQuery('#headerregioncontent select[name="tx_mgskiresort_pi1[location][theatre]"]').val();
			var country = jQuery('#headerregioncontent select[name="tx_mgskiresort_pi1[location][country]"]').val();
			var region = jQuery('#headerregioncontent select[name="tx_mgskiresort_pi1[location][region]"]').val();
			
			url = ajaxURL + '&tx_mgskiresort_pi1[action]=location&tx_mgskiresort_pi1[location][localregion]=' + e.val() + '&tx_mgskiresort_pi1[location][theatre]=' + theatre + '&tx_mgskiresort_pi1[location][country]=' + country + '&tx_mgskiresort_pi1[location][region]=' + region + '&tx_mgskiresort_pi1[piVars]=' + jQuery('#regionSelectForm input[name="pivars"]').val() ;
			jQuery.ajax({
				type: "POST",
				url: url,
				cache: false,
				dataType: "html",
				success: function(response,textStatus){
					formAction = jQuery(response).find('#regionSelectForm').attr('action');
                    button = jQuery(response).find('#localregionSelect div.buttons').html();
					jQuery('#localregionSelect div.buttons').html(button);
					
                    regionSubmit = 1; 
					
				}
			});     
		},
		
		submitRegionSelectForm: function(){
			href =  jQuery('#regionSelectForm a.submit').attr('href');
			if (regionSubmit == 0) {
				setTimeout(function(){
					jQuery.submitRegionSelectForm();
				},20);
			} else {
				location.href= href;    
			}

		} 
	});

	jQuery('.tx-mgskiresort-pi1 .detail .testReport').mouseover(function(){
		jQuery(this).addClass('link');

	}).mouseout(function(){
		jQuery(this).removeClass('link');
	});




	// *********************************************************
	// Tooltip
	jQuery('div.resortDetail a.tooltip').each(function(){
		jQuery(this).qtip({   show: 'mouseover',
			hide: 'mouseout',
			position: {
				corner: {
					target: 'topLeft',
					tooltip: 'bottomLeft'
				}
			},
			content: {
				url: 'index.php?id=42&type=997&tx_mgskiresort_pi1[action]=getToolTip'  ,
				data: { 'tx_mgskiresort_pi1[tid]': jQuery(this).attr('id') },
				method: 'get'
			},
			style: {   
				name: 'light', 
				tip: 'bottomLeft',
				width: 600,
				border: {
					width: 5,
					radius: 5,
					color: '#CDDCE5'
				} 
			} 
		});    


	});

	jQuery('div.mapcontainer a.tooltip').each(function(){
		jQuery(this).qtip({   show: 'mouseover',
			hide: 'mouseout',
			position: {
				corner: {
					target: 'bottomLeft',
					tooltip: 'topLeft'
				}
			},
			content: {
				url: 'index.php?id=42&type=997&tx_mgskiresort_pi1[action]=getToolTip'  ,
				data: { 'tx_mgskiresort_pi1[tid]': jQuery(this).attr('id') },
				method: 'get'
			},
			style: {   
				name: 'light', 
				tip: 'topLeft',
				width: 600,
				border: {
					width: 5,
					radius: 5,
					color: '#CDDCE5'
				} 
			} 
		});    


	});

	jQuery('a.tooltipstatic[title]').css('cursor','pointer'); 
	jQuery('a.tooltipstatic[title]').qtip({ 
		hide: 'mouseout',
		position: {
			corner: {
				target: 'bottomLeft',
				tooltip: 'topLeft'
			}
		},
		style: {   
			name: 'light', 
			tip: 'topLeft',
			width: { 
				min: 120 ,
				max: 450
			},
			border: {
				width: 5,
				radius: 5,
				color: '#CDDCE5'
			} 
		}

	} )


	jQuery('.contactFailureForm form input[type=submit]').click(function(){
		jQuery('.contactFailureForm #loadingBg').show();
		jQuery('.contactFailureForm #loading').show();

		jQuery('.contactFailureForm #loading').css('background-image','url(/typo3conf/ext/mg_skiresort/res/img/ajax-loader_contactForm.gif)');

	});
	jQuery('.contactFailureForm form').submit(function() {
		if (jQuery('.contactFailureForm form textarea').val() == '') {
			jQuery('.contactFailureForm #loadingBg').hide();
			jQuery('.contactFailureForm #loading').hide();
			jQuery('label[for=tx_mgskiresort_pi1[desc]]').append('<span style="color:red"><br/ >Dieses Feld darf nicht leer bleiben.</span>');
			jQuery('textarea[name=tx_mgskiresort_pi1[desc]]').css('border','1px solid red');

			return false;          
		}

	});









});

function goToByScroll(id){
	jQuery('html,body').animate({scrollTop: jQuery("#"+id).offset().top},'slow');
}
function setResortlist(url,pid){
	//console.log(url) ;
	jQuery.post('index.php?eID=mg_skiresort&action=setResortlist&url=' + encodeURIComponent(url) + '&pid=' + pid); 
}

function setExit() {
	//jQuery.post('index.php?eID=mg_skiresort&action=setExit' ); 
}
function resetExit() {
	//alert('resetExit');
	//jQuery.post('index.php?eID=mg_skiresort&action=resetExit' );

}

function getListInfoAndUpdate() {
	jQuery.post('index.php?eID=mg_skiresort&action=getListInfo' ,'' , function(data){
		url = jQuery(data).find('ret').text() + '&type=997';
		getResortList(url);        
	},'xml');
}
function getExit() {

}

function getResortList(url) {
	showLoading();
	jQuery.ajax({
		type: "GET",
		url: url,
		cache: ajaxCache,
		dataType: "html",

		success: function(response,textStatus){
			var html=jQuery('#resortList',response).html(); 
			jQuery('#resortList').html(html);
			updateContentAferAjaxInList(response);
			hideLoading();
		}
	});

}


function activateRegion(region,srcOrg,MapCountry) {
	jQuery('.regiontext ul').find('a[id="'+region+'"]').addClass('aktiv') ;
	if (srcOrg) {
		//file = srcOrg.substring(mapFolder.length+2,srcOrg.length) ;
		file = jQuery.url.setUrl(srcOrg).attr('file');
		type = file.slice(0,1);
		filname= type+MapCountry+region+'.png';
		newSrc = baseURL +  mapFolder + '/'+ filname;
		//console.log(newSrc);

		jQuery('.mapcontainer .mapcontent img').attr('src', newSrc);    
	}


}

function deActivateRegion(region,srcOrg,MapCountry) {
	jQuery('.regiontext ul').find('a[id="'+region+'"]').removeClass('aktiv') ;
	if (srcOrg) {
		jQuery('.mapcontainer .mapcontent img').attr('src', srcOrg);
	}
}

function updateContentAferAjaxInList(response) {
	jQuery('.pagebrowser').html(jQuery('.pagebrowser',response).html());
	jQuery('.sortfields .right').html(jQuery('.sortfields .right',response).html());
	jQuery('#resortListFilterForm').html(jQuery('#resortListFilterForm',response).html());

	piVars = jQuery('#resortListFilterForm input[name="piVars"]',response).val();
	jQuery('#resortListFilterForm input[name="piVars"]').val(piVars);

	searchHeader = jQuery('.searchheader .text',response).html();
	jQuery('.searchheader .text').html(searchHeader);

	fieldsite = jQuery('.searchfields .fieldsite',response).html();

	jQuery('.searchfields .fieldsite').html(fieldsite);


}
//show loading bar

function showLoading(){
	if(jQuery("#loader").length == 0){
		jQuery('<div id="loader"><div id="loaderInner"><img src="/typo3conf/ext/mg_skiresort/res/img/ajax-loader_contactForm.gif" /></div></div>').appendTo('body');
		jQuery("#loader").show();
		//jQuery('#loaderInner').css('background-image','url(/typo3conf/ext/mg_skiresort/res/img/ajax-loader_contactForm.gif)');
		//jQuery('#loader').fadeTo(100,1);    

	}

}
//hide loading bar
function hideLoading() {
	jQuery('#resortList').show();
	jQuery("#loader").fadeTo(100, 0);
	/*jQuery('#resortList').fadeTo(250, 1);*/

	jQuery("#loader").remove();

};

function loadWebcams(uid) {
	return true;

	if (jQuery('#detailcontent .nav3_3').length > 0 ) {
		url = ajaxURL + '&tx_mgskiresort_pi1[action]=webcamsAll&tx_mgskiresort_pi1[uid]=' + uid;    
		showLoadingWebcams();
		jQuery.ajax({
			type: "GET",
			url: url,
			cache: ajaxCache,
			dataType: "html",
			success: function(response,textStatus){
				var html=jQuery('#content',response).html(); 
				jQuery('#detailcontent .nav3_3').html(html);
				hideLoadingWebcams();
			}
		});
	}
}


function showLoadingWebcams(){
	jQuery('#detailcontent .nav3_3').html('<div id="loader" ></div>');
	jQuery('#loader').fadeTo(100,1);
}
//hide loading bar
function hideLoadingWebcams(){
	jQuery("#loader").fadeTo(100, 0);
	jQuery("#loader").remove();

};

function preDomLoad() {
	
	checkSuperBanner();
	// Elemente aktivieren!
	jQuery('.mapcontainer select[name=sort]').attr('disabled', false);
	jQuery('#resortListSearch input[name="sword"]').attr('disabled', false); 
	jQuery('.autoclear').autoclear();

	jQuery('input[name="tx_mgskiresort_pi1\\[resortlist\\]\\[specialfilter\\]\\[open\\]"]').attr('disabled', false); 


	jQuery('#cse-search-box input[name="q"]').removeAttr('disabled'); 
	// der Chrome behält sonst immer seine ausgegraute Farbe, blöder Workaround: 
	jQuery('#cse-search-box input[name="q"]').focus();
	jQuery('#cse-search-box input[name="q"]').blur();


	jQuery('#headerregionbutton').removeClass('inactive');
	jQuery('#headerregionbutton DIV.button img').removeClass('inactive'); 



	// Sortierung in Resortliste
	jQuery('.mapcontainer select[name=sort]').change(function(){
		showLoading();
		jQuery(this).attr('disabled', true); 
		window.location = jQuery(this).val();

	});

	// *********************************************************
	// Suche in Resortliste
	jQuery('#resortListSearch input[name="sword"]').keyup(function(e) {
		//console.log(e.keyCode);
		jQuery.updateSearchInput(jQuery(this));
		if(e.keyCode == 13) { 
			jQuery.searchResort();    
		}       

	});
	jQuery('#resortListSearch input[name="submit"]').click(function(){
		jQuery.searchResort();
		return false;
	});
	jQuery('#resortListSearch input[name="reset"]').click(function(){
		showLoading();
		window.location = jQuery('#resortListSearch input[name="searchresetaction"]').val();
	});
	// *********************************************************
	// Leeren des Suchfelds 
	/*
	jQuery('#resortListSearch input[name="sword"]').focus(function(){
		var sword = jQuery(this).val();
		jQuery('#resortListSearch input[name="sword_h"]').val(sword);
		if (jQuery(this).val() == searchDefaultVal) {
			jQuery(this).val('');       
		}
	} );

	jQuery('#resortListSearch input[name="sword"]').blur(function(){
		jQuery.updateSearchInput(jQuery(this));
	});
    */

	// *********************************************************
	// Regionen Auswahl oben (Ausklappbox)
	jQuery('#headerregioncontent select[name="tx_mgskiresort_pi1[location][theatre]"]').live('click',function(){
		jQuery.regionTheatreClick(jQuery(this),false);    
	});

	jQuery('#headerregioncontent select[name="tx_mgskiresort_pi1[location][country]"]').live('click',function(){
		jQuery.regionCountryClick(jQuery(this),false);
	});

	jQuery('#headerregioncontent select[name="tx_mgskiresort_pi1[location][region]"]').live('click',function(){
		jQuery.regionRegionClick(jQuery(this),false);
	});
	
	jQuery('#headerregioncontent select[name="tx_mgskiresort_pi1[location][localregion]"]').live('click',function(){
		jQuery.localregionRegionClick(jQuery(this),false);
	});
	


	jQuery('#regionSelectForm a.submit').live('click',function(e){
		jQuery.submitRegionSelectForm();
		e.preventDefault();

	});

	jQuery('#headerregioncontent .regionshow').live('click', function(){
		jQuery(this).hide();
		jQuery('#headerregioncontent .regions').show();
		return false;
	});

	// *********************************************************
	// Suche rechts oben
	var globalSearchDefaultVal = jQuery('#tx-indexedsearch-searchbox-sword').val();
	jQuery('#tx-indexedsearch-searchbox-sword').focus(function() {
		if (jQuery(this).val() == globalSearchDefaultVal) {
			jQuery(this).val('');    
		}  
	});
	jQuery('#tx-indexedsearch-searchbox-sword').blur(function() {
		if (jQuery(this).val() == '') {
			jQuery(this).val(globalSearchDefaultVal);    
		}  
	});
	if (jQuery('#detailcontent .nav3_3').length > 0 ) { 
		jQuery(".nav3_3 a.fancygroup").livequery(function(){
			jQuery(this).fancybox();
		});
	}

	// *********************************************************
	// hover auf div funtkioniert beim IE leider nicht
	jQuery('#headerregionbutton').hover(function(){
		jQuery(this).children('.headerregionbuttontext').toggleClass('highlight');
		jQuery('#headerregionbutton .buttonWrapper').toggleClass('highlight');
	});

	// *********************************************************
	// ausklappen Testbericht langtext
	jQuery('#detailcontent .testreporttext').css('cursor','pointer');
	jQuery('#detailcontent .testreporttext').click(function() {
		if (jQuery('#detailcontent .testreporttext.short').is(':visible')) {
			jQuery('#detailcontent .testreporttext.short').hide();
			jQuery('#detailcontent .testreporttext.long').show();
		} else {
			jQuery('#detailcontent .testreporttext.short').show();
			jQuery('#detailcontent .testreporttext.long').hide();    
		}

	});



	// *********************************************************
	// Ein / auskplappen beim Testbericht
	//Box für die Testbericht Show Hide
	jQuery('.result .testberichte .colexp').click(function(event){
		jQuery(this).fadeOut("fast");
		jQuery(this).fadeIn("slow");
		jQuery(this).toggleClass("aktiv");
		if (jQuery(this).next('div.rowshowhide').css('display') == 'none') { 
			jQuery(this).next('div.rowshowhide').slideDown("slow");
		} else {
			jQuery(this).next('div.rowshowhide').slideUp("slow");
		}
		//jQuery(this).next('div.rowshowhide').slideToggle("slow");
		event.preventDefault();
	});

	jQuery('.result .testberichte .rowshowhide .button a').click(function(event){
		jQuery(this).parent('div.button').parent('div.rowshowhide').slideUp("slow");
		jQuery(this).parent('div.button').parent('div.rowshowhide').prev('div.row').fadeOut("fast");
		jQuery(this).parent('div.button').parent('div.rowshowhide').prev('div.row').fadeIn("slow");
		jQuery(this).parent('div.button').parent('div.rowshowhide').prev('div.row').removeClass("aktiv");
		event.preventDefault();
	});

	// *********************************************************
	// Zählen der extenen Links
	jQuery("a[href^='http:']").not("[href*='"+baseURL+"']").click(function(){
		jQuery.post('index.php?eID=mg_skiresort&action=externalLink','url=' + jQuery(this).attr('href')) ;
	});


	// *********************************************************
	// Sprungmarke beim Testbericht
	var anchor = jQuery.url.attr("anchor");
	if (anchor) {
		jQuery('a[id="' + anchor + '"]').parent().click();
		goToByScroll(anchor); 
	}

	// *********************************************************
	// Karte in Resorliste
	var srcOrg = jQuery('.mapcontainer .mapcontent img').attr('src');
	var MapCountry = jQuery('.mapcontainer #MapCountry').val();


	jQuery('.mapcontainer .regiontext a').mouseover(function(){
		region = jQuery(this).attr('id');

		if (region != '') {
			activateRegion(region,srcOrg,MapCountry);    
		}

	});
	jQuery('.mapcontainer map area').mouseover(function(){
		region = jQuery(this).attr('id');
		region = region.substring(1,region.length);
		activateRegion(region,srcOrg,MapCountry);    
	});

	jQuery('.mapcontainer .regiontext a').mouseleave(function(){
		region = jQuery(this).attr('id');
		if (region != '' ) {
			deActivateRegion(region,srcOrg,MapCountry);
		}
	});
	jQuery('.mapcontainer map area').mouseleave(function(){
		region = jQuery(this).attr('id');
		region = region.substring(1,region.length);
		deActivateRegion(region,srcOrg,MapCountry);

	});

	jQuery('.mapcontainer .moveup').mouseover(function(){
		var topVal = jQuery(this).parents(".map").find(".mapcontent").css("top");
		jQuery(this).parents(".map").find(".mapcontent").css("top", topVal-10);

	});



	// *********************************************************
	// Filter in Resortliste
	jQuery('input[name="tx_mgskiresort_pi1[resortlist][specialfilter][open]"]').click(function(){
		showLoading();
		window.location = jQuery('input[name="filterURL"]').val();
	});

	//**********************************
	//  Webcams

	if (jQuery('.webcamPreview.loader div').length > 0) {

		webcamUid = parseInt(jQuery('.webcamPreview.loader div').html());
		jQuery('.webcamPreview.loader div').each(function(){

			var targetEl = jQuery(this).parent();
			var webcam = jQuery(this).html();
			var webcamArray = webcam.split(";");
			webcamUid = parseInt(webcamArray[0]);
			type = webcamArray[1];
			url = ajaxURL + '&tx_mgskiresort_pi1[action]=webcamSingle&tx_mgskiresort_pi1[webcam]=' + webcamUid + '&tx_mgskiresort_pi1[type]=' + type; 

			jQuery.ajax({
				type: "POST",
				url: url,
				cache: false,
				dataType: "html",
				success: function(response,textStatus){

					targetEl.html(response);
					targetEl.removeClass('loader');        

				}
			});

		});

	}


	// Fancybox
	jQuery("a.fancygroup").fancybox({
		'zoomSpeedIn': 300, 
		'zoomSpeedOut': 300, 
		'overlayShow': true, 
		'imageScale': true
	});
	jQuery("a.fancygroup").removeAttr('onclick');
	
	 

}


// Tiscover
jQuery(document).ready(function() {
	jQuery("#jse").val("1");
	jQuery("#c, #c0, #c1, #c2, #c3").change(cChanged);
	if (lang == 'de') {
		jQuery("#sd").val(jQuery.datepicker.formatDate('dd.mm.yy', new Date(new Date().getTime() + (1000*60*60*24))));
		jQuery("#ed").val(jQuery.datepicker.formatDate('dd.mm.yy', new Date(new Date().getTime() + (1000*60*60*24*8))));
	} else {
		jQuery("#sd").val(jQuery.datepicker.formatDate('dd/mm/yy', new Date(new Date().getTime() + (1000*60*60*24))));
		jQuery("#ed").val(jQuery.datepicker.formatDate('dd/mm/yy', new Date(new Date().getTime() + (1000*60*60*24*8))));
	}
	jQuery("#sd").datepicker({dependOn: "#ed", triggerHandle: "#sd-handle"});
	jQuery("#ed").datepicker({minDate: '1d', dependOn: "#sd", triggerHandle: "#ed-handle", beforeShowDay : jQuery.datepicker.disableDatesBeforeDependentDatepickerValue, monthPosBasedOnDependent: true }); 

	jQuery(function(){
        jQuery.datepicker.regional['de'] = {clearText: 'löschen', clearStatus: 'aktuelles Datum löschen',
			closeText: 'schließen', closeStatus: 'ohne Änderungen schließen',
			prevText: '&#x3c;zurück', prevStatus: 'letzten Monat zeigen',
			nextText: 'Vor&#x3e;', nextStatus: 'nächsten Monat zeigen',
			currentText: 'heute', currentStatus: '',
			monthNames: ['Januar','Februar','März','April','Mai','Juni',
			'Juli','August','September','Oktober','November','Dezember'],
			monthNamesShort: ['Jan','Feb','Mär','Apr','Mai','Jun',
			'Jul','Aug','Sep','Okt','Nov','Dez'],
			monthStatus: 'anderen Monat anzeigen', yearStatus: 'anderes Jahr anzeigen',
			weekHeader: 'Wo', weekStatus: 'Woche des Monats',
			dayNames: ['Sonntag','Montag','Dienstag','Mittwoch','Donnerstag','Freitag','Samstag'],
			dayNamesShort: ['So','Mo','Di','Mi','Do','Fr','Sa'],
			dayNamesMin: ['So','Mo','Di','Mi','Do','Fr','Sa'],
			dayStatus: 'Setze DD als ersten Wochentag', dateStatus: 'Wähle D, M d',
			dateFormat: 'dd.mm.yy', firstDay: 1, 
			initStatus: 'Wähle ein Datum', isRTL: false};

		jQuery.datepicker.regional['en'] = {dateFormat: 'dd/mm/yy'};
		if (lang=='de') {
			jQuery.datepicker.setDefaults(jQuery.datepicker.regional['de']);
		} else {
			jQuery.datepicker.setDefaults(jQuery.datepicker.regional['en']);
		}
	});

	jQuery.datepicker.setDefaults({
		numberOfMonths : 2,
		showOtherMonths : true,
		showOn : 'both',
		prevText : 'vorheriges Monat',
		nextText : 'n&auml;chstes Monat',
		closeText : 'Fenster schlie&szlig;en',  
		monthNames : ['Januar','Februar','M&auml;rz','April','Mai','Juni','Juli','August','September','Oktober','November','Dezember'],
		monthNamesShort : ['Jan','Feb','M&auml;r','Apr','Mai','Jun','Jul','Aug','Sep','Okt','Nov','Dez'],
		dayNames : ['Sonntag','Montag','Dienstag','Mittwoch','Donnerstag','Freitag','Samstag'],
		dayNamesMin : ['So','Mo','Di','Mi','Do','Fr','Sa'],
		dateFormat : 'dd.mm.yy',
		altFormat : 'dd.mm.yy',
		firstDay : 1, 
		minDate : '0d',
		maxDuration : 50,
		onClose : function(date) {
			
			var startDate = jQuery.datepicker.parseDate('dd.mm.yy', jQuery("#sd").val());
			var endDate = jQuery.datepicker.parseDate('dd.mm.yy', jQuery("#ed").val()); 
			if (startDate.getTime() >= endDate.getTime()) {
				jQuery("#ed").val(jQuery.datepicker.formatDate('dd.mm.yy', new Date(startDate.getTime() + (1000*60*60*24))));
			}
			//jQuery.datepicker.validate("#sd", "#ed", "#datepickerErrorField"); 
		},
		beforeShowDay : jQuery.datepicker.highlightDependentDatepickerValue,
		errmsg_invalidformat : 'Ung&uuml;ltiges Datumsformat',
		errmsg_dateinpast : 'Datum liegt in der Vergangenheit!',
		errmsg_todateafterfromdate : 'Abreisedatum vor Anreisedatum!',
		errmsg_invalidduration : 'Reisedauer muss k&uuml;rzer als 50 Tage sein!'
	});


});

function cChanged() {
	(this.id.length == 1) ? id = "" : id = this.id.substr(1);
	value = jQuery(this).val();
	jQuery("#room"+id+" #ca").addClass("h");
	jQuery("#room" + id + " .cage").addClass("h");
	jQuery("#room" + id + " .cage input").attr("disabled", "disabled");

	if (value > 0) {
		for (i = 0; i < value; i++) {
			jQuery("#room" + id + " .rca" + i + ", #room" + id + " #ca").removeClass("h");
			jQuery("#room" + id + " .rca" + i + " select").attr("disabled", null);
		}
	}
}

/** missing functionality 
* copy values from #room to #room1 when nr of rooms changed
* after changing of room lines examine values of chage to correctly display chage select boxes
*/





if (jQuery.browser.msie) {
	if (parseInt(jQuery.browser.version, 10) < 7) {
		jQuery.datepicker.setDefaults({
			duration: '',
			numberOfMonths: 1,
			beforeShowDay : jQuery.datepicker.highlightDependentDatepickerValue
		});
	} else if (parseInt(jQuery.browser.version, 10) < 8) {
		jQuery.datepicker.setDefaults({
			duration: '',
			numberOfMonths: 2,
			beforeShowDay : jQuery.datepicker.highlightDependentDatepickerValue
		});
	}
}

Date.prototype.toJulianDate = function() {
	MM = this.getMonth() + 1;
	DD = this.getDate();
	YY = this.getFullYear();
	with (Math) {  
		GGG = 1;
		if (YY <= 1585) GGG = 0;
		JD = -1 * floor(7 * (floor((MM + 9) / 12) + YY) / 4);
		S = 1;
		if ((MM - 9)<0) S=-1;
		A = abs(MM - 9);
		J1 = floor(YY + S * floor(A / 7));
		J1 = -1 * floor((floor(J1 / 100) + 1) * 3 / 4);
		JD = JD + floor(275 * MM / 9) + DD + (GGG * J1);
		JD = JD + 1721027 + 2 * GGG + 367 * YY;
	}
	return JD;
};

function checkSuperBanner() {
	if (jQuery('#adWrapper a img').height() != 1 ) {
		jQuery('#adWrapper').addClass('hasAd');
	}
}
