function panorama(){

	//imwid=1385; 
	imwid=parseFloat($('pano').readAttribute('rel'));
	imhei=413; 
	panwid=620; 
	panhei=413; 
	
	speed=25; 
	move=5; 
	
	tim=0;
	noscroll=true;
	imw=imwid*panhei/imhei;
	imh=panhei;
	imstart=panwid/2-imw*1.5;
	jumpa=panwid/2-imw*2.5;
	jumpwida=imw-move;
	jumpb=panwid/2-imw/2;
	jumpwidb=imw+move;
		
}

function sr(){
	
  if(!noscroll){	
  		
   now=parseFloat(document.getElementById("pano").style.left);
	
   if (now<=jumpa){now+=jumpwida;} else{ now-=move; }
    
   document.getElementById("pano").style.left=now+"px";  
  
   tim=setTimeout("sr()",speed);
  
  }
}

function sl(){
	
  if(!noscroll){
		
	now=parseFloat(document.getElementById("pano").style.left);
	
    if (now>=jumpb){now-=jumpwidb;} else{  now+=move; }
  
    document.getElementById("pano").style.left=now+"px";
  
    tim=setTimeout("sl()",speed);
  }
}

function slide180(){
	
	noscrollsl=true;
	
	timer = 0;
	
	speedSl = 25;
	
	elWidth = parseFloat(document.getElementById("pano").style.width);
	
	elWidth = 0 - elWidth+640;
	
}
function slide_r(){
	
	if(!noscrollsl){
		
	  current=parseFloat(document.getElementById("pano").style.left);
	  
	  if (current > elWidth){
	  	
	    	current-=5;
	  	
	  }
	  
	  document.getElementById("pano").style.left=current+"px";
	  timer=setTimeout("slide_r()",speedSl);		
		
	}
	
	
}


function slide_l(){
	
	if(!noscrollsl){
		
	  current=parseFloat(document.getElementById("pano").style.left);
	  
	  if (current <  0){
	  	
	  	 current += 5; 
	  	 
	  } 
	  
	  document.getElementById("pano").style.left=current+"px";
	  
	  timer=setTimeout("slide_l()",speedSl);
				
	}
	
}

function stopSl(){
	
	clearTimeout(timer); 
	
	noscrollsl=true;
}
function stop(){
	
	clearTimeout(tim); 
	
	noscroll=true
}

function uncache(url){
	var d = new Date();
	var time = d.getTime();
	return url + 'time='+time;
} 
function selectAct(formId,elementId,updateElement){
	var form = $(formId);
	var input = form[elementId];
    var input_value = $(input).getValue();
    if(input_value == 0){
    	var href = $(formId).readAttribute('rel');
    	ajax(href,'ajax_conts');
    }else{
      var href = $(formId).readAttribute('action');
      ajax(href+"-"+input_value,updateElement);
    }
}
var running = false;
function ajax(href,cont){
  running = true;
  new Effect.Opacity(cont, { 
	  from: 1.0,
	  to: 0.01, 
	  duration: 0.25, 
	  afterFinish:function(){
	    new Ajax.Updater(cont,href,{
	    	  asynchronous:true, 
	    	  evalScripts:true, 
	    	  parameters: {text: uncache("k")},
	    	  onComplete:function(request){
	    		  
	    		new Effect.Opacity(cont, { 
	    			 from: 0, 
	    			 to: 1.0, 
	    			 duration: 0.25,
	    			 afterFinish:function(){
	    			   running = false;
	    		     }	 
	    		});
	    		
	    	    if($('personal_conts') && $('person_desc')){ 

				 	$$('#personal_conts a[id]').each(function(id){  
				 		
			    	 var link = $(id).readAttribute('id');	
			    	 var href = $(id).readAttribute('href'); 
			    	      
			    	
					     Event.observe(link, 'click', function(event){ 
					           	   
					       var selEl =   $(id);  
					          
					       $$('#personal_conts a[id]').each(function(ids){  
					       	
					       	   var nameEl = ids.identify();
					       	     
					       	   if(link != nameEl){
					       	   	
					       	   	 $(ids).removeClassName('selected_person');
					       	   	 
					       	   }
					       	   
					       });
					       
					       selEl.addClassName('selected_person');    
                             	   
					       ajax(href,'pageConts'); 		        
				           
					       Event.stop(event); 
					       
					    }, false);    	     
			         }); 
		         
	    	    }
	    	  
	      	
	    		
	    	  }, 
	  requestHeaders:['X-Update', cont]})
  }});
}

function showPage(id,btnId){
	
	$$('#pageConts .sel').each(function(ids){	 
			
	 	$(ids).hide();	 
	 	$(ids).removeClassName('sel');
	 	
	 		
	 });
   $$('.currentPage').each(function(ids){	 	
	 		 
	 	$(ids).removeClassName('currentPage');
	 	$(ids).addClassName('paginator_btn');
	 	
	 		
	 }); 
	 
	Effect.Appear(id,{ duration: 0.5 });
	
	$(id).addClassName('sel');
	$(btnId).removeClassName('paginator_btn');
	$(btnId).addClassName('currentPage');
	
	
}

