var fileTypes = {
  doc: baseurl+'lib/img/icons/doc.png',
  xls: baseurl+'lib/img/icons/xls.png',
  pdf: baseurl+'lib/img/icons/pdf.png',
  txt: baseurl+'lib/img/icons/txt.png',
  zip: baseurl+'lib/img/icons/zip.png',
  ppt: baseurl+'lib/img/icons/ppt.png'
};

Shadowbox.loadSkin('classic', 'lib/js/shadowbox');
Shadowbox.loadLanguage('it', 'lib/js/shadowbox/lang');
Shadowbox.loadPlayer(['flv', 'html', 'iframe', 'img', 'qt', 'swf', 'wmp'], 'lib/js/shadowbox/player');

$(document).ready(function(){

//shadowbox
Shadowbox.init();

// this is like $.each() above, except
// it iterates over the matched elements
$('.atch a').each(function() {
 
  // get a jQuery object for each anchor found
  var $a = $(this);
 
  // get the href attribute
  var href = $a.attr('href');
 
  // get the extension from the href
  var hrefArray = href.split('.');
  var extension = hrefArray[hrefArray.length - 1];
 
  var image = fileTypes[extension];
 
  if (image) {
    $a.css({
      background: 'transparent url("' + image + '") no-repeat center left'
    });
  }
 
});

  $('#print').click(function(){print();});
   
  $('div.flash_visore ul').hide();
  $('#slide_menu a').mouseover(function(){
    $('div.flash_visore ul').hide();
    menu_clear();
    $(this).addClass('active');
    $('div.flash_visore ul.'+$(this).attr('id')).show();
    if($(this).attr('id')){
      $(this).click(function(){return false;});
    } 
    
  });
  
  $('div.flash_visore ul').mouseover(function(){
    ($('#' + $(this).attr('class'))).addClass('active');
  });
  
  $('#slide_menu a').mouseout(menu_clear);
  
/*  
  $("#invia_form").validate({
    rules: {
      'messaggio': "required",
      'nome': "required",
      't_nome': "required",
      't_email': "required",
      'email':{
        required: true,
        email: true
      },
      't_email':{
        required: true,
        email: true
      }
    }
  });

  $('#invia_form').submit(function(){
  

          var inputs = [];
          $(':input', this).each(function() {
            inputs.push(this.name + '=' + escape(this.value));
          })
          $(':textarea', this).each(function() {
            inputs.push(this.name + '=' + escape(this.value));
          })
          
          // now if I join our inputs using '&' we'll have a query string
          $.ajax({
            data: inputs.join('&'),
            url: this.action,
            timeout: 2000,
            type: 'POST',
            error: function() {
              console.log("Failed to submit");
            },
            success: function(r) { 
              $(this).slideToggle();
              return false;
            }
          });
          
          return false;
  });
*/  
  if($('#invia_pagina')){
    $('#invia_pagina').hide();
    $('a.invia_amico').click(function(){$('#invia_pagina').slideToggle(); return false;});
  }
  

});

function menu_clear(){
  $('#slide_menu a').removeClass('active'); 
}
  
function error_pwd(){
 	Element.show('error_head');
 	setTimeout("Element.hide('error_head');",5000);
}

function validate_amico(){
}
var loader = '';
  jQuery(function() {
    loader = $('#response_invio').css({color: "#C00", fontSize:'14px'}).hide();
    jQuery().ajaxStart(function() {      
    }).ajaxStop(function() {
      setTimeout("loader.hide()",5000);
    }).ajaxError(function(a, b, e) {
      throw e;
    });
    
    var v = jQuery("#invia_form").validate({
      submitHandler: function(form) {
        jQuery(form).ajaxSubmit({
          target: '#response_invio',
          success:    function() { 
                        $('#invia_pagina').slideToggle();
                        loader.show();
                      } 
        });
      }
    });

  });