var timeout    = 1000;
var closetimer = 0;
var ddmenuitem = 0;

var $jwPlayer;

function jsddm_open() {
  jsddm_canceltimer();
   jsddm_close();
   ddmenuitem = $(this).find('.children');
   if (ddmenuitem.css('display') == 'none') {
    //ddmenuitem.show('slow');
     ddmenuitem.css('display', 'block');
  }
}

function jsddm_close()
{  if(ddmenuitem) ddmenuitem.css('display', 'none');}

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

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

document.onclick = jsddm_close;

$(document).ready(function(){

    $galleryElement = $('#main .widget-area ul ul ul.sub-menu').parent();
    $galleryElement.children('a').click(function() {
        if ($(this).html().toUpperCase() == "GALLERIES") {
          return false;
        }
    });
    $galleryElement.hover(
      function() {
          if ($(this).children('a').html().toUpperCase() == "GALLERIES") {
            setTimeout(function() {
              $galleryElement.children('ul.sub-menu').stop(true, true).show('medium');
            }, 300);
            //return false;
          }
      },
      
      function() {
          if ($(this).children('a').html().toUpperCase() == "GALLERIES") {
            setTimeout(function() { 
              $galleryElement.children('ul.sub-menu').stop(true, true).hide('medium');  
            }, 600);
            //return false;
          }
      }
    );
    
    
//  Replace the menu items with images
//  $('#primary li a').each(function(index) {
//    if ($(this).attr('title') == 'Home Page') {
//      $(this).html('');
//      $(this).append('<img src="/TakeAimPhotography/wp-content/themes/TakeAimDemo/images/HomeText98_29.png" />');
//    } else if ($(this).attr('title') == 'About') {
//      $(this).html('');
//      $(this).append('<img src="/TakeAimPhotography/wp-content/themes/TakeAimDemo/images/About125_36.png" />');
//    } else if ($(this).attr('title') == 'Galleries') {
//      $(this).html('');
//      $(this).attr('href', '#');
//      $(this).click(function() {
//        return false;
//      });
//      $(this).append('<img src="/TakeAimPhotography/wp-content/themes/TakeAimDemo/images/Galleries205_39.png" />');
//    } else if ($(this).attr('title') == 'Blog') {
//      $(this).html('');
//      $(this).append('<img src="/TakeAimPhotography/wp-content/themes/TakeAimDemo/images/Blog98_41.png" />');
//    }
//  });
  
});

function verticalAlignDivInPage($divToAlign) {
  var divHeight = $divToAlign.height();
  var pageHeight = $(window).height();
  var margin = 0;
  if (divHeight > pageHeight) {
     margin = 0;
  } else {
    margin = ((pageHeight - divHeight) / 2)
  }
  $divToAlign.css('margin-top', '' + margin + 'px');
}

