// ----- CUSTOM JQUERY FUNCTIONS --------

  jQuery.fn.center = function () {
      this.css("position","absolute");
      this.css("top", ( $(window).height() - this.height() ) / 2+$(window).scrollTop() + "px");
      this.css("left", ( $(window).width() - this.width() ) / 2+$(window).scrollLeft() + "px");
      return this;
  }
  
  
// -------------------------------
// Menu JS ---------------------
var timeout = 500;
var closetimer = 0;
var zoomenuitem = 0;

// zoomenuitem (tert items)
function zoo_open() {
    zoo_canceltimer();
    zoo_close();
    zoomenuitem = $(this).find('ul').eq(0).css('visibility', 'visible');
    $(this).find('a').eq(0).addClass("tempOn");
}
function zoo_close()
{
    if (zoomenuitem) {
		zoomenuitem.css('visibility', 'hidden');
        $(this).find('a').eq(0).removeClass("tempOn");
	}
}

// timer and close
function zoo_timer()
{ closetimer = window.setTimeout(zoo_close, timeout); }
function zoo_canceltimer() {
    if (closetimer) {
        window.clearTimeout(closetimer);
        closetimer = null;
    }
}
$(document).ready(function() {
    //$('#menu-ct ul#menu.menu > li').bind('mouseover', zoo_open);
    //$('#menu-ct ul#menu.menu > li').bind('mouseout', zoo_close);
	
	$('ul.menu').superfish({ 
        delay:       200,                            // one second delay on mouseout 
        animation:   {opacity:'show'},  // fade-in and slide-down animation 
        speed:       100,                          // faster animation speed 
        autoArrows:  false,                           // disable generation of arrow mark-up 
        dropShadows: false                            // disable drop shadows 
    }); 
	
});
//document.onclick = zoo_close;



// ------------------------------
  // Legacy ------------------------------------------------------------------

  Zoomedia = {

    version: '1.0',

    redirect: function(url) {
      var anchor_pos = url.indexOf("#");
      document.location.href = (anchor_pos == -1) ? url : url.substr(0, anchor_pos);
    },

    print: function() {
      if (window.print) {
        window.print();
      } else {
        alert("Sorry, your browser doesn't support this feature.\nPlease use your browser's print button");
      }
      return false;
    }
  };

  // --------------------------------------------------------------------------
  // --------------------------------------------------------------------------

  Zoomedia.Glossary = new function() {

    // ------------------------------------------------------------------------

    this.current = null;

    // ------------------------------------------------------------------------

    this.items = {};

    // ------------------------------------------------------------------------

    this.tpl = '<div class="glossary">'+
                '<div class="header">%POPUP_TITLE%</div>'+
                '<div class="main">%POPUP_CONTENT%</div>'+
                '<div class="footer"><a href="#" onclick="Zoomedia.Glossary.hide(\'div_%GLOSSARY_ID%\'); return false;">close</a></div>'+
               '</div>';

    // ------------------------------------------------------------------------

    this.setItems = function(items) {
      this.items = items;
    };

    // ------------------------------------------------------------------------

    this.show = function(a, id, event) {
      if (this.current) {
        this.hide(this.current);
      }

      var div = document.createElement('div');
          div.setAttribute('id', 'div_'+id);
          div.onclick = function() { Zoomedia.Glossary.hide( 'div_'+id ); };
          div.className = 'gloss_def';
          div.style.position = 'absolute';
          div.style.display = 'none';
          div.style.zIndex = 2000;

          /*offset = document.body.scrollTop ? document.body.scrollTop : document.documentElement.scrollTop;
          if (!offset) {
            offset = 0; // stupid ie5/mac
          }

          div.style.top = (offset + event.clientY)+'px';
          div.style.left = event.clientX+'px';*/

          div.innerHTML = this.tpl.replace('%GLOSSARY_ID%', id).replace('%POPUP_TITLE%', this.items[id].title).replace('%POPUP_CONTENT%', this.items[id].content);

      //insert div before anchor tag
      a.parentNode.insertBefore(div, a);

      div.style.top  =  (a.offsetTop - a.clientHeight - div.clientHeight) + 'px';
      div.style.left = a.offsetLeft+'px';
      div.style.display = 'block';

      this.current = 'div_'+id;

      //close removes the dynamically created div
      //div.parentNode.removeChild(div);
    };

    // ------------------------------------------------------------------------

    this.hide = function(eleId) {
      var div = document.getElementById(eleId);
      if (div) {
        div.parentNode.removeChild(div);
      }
    };

    // ------------------------------------------------------------------------

  };
  
  Zoomedia.FontSize = function(font_size) {

    // ------------------------------------------------------------------------

    var sizes = ['small', 'medium', 'large'];

    // ------------------------------------------------------------------------

    var body = document.getElementsByTagName('body')[0];

    // ------------------------------------------------------------------------

    var current_font_size = 'medium';

    // ------------------------------------------------------------------------

    var match = document.cookie.match(/(?:font_size=(.+)(?:;?|$))/);

    // ------------------------------------------------------------------------

    if (match) {
      current_font_size = match[1];
      if (font_size == current_font_size) {
        return;
      }
    }

    // ------------------------------------------------------------------------

    body.className = body.className.replace('/ '+current_font_size+'/', '');

    // ------------------------------------------------------------------------

    body.className = ' '+font_size;

    // ------------------------------------------------------------------------

    document.cookie = 'font_size='+font_size+';path=/;';

    // ------------------------------------------------------------------------

  };

  // --------------------------------------------------------------------------

  var hbx = undefined;

  // --------------------------------------------------------------------------

  Zoomedia.Form = new function() {

    // ------------------------------------------------------------------------

    this.submit = function(form) {
      if (hbx != undefined) {
        hbx.pn += '+FORM+SUBMIT';
      }
      document.getElementById(form).submit();
    };

    // ------------------------------------------------------------------------

    this.formatNumber = function(value) {
      return value.replace(/[^\d.]/g, '');
    };

    // ------------------------------------------------------------------------

    this.formatTelephoneNumber = function(value) {
      return value.replace(/[^\d]/g, '');
    };

    // ------------------------------------------------------------------------

  };

    // --------------------------------------------------------------------------

  Zoomedia.SharePage = new function(id) {

    // ------------------------------------------------------------------------

    this.timer = null;

    // ------------------------------------------------------------------------

    this.delay = 500;

    // ------------------------------------------------------------------------

    this.active = false;

    // ------------------------------------------------------------------------

    this.setActive = function(enabled) {
      this.active = enabled;
    };

    // ------------------------------------------------------------------------

    this.isActive = function() {
      return this.active;
    };

    // ------------------------------------------------------------------------

    this.setTimeOut = function(el) {
      var self = this;
      var id = el.getAttribute('id');
      this.timer = window.setTimeout(function() { self.mouseOut(document.getElementById(id)); }, this.delay);
    };

    // ------------------------------------------------------------------------

    this.hide = function(el) {
      this.setActive(false);
      document.getElementById('share-page-widget').style.display = 'none';
    };

    // ------------------------------------------------------------------------

    this.show = function(a) {
      //if (this.isActive()) {
        //return;
      //}

      this.setActive(true);

      var widget = document.getElementById('share-page-widget');
      if (widget) {
        widget.style.top  = (a.offsetTop + a.offsetHeight) + 'px';
        widget.style.left = a.offsetLeft+'px';
        widget.style.display = 'block';
      }

      return false;
    };

    // ------------------------------------------------------------------------

  }; //Zoomedia.SharePage

  // --------------------------------------------------------------------------

