/*!
 * common.js
 *
 * @project   Cosmovel
 * @author    emmanuel.sammut
 * @version   1.0
 * @use       common JavaScipt for all pages
 */

/* ----------------------------------------------------------------
 * 1. FUNCTIONS
 */

  /** Protected alias $ of jQuery object */
  (function($){

    /**
     * <p>Fix an error in Internet Explorer 6 when a container is positioned over a selecbox</p>
     * <p>Added or removed a iframe after this return element</p>
     *
     * @param {Boolean} add used true for add iframe element
     * @return {jQuery}
     */
    $.fn.fixIframe = function(add){
      var that = $(this);
      // if IE6
      if(navigator.userAgent.indexOf("MSIE 6") != -1){
        if(add){
          that.after("<iframe frameborder=\"0\" scrolling=\"no\" style=\"width:" + that.outerWidth() + "px; height:" + that.outerHeight() + "px;\position:absolute; top:0; left:0; z-index:-1;\"></iframe>");
        }else{
          that.parent().find("iframe").remove();
        }
      }
      return that;
    };

    /**
     * <p>Using basic the Console API of Firebug or use javascript method alert().</p>
     *
     * @param {Object} val test value
     * @param {String} [fn] used valid method to Console API
     */
    $.alert = function(val, fn){
      fn = fn || "info";
      if(val){
        if(console && console[fn]){
          console[fn](val);
        }else{
          alert(val);
        }
      }
    };

  })(jQuery);


/* ----------------------------------------------------------------
 * 2. EVENTS
 */

  /** jQuery onload DOM */
  $(function(){

    /**
     * <p>Set parameter for nyroModal jQuery plugin</p>
     */
    $.nyroModalSettings({
      bgColor: "#d0dce6",
      width: 300,
      height: 200,
      minWidth: 300,
      minHeight: 200
    });

    /**
     * @event navigation
     *
     * <p>Show or hide markup <ul> when the user focuses on class continent or not.</p>
     * <p>Initialize by default at hide.</p>
     */
    $("#nav").
      find(".continent").
        hover(
          function(){
            $("ul", this).
              show().
              fixIframe(true).
              prev("p").
              addClass("over");
          },
          function(){
            $("ul", this).
              hide().
              fixIframe(false).
              prev("p").
              removeClass("over");
          }
        ).
        find("ul").
          css("position", "absolute").
          hide().
          find("li").
            hover(
              function(){
                $(this).addClass("over");
              },
              function(){
                $(this).removeClass("over");
              }
            );

  });

