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;

$j=jQuery.noConflict();
$j(document).ready(function(){

//    $("#socialSection").FishEye({
//       fishEyeItemName: ".fisheyLink img",
//       maxScalePct: 120,
//       scaleStepPct: 60
//    });

    $j("#donateButton a").hover(
      function() {
          $j(this).children('img').attr('src', 'http://www.yourownapplication.com/NovakForCongress/wp-content/themes/PoliticalCallToActionTheme/images/DonateButtonSelected.png');
      },
      function () {
          $j(this).children('img').attr('src', 'http://www.yourownapplication.com/NovakForCongress/wp-content/themes/PoliticalCallToActionTheme/images/DonateButton.png');
      }
    );

    $j("#ButtonSection a").hover(
      function() {
          $j(this).children('div').addClass('hoverClass');
      },
      function () {
          $j(this).children('div').removeClass('hoverClass');
      }
    );
		
		$j('#mc_signup_form div:eq(1)').css('display', 'block');
		$j('#mc_signup_form div:eq(2)').css('display', 'block');
    $j('#eMailSection br').remove();
    $j('#eMailSection input').click(function() {
         $j('#eMailSection').addClass('emailEditSection');
    });
    
    /*
    $j("#socialSection").Fisheye(
				{
					maxWidth: 70,
					items: 'a',
					itemsText: 'span',
					container: '.fisheyeContainter',
					itemWidth: 60,
					proximity: 20,
					halign : 'center'
				}
			);
    */
    $galleryElement = $j('#main .widget-area ul ul ul.sub-menu').parent();
    $galleryElement.children('a').click(function() {
        if ($j(this).html().toUpperCase() == "GALLERIES") {
          return false;
        }
    });
    $galleryElement.hover(
      function() {
          if ($j(this).children('a').html().toUpperCase() == "GALLERIES") {
            setTimeout(function() {
              $galleryElement.children('ul.sub-menu').stop(true, true).show('medium');
            }, 300);
            //return false;
          }
      },
      
      function() {
          if ($j(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');
}

