
/**
 * Fire on document ready
 */
$(document).ready(function() {
  // bind fancybox to anchor elements
  $("a.fancyZoom").fancybox();

  // Mouse effect on Servizi gallery
  $("div.pic").mouseover(function() {
    $(this).stop(true, false).animate({
      width: $(this).children().width()
    }, 500);
  });

  // Mouse effect on Servizi gallery
  $("div.pic").mouseout(function() {
    $(this).stop(true, false).animate({
      width: '60px'
    }, 250);
  });

  setTimeout("openUpcomingBox()", 2000);

  // # Header image swap code..
  $('#leftHeader').addClass('loading');
  $('#headerPic').hide();

  // bind laoding event with DOM image
  $('#headerPic').load(function () {
    $(this).fadeIn(550);
    $('#leftHeader').removeClass('loading');
    
    // swap only if there are more than one pictures
    if(headerPic.length > 1) {setTimeout("swapPic()", 5000);}
    
  }).error(function () {
    $('#leftHeader').removeClass('loading');
    $('#leftHeader').append('<p class="small" style="padding-left:20px;">404: Errore nel caricamento</p>');
  }).attr('src', headerPic[headerPicIndex]);
  // ...end #
});


/**
 * Swap header pictures
 *
 * @headerPicIndex integer
 */
var headerPicIndex = 0;

function swapPic() {
  // index check and reset
  if(headerPicIndex >= headerPic.length-1) {headerPicIndex = 0;}
  else {headerPicIndex++;}

  $('#headerPic').fadeOut(300, function() {
    $('#leftHeader').addClass('loading');
    $(this).attr({
      'src': headerPic[headerPicIndex]
    });
  })
}


/**
 * open upcoming box
 */
function openUpcomingBox() {
  $("#upcoming").slideDown(500);
}


/**
 * open google maps from input
 */
function getDirections(s) {
  a = $("#"+s).val();
  var win = window.open('','map');
  win.location = "http://maps.google.it/maps?f=d&hl=it&saddr="+a+"&daddr=Autoparco+Brescia+Est‎&ie=UTF8";
}


/**
 * Swap banner images on the right side
 *
 * @i integer ticker's index
 */
var i = 1;

function ticker(id, max) {
  $('#'+id+i).fadeOut('fast', function () {
    if(i >= max) {
      i=1;
    } else {
      i++;
    }
    $('#'+id+i).fadeIn('fast');
  });
}

