var Site = {
	init: function() {
		
		if ( $('home') ) acc.accord();
		if ( $('home') ) pocasie.pocasie_funct();
		
		
		if ($('reg')) show.show_content();
		if ($$('.klikni')) popup.popup_fn();
		if ($('response'))  formular.formular_fn();
		mapa.mapa_stranok();
		
	}
};


var popup = {
	
	  popup_fn: function() {
		var klik = $$('.klikni');
		klik.each(function(element,i) {
		element.addEvent('click', function() {
		
		var id = element.getProperty('id').split('-');
		//console.log(id);
		var elem = new Element('div',{'id':'overlay', 'title': 'Zavri okno'}).injectInside(document.body).setOpacity(0).setStyle('z-index','500');
		var loadingFX = new Fx.Elements($$('#overlay'), {wait:false, duration:500});
		loadingFX.start({
				'0': {'opacity': 0.5}
			});
		if($defined($('banner'))){
			$('banner').setStyle('display','none');
		}
		$('popup-'+id[1]).setStyle('display','block').setStyle('z-index','5000000').injectInside(document.body);
		var pop = new Fx.Styles('popup-1', { wait: false, duration:1000, transition:Fx.Transitions.Expo.easeOut });
		 pop.start({
				   'height': [0,400],
				   'width': [0,400]
				   
				   });
		var pop = new Fx.Styles('popup-2', { wait: false, duration:1000, transition:Fx.Transitions.Expo.easeOut });
		 pop.start({
				   'height': [0,300],
				   'width': [0,450]
				   
				   });
		 $('overlay').addEvent('click',function(){ $('overlay').setOpacity(0); $('popup-'+id[1]).setStyle('display','none');})
		  

		
		$('zavri-'+id[1]).addEvent('click',function(){ $('overlay').setOpacity(0); $('popup-'+id[1]).setStyle('display','none');})
		
		}); 
		
	  });
		
	

	  }
	  
	

}

var formular = {
	
  formular_fn: function() {
	  
	  $('send').addEvent('click', function(e) {


	     var myFx = new Fx.Styles('response', { wait:false, duration:1200, transition: Fx.Transitions.Back.easeInOut });
		 new Element('div',{'id':'overlay'}).injectInside('formular').setOpacity(0).setStyle('z-index','10');
		var loadingFX = new Fx.Elements($$('#overlay'), {wait:false, duration:500});
		loadingFX.start({
				'0': {'opacity': 0.5}
			});
       
	  new Element('div').setProperty('id','loading').injectInside('overlay');
	 
	  new Event(e).stop();
	  var params = 'datum_od='+document.getElementById('datum_od').value+'&datum_do='+document.getElementById('datum_do').value+'&name='+document.getElementById('name').value+
	  '&priez='+document.getElementById('Priezvisko').value+'&email='+document.getElementById('email').value+'&osob='+document.getElementById('osob').value+
	  '&pozn='+document.getElementById('pozn').value+'&id='+document.getElementById('id').value+'&phone='+document.getElementById('phone').value+'&lang='+document.getElementById('lang').value;

		var url = '/ubytovanie/rezerv.php';
	    var myXHR =  new XHR ({ 
		  method: 'get',
		  onSuccess: function(){ 
		  
		  var myStringArray = new Array();

          var myString = myXHR.response.text;

		 
         	
			 myStringArray = myString.split("|");
			 
			 if (myStringArray[0] == 1) {
               	 
				 for(i=1;i<myStringArray.length;i+=1) {
          
                 $('error'+i).innerHTML = myStringArray[i];

              }
				 $('overlay').remove();
			
		   } 
		   
		   if (myStringArray[0] == 0) {
			
			$('response').setHTML(myStringArray[1]);
			
			myFx.start({
					   
					   'background-color' : ['FF9900','FFF'],
					   'color' : ['FFF', 'FF9900']
					   
					   });
			
			$('formular').remove();
			$('overlay').remove();
			
			  
		  	  } 
		  	 
			
		  }
	  		
		}).send(url, params);



		});
	  
	  
  }
	
	
	
}


