/* Event:Selector */

var Rules = {
   '#city_search #auto_city': function(element) {
     if(element.value == ''){
       element.className = "auto-search-back"
     }
   },
   
   '#city_search #auto_city:focus': function(element) {
     element.className = "auto-search-blank";
   },
   
   '#city_search #auto_city:blur': function(element) {
     if(element.value == ''){
     element.className = "auto-search-back";}
   },
      
   'p.star a:click': function(element) {
     star = $$("p.star a");
     for(i=0;i < star.length;i++){
       if(i < parseInt(element.innerHTML)){
         star[i].className = 'star-on';}
       else{
         star[i].className = 'star-off';
       }
     }
     document.getElementById('vote_rate').value = parseInt(element.innerHTML);
   },
   
   'p.star a:mouseover': function(element) {
     star = $$("p.star a");
     for(i=0;i < star.length;i++){
       if(i < parseInt(element.innerHTML)){
         star[i].className = 'star-on';}
       else{
         star[i].className = 'star-off';
       }
     }
   },
   
   'p.star a:mouseout': function(element) {
     star = $$("p.star a");
     for(i=0;i < star.length;i++){
       if(i < parseInt(document.getElementById('vote_rate').value)){
         star[i].className = 'star-on';
         }
       else{
         star[i].className = 'star-off';
       }
     }
   },
  
   'a.reorder_pictures:click': function(element) {
     mostra = $$("div.resource_cmd");
     for(i=0; i<mostra.length; i++){
       toggle_effect(mostra[i])
      } 
   },
   
   'a.reorder_documents:click': function(element) {
     mostra = $$("span.doc-maniglia");
     for(i=0; i<mostra.length; i++){
       toggle_effect(mostra[i])
     }
   },
   
   'a.reorder_detail:click': function(element) {
     mostra = $$("span.detail-maniglia");
     for(i=0; i<mostra.length; i++){
       toggle_effect(mostra[i])
     }
   },
  
   '#icons a:mouseover': function(element) {
        var app = element.id;
        new Effect.BlindDown(app + '-content', {queue: 'end', duration: 0.2});
      },
       
   'a.select_all:click': function(element) { 
       var sel= (element.id !=  '') ? (sel = "input." + element.id) : (sel = "input.select");      
       check = $$(sel); 
       for(i=0; i<check.length; i++){check[i].checked =true;}   
    },
    
    'a.deselect_all:click': function(element) { 
        var sel= (element.id !=  '') ? (sel = "input." + element.id) : (sel = "input.select"); 
        check = $$(sel); 
        for(i=0; i<check.length; i++){check[i].checked =false;}
     },
  
    /* Inizio hover per rimuovere favoriti e ricerche */
  	'#inner-col-right li.edit:mouseover': function(element) {
  	    var app = "edit_" + element.id;
        if(over_element==''){
          over_element = app;}
        else{
          if(document.getElementById(over_element))
            Element.hide(over_element);
          restore_background(over_element);
           over_element = app;}
           element.style.backgroundColor = "#f0f0ce";
       if(document.getElementById(app))
         Element.show(app);
  	  },

     '#inner-col-right ul.items-list:mouseout': function (element){
       if(document.getElementById(over_element)){
         Element.hide(over_element);
         restore_background(over_element);}
     }
     /* Fine hover per rimuovere favoriti e ricerche */
}

function restore_background(element){
  var colore = document.getElementById(element.substring(5))
    if(colore && colore.className=="edit odd"){colore.style.backgroundColor = "#ffffff";}
     else{
       if(colore){
       colore.style.backgroundColor = "#fafaed";}
       }
}


function buttonStateHandler(button, enabled) {
if (button == "prev-arrow-small") 
$('prev-arrow-small').src = enabled ? "images/left-enabled.gif" : "images/left-disabled.gif"
else 
$('next-arrow-small').src = enabled ? "images/right-enabled.gif" : "images/right-disabled.gif"
}

function clear_fields(div) {
  clear_input = $$('#' + div + " input");
  for(i=0; i<clear_input.length; i++){Field.clear(clear_input[i]);}
}

function animHandler(carouselID, status, direction){
var region = $$("#" + carouselID + " .carousel-clip-region")[0] 
if(status == "before"){Effect.Fade(region, {to: 0.3, queue: {position:'end', scope: "carousel" }, duration: 0.2})}
if(status == "after"){Effect.Fade(region, {to: 1, queue: {position:'end', scope: "carousel" }, duration: 0.2})}}

var over_element = '';

function toggle_effect(element){
   if(element.style.display == 'none'){
     new Effect.Appear(element, {queue: 'end', duration: 0.2});}
   else{
     new Effect.Fade(element, {queue: 'end', duration: 0.2});}
};

Event.observe(window, 'load', function(event){ EventSelectors.start(Rules); });
