var cnt = 0;
var index = 0;
var top5fx = [];
var bot5fx = [];
var per;

window.addEvent("domready", function(){	
	
	if ($("bigImageRotator")){
	    $$("div.rotatorSlide").each(function(el, index){
	        if(el.getStyle("display")=="none"){
	            el.setStyles({"display": "block", "opacity": "0"});
	        }
	        if(index==0) el.setStyles({"display": "block", "opacity": "1"});
	        top5fx.push(new Fx.Tween(el, {duration:750, wait:false}));
	    })
	    
	    
	    $$("a.clickable").each(function(el, index){
	    
	        bot5fx.push(new Fx.Tween(el, {duration:750, wait:false}));
	        el.setStyle("cursor","pointer");
	        el.setProperty("res", index);
	         
	        el.addEvents({
	            "click":function(){
	                $clear(per);
	              
	               $$("a.active").each(function(ele){
	                 ele.removeClass("active");
	               });
	                
	                el.addClass("active");
	                $$("div.rotatorSlide").each(function(el, index){
	                    if(el.getStyle("opacity")!=0) {
	                        top5fx[index].start('opacity', 0);
	                    }
	                });		
	                			
	                top5fx[el.getProperty("res")].start('opacity', 1);	
	                
	                cnt=index;
	                per = fx.periodical(5000);
	            }
	        })
	    })
	    
	    per = fx.periodical(5000);
	}
	
	$$('input.DatePicker').each( function(el){
		 new DatePicker(el, {
			 pickerClass: 'datepicker_vista',
			 format: 'd.m.Y',
			 inputOutputFormat: 'd.m.Y',
			 yearPicker: false,
			 timePicker: false,
			 allowEmpty: true
		 });
	 });
	
	$$('input.TimePicker').each( function(el){
	   new DatePicker(el, {
	       pickerClass: 'datepicker_vista',
	       format: 'H:i',
	       inputOutputFormat: 'H:i',
	       timePickerOnly: true,
	       allowEmpty: true
	   });
	
	});
	 
	if ($("formaprijava")) {
		new FormCheck('formaprijava', {
		display : {
			errorsLocation : 1,
			indicateErrors : 2,
			showErrors : 0
			}
		});
	}
})


function fx(){
    cnt++;
    if (cnt==top5fx.length) cnt = 0;
    top5fx[cnt].start('opacity', 1);
   
    $$("a.active").each(function (el){
        el.removeClass("active");
    })
    $$("a.clickable")[cnt].addClass("active");
    $$("div.rotatorSlide").each(function(el, indx){
        if(el.getStyle("opacity")!=0){
            top5fx[indx].start('opacity', 0);
        }
    })
}
