var HIDE_LEFT_ATTRIB = 'nu_orig_left';
var HIDE_TOP_ATTRIB = 'nu_orig_top';
var HIDE_POSITION_ATTRIB = 'nu_orig_position';
var HIDE_HEIGHT_ATTRIB = 'nu_orig_height';
var GROUP_ATTRIB = 'nu_orig_group';
var HIDE_POSITION_TOP = '-300000em';

function toggle_the_div(div,fast,with_fade,customFunction)
{
    div.each( function() {
        var item = $(this);
        if (HIDE_POSITION_TOP==item.css('top'))
            show_the_div(item,fast,with_fade,customFunction);
        else
            hide_the_div(item,fast,with_fade,customFunction);
    });
}

function hide_the_div(div,fast,with_fade,customFunction)
{
    div.each( function() {
        var item = $(this);
        if (HIDE_POSITION_TOP == item.css('top'))
            return;

        item.attr( HIDE_TOP_ATTRIB, item.css('top') );
		item.attr( HIDE_LEFT_ATTRIB, item.css('left') );
        item.attr( HIDE_POSITION_ATTRIB, item.css('position') );

        if (item.height()!='100%')
            item.attr( HIDE_HEIGHT_ATTRIB, item.height() );

        if (fast) {
            item.css('height','0px').css('position','absolute').css('top',HIDE_POSITION_TOP).css('left',0);
        }

        else {
            var settings = null;
            if (with_fade)
                settings = {height:'0px',opacity:0.0};
            else
                settings = {height:'0px'};
            // Now it's been stored we can animate and hide the div
            item.animate( settings, 'normal', function() {
                $(item).css('position','absolute').css('top',HIDE_POSITION_TOP).css('left',0);
				if (customFunction != undefined) customFunction();
            });
        }
    } );
}

function show_the_div(div,fast,with_fade,customFunction)
{
    div.each( function() {
		var item = $(this);	 

		if (item.attr(HIDE_TOP_ATTRIB) == item.css('top'))
            return;			   

        if (undefined == item.attr(HIDE_TOP_ATTRIB))
            return;

		if (undefined == item.attr(HIDE_LEFT_ATTRIB))
            return;

        if (with_fade)
            item.css('opacity',0.0);
        item.css('top', item.attr(HIDE_TOP_ATTRIB) );
		item.css('left', item.attr(HIDE_LEFT_ATTRIB) );
        item.css('position', item.attr(HIDE_POSITION_ATTRIB) );

        if (undefined == item.attr(HIDE_HEIGHT_ATTRIB))
           var new_height = '';
        else
            var new_height = item.attr(HIDE_HEIGHT_ATTRIB);       

        if (with_fade) {
            item.animate( {opacity:1.0,height:new_height}, 'slow', function() { $(this).height(''); if (customFunction != undefined) customFunction();; });
        }
        else {            
            item.css('opacity',1.0).animate( {height:new_height}, function() { $(this).height(''); if (customFunction != undefined) customFunction();; });
        }
    } );
}

function showDlOnId(elementId) {
    var dt = $("dt"+elementId);

    if(dt != null) {
        $(dt).children("span").addClass("close");
        $(dt).children("span").text("Less").css("font-weight","normal");
        $(dt).css({fontWeight:"bold", color:"#000"});
        
        show_the_div($(dt).next(),false,false);
    }
}


jQuery(document).ready(function(){
	$("dl dt:even").addClass("alt");
	$("dl dd:even").addClass("alt");
	$("dt").prepend("<span class='moreLink'>More</span>");
	hide_the_div($("dl dd"),true,false);
	$("dt").click(function () {
		$(this).children("span").toggleClass("close");
		if ($(this).children("span").text()==("Less")){
			$(this).children("span").text("More").css({fontWeight:"normal", color:"#039"});
			$(this).css({fontWeight:"normal", color:"#039"});
		}
		else {
			$(this).children("span").text("Less").css("font-weight","normal");
			$(this).css({fontWeight:"bold", color:"#000"});
		}
		toggle_the_div($(this).next(),false,false);
	});

	var urlRegExp = new RegExp('\#[a-zA-Z0-9\/\?\%\-]+');

	$('a[href*="#"]').each( function() {
		if (location.pathname == this.pathname && location.host == this.host) {
			var href = $(this).attr('href').match(urlRegExp);
			var dt = $("dt"+href);

			if((href != null) && (dt != null)) {
				$(this).click( function() {
					var href = $(this).attr('href').match(urlRegExp);
					var dt = $("dt"+href);

					$(dt).children("span").addClass("close");
					$(dt).children("span").text("Less").css("font-weight","normal");
					$(dt).css({fontWeight:"bold", color:"#000"});

					show_the_div($(dt).next(),false,false);
				});
			}
		}
	});

	var pageUrl = window.location.href;
	var href = pageUrl.match(urlRegExp);
	
	if (href != null) {
		var dt = $("dt"+href);
		$(dt).children("span").addClass("close");
		$(dt).children("span").text("Less").css("font-weight","normal");
		$(dt).css({fontWeight:"bold", color:"#000"});
		show_the_div($(dt).next(),false,false);
	}
	
	// Show Hide Code
	$(".showHideContent").before("<p class='showHideLink'><a href='#'>More information</a></p>");
	hide_the_div($(".showHideContent"),true,false);
	
	$(".showHideLink").click(function () {
		toggle_the_div($(this).next('.showHideContent'),false,false);
		if ($(this).children("a").text()==("More information")){
			$(this).children("a").text("Less information");
			$(this).children("a").toggleClass("less");
		}
		else {
			$(this).children("a").text("More information");
			$(this).children("a").toggleClass("less");
		}
		return false;
	});
	
	if (href != null) {
		var div= $("div"+href);
		//$(div).children().children("a").text("Less information");
		$(div).children().children("a").toggleClass("less");
		show_the_div($(div).children('.showHideContent'),false,false);
	}
	
	// List Show Hide
	hide_the_div($("ul.showHide ul"),true,false);
	$("ul.showHide h2").click(function () {
		toggle_the_div($(this).next('ul'),false,false);
	});
	$("ul.showHide h3").click(function () {
		toggle_the_div($(this).next('ul'),false,false);
	});
});