var timeout = 500;
var closetimer = 0;
var ddmenuitem = 0;

function jsddm_open() {
    jsddm_canceltimer();
    jsddm_close();
    ddmenuitem = $(this).find('ul').css('visibility', 'visible');
}

function jsddm_close()
{ if (ddmenuitem) ddmenuitem.css('visibility', 'hidden'); }

function jsddm_timer()
{ closetimer = window.setTimeout(jsddm_close, timeout); }

function jsddm_canceltimer() {
    if (closetimer) {
        window.clearTimeout(closetimer);
        closetimer = null;
    }
}





$(document).ready(function () {
    $(".address").parent().hide();

    if (!window.console) {
        window.console = {};
        methods = ['trace', 'log', 'info', 'debug', 'warn', 'error'];
        for (var key in methods) {
            window.console[methods[key]] = function (msg) { };
        };
    };

    //Menu
    $('#jsddm > li').bind('mouseover', jsddm_open)
    $('#jsddm > li').bind('mouseout', jsddm_timer)
    document.onclick = jsddm_close;

    $(function () {
        $('.collection a').lightBox({ fixedNavigation: true });
    });
  

    $("li.headlink").live('mouseover mouseout mousedown mouseup', function (event) {
        if (event.type == 'mouseover') {
            $(this).addClass('active');
        }
        else if (event.type == 'mouseout') {
            $(this).removeClass('active');
        }
        else if (event.type == 'mousedown') {

        }
    });


    $("#submenu a").live('mouseover mouseout mousedown mouseup', function (event) {
        if (event.type == 'mouseover') {
            $(this).addClass('active');

            var at = $(this).attr('id')
            $('.pagebody .' + at + '').show();


        }
        else if (event.type == 'mouseout') {
            $(this).removeClass('active');

            var at = $(this).attr('id')
            $('.pagebody .'+at+'').hide();
        }
        else if (event.type == 'mousedown') {

        }
    });

    $(".downloads a").live('mouseover mouseout mousedown mouseup', function (event) {
        if (event.type == 'mouseover') {
            $(this).addClass('active');
        }
        else if (event.type == 'mouseout') {
            $(this).removeClass('active');
        }
        else if (event.type == 'mousedown') {

        }
    });
  
      $(".downloads h1").live('mouseover mouseout mousedown mouseup', function (event) {
        if (event.type == 'mousedown') {


            $(".download-collection").removeClass('active');

            if ($(this).next().hasClass('active')) {
                $(this).next().removeClass('active');
            }
            else {
                $(this).next().addClass('active');
            }

        }
        else if (event.type == 'moused') {

        }
        else if (event.type == 'mousedown') {

        }
    });
  
  $(window).resize(function() {
    if($('.collection').length > 0)
    {
      var h = $(window).height() - 462;
      $('.collection').css('padding-top',h);
      console.log($(window).height())
        console.log($('.collection').height())
        console.log(h)
    }
  });
      
    if($('.collection').length > 0)
    {
      var h = $(window).height() - 462;
      $('.collection').css('padding-top',h);
      console.log($(window).height())
        console.log($('.collection').height())
        console.log(h)
    }
      /*
  if($('.collection').length > 0)
    {
      var h = $(window).height() - $('.collection').height() - 150;
      $('.collection').css('margin-top',h);
      console.log($(window).height())
        console.log($('.collection').height())
        console.log(h)
    }
        */
       
        /* 
  $(window).resize(function() {
    if($('.collection').length > 0)
    {
      var h = $(window).height() - $('.collection').height() - 200;
      $('.collection').css('margin-top',h);
    }
  });
  
  if($('.collection').length > 0)
    {
      var h = $(window).height() - $('.collection').height() - 150;
      $('.collection').css('margin-top',h);
      console.log($(window).height())
        console.log($('.collection').height())
        console.log(h)
    }*/
});