//Inicijuojam scriptus - eventus
function initScripts() {
	
	if($('img_slide')){
	   var images = [
			SITE_URL+"/img/pageStyle/slide/1.jpg",
			SITE_URL+"/img/pageStyle/slide/2.jpg",
			SITE_URL+"/img/pageStyle/slide/3.jpg",
			SITE_URL+"/img/pageStyle/slide/4.jpg",
			SITE_URL+"/img/pageStyle/slide/5.jpg",
			
		];
				
		new Blender("img_slide", images);
   }	
	
	if($('panorama')){
		
		panorama();
		
	}
	if($('sliding')){
		
		slide180();
		
	}
	
	if($('google_map')){
		
		Event.observe($('google_map'), 'click', function(event){ 
			
			 var href = $('google_map').readAttribute('href'); 
			 ajax(href); 
			 Event.stop(event); 
			  
		},false);
	}
		
	if($('horizontal_carousel_tools')){ 
	 	
	   var carSer = new Carousel($('horz_cont'), $$('#horz_cont .slide'),$$('#horizontal_carousel_tools div.carousel-control'),{  duration: 1, auto: false});
	   
	   $$('#container-1 img[id]').each(function(id){
	   			
    	    var imgId = $(id).readAttribute('id');
    	    var imgUrl = $(id).readAttribute('alt');
    	    
    	    Event.observe(imgId, 'mousemove', function(event){ $(imgId).setOpacity(0.5); },false); 
	    	Event.observe(imgId, 'mouseout', function(event){  $(imgId).setOpacity(1);  },false); 
	    	Event.observe(imgId, 'click', function(event){  
	    		  $('big_image').src = SITE_URL+"/img/user_img/thumbs/tool_"+imgUrl;		
	    	 },false);	       	     
      }); 
		    	 	
	 }
	 
	 if($('personal_conts')){ 
	 	
	 	$$('#personal_conts a[id]').each(function(id){  //prideti main meniu ivykius (events)
    	 var link = $(id).readAttribute('id');	//nuorodos id
    	 var href = $(id).readAttribute('href'); //nuorodos url
    	      
	     Event.observe(link, 'click', function(event){ 
	        
	        var selEl =   $(id);  
					          
			$$('#personal_conts a[id]').each(function(ids){  
					       	
			var nameEl = ids.identify();
					       	     
			if(link != nameEl){
					       	   	
			   $(ids).removeClassName('selected_person');
					       	   	 
		    }
					       	   
			});
					       
		   selEl.addClassName('selected_person'); 
 	   
	       ajax(href,'pageConts');
	       
	        

	       Event.stop(event); 
	       
	    }, false);    	     
    }); 
	 	
	 	
	 	
	 } 
	 
//	 if($('free_text') && $('ajax_conts')){
//	 	
//	 	 var ids = $('free_text');
//	 	
//	 	 var hrefs = ids.readAttribute('href');
//	 	 
//	 	 Event.observe(ids, 'click', function(event){ 
//	 	 	
//	 	 	ajax(hrefs,'pageConts'); 
//	 	 	 
//	 	 	Event.stop(event);
//	 	 	
//	 	 },false);
//	 	
//	 }
	 $$('#navigation a[id]').each(function(id){  //prideti main meniu ivykius (events)
    	 
	    var link = $(id).readAttribute('id');	//nuorodos id
	    var href = $(id).readAttribute('href'); //nuorodos url
	    	 
	    var idName = $(id).identify();
	    	 
	    if(idName == "free_text"){
		       	  	
		     Event.observe(link, 'click', function(event){ 
		 	 	
		 	 	ajax(href,'ajax_conts'); 
		 	 	 
		 	     	Event.stop(event);
		 	 	
		 	},false);
	  	
	     }else{
	     	
	     	 var img = SITE_URL+"/img/pageStyle/translate/menu/"+$(id).readAttribute('rel')+"_over.gif";
    	      
		     Event.observe(link, 'click', function(event){ 
		       if(running == false) {	   
			       ajax(href,'ajax_conts'); //isokantis langas ajax
			       
			       $$('#navigation a[id]').each(function(id){
			       	
			       	  var idName = $(id).identify();
			       	
			       	  if(idName != "free_text"){
			       	  	
				       	  var link = $(id).readAttribute('id');	//nuorodos id
				       	  
				       	  var  downel =  $(link).down();  
				  
				  	      downel.src = SITE_URL+"/img/pageStyle/translate/menu/"+$(id).readAttribute('rel')+".gif";
			       	  }
			       	
			       });
			       
		           imgEl =  $(link).down();
			
			       imgEl.src = img;
		       }
	  
		       Event.stop(event); 
		       
		    }, false);  
	     }
	    
	     
	  	 
    }); 
		
}
Event.observe(window, "load", initScripts);
