function hvr0 (a) {
	$(a).getElement('a').setStyle('background-position', '0px -40px');
}

function dvt0 (a) {
	$(a).getElement('a').setStyle('background-position', '0px 0px');
}

function hvr(a) {
	$(a).getParent('li').getElement('a').setStyle('background-position', '0px -40px');
}

function dvt(a) {
	$(a).getParent('li').getElement('a').setStyle('background-position', '0px 0px');
}

function nhvr (a, b, c, d, e, f) {
	$(a).setStyle('z-index', b);
	$(a).setStyle('visibility', c);
	$(d).setStyle('background-position', e+'px '+f+'px');
}


var startMenu = function() {
if (document.all&&document.getElementById) 
{
	cssmenu = document.getElementById("csstopmenu");
	for (i=0; i<cssmenu.childNodes.length; i++) 
	{
		node = cssmenu.childNodes[i];
		if (node.nodeName=="LI") 
		{
			node.onmouseover=function() 
			{
				this.className+=" over";
			}
			node.onmouseout=function()
			{                  
				this.className=this.className.replace(" over", "")
			}
		}
	}
}
}



if (window.attachEvent)
window.attachEvent("onload", startMenu)
else
window.onload=startMenu;

window.addEvent('domready', function() { 
	myCal = new Calendar({ anreise: { anreise: 'd.m.Y' }, abreise: { abreise: 'd.m.Y' }}, { direction: 0, tweak: {x: 0, y: 0} });
    myCal_f = new Calendar({ anreise_f: { anreise_f: 'd.m.Y' }}, { direction: 1, tweak: {x: 0, y: 0} });
    myCal_b = new Calendar({ anreise_b: { anreise_b: 'd.m.Y' }, abreise_b: { abreise_b: 'd.m.Y' }}, { direction: 0, tweak: {x: 0, y: 0} });
    myCal_b_f = new Calendar({ anreise_b_f: { anreise_b_f: 'd.m.Y' }}, { direction: 1, tweak: {x: 0, y: 0} });
	myCal_d = new Calendar({ uid1189: { uid1189: 'd.m.Y' }, uid1190: { uid1190: 'd.m.Y' }}, { direction: 0, tweak: {x: 0, y: 0} });
	
	myCal = new Calendar({ anreisefewo: { anreisefewo: 'd.m.Y' }}, { direction: 0, tweak: {x: 0, y: 0} });
	
	/*
	if ($('box_video_bilder_tab'))
	{
  	tabbottom = new MGFX.Tabs('#box_video_bilder_tab','.box_content_gallery',{
          				            autoplay: false,
          				            transitionDuration:500,
          				            slideInterval:6000,
          				            startIndex: 0,
          				            hover:true
          			       });
	
	$('tabb1').addEvent('click', function(e){
		e.stop();
		$('box_video_bilder_tab').setStyle('background-position', '0px 0px');
	});

	$('tabb2').addEvent('click', function(e){
		e.stop();
		$('box_video_bilder_tab').setStyle('background-position', '0px -21px');

	});


	};
	*/
	
	
	/////////////////////////////////////////////////////
	/// Box Cart
	/////////////////////////////////////////////////////
	
	
	if($('status_cart')){

	}else{
		if ($('warenkorbRight')){
			var rand = Math.floor(10000 * Math.random());
			var host = window.location.host;
			var pageL=0;
			if ($('system_language_uid')){
				pageL=$('system_language_uid').get('value');
			}
			
			var season=0;
			if ($('system_season')) 
			{
				season=$('system_season').get('value');
			}
			var id_season=new Array('1390', '1533');
			
			var link_php_shop='http://'+host+'/index.php?id='+id_season[season]+'&L='+pageL+'&rand='+rand;
				var log = $('warenkorbRight').empty();
				var req = new Request({   
					url: link_php_shop,     
					method: 'get',    
					onComplete: function(response) {    
						$('warenkorbRight').setStyle('opacity','0');	
						$('warenkorbRight').set('html',response);  
						var fx = new Fx.Tween('warenkorbRight',{duration : 1200});	
						fx.start('opacity', '0', '1');
					}   
				}).send();   
		}
	}
	
	/////////////////////////////////////////////////////
	/// Bottom livecams
	/////////////////////////////////////////////////////
	
	if ($('bottom_livecams'))
	{
		var pageL=0;
		if ($('system_language_uid')) 
		{
				pageL=$('system_language_uid').get('value');
		}
		
		var host = window.location.host;
		var rand = Math.floor(10000 * Math.random());		
		var link_php_bottom_livecams='http://'+host+'/fileadmin/files/livecamsbottom/livecams_'+pageL+'.html?rand='+rand;
	
	
		var req = new Request({   
			url: link_php_bottom_livecams,     
			method: 'get',    
			onComplete: function(response) 
			{  	
				$('bottom_livecams').setStyle('opacity','0');
				$('bottom_livecams').setStyle('display','block');
				$('bottom_livecams_ajax').set('html',response);  
				var fx = new Fx.Tween('bottom_livecams',{duration : 1200});	
				fx.start('opacity', '0', '1');
				Mediabox.scanPage();
			}   
		  }).send(); 
	}

	
	/////////////////////////////////////////////////////
	/// List Button Social
	/////////////////////////////////////////////////////
	
	var listButtonSocial= new Class({
	
		Implements: [Options, Events],
		options: {
			globalLock: false,
			listProcessPage: null,
			statusButton: new Array(),
			listButtonElement: new Array()
		},
		
		
		initialize: function(options){
				
				this.setOptions(options);
				
				$$('#buttonsocial_list div').each(function(elm,index){ 
				
					this.options.statusButton[index]=0;
					this.options.listButtonElement[index]=elm;
					
					$(elm).addEvent('click', function(event){
						
						if(!this.options.globalLock)
						{
							this.options.globalLock=true;
							
							if (this.options.statusButton[index]==0) 
							{
								//Bottone non selezionato
							
								//controllo se non ci sono bottoni selezionati
								var indexButtonOpen=this.options.statusButton.indexOf(1);	
								if (indexButtonOpen==-1)
								{
									//Nessun altro bottone selezionato, apro il box
									event.stop();
									this.openClose();
									(function(){  this.options.globalLock=false;  }.bind(this)).delay(750);
								}
								else
								{
									//C'è bottone selezionato lo deseleziono
									this.options.statusButton[indexButtonOpen]=0;
									this.changeButtonStatus(this.options.listButtonElement[indexButtonOpen],0);
									this.options.globalLock=false;
								}
								
								//seleziono il bottone premuto
								this.options.statusButton[index]=1;
								this.changeButtonStatus(this.options.listButtonElement[index],1);
								
								this.startAjax(this.options.listButtonElement[index]);
							}
							else
							{
								//Bottone è selezionato, chiudo box
								event.stop();
								
							     //forse svuotare div
								this.openClose();
								//deselezioni il bottone
								this.options.statusButton[index]=0;
								this.changeButtonStatus(this.options.listButtonElement[index],0);
								
								(function(){  this.options.globalLock=false;  }.bind(this)).delay(500);		
							}
						
						}
					}.bind(this));
					
					
					$(elm).addEvent('mouseover', function(event){
										
							if (this.options.statusButton[index])
							{
								elm.setStyle('background-position','0px -138px');
							}
							else
							{
								elm.setStyle('background-position','0px -92px');
							}

					}.bind(this));
					
					$(elm).addEvent('mouseleave', function(event){
						
						if (this.options.statusButton[index])
						{
							elm.setStyle('background-position','0px -46px');
						}
						else
						{
							elm.setStyle('background-position','0px 0px');
						}
						
					}.bind(this));
					
				}.bind(this));
				
		},
		
		openClose: function(){
			
			var contentSocialHeight= $('buttonsocial_content').getStyle('height').toInt();
	
			if (contentSocialHeight==346)
			{
			   //Chiusura Box
			   var contentSocialFx = new Fx.Tween('buttonsocial_content', {
				duration: 'normal',
				transition: 'quart:in',
				property: 'height',
				onComplete : function(){ $('buttonsocial_content').empty(); }
				});
				contentSocialFx.start(346, 0);	
				
			}
			else
			{
				//Apertura Box
			    var contentSocialFx = new Fx.Tween('buttonsocial_content', {
				duration: 'long',
				transition: 'bounce:out',
				property: 'height'
				});
			  contentSocialFx.start(0, 346);
			}
			
		},
		
		changeButtonStatus: function(nameElementButton,status){	
			if (status)
			{	
				nameElementButton.setStyle('background-position','0px -46px');
			}
			else
			{
				nameElementButton.setStyle('background-position','0px 0px');		
			}

		},
		startAjax : function(nameElementButton){
			var host = window.location.host;
			var rand = Math.floor(10000 * Math.random());	
		    var pageL=0;
			var pageS='wi';
			
	        $('buttonsocial_content').empty().set('html','<div id="buttonsocial_content_ajax"></div>'); 
			
			var my_element_content=$('buttonsocial_content_ajax');

			
			if ($('system_language_uid')) 
			{
				pageL=$('system_language_uid').get('value');
			}
			if ($('system_season')) 
			{
				pageS=$('system_season').get('value');
			}
			
			var link_php_start='http://'+host+'/'+this.options.listProcessPage[nameElementButton.get('id')]+'?L='+pageL+'&season='+pageS+'&rand='+rand;
	
			var loadingAjax = my_element_content.addClass('ajax-loading-box-social');
			
			var req = new Request.HTML({   
				url: link_php_start,     
				method: 'get',    
				onComplete: function(responseTree, responseElements, responseHTML, responseJavaScript) 
				{  	
				
					my_element_content.removeClass('ajax-loading-box-social');
					my_element_content.setStyle('opacity','0');	
					//my_element_content.set('html',response);   
					var fx = new Fx.Tween(my_element_content,{
									duration : 500,
									onComplete: function() {
										if (responseJavaScript!='')
										{
											//Caso in cui c'è javascript nel codice html
											my_element_content.set('html',responseHTML+'<script type="text/javascript">'+responseJavaScript+'</script>');
											start_javascript_extern(); 
										}
										else
										{
											my_element_content.set('html',responseHTML);  
										}
										//this.closeDivHeader();
										
									}.bind(this)
									 });	
					fx.start('opacity', '0', '1');
				}.bind(this)  
				
			  }).send();
		}
	});
	
	
	var button= new listButtonSocial({listProcessPage : { 
							"buttonsocial_facebook":"fileadmin/files/buttonsocial/facebook_view.php", 
							"buttonsocial_twitter" : "fileadmin/files/buttonsocial/twitter_view.php",
							"buttonsocial_youtube":"fileadmin/files/buttonsocial/youtube_view.php",
							"buttonsocial_flickr_de":"fileadmin/files/buttonsocial/flickr_view.php",
							"buttonsocial_flickr_en":"fileadmin/files/buttonsocial/flickr_view.php"
							 }} );






	/////////////////////////////////////////////////////
	/// Menu Top
	/////////////////////////////////////////////////////
	


	var MenuTop= new Class({
	
		Implements: [Options, Events],
		options: {
			globalLock: false,
			responseJSON: '',
			IdFather: null

		},
		
		
		initialize: function(options){
				
				this.setOptions(options);



				$$('#csstopmenu a.menuLinkFather').each(function(elm,index){ 
			 
					//console.log(elm);
				
					var elementLIFather=$(elm).getParent('li');
					var elementMenuContent=elementLIFather.getChildren('div.submegamenu div.submenucontent');
					
					//Aggiunta del evento su i LI padri
					$(elm).addEvent('mouseover', function(event){
						
						//Posiziona freccia
						var coordinates=$(elm).getCoordinates($('top'));
						var positionArrow=coordinates.left+(coordinates.width/2).round()-210;
	                    $$('.submegamenuarrow').setStyle('background-position',positionArrow+'px 0px');
	
						//Carica Ajax
						this.ajaxMenuTop(elm,elementMenuContent,true);
			
					}.bind(this));
				
				    //Aggiunta dell'evento sui sotto link
					elementLIFather.getChildren('div.submegamenu ul.submenulist li a').each(function(elmsub,index){ 
				
						//Evento che chiama l'ajax per ogni sotto menu solamente se il mouse rimane all'interno per un tot tempo
						$(elmsub).addEvent('mouseenter', function(event){
						
							if ( !$(elmsub).hasClass('t_hoverdelay') && event!='hoverconfirm' ) 
							{
								$(elmsub).addClass('t_hoverdelay');
								$(elmsub).fireEvent('mouseenter','hoverconfirm',420);
							}
							else if ( $(elmsub).hasClass('t_hoverdelay') && event=='hoverconfirm' ) 
							{
								$(elmsub).removeClass('t_hoverdelay');
								this.ajaxMenuTop(elmsub,elementMenuContent,false);
							}
						}.bind(this));
				   
						$(elmsub).addEvent('mouseleave', function(event){ this.removeClass('t_hoverdelay'); } );
				 
			
					}.bind(this));
				
				}.bind(this));

		},
   
   
 	   ajaxMenuTop: function (nameElementA,elementMenuContent,saveIdFather){
		     
			 //Carica contenuto  
			
			var host = window.location.host;
			var rand = Math.floor(10000 * Math.random());	
		    var pageL=0;
			var pageS=0;
			
			
			if ($('system_language_uid')) 
			{
				pageL=$('system_language_uid').get('value');
			}
			if ($('system_season')) 
			{
				pageS=$('system_season').get('value');
			}
			
			
			var idPageLink='n'+nameElementA.getProperty('rel');
			
			if (saveIdFather)
			{
				this.options.IdFather=idPageLink;
			}
			
			//link che come risultato rimanda un JSON con tutti i contenuti per il menu
			var link_php_menu='http://'+host+'/fileadmin/files/menu/menu_'+pageS+'_'+pageL+'.html?rand='+rand;
			
			
			
			if ((this.options.responseJSON=='') && (!this.options.globalLock))
			{
			
				//Caricamento del contenuto del menu, viene fatta solo la prima volta
				this.options.globalLock=true;
				elementMenuContent.addClass('ajaxLoadingMenu');
				
				var jsonReq = new Request.JSON({ 
					  url: link_php_menu, 
					  method: 'get', 
					
					  onComplete: function(jsonObj){
						  
							elementMenuContent.removeClass('ajaxLoadingMenu'); 
							this.options.responseJSON=jsonObj;
							
							if(this.options.responseJSON[idPageLink])
							{
									elementMenuContent.set('html',this.options.responseJSON[idPageLink]); 
							}
							else
							{
								   elementMenuContent.set('html',this.options.responseJSON[this.options.IdFather]);
							}
							this.options.globalLock=false;
						
					 }.bind(this) 
				}).send() ; 
		
			}
			else if (!this.options.globalLock)
			{
				if(this.options.responseJSON[idPageLink])
				{
					elementMenuContent.set('html',this.options.responseJSON[idPageLink]); 
				}
				else
				{
					elementMenuContent.set('html',this.options.responseJSON[this.options.IdFather]);
				} 
				
			}
			

  		} 
  });
  
  
  	var menutop_new= new MenuTop();
	



});

