jQuery(document).ready(function(){
   if(jQuery(".gallery_img").is("div")){
    var gallery_scroller=jQuery(".gallery_img_content");
    var gallery_contenitor=jQuery("ul",".gallery_img_content");
    var gallery_contenitor_child=jQuery("li",gallery_contenitor);
    var initial_counter=9;
    var current_counter=9;
    var all_child=jQuery(gallery_contenitor_child).size();
    var w_child=jQuery(gallery_contenitor_child).width()
    var in_animation=false;
    jQuery(".gallery_img_left").bind("click",function(e){
       e.preventDefault();
       if(!in_animation){
         if(all_child > initial_counter && current_counter > initial_counter){
          in_animation=true;
          jQuery(gallery_scroller).animate({left: '+='+w_child},400, function() {
             current_counter--;
             in_animation=false;
          });
         }
       }
    });
    
    jQuery(".gallery_img_right").bind("click",function(e){
       e.preventDefault();
       if(!in_animation){
         if(all_child > initial_counter && current_counter <all_child){
          in_animation=true;
          jQuery(gallery_scroller).animate({left: '-='+w_child},400, function() {
             current_counter++;
             in_animation=false;
          });
         }
       }
    })
    
   }
   if(jQuery(".gallery").is("ul")){
    jQuery(".gallery a[rel^='prettyPhoto']").prettyPhoto({
       show_title: false,
       overlay_gallery:false,
       social_tools:'',
       deeplinking: false
    });
   }
   
   if(jQuery(".monografie-icon").is("a")){
    jQuery(".monografie-icon").prettyPhoto({
       show_title: false,
       overlay_gallery:false,
       social_tools:'',
       deeplinking: false
    });
   }
   
   if(jQuery(".news").is("li")){      
      jQuery(".news_menu a").bind("click",function(e){
        e.preventDefault();
        //console.log(jQuery(this).attr("id"));
        if(!jQuery(this).hasClass("disabled")){
          var old_selectd=null;
          if(!jQuery(this).hasClass("selected") ){
            jQuery(".news_menu a.selected").removeClass("selected");
            jQuery(this).addClass("selected");
          }
          jQuery(".news_loader","li.news").show();
          
          $_tmp=(jQuery(this).attr("id")).split("_");
          if(typeof($_tmp)=='object'&&($_tmp instanceof Array)){
             jQuery.ajax({
              url: "/ajax.php",
              global: false,
              type: "POST",
              data: ({type: $_tmp[0],cat : $_tmp[1]}),
              dataType: "html",
              async:true,
              success: function(msg){
                jQuery(".box_container","li.news").html(msg);
                jQuery(".news_loader","li.news").hide();
              }
             });
          }else{
            jQuery.ajax({
              url: "/ajax.php",
              global: false,
              type: "POST",
              data: ({type: jQuery(this).attr("id")}),
              dataType: "html",
              async:true,
              success: function(msg){
                jQuery(".box_container","li.news").html(msg);
                jQuery(".news_loader","li.news").hide();
              }
             });
           }
         }
      });
   }
   
   
   
if(jQuery("#tw_channel_contenitor").is("ul")){
  
  jQuery("li#channel_architect").show();
  jQuery("li#channel_engineer").hide();
  
  jQuery("a#channel_architect_handler").bind("click",function(e){
    e.preventDefault();
    if(!jQuery("li#channel_architect").hasClass("selected")){
       jQuery("li#channel_architect").show();
       jQuery("li#channel_engineer").hide();
       jQuery(this).addClass("selected");
       jQuery("a#channel_engineer_handler").removeClass("selected");
    }
  });
  
  jQuery("a#channel_engineer_handler").bind("click",function(e){
    e.preventDefault();
    if(!jQuery("li#channel_engineer").hasClass("selected")){
       jQuery("li#channel_engineer").show();
       jQuery("li#channel_architect").hide();
       jQuery(this).addClass("selected");
       jQuery("a#channel_architect_handler").removeClass("selected");
    }
  });
  
  
}

if(jQuery("#curiosita_detail_prev_handler").is("a") && jQuery("#curiosita_detail_next_handler").is("a")){
  counter=1;
  jQuery("#curiosita_detail_next_handler").bind("click",function(e){
     e.preventDefault();
     //load
     jQuery.ajax({
              url: "/ajax.php",
              global: false,
              type: "POST",
              data: ({'type':'curiosita','position':counter}),
              dataType: "html",
              async:true,
              success: function(msg){
                //write
              }
             });
     //slide
  });
  
  jQuery("#curiosita_detail_prev_handler").bind("click",function(e){
     e.preventDefault();
     //slide
  });
  
}

jQuery('a.event_handler').each(function(i){
     jQuery(this).qtip({
        id:"tooltip"+i,
        overwrite: true,
        content: {
            text: '<p class="loading"> Caricamento in corso</p>',
            ajax: {
                url: '/ajax.php',
                type: 'GET',
                data: {
                    calendar:'calendar',
                    id: jQuery(this).attr('rel'),
                    random: Math.floor(Math.random()*11)
                },
                dataType: 'html',
                once:false
            },
            title: {
               text: 'Eventi <span>Del Giorno</span>' , // Give the tooltip a title using each elements text
               button: true
            }
         },
         position: {
            at: 'bottom center', // Position the tooltip above the link
            my: 'top center',
            viewport: jQuery(window), // Keep the tooltip on-screen at all times
            target: jQuery(this),
            effect: false // Disable positioning animation
         },
         show: {
            event: 'click',
            solo: true // Only show one tooltip at a time
         },
         hide: 'unfocus',
         style: {
           classes: 'ui-tooltip-event-day ui-tooltip-light ui-tooltip-shadow'
         }
      }).click(function(e){e.preventDefault()});
     
  });

   if(jQuery("#prev_button_calendar").is("a") && jQuery("#next_button_calendar").is("a")){
      current_step=0;
     jQuery("#prev_button_calendar").bind("click",function(e){
       e.preventDefault();
       current_step--;
       jQuery(".news_loader").show();
        jQuery.ajax({
              url: "/ajax.php",
              global: false,
              cache:false,
              type: "GET",
              data: ({'multi_calendar':'multi_calendar','step':current_step}),
              dataType: "html",
              async:true,
              success: function(msg){
                jQuery("#multicalendar").html(msg);
                jQuery('a.event_handler').each(function(i){
     jQuery(this).qtip({
        id:"tooltip"+i,
        overwrite: true,
        content: {
            text: '<p class="loading"> Caricamento in corso</p>',
            ajax: {
                url: '/ajax.php',
                type: 'GET',
                data: {
                    calendar:'calendar',
                    id: jQuery(this).attr('rel'),
                    random: Math.floor(Math.random()*11)
                },
                dataType: 'html',
                once:false
            },
            title: {
               text: 'Eventi <span>Del Giorno</span>' , // Give the tooltip a title using each elements text
               button: true
            }
         },
         position: {
            at: 'bottom center', // Position the tooltip above the link
            my: 'top center',
            viewport: jQuery(window), // Keep the tooltip on-screen at all times
            target: jQuery(this),
            effect: false // Disable positioning animation
         },
         show: {
            event: 'click',
            solo: true // Only show one tooltip at a time
         },
         hide: 'unfocus',
         style: {
           classes: 'ui-tooltip-event-day ui-tooltip-light ui-tooltip-shadow'
         }
      }).click(function(e){e.preventDefault();})
     
  });
  jQuery(".news_loader").hide();
              }
             });
       
     });
     
     jQuery("#next_button_calendar").bind("click",function(e){
       e.preventDefault();
       current_step++;
       jQuery(".news_loader").show();
       jQuery.ajax({
              url: "/ajax.php",
              global: false,
              cache:false,
              type: "GET",
              data: ({'multi_calendar':'multi_calendar','step':current_step}),
              dataType: "html",
              async:true,
              success: function(msg){
                jQuery("#multicalendar").html(msg);
                jQuery('a.event_handler').each(function(i){
     jQuery(this).qtip({
        id:"tooltip"+i,
        overwrite: true,
        content: { 
            text: '<p class="loading"> Caricamento in corso</p>',
            ajax: {
                url: '/ajax.php',
                type: 'GET',
                data: {
                    calendar:'calendar',
                    id: jQuery(this).attr('rel'),
                    random: Math.floor(Math.random()*11)
                },
                dataType: 'html',
                once:false
            },
            title: {
               text: 'Eventi <span>Del Giorno</span>' , // Give the tooltip a title using each elements text
               button: true
            }
         },
         position: {
            at: 'bottom center', // Position the tooltip above the link
            my: 'top center',
            viewport: jQuery(window), // Keep the tooltip on-screen at all times
            target: jQuery(this),
            effect: false // Disable positioning animation
         },
         show: {
            event: 'click',
            solo: true // Only show one tooltip at a time
         },
         hide: 'unfocus',
         style: {
           classes: 'ui-tooltip-event-day ui-tooltip-light ui-tooltip-shadow'
         }
      }).click(function(e){e.preventDefault();})
     
  });
  jQuery(".news_loader").hide();
              }
             });
     });
   }
   
   
   
   if(jQuery(".next_button_month_event").is("a") && jQuery(".prev_button_month_event").is("a")){
   month_current_step=0
     jQuery(".next_button_month_event").bind("click",function(e){
       e.preventDefault();
       month_current_step++;
       jQuery(".news_loader_eventi").show();
       jQuery.ajax({
              url: "/ajax.php",
              global: false,
              cache:false,
              type: "GET",
              data: ({'month_event':'month_event','step':month_current_step}),
              dataType: "html",
              async:true,
              success: function(msg){
                jQuery(".month_events").html(msg);
                 jQuery(".news_loader_eventi").hide();
              }
             });
      });
      jQuery(".prev_button_month_event").bind("click",function(e){
       e.preventDefault();
       month_current_step--;
       jQuery(".news_loader_eventi").show();
       jQuery.ajax({
              url: "/ajax.php",
              global: false,
              cache:false,
              type: "GET",
              data: ({'month_event':'month_event','step':month_current_step}),
              dataType: "html",
              async:true,
              success: function(msg){
                jQuery(".month_events").html(msg);
                 jQuery(".news_loader_eventi").hide();
     
              }
             });
      });
   
   
   
  }
  
  
  if(jQuery("#green_tab1").is("a") && jQuery("#green_tab2").is("a")&& jQuery("#green_tab3").is("a")){
     
     jQuery("#green_tab1").bind("click",function(e){
        e.preventDefault();
         jQuery("#open_tab_1").show();
         jQuery("#green_tab1").addClass("selected");
         
         jQuery("#open_tab_2").hide();
         jQuery("#green_tab2").removeClass("selected");
         
         jQuery("#open_tab_3").hide();
         jQuery("#green_tab3").removeClass("selected");
     });
     
     jQuery("#green_tab2").bind("click",function(e){
        e.preventDefault();
        jQuery("#open_tab_1").hide();
        jQuery("#green_tab1").removeClass("selected");
         
         jQuery("#open_tab_2").show();
         jQuery("#green_tab2").addClass("selected");
         
         jQuery("#open_tab_3").hide();
         jQuery("#green_tab3").removeClass("selected");
     });
     
     jQuery("#green_tab3").bind("click",function(e){
        e.preventDefault();
        jQuery("#open_tab_1").hide();
        jQuery("#green_tab1").removeClass("selected");
        
         jQuery("#open_tab_2").hide();
         jQuery("#green_tab2").removeClass("selected");
         
         jQuery("#open_tab_3").show();
         jQuery("#green_tab3").addClass("selected");
     });
  }

 if(jQuery("#curiosita_detail_prev_handler").is("a") && jQuery("#curiosita_detail_next_handler").is("a")){
    c=0;
    all=jQuery(".curiosita_detail_post");
    jQuery("#curiosita_detail_next_handler").bind("click",function(e){
       current_c=c;
       if(current_c<all.length-1){
         jQuery(".curiosita_detail_container").animate({"left": "-="+150+"px"}, "slow");
         current_c=c++;
       }else{
          return false;
       }
       
    });
    
    jQuery("#curiosita_detail_prev_handler").bind("click",function(e){
       if(--c>=0){
         jQuery(".curiosita_detail_container").animate({"left": "+="+(150)+"px"}, "slow");
       }else{
          return false;
       }
    });
 }
 
if(jQuery("#searcheventi").is("form")){    
    jQuery( "#event_data_da" ).datepicker({dateFormat:'dd/mm/yy',
                        showOn: "button",
			buttonImage: "/wp-content/themes/thematic/images/transparent.png",
			buttonImageOnly: true}
                );
    jQuery( "#event_data_a" ).datepicker({dateFormat:'dd/mm/yy',showOn: "button",
			buttonImage: "/wp-content/themes/thematic/images/transparent.png",
			buttonImageOnly: true});
                    
    jQuery.datepicker.regional['it'] = {
	                closeText: 'Chiudi',
	                prevText: '&#x3c;Prec',
	                nextText: 'Succ&#x3e;',
	                currentText: 'Oggi',
	                monthNames: ['Gennaio','Febbraio','Marzo','Aprile','Maggio','Giugno',
	                        'Luglio','Agosto','Settembre','Ottobre','Novembre','Dicembre'],
	                monthNamesShort: ['Gen','Feb','Mar','Apr','Mag','Giu',
	                        'Lug','Ago','Set','Ott','Nov','Dic'],
	                dayNames: ['Domenica','Luned&#236','Marted&#236','Mercoled&#236','Gioved&#236','Venerd&#236','Sabato'],
	                dayNamesShort: ['Dom','Lun','Mar','Mer','Gio','Ven','Sab'],
	                dayNamesMin: ['Do','Lu','Ma','Me','Gi','Ve','Sa'],
	                weekHeader: 'Sm',
	                dateFormat: 'dd/mm/yy',
	                firstDay: 1,
	                isRTL: false,
	                showMonthAfterYear: false,
	                yearSuffix: ''}
    jQuery.datepicker.setDefaults(jQuery.datepicker.regional['it']);
}

if(jQuery("#searcheventihome").is("form")){    
    jQuery( "#event_data_da_home" ).bind('click',function(e){
        e.preventDefault();
        //console.log("asdasdasdsadas");
    })
    
    jQuery( "#event_data_da_home" ).datepicker({dateFormat:'dd/mm/yy',
                        showOn: "button",
			buttonImage: "/wp-content/themes/thematic/images/transparent.png",
			buttonImageOnly: true}
                );
    jQuery( "#event_data_a_home" ).datepicker({dateFormat:'dd/mm/yy',showOn: "button",
			buttonImage: "/wp-content/themes/thematic/images/transparent.png",
			buttonImageOnly: true});
    jQuery.datepicker.regional['it'] = {
	                closeText: 'Chiudi',
	                prevText: '&#x3c;Prec',
	                nextText: 'Succ&#x3e;',
	                currentText: 'Oggi',
	                monthNames: ['Gennaio','Febbraio','Marzo','Aprile','Maggio','Giugno',
	                        'Luglio','Agosto','Settembre','Ottobre','Novembre','Dicembre'],
	                monthNamesShort: ['Gen','Feb','Mar','Apr','Mag','Giu',
	                        'Lug','Ago','Set','Ott','Nov','Dic'],
	                dayNames: ['Domenica','Luned&#236','Marted&#236','Mercoled&#236','Gioved&#236','Venerd&#236','Sabato'],
	                dayNamesShort: ['Dom','Lun','Mar','Mer','Gio','Ven','Sab'],
	                dayNamesMin: ['Do','Lu','Ma','Me','Gi','Ve','Sa'],
	                weekHeader: 'Sm',
	                dateFormat: 'dd/mm/yy',
	                firstDay: 1,
	                isRTL: false,
	                showMonthAfterYear: false,
	                yearSuffix: ''}
    jQuery.datepicker.setDefaults(jQuery.datepicker.regional['it']);
}



  if(jQuery("#video_embed_id").is("div")){
    FlashHeed.heed(document.getElementById('video_embed_id'));
  }
})

