var main_host;
var img_array = new Array();
var swap_img = "";
var debug = true;
var rel_root = '/';

$(function() {

	main_host = location.href.replace(location.pathname, '').replace(location.search, '')+rel_root;
  
  log('Campi restricted: '+$('.restricted').size());
  $('.restricted').bind('keypress', function(e) {
    return restricted(e, $(this).attr('rel'));
  });

  /**
   * Gestione degli helptip.
   */
  $('.helptip').hover(function() { showhelptip(this);}, function () {hidehelptip()});
  $('.helptip').bind('click', function() { return false; });

  $('.newwindow').each(function() {
    $(this).attr({'title' : $(this).attr('title')+' '+getLang('base', 'NEW_WINDOW')});
  });

  $('.newwindow').bind('click', function() {
    href = $(this).attr('href');
    height = $(window).height()-30;
    width = $(window).width()-30;
    window.open(href, '', 'width='+width+',height='+height);
    return false;
  });
  
  if($('#infortemplatedialog').length > 0) {
    $('#infotemplate').click(function() {
      $('#infortemplatedialog').dialog({'position':[0, 100], width:'400px', 'title': getLang('base', 'INFO_TEMPLATE')});
    });
  }
  
  $("[placeholder]").focus(function() {
    var input = $(this);
    if (input.val() == input.attr("placeholder")) {
      input.val("");
      input.removeClass("placeholder");
    }
  }).blur(function() {
    var input = $(this);
    if (input.val() == "" || input.val() == input.attr("placeholder")) {
      input.addClass("placeholder");
      input.val(input.attr("placeholder"));
    }
  }).blur();  
  
  if($('#headerHomeImg').find('img').length > 1) { 
    setInterval( "slideSwitch()", 5000 );
  }

});


function slideSwitch() {
    var $active = $('#headerHomeImg img.active');

    if ( $active.length == 0 ) $active = $('#headerHomeImg img:last');

    var $next =  $active.next().length ? $active.next() : $('#headerHomeImg img:first');

    $active.addClass('last-active');

    $next.css({opacity: 0.0})
        .addClass('active')
        .animate({opacity: 1.0}, 1000, function() {
            $active.removeClass('active last-active');
        });
}

