$(function() {

	// show current nav/sub-nav
	if( currentNav != "id" ) {
		var newSrc = $("#"+currentNav).attr("src").replace(".gif","-on.gif");
		$("#"+currentNav).attr("src", newSrc);
		$("#sub"+currentNav).animate( { height: "toggle" }, { duration: "fast" } );
	}

	if( currentSubNav != "subid" ) {
		$("#"+currentSubNav).animate( { height: "toggle" }, { duration: "fast" } );
		var newSrc = $("#img"+currentSubNav).attr("src").replace(".gif","-on.gif");
		$("#img"+currentSubNav).attr("src", newSrc);
	}

	// slider for multi-column layout
	$.fn.PerformSlide = function ( t, currentPage ) {
		if( t == "next" ) {
			var newLeft = (576 * currentPage) + 2; //(588 * currentPage) + 2;
			currentPage++;
			$('#copy-main').animate({ left: -newLeft }, { duration: 'normal' });

		} else if( t == "prev" ) {
			currentPage--;
			if( currentPage == 1 ) {
				$('#copy-main').animate({ left: 0 }, { duration: 'normal' });
			} else {
				var newLeft = (576 * (currentPage-1)); //(588 * (currentPage-1));
				$('#copy-main').animate({ left: -newLeft }, { duration: 'normal' });
			}
		}

		var htmlStr = '';
		if( currentPage > 1 ) {
			htmlStr = '<a href="javascript:void(0);" onclick="$().PerformSlide(\'prev\', '+currentPage+');">&laquo; PREVIOUS</a>';
			htmlStr += ' &nbsp; Page '+currentPage+' of '+totalPages+' &nbsp; ';
		}

		if( currentPage < totalPages ) {
			htmlStr = 'Page '+currentPage+' of '+totalPages+' &nbsp; ';
			htmlStr += '<a href="javascript:void(0);" onclick="$().PerformSlide(\'next\', '+currentPage+');">NEXT &raquo;</a>';
		}

		if( currentPage > 1 && currentPage < totalPages ) {
			htmlStr = '<a href="javascript:void(0);" onclick="$().PerformSlide(\'prev\', '+currentPage+');">&laquo; PREVIOUS</a>';
			htmlStr += ' &nbsp; Page '+currentPage+' of '+totalPages+' &nbsp; ';
			htmlStr += '<a href="javascript:void(0);" onclick="$().PerformSlide(\'next\', '+currentPage+');">NEXT &raquo;</a>';
		}

		$("#moreLess").html(htmlStr);

		return this;
	};

	// previous/next pages info
	var totalColumns = $("#copy-main .copy-column").length;
	var currentPage = 1;
	var totalPages = Math.ceil(totalColumns / 3);

	if( totalColumns > 3 ) {
		$("#moreLess").html('Page '+currentPage+' of '+totalPages+' &nbsp; <a href="javascript:void(0);" onclick="$().PerformSlide(\'next\', '+currentPage+');">NEXT &raquo;</a>');
	}

	$(".rollover").hover(
		function() {	
			if( $(this).attr("id") != currentNav ) {
				if($(this).attr("src").indexOf("-on") == -1) {
					var newSrc = $(this).attr("src").replace(".gif","-on.gif");
					$(this).attr("src", newSrc);
				}
			}
		},
		function() {
			if( $(this).attr("id") != currentNav ) {
				if($(this).attr("src").indexOf("-on.gif") != -1) {
					var oldSrc = $(this).attr("src").replace("-on.gif",".gif");
					$(this).attr("src", oldSrc);
				}
			}
		}
	);

	$(".rollover").click(
		function() {
			var tmpID = $(this).attr("id");
			if( tmpID != currentNav ) {
				if( currentNav != 'id' ) {
					$("#sub"+currentNav).fadeOut("fast", function() { ShowNav(tmpID); });
					var oldSrc = $("#"+currentNav).attr("src").replace("-on.gif",".gif");
					$("#"+currentNav).attr("src",oldSrc);
					currentNav = tmpID;
				} else {
					currentNav = tmpID;
					ShowNav(tmpID);	
				}
			}
		}
	);

	$(".subrollover").hover(
		function() {	
			if( $(this).attr("id") != 'img'+currentSubNav ) {
				if($(this).attr("src").indexOf("-on") == -1) {
					var newSrc = $(this).attr("src").replace(".gif","-on.gif");
					$(this).attr("src", newSrc);
				}
			}
		},
		function() {
			if( $(this).attr("id") != 'img'+currentSubNav ) {
				if($(this).attr("src").indexOf("-on.gif") != -1) {
					var oldSrc = $(this).attr("src").replace("-on.gif",".gif");
					$(this).attr("src", oldSrc);
				}
			}
		}
	);

	$(".left-entry").hover(
		function() {
			$(this).addClass("hover");
		},
		function() {
			$(this).removeClass("hover");
		}
	);

});

function ShowNav( nid ) {
	$("#sub"+nid).slideDown("fast");
}