var block;

var username = "  :: USERNAME";
var password = "  :: PASSWORD";
var searchString  = "  :: SEARCH BY KEYWORD";

$(document).ready( function() {
	
		$(".logInBox").click( function( coordinates ) {
			var offset = $(this).offset();
			$("#logInBox").css("display","block");
			$("#logInBox").css("left", (offset['left']) - 75 );
			$("#logInBox").css("top", (offset['top'] - 120) );
		});
		
		$(".emailBox").click( function( coordinates ) {
			var offset = $(this).offset();
			
			$("#emailBox").css("display","block");
			$("#emailBox").css("left", (offset['left']) - 75 );
			$("#emailBox").css("top", (offset['top'] - 120) );
		});
	
	$(".grayed-out").css("opacity",".7");
	
	$(".search-submenu").css("display","none");
	
	$("input").focus( function() {
		if( $(this).val() == username || $(this).val() == password || $(this).val() == searchString )
		{
			$(this).val("");	
		}
	});
							
	$("input").blur( function() {
		if( $(this).val() == "" )
		{
			if( $(this).attr("name") == "username"  || $(this).attr("name") == "user")
			{
				$(this).val(username);
			}
			if( $(this).attr("name") == "password" || $(this).attr("name") == "pass")
			{
				$(this).val(password);
			}
			if( $(this).attr("name") == "searchString" )
			{
				$(this).val(searchString);
			}
			if( $(this).attr("name") == "tx_indexedsearch[sword]" )
			{
				$(this).val(searchString);
			}
		}
	});
	
	$(function() {
		$("#left-search").tabs();
	});
		
	 $(".search-result-format a").click(function () {
        if( $(this).next().css("display") == "none" )
		{
			$(this).find(".twist-white").attr("src","images/twist-open.png");
			$(this).next().slideDown("normal");
			$(this).parent().parent().find(".hidden").css("display","block");
			$(this).parent().parent().find(".hidden").prev().css("display","none");
			$(this).css("color","#ee7c1f");
			$(this).css("font-weight","bold");
		}
		else
		{
			block = 0;
			$(this).find(".twist-white").attr("src","images/twist-closed.png");
			$(this).css("color","#818386");
			$(this).css("font-weight","normal");
			
			$(".section1 .inner-search-result").each( function(intIndex) {
					if( $(this).css("display") == "block")
					{
						block++;
					}
				  });
			
				if( block <= 1 )
				{
					$(this).parent().parent().find(".hidden").css("display","none");
					$(this).parent().parent().find(".hidden").prev().css("display","block");
				}

			$(this).next().slideUp("normal", function() { 
				
			});
		}
		

    });

	
	 $("#left-search .search-header-item").children("a").click(function () {
        if( $(this).next().css("display") == "none" )
		{
			$(this).children(".twist-brown").attr("src","images/twist-open.png");
			$(this).next().css("display","block");
		}
		else
		{
			$(this).children(".twist-brown").attr("src","images/twist-closed.png");
			$(this).next().css("display","none");
		}
    });


	/**
	***
	***	Puts the borders on the tables, but automatically does not put the right border on the last item
	***
	**/
	$(".search-table tr td").css("border-width","0 1px 0 0");
	$(".search-table tr th").css("border-width","0 1px 0 0");	
	
	$("#.search-table tr").each( function(intIndex) {
			$(this).find("td:last").css("border-width","0");
			$(this).find("th:last").css("border-width","0");
	});
	
	$("#shareToolsLink").click( function() {
									 if( $(this).parent().find("#shareToolsHidden").css("display") == "none" )
									 {
										 toggleShareTools("block");
									 }
									 else if( $(this).parent().find("#shareToolsHidden").css("display") == "block" )
									 {
										 toggleShareTools("none");
									 }
									 });
});

function callPNGFix()
{
	$(document).ready( function() {
		setTimeout("DD_belatedPNG.fix('img, div, li')",100);
	});
}

function closeLogInBox()
{
	$("#logInBox").css("display","none");
}

function closeEmailBox()
{
	$("#emailBox").css("display","none");
}

function toggleShareTools( value )
{
	$("#shareToolsHidden").css("display",value);
}

function displaymessage()
{
   alert("Hello World!");
}

function changeGETx() {

   var sHref = document.getElementById("glink").href;
   sHref = sHref.substring(0, sHref.indexOf('?'));
   document.getElementById("glink").href = sHref;
   
   return;

}
function changeGET(tmpl)
   {
      var shref = document.getElementById("glink").href;
      var shref2 = shref.substr(0,shref.lastIndexOf("&"));

      /* this changes the link text */
      switch (tmpl) {
         case 0:
            tmplname = "No";
            break;
         case 1:
            tmplname = "Housing";
            break;
         case 2:
            tmplname = "Environment";
            break;
         case 3:
            tmplname = "Economy";
            break;
      }
      document.getElementById("glink").innerHTML="Download all files for this group<br />" + tmplname + " Template";

      /* this changes the link / href */
      document.getElementById("glink").href = shref2 + "&tmpl=" + tmpl;
      return;
   }


