// JavaScript Document

$(document).ready(
  function() 
    {
      //movelogo();
      hoverMenu();
      //setTimeout(function(){$('#booking').show();},3000);
      //caricamento asincrono social network
      
      setTimeout(function(){$.ajax({
         url: '/wp-content/themes/arciduca/social.php',
         success: function(data) {
	    $('#social').html(data);
         }
      })},
      3000);
      
      //caricamento asincrono booking
      /*setTimeout(function(){$.ajax({
         url: '/wp-content/themes/arciduca/booking.php',
         success: function(data) {
	    $('#booking').html(data);
	    $('#booking').show();
         }
      })},
      3000);*/ 
      
      
        //$.preLoadImages("");
      //$('#slide').show();
    }
);
function movelogo()
{
  $('#logo').stop().animate(
      {
        marginTop: '22px'
      }
    ,1500)
}

function hoverMenu()
{
  $('#wpm1 ul li').hover(
    
      function()
      {
        //ricavo parametri
        var position = $(this).position();
        var larg=$(this).width();
        var posT=$('.sf-blue ul').position();
        //alert(posT.left);
        //imposto coverMenu
        $('#coverMenu').css('margin-top','-68px');
        $('#coverMenu').show();
        $('#coverMenu').css('left',(position.left+posT.left));
        $('#coverMenu').css('width',(larg+0)); /*30 è il padding*/
        $('#coverMenu').stop().animate(
          {
            marginTop:  0 
          },
        400);
        
      },
      function()
      {
                
        $('#coverMenu').css('margin-top','0px');
        $('#coverMenu').stop().animate(
          {
            marginTop:  '-68px' 
          },
        400);
      }
    
  );
  $('#wpm1 ul li li').hover(
  
    function(){
    $('#coverMenu').stop();
    $('#coverMenu').hide();
    },
    function(){
    $('#coverMenu').stop();
    }
  );
}

function iscrizioneNews(valore)
{
  
  //loading immagine
   $('#results').html('<center><img src="/wp-content/themes/arciduca/images/loader.gif"></center>'); 

   $.ajax({
   type: "POST",
   url: "http://www.n3ws.it/setExternalUser.php",
   cache: false,
   data: $("#form_news").serialize(),
   dataType: "jsonp",
   success:function(data){
    if(data=='1')
    {
      $('#results').html('<span style="color:green;">Registtrazione effettuata.Grazie.</span>');
    }
    else
    {
      $('#results').html('<span style="color:red;">Email errata o presente.</span>');
    }
   }
 }); 
}

function sendContactForm()
{
  $('#resultsCont').html('<img src="/wp-content/themes/arciduca/images/loader.gif">');
  $.ajax({
    type: "POST",
    url: "/wp-content/themes/arciduca/sendContact.php",
    cache: false,
    data: $("#form_contact").serialize(),
    success: function(html)
    {
      $('#resultsCont').html(html);
    }
  });
}

(function($) {
  var cache = [];
  // Arguments are image paths relative to the current page.
  $.preLoadImages = function() {
    var args_len = arguments.length;
    for (var i = args_len; i--;) {
      var cacheImage = document.createElement('img');
      cacheImage.src = arguments[i];
      cache.push(cacheImage);
    }
  }
})(jQuery)