function rolloverButton (id, state) {
  if (document.getElementById) {
    var element_id = document.getElementById(id);
       if(id=="submit"){
	if (state == 'over') {
	  element_id.className = 'button109x34over'
	}else{
	  element_id.className = 'button109x34'
	}
      }
      if(id=="invia_form"){
	if (state == 'over') {
	  element_id.className = 'invia_formhover'
	}else{
	  element_id.className = 'invia_form'
	}
      }
      if(id=="invia_form_azienda"){
	if (state == 'over') {
	  element_id.className = 'invia_form_aziendahover'
	}else{
	  element_id.className = 'invia_form_azienda'
	}
      }
      if(id=="searchsubmit"){
	if (state == 'over') {
	  element_id.className = 'searchsubmithover'
	}else{
	  element_id.className = 'searchsubmit'
	}
      }
      if(id=="inviasubmit"){
	if (state == 'over') {
	  element_id.className = 'inviasubmithover'
	}else{
	  element_id.className = 'inviasubmit'
	}
      }
      if(id=="searchsubmitazienda"){
	if (state == 'over') {
	  element_id.className = 'searchsubmitaziendahover'
	}else{
	  element_id.className = 'searchsubmitazienda'
	}
      }
      if(id=="searchsubmitprodotti"){
	if (state == 'over') {
	  element_id.className = 'searchsubmitprodottihover'
	}else{
	  element_id.className = 'searchsubmitprodotti'
	}
      }
      if(id=="searchsubmit_lavoro_offerte"){
	if (state == 'over') {
	  element_id.className = 'searchsubmit_lavoro_offertehover'
	}else{
	  element_id.className = 'searchsubmit_lavoro_offerte'
	}
      }
      if(id=="noresults-searchsubmit"){
	if (state == 'over') {
	  element_id.className = 'noresults-searchsubmithover'
	}else{
	  element_id.className = 'noresults-searchsubmit'
	}
      }
      if(id=="avvia_ricerca"){
	if (state == 'over') {
	  element_id.className = 'avvia_ricercahover'
	}else{
	  element_id.className = 'avvia_ricerca'
	}
      }
     if(id=="error404-searchsubmit"){
	if (state == 'over') {
	  element_id.className = 'error404-searchsubmithover'
	}else{
	  element_id.className = 'error404-searchsubmit'
	}
      }
  }
}