var mapa = {
	
	mapa_stranok: function() {
	var site_map = new Fx.Slide('site_map', { wait: false, duration:1000, transition:Fx.Transitions.Expo.easeOut });	
	//var color = new Fx.Styles('site_map');
	site_map.hide();
	$('mapa_open').addEvent('click', function(){
							site_map.toggle();
							
											  });
	
		
		
		
	}
}

var pocasie = {
	
	pocasie_funct:function() {
var aktualComment = new Fx.Slide('actual', { wait: false, duration:1000, transition:Fx.Transitions.Expo.easeOut });
var aktuallink = new Fx.Styles('actual');
var aktualne = new Fx.Styles('aktualne');
var predlink = new Fx.Styles('predpoved');
var predpov = new Fx.Styles('predpov');


aktualne.start({
				'background-color' : '#4d8aba'
				 });

		$('aktualne').addEvent('click', function(){
				aktualComment.toggle();
				aktuallink.start({
				'background-color' : ['#175997', '#4d8aba']
				 });
				aktualne.start({
				'background-color' : ['#175997', '#4d8aba']
				 });
				predpov.start({
				'background-color' : '#175997'
				 });
				
		});
		$('aktualne').addEvent('click', function(){
				predComment.slideOut();
		});
		


var predComment = new Fx.Slide('predpoved', { wait: false, duration:1000, transition:Fx.Transitions.Expo.easeOut });

		predComment.hide();
		$('predpov').addEvent('click', function(){
				opacity: true,
				predComment.toggle();
				predlink.start({
				'background-color' : ['#175997', '#4d8aba']
				 })
				aktualne.start({
				'background-color' : ['#4d8aba', '#175997']
				 })
				predpov.start({
				'background-color' : ['#175997', '#4d8aba']
				 })
				
		});
		$('predpov').addEvent('click', function(){
				aktualComment.slideOut();
		});
	}
}



var show = {
	
	show_content: function(){
		var myComment = new Fx.Slide('login', { wait: false, duration:1000, transition:Fx.Transitions.Expo.easeOut });
		myComment.hide();
		$('reg').addEvent('click', function(){
				myComment.toggle();
		});
	
	}
}



// Accordion


var acc = {
	
	accord: function(){

var accordion = new Accordion('h3.atStart', 'div.atStart', {
	
	'transition': Fx.Transitions.Expo.easeOut,
	'duration' : 900,
	opacity: true,
	onActive: function(toggler, element){
		alwaysHide: false,
		toggler.setStyle('background-color', '#134a86');
		
	},
 
	onBackground: function(toggler, element){
		toggler.setStyle('background-color', '#4d8aba');
		
	}
}, $('accordion'));
 
 /*
 var newTog = new Element('h3', {'class': 'toggler'}).setHTML('Common descent');
 
var newEl = new Element('div', {'class': 'element'}).setHTML('<p>A group of organisms is said to have common descent if they have a common ancestor. In biology, the theory of universal common descent proposes that all organisms on Earth are descended from a common ancestor or ancestral gene pool.</p><p>A theory of universal common descent based on evolutionary principles was proposed by Charles Darwin in his book The Origin of Species (1859), and later in The Descent of Man (1871). This theory is now generally accepted by biologists, and the last universal common ancestor (LUCA or LUA), that is, the most recent common ancestor of all currently living organisms, is believed to have appeared about 3.9 billion years ago. The theory of a common ancestor between all organisms is one of the principles of evolution, although for single cell organisms and viruses, single phylogeny is disputed</p>');
 
accordion.addSection(newTog, newEl, 2);  */

}
}







function okno(n,w,h){
window.open(n,"Podmienky","left=100, top=100, width="+w+", height="+h+", menubar=no, directories=no,toolbar=no,location=no,status=yes,scrollbars=yes,resizable=no");
}


function showLoadingIcon(div_id) {
	    
        var temp_HTML ="<img src=../images/icons/icn_loading_animated.gif align=\"absmiddle\"> Loading...";
		
		
		var div = $('load');
		var loading = new Fx.Styles(div ,{wait: true, duration: 900, transition: Fx.Transitions.Quint.easeOut});
			
				loading.start({
                //'background-color' : ['#b9b9b9', '#ffff']
				'opacity': [0, 1]
				
				 })
			
									 

		
        document.getElementById(div_id).innerHTML = temp_HTML; 
}
