var over = false;

$(function(){
	
	$(".mouseover")
		.css("cursor","pointer")
		.mouseover(function(){
			$(this).attr("src",$(this).attr("src").replace(".png","1.png"));
		})
		.mouseout(function(){
			$(this).attr("src",$(this).attr("src").replace("1.png",".png"));
		});
		
	if ($(".whatsup").length>0)
	{
		var p = $(".whatsup P");
		if ($(p).length>whatsup_init_show)
		{
			hideExtraElem(p,whatsup_init_show);
			$(".whatsup").append("<div align=\"center\"><br/><img class=\"wtoggle\" src=\"/nyp/slot/u100/style/homepage/expand.jpg\"/></div>");
		}
	}
	
  $(".sitemenu LI A")
	.mouseover(function(event){
		var obj = $(this).closest("LI").find(".dropmenu");
		if ($(obj).length>0)
		{	$(obj).css("display","block");	}
	})
	.mouseout(function(event){
		var obj = $(this).closest("LI").find(".dropmenu");
		if ($(obj).length>0)
		{	
			var mid=$(obj).attr("id");
			setTimeout("really_hide('"+mid+"')","200");
		}
	});

  $(".sitemenu .dropmenu")
	.css("display","none")
	.mouseover(function(){
		over = true;
		$(this).css("display","block");
	})
	.mouseout(function(){
		over = false;
		$(this).css("display","none");
	});
	
	$(".wtoggle").css("cursor","pointer").live("click",function(){
		var src = $(this).attr("src");
		if (src.toString().indexOf("expand.jpg")>0)
		{
			$(this).attr("src",src.toString().replace("expand","collapse"));
			$(".whatsup P").show();
		}
		else
		{
			$(this).attr("src",src.toString().replace("collapse","expand"));
			hideExtraElem($(".whatsup P"),whatsup_init_show);
		}
	});
		
	if ((window.location.pathname!="/")&&(enableLike=='1'))
	{		
		var fb = "<div class=\"fblike_cnt\"><div class=\"fblike\"><iframe src=\"//www.facebook.com/plugins/like.php?app_id=218763318180238&amp;href="+escape(window.location)+"&amp;send=false&amp;layout=button_count&amp;width=100&amp;show_faces=false&amp;action=like&amp;colorscheme=light&amp;font=arial&amp;height=21\" scrolling=\"no\" frameborder=\"0\" style=\"border:none; overflow:hidden; width:100px; height:21px;\" allowTransparency=\"true\"></iframe></div></div>";
		$(fb).insertAfter(".pagecontent_box h1");	
	}
	
	if (window.location.pathname!="/")
	{	$("<div class=\"pagetitle_sep\"><p></p></div>").insertAfter(".pagecontent_box H1");	}

	$("a").click(function(){
		if (($(this).attr("target")=="") && (!$(this).hasClass("nivo-control")))
		{
			var path = $(this).attr("href");
			var hostname = window.location.hostname;
			
			if ((path.indexOf(".pdf")>-1)||((path.indexOf("http")==0)&&(path.indexOf(hostname)==-1)))
			{	window.open(path);		}
			else		
			{	window.location=path;	}
		
			return false;
		}
	});
});

function hideExtraElem(obj, len)
{
	for (var i=len;i<$(obj).length;i++)
	{	$(obj[i]).hide();	}
}

function really_hide(mid)
{ 
  if (!over)
  {  $("#"+mid).css("display","none");  }
}

