// JavaScript Document
$(document).ready(function () {	
	$('#nav li.dropdown').hover(
		function () {
			//show its submenu
			$('ul', this).slideDown("1000");

		}, 
		function () {
			//hide its submenu
			$('ul', this).slideUp("1000");			
		}
	);
	//$("dd:not(:first)").hide();
	$("dt a").click(function(){			 
		//$("dd:visible").slideUp("normal");
			
		var curr_dd = $(this).parent().next();	
    	if (curr_dd.css("display") != "none") {
    		//curr_dd.slideUp("normal");
			return true;
		}
		else {
			curr_dd.slideDown("normal");
			return false;
		}
	});

	$("#left-column-nav ul li ul").hide();
	$(".nav-dropdown").click(function(){
		$("#left-column-nav ul li ul:visible").slideUp("normal");
					
		var curr_dd = $(this).parent().children(":nth-child(even)");	
        if (curr_dd.css("display") != "none") {
         	//curr_dd.slideUp("normal");
			return true; 
		}
		else {
			curr_dd.slideDown("normal");
			$(this).parent().children(":nth-child(even)").slideDown("normal");
			return false;
		}
	});
	
	$(".submenu").click(function(){
		var href = $(this).attr("href");
		
		$(".highlight").removeClass("highlight").css('color', '').css('text-decoration', '');
		$(this).addClass("highlight").css('color', '#FFF').css('text-decoration', 'underline'); 
		
		$.ajax({ url: href, dataType: "html", success: function(data){
			$("#right-column-content").html($("#right-column-content", data)[0].innerHTML);
			//initGallery();
     	}});
	  
		return false;
	});
	
	highlightLink();
	
	$('a.lightbox').lightBox();
	
	$('#midBanner').cycle();

}); 

function highlightLink() {
	if (getUrlEncodedKey("id"))	 {
		$("#link" + getUrlEncodedKey("id")).addClass("highlight").css('color', '#FFF').css('text-decoration', 'none');
		$("#mlink" + getUrlEncodedKey("id")).addClass("highlight").css('color', '#FF0000').css('text-decoration', 'none');
	}
}

function mailpage()
{
mail_str = "mailto:?subject=Check out the " + document.title;
mail_str += "&body=I thought you might be interested in the " + document.title;
mail_str += ". You can view it at, " + location.href;
location.href = mail_str;
}

//function initGallery() {
//}

getUrlEncodedKey = function(key, query) {
    if (!query)
        query = window.location.search;    
    var re = new RegExp("[?|&]" + key + "=(.*?)&");
    var matches = re.exec(query + "&");
    if (!matches || matches.length < 2)
        return "";
    return decodeURIComponent(matches[1].replace("+", " "));
}

