	var showDuration = 5000;
	var currentIndex = 0;
	var interval;
	var pojam='';
	
    window.addEvent("domready",function() {
		
    	if ($('anima')){
			var container = $('anima');
			
			var images = container.getElements('div.slide');
			var imagesbutton = $('anima_nav').getElements('a.clickableImage');
			/* opacity and fade */
			images.each(function(img,i){ 
			  if(i > 0) {
			    img.set('opacity',0);
			  }
			});
			
			/* worker */
			var show = function() {
				$$("a.anima_nav_curr").each(function(ele){
					ele.removeClass("anima_nav_curr");
				});
				
				imagesbutton[currentIndex < images.length - 1 ? currentIndex+1 : 0].addClass("anima_nav_curr");
				
				images[currentIndex].fade('out');
			    images[currentIndex = currentIndex < images.length - 1 ? currentIndex+1 : 0].fade('in');
			};
			
			/* start once the page is finished loading */
			window.addEvent('load',function(){
			  interval = show.periodical(showDuration);
			});
			
			
			 $$("a.clickableImage").each(function(el, index){
	        	$clear(interval);	    
	            el.setProperty("res", index);
	             
	            el.addEvents({
	                "click":function(){
	                    $clear(interval);	    
	                  
	                   $$("a.anima_nav_curr").each(function(ele){
	                     ele.removeClass("anima_nav_curr");
	                   });
	                     
	                    el.addClass("anima_nav_curr");
	                    
	                    images.each(function(img,i){ 
						  img.fade('out');
						});
	                    
			 			images[index].fade('in');   
			 			currentIndex = index;
	                }
	            })
	        })
			
			  
		}
    	
    	if ($("korisnikprijava")) {
	    	new FormCheck('korisnikprijava', {
	    		display : {
	    			errorsLocation : 1,
	    			indicateErrors : 1,
	    			showErrors : 0
	    		},
	    		submit : false,
	    		onValidateSuccess : saljimail
	    	});
	    }
	    
	    if ($("saljiprijatelju")) {
	    	new FormCheck('saljiprijatelju', {
	    		display : {
	    			errorsLocation : 1,
	    			indicateErrors : 1,
	    			showErrors : 0
	    		}
	    	});
	    }
	    
	    
	     $$("a.godine").each(function(el, index){
            el.addEvents({
                "click":function(){
                    $$("a.godine").each(function(ele){
                    	ele.removeClass("ref_nav_curr");
                    });
                    el.addClass("ref_nav_curr");
                    
                    $$("span.godinebr").each(function(ele,index2){
                    	if (index==index2){
                    		ele.setStyle('opacity','1');
                    	}else{
                    		ele.setStyle('opacity','0');
                    	}
                    });
                    
                    
                    
                }
            })
        })
        
        $$("span.godinebr").each(function(el, index){
	        if(el.getStyle("display")=="none"){
	            el.setStyles({"display": "block", "opacity": "0"});
	        }
	        if(index==0) el.setStyles({"display": "block", "opacity": "1"});
	    })

    })
    
    
    function saljimail(){
		
		var myRequest = new Request({
		    url:'ajax.aspx?action=saljimail',
		    method: 'post',
			data: 'ime=' + $('ime').value + '&email=' + $('email').value + '&zanimame=' + $('zanimame').value + '&telefon=' + $('telefon').value,
		    onRequest: function(){
		       $('spinnergif').setStyle('display','block')
		    },
		    onSuccess: function(responseText){
		    	$('spinnergif').setStyle('display','none')
		    	if (responseText="ok"){
		    		$('rezultati').innerHTML="<div class='success'>Vaša je poruka uspješno poslana.<br />Kontaktirat ćemo Vas u roku 24h!</div>";
		    	}else{
		    		$('rezultati').innerHTML="<div class='error'>Vaša poruka nije poslana!</div>";
		    	}
		        
		    },
		    onFailure: function(){
		        $('spinnergif').setStyle('display','none');
		        alert('Došlo je do greške"');
		    }
		});
		myRequest.send()
		
	}
	
	
	function getNews(godina,page,pojam,lng){
		
		var myRequest = new Request({
		    url:'ajax.aspx?action=reference&godina=' + godina + '&page=' + page + '&lng=' + lng,
		    method: 'post',
		    data: 'pojam=' + pojam,
		    onRequest: function(){
		       //$('spinnergif').setStyle('display','block')
		    },
		    onSuccess: function(responseText){
		    	//$('spinnergif').setStyle('display','none')
		    	$('reference').innerHTML=responseText;
		    	if (page!=1) new Fx.Scroll(window).toElement($('ref_h1')); 
		    },
		    onFailure: function(){
		        //$('spinnergif').setStyle('display','none');
		        alert('Došlo je do greške"');
		    }
		});
		myRequest.send()
		
	}
	
	

    
