$(document).ready(function()
{
	//createMouseOver(".ngg-gallery-thumbnail a", "#ngg-image-full div", "image-sm", "image-lg");
	createMouseOver(".video-thumb a", "#videos div", "video-sm", "video-lg");
	
	$(".toggle").each(function()
	{
		height = $(this).parent().height();
		$(this).parent().height(height);
		$(this).data("state", "closed");
		$(this).parent().data("origHeight", height);
	});
	$(".toggle").click(function()
	{
		var postContainer, postID, postEntry;
		
		$this = $(this);
		postContainer = $(this).parent();
		postID = parseInt(postContainer.attr("id").replace("post-", ""));
		postEntry = $("#post-" + postID + " > .entry");
		loading = $(".loading", this);
		
		if($(this).data("state") == "closed")
		{
			$(this).data("state", "open");
			if(postContainer.data("html") != "")
			{
				postEntry.data("html", postEntry.html());
				loading.css("display", "block");
				$.ajax(
				{
					url: "/wp-content/themes/lin/ajax.php?get=the_content&id=" + postID,
					success: function(data)
					{
						postEntry.html(data);
						calcHeight = 0;
						calcHeight = postEntry.height() + 15;
						postContainer.stop().animate({height: calcHeight + "px"}, 500);
						loading.css("display", "none");
						$($this).removeClass("closed");
						$($this).addClass("open");
					}
				});
			}
		} else if($(this).data("state") == "open")
		{
			$(this).data("state", "closed");
			postContainer.stop().animate({height: postContainer.data("origHeight") + "px"}, 500, "", function()
			{
				postEntry.html(postEntry.data("html"));
			});
			$this.removeClass("open");
			$this.addClass("closed");
		}
		return false;
	});
	$(".toggle2").click(function()
	{
		$(this).parent().siblings(".toggle").click();
		return false;
	});
});
function createMouseOver(hover, container, smallClass, largeClass)
{
	var numberOfImages = $(container).size();
	for(i = 2; i <= numberOfImages; i++)
	{
		$("#" + largeClass + "-" + i).css("display", "none");
	}
	$(hover).mouseenter(function()
	{
		imageToShow = $(this).attr("id").replace(smallClass, largeClass);
		dontHideId = $(this).attr("id").replace(smallClass + "-", "");
		$("#" + imageToShow).css("display", "block");
		for(i = 1; i <= numberOfImages; i++)
		{
			if(i != dontHideId)
				$("#" + largeClass + "-" + i).css("display", "none");
		}
	});
}
function clearIt(what)
{
	if(what.value=="SERCH <DIALOGUE")
  		what.value='';
}
function restore(what,txt)
{
	if(what.value=="")
		what.value=txt;
}
