// JavaScript Document

jQuery(document).ready(function() {
  $("#content").fadeIn(1000);
  $(".popupLink").fancybox({
    'width' : 1000,
    'height' : 700,
    'autoScale' : false,
    'transitionIn' : 'elastic',
    'transitionOut' : 'elastic',
    'type' : 'iframe'
  });
  
  $(this).oneTime("0.5s", function() {
    $(".automaticPopup").trigger("click");
  });
  
  //$(".automaticPopup").css('display', 'none');
  
  $(".automaticPopup").fancybox({
    'width' : 1000,
    'height' : 700,
    'autoScale' : false,
    'transitionIn' : 'elastic',
    'transitionOut' : 'elastic',
    'type' : 'iframe'
  });
   
  //pointer-events:none for IE
  if($.browser.msie){
    $("div#menu li a").click(function(event) {
      window.location = event.target.href;
    });
    $("#banner-image").mousemove(passThroughHover);
    $("#banner-image").click(passThroughClick);
  }
});

function passThroughHover(e) {
    var wasOverMenu = false;
    $("div#menu li").each(function() {
       // check if hovered point (taken from event) is inside element
       var mouseX = e.pageX;
       var mouseY = e.pageY;
       var offset = $(this).offset();
       var width = $(this).width();
       var height = $(this).height();

       if (mouseX > offset.left && mouseX < offset.left+width 
           && mouseY > offset.top && mouseY < offset.top+height)
       {
         $(this).addClass("active_ie"); // force active state
         $("#banner-image").css( "cursor", "pointer" ); //force pointer change
         wasOverMenu = true;
       }
      else
        $(this).removeClass("active_ie");
      
    });
  if(!wasOverMenu)
  {
    $("#banner-image").css( "cursor", "auto" ); //pointer normal
  }
}

function passThroughClick(e) {
    $("div#menu li").each(function() {
       // check if clicked point (taken from event) is inside element
       var mouseX = e.pageX;
       var mouseY = e.pageY;
       var offset = $(this).offset();
       var width = $(this).width();
       var height = $(this).height();

       if (mouseX > offset.left && mouseX < offset.left+width
           && mouseY > offset.top && mouseY < offset.top+height)
       {
         $(this).find("a").trigger("click"); // force click event
       }
    });
}

