window.addEvent('domready',function(){
	
	var scroller = new Fx.Scroll(window,{
		link:'cancel',
		duration:100,
		transition:'quad:in:out'
	});
	
	

	
	
	//create our Accordion instance
	var myAccordion = new Accordion($('accordion'), 'h2.toggler', 'div.element', {
		opacity: false,
		onActive: function(toggler, element){
			/*toggler.setStyle('color', '#41464D');*/
		},
		onBackground: function(toggler, element){
			/*toggler.setStyle('color', '#999');*/
		}
	});
	
	
	
    $$('.del').addEvent("click",function(){
	    if(confirm("Изтриване?")){
		       window.location=this.href;	
	    }else{
		    return false;
		    this.href='';
	    }
    });
	


	$$('.ifile').each(function(e,i){
		
		finput=e.getElement('input').setStyle('opacity',0.000001);
		finput.setStyle('width',380);
		finput.setStyle('height',35);
		finput.setStyle('border','none');
		finput.setStyle('font-size',11);
		finput.setStyle('z-index',4);
		finput.setStyle('position','absolute');
		var fake = new Element('input',{
			'type':'text',
			'class':'fake-text',
			'value':'Моля изберете файл'
		});
		fake.injectAfter(finput);
		finput.addEvent('change',function(){
			fake.set('value',this.get('value'));
		});
		
		fake.setStyle('position','absolute');
		finput.setStyle('z-index',5);
		
	});
    
	
		$$('.vote_up').addEvent('click',function(){
			var url='/up_zavedenie.php?id='+this.name;
			var el=this;
			var num=$('res_'+this.name);
			var reqnew = new Request({
			url: url,
			onComplete: function(rmsg){
				if(rmsg!='false'){
					/*
					element.get('tween', {property: 'opacity', onComplete : function(){ 
						element.set('html',rmsg);
						element.get('tween', {property: 'opacity', onComplete : function(){}}).start(1);
						setTips();
						element.set('id','product'+id);
						element.set('title',id);
					}}).start(0);
						*/
					//alert("IMA: "+rmsg);
					num.set('text',rmsg);
					el.addClass('give_vote_now2_voted');
				}else{
					//alert("Вече сте гласували!");
				}
			}
			}).send();
			
			return false
		});
	
	    if(document.getElementById('izprati')){ 
             $('izprati').addEvent('submit', function(e) {
              //Prevents the default submit event from loading a new page.
              e.stop();
              //Empty the log and show the spinning indicator.
              var log = $('logresult').addClass('ajax-loading');
              //Set the options of the form's Request handler. 
              //("this" refers to the $('myForm') element).
              this.set('send', {onComplete: function(response) { 
               log.removeClass('ajax-loading');
               if(response == 'Запитването е успешно!')
               {
				   window.location.reload();
               }
			   else
               {
                   if(response == 'Съобщението е изпратено успешно!')
                        $('top_errorline').setStyle("display","none");
                   log.set('html', response);
               }
              }});
              //Send the form.
              this.send();
			  return false;
             });
    	}
		
		
	    if(document.getElementById('zapitvane')){ 
             $('zapitvane').addEvent('submit', function(e) {
              //Prevents the default submit event from loading a new page.
              e.stop();
              //Empty the log and show the spinning indicator.
              var log = $('logresults').addClass('ajax-loading');
              //Set the options of the form's Request handler. 
              //("this" refers to the $('myForm') element).
              this.set('send', {onComplete: function(response) { 
               log.removeClass('ajax-loading');
               if(response == 'Запитването е успешно!')
               {
				   window.location.reload();
               }
			   else
               {
				   //alert(response);
                   if(response == 'Запитването е успешно!')
                        $('top_errorline').setStyle("display","none");
                   log.set('html', response);
               }
              }});
              //Send the form.
              this.send();
			  return false;
             });
    	}
		
		
		
			 if(document.getElementById('izprati2')){ 
             $('izprati2').addEvent('submit', function(e) {
              //Prevents the default submit event from loading a new page.
              e.stop();
              //Empty the log and show the spinning indicator.
              var log = $('logresult').addClass('ajax-loading');
              //Set the options of the form's Request handler. 
              //("this" refers to the $('myForm') element).
              this.set('send', {onComplete: function(response) { 
               log.removeClass('ajax-loading');
               if(response == '')
               {
				   window.location.reload();
               }
			   else
               {
				  // alert(response);
                   if(response == 'Коментара е добавен успешно!')
                        $('top_errorline').setStyle("display","none");
                   log.set('html', response);
               }
              }});
              //Send the form.
              this.send();
			  //return false;
             });
    	}
		
		
			 if(document.getElementById('izprati3')){ 
             $('izprati3').addEvent('submit', function(e) {
              //Prevents the default submit event from loading a new page.
              e.stop();
              //Empty the log and show the spinning indicator.
              var log = $('logresult').addClass('ajax-loading');
              //Set the options of the form's Request handler. 
              //("this" refers to the $('myForm') element).
              this.set('send', {onComplete: function(response) { 
               log.removeClass('ajax-loading');
               if(response == '')
               {
				   window.location.reload();
               }
			   else
               {
				   
                   if(response == 'Коментара е добавен успешно!')
                       $('top_errorline').setStyle("display","none");
                   log.set('html', response);
				   //alert(response);
               }
			   
              }});
              //Send the form.
              this.send();
			  //return false;
             });
    	}
		
		
		
	    if(document.getElementById('izprati4')){ 
             $('izprati4').addEvent('submit', function(e) {
              //Prevents the default submit event from loading a new page.
              e.stop();
              //Empty the log and show the spinning indicator.
              var log = $('logresult2').addClass('ajax-loading');
              //Set the options of the form's Request handler. 
              //("this" refers to the $('myForm') element).
              this.set('send', {onComplete: function(response) { 
               log.removeClass('ajax-loading');
               if(response == 'Успешно се логнахте!')
               {
				   //alert(response);
				   //window.location.reload();
				   window.location = "http://www.zadbara.com/edit"

               }
			   else
               {
				   //alert(response)
				   if(response == 'Успешно се логнахте!')
                        $('top_errorline').setStyle("display","none");
                   log.set('html', response);
               }
              }});
              //Send the form.
              this.send();
			  return false;
             });
    	}
		

	    if(document.getElementById('forgotten-password-form')){ 
             $('forgotten-password-form').addEvent('submit', function(e) {
              //Prevents the default submit event from loading a new page.
              e.stop();
              //Empty the log and show the spinning indicator.
              var log = $('logresult3').addClass('ajax-loading');
              //Set the options of the form's Request handler. 
              //("this" refers to the $('myForm') element).
              this.set('send', {onComplete: function(response) { 
				log.removeClass('ajax-loading');
				log.set('html', response);
              }});
              //Send the form.
              this.send();
			  return false;
             });
    	}
		
		
		
		
		
		if(document.getElementById('sendcontact')){ 
             $('sendcontact').addEvent('submit', function(e) {
              //Prevents the default submit event from loading a new page.
              e.stop();
              //Empty the log and show the spinning indicator.
              var log = $('logresult').addClass('ajax-loading');
              //Set the options of the form's Request handler. 
              //("this" refers to the $('myForm') element).
              this.set('send', {onComplete: function(response) { 
               log.removeClass('ajax-loading');
               if(response == 'true')
               {
				  // window.location = "/контакти";return;
               }else
               {
                   if(response == 'Запитването е успешно!')
                        $('top_errorline').setStyle("display","none");
                   log.set('html', response);
               }
              }});
              //Send the form.
              this.send();
			  return false;
             });
    	}


	
	
	
	
	
	
	if (document.getElementById('toForm'))
	{
		$('showMap').addEvent('click',function(e){
			var showMap = new Fx.Slide('map').slideIn('vertical');
			e.preventDefault();
			scroller.toElement($('map'));
		});
	}
	if (document.getElementById('calendar'))
	{
		new vlaDatePicker('calendar',{openWith: 'togglePicker'});
	}
	
	if (document.getElementById('slider'))
	{	
		//variables for making things more simple below
		var itemsHolder = $('slider');
		var myItems = $$('.onfocus');
		var thePrevBtn = $('prev_btn');
		var theNextBtn = $('next_btn');
		
		
		//create an instance of the slider, and start it up
		var mySlider = new SL_Slider({
			slideTimer: 6000,
			isPaused: false,
			container: itemsHolder,
			items: myItems,
			prevBtn: thePrevBtn,
			nextBtn: theNextBtn
		});
		mySlider.start();
		
		
		//adding a little animated rollover highlight to the play and prev/next buttons
		var origBkgdColor = thePrevBtn.getStyle('background-color');
		var newBkgdColor = "#251d7a";
		var btnArray = new Array(thePrevBtn, theNextBtn);
		
		btnArray.each(function(e, i){
			e.set('tween', {duration: 350, transition: 'cubic:out', link: 'cancel'});
		});
		
		$$('.minbtn').addEvent('click',function(){
			$('big_top').setStyle('display',"none");
			$('small_top').setStyle('display',"block");
		});
		
		
		
		$$('.maxbtn').addEvent('click',function(){
			$('small_top').setStyle('display',"none");
			$('big_top').setStyle('display',"block");
		});
		
		
		
		
		/*
		     $('signin').addEvent('click', function(e) {   
                if($('signoutdiv').getStyle('display')=="none"){
                    $('signoutdiv').setStyle("display","block");
                    $('signdiv').setStyle("display","none");
                }else
                {
                    $('signoutdiv').setStyle("display","none");
                    $('signdiv').setStyle("display","block");
                }
                return false;
             });  
		*/
		
		
	}
	
	
	
});


/* Modified to support Opera */
function bookmarksite(title,url){
if (window.sidebar) // firefox
	window.sidebar.addPanel(title, url, "");
else if(window.opera && window.print){ // opera
	var elem = document.createElement('a');
	elem.setAttribute('href',url);
	elem.setAttribute('title',title);
	elem.setAttribute('rel','sidebar');
	elem.click();
} 
else if(document.all)// ie
	window.external.AddFavorite(url, title);
}


