$j=jQuery.noConflict();

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

function jsddm_open()
{  jsddm_canceltimer();
   jsddm_close();
   ddmenuitem = $j(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.onclick = jsddm_close;
	  
jQuery(function(){
	console.log('test');	
	if ($j(".page-id-51").length < 0){
	$j(".contentItem:odd").addClass("odd");
	}
	$j(".contentItem br").remove();
	$j("#slideshow br").remove();
	$j("#slideshow a").click(function(){alert("test");});
	$j(".contentItem p:empty").remove();
	var totalHeight = 0;
	var tooBig = parseFloat($j("#newsHolder").innerHeight() - $j("#newsHolder h2").outerHeight());
	$j("#newsHolder li").each(function(){
		totalHeight = totalHeight + $j(this).outerHeight();
		if (totalHeight > tooBig) {
			//$j(this).remove();
		}
	});

  $j('#menu-header-menu > li').bind('mouseover', jsddm_open)
   $j('#menu-header-menu > li').bind('mouseout',  jsddm_timer)

	$j("#menu-header-menu ul").each(function(){
		$j(this).append("<div class = 'menubottom'></div><div class = 'menutop'></div>");
		$j(this).children("li:last").addClass('last');
	});

	
	$j("#pagerInner").css("margin-left",($j("#pager").width() - $j("#pagerInner").width())/2)
	$j("#slideshow").cycle({fx: 'fade', pager: "#pager", timeout: 6000, speed: 1250})

	$j(".glowphoto").each(function(){
		$j(this).wrap('<div class="photo" />')
	});
	
	
	$j("#interior img").each(function(){
	if ($j(".page-id-51").length < 0){
		console.log('test');
		if($j(this).attr("src") != "http://www.ourmilitarykids.org/images/page_white_acrobat.png") {
		$j(this).wrap("<div class = 'photo' />");
		}
	}
	});
	
	$j("p").each(function(){
		if ($j(this).html().length == 0){
			$j(this).remove();
		}
	});
	
	
	$j("#interior img.alignleft").each(function(){
		$j(this).parents(".photo").addClass("alignleft");
	});
	
	$j("#interior img.alignright").each(function(){
		$j(this).parents(".photo").addClass("alignright");
	});
	
	$j("#interior img.alignnone").each(function(){
		$j(this).parents(".photo").addClass("alignleft").after("<div class = 'clearer'></div>");
	});
	
	$j(".photo").each(function(){
		$j(this).append("<div class = 'glowBox topLeft'>").append("<div class = 'glowBox topRight'>").append("<div class = 'glowBox bottomLeft'>").append("<div class = 'glowBox bottomRight'>").append("<div class = 'glowBox top'>").append("<div class = 'glowBox bottom'>").append("<div class = 'glowBox left'>").append("<div class = 'glowBox right'>");
	})	
	$j(".sub-menu").each(function(){
		$j(this).children("li:last").addClass('last');
	})

	$j("#menu-footer-menu").children("li:first").addClass("first")

	$j("body").css("min-height",$j(window).height())
})

$j(window).resize(function() {
	$j("body").css("min-height",$j(window).height())
});

$j(window).load(function(){
	
	$j("#kidOfTheMonth .photo").css("margin-left",($j("#photoHolder .inner").width() - $j("#kidOfTheMonth .photo").width())/2);
});
