// POPUP FOR EMAIL A FRIEND ---------------------------------------
function popupWindow(url){
  var aWindow = window.open(url,"sendEmail","width=455,height=330,menubar=no,toolbar=no,resizable=no,scrollbars=no,copyhistory=no");  
}

function popupWindowNew(url, width, height){
this.width = width;
this.height = height;

  var aWindow = window.open(url,"sendFeedback","width=" + width +",height="+ height +",menubar=no,toolbar=no,resizable=no,scrollbars=no,copyhistory=no");   //alert("height= " + height);
}

// ON DOCUMENT.READY ---------------------------------------------
$(document).ready(function(){
						   
	// LEFT NAV HIGHLIGHTER
	link_scanner($(".left_links li a"), window.location.href, "sn_active")
	
	// GRAB INNERHTML FROM DIV - ASSIGN TO VARIABLE - PASS VARIABLE TO JCRUMB - WORKS!!
	var sp_webname = $("#sp_webname").text();

		var sp_section = document.getElementById('sp_section').innerHTML;
	if (sp_section == "" || sp_section == null)
	{	
		var sp_section = "sect_0";
	}
	var sp_pagetitle = document.getElementById('sp_pagetitle').innerHTML;
	sp_pagetitle = sp_pagetitle.replace(/;/gi,'');
	sp_pagetitle = sp_pagetitle.replace(/&amp/gi,'&');
	
	// top navigation - highlight current section
	$('#' + sp_section).addClass('n_active');
	$('#sp_section').css('display','none');
	

	// BREAD CRUMB TRAIL
	
	$('#bc').html('Visited Pages: ');
	$('#bc').jCrumb({
		maxCrumbs:4,
		maxMemory : 12,
		seperator : "&raquo;",
	//	title : siteProperties.pageTitle -- old line using namespace
		title : sp_pagetitle
	});
	$('#bc').css('visibility','visible');
						   
						   
// ROW STRIPES -- RIGHT COLUMN
$('ul.stripeList li:nth-child(odd)').addClass('rowOdd'); 
$('ul.stripeList li:nth-child(even)').addClass('rowEven');

$('table.stripeRow tr:odd').addClass('rowEven');


// BOTTOM BAR SHOW / HIDE FUNCTIONALITY
	$("#min").click(function(){
		$("#floatingBar").slideToggle('slow', function(){
			$("#floatingBarOpen").slideToggle('slow')});	
		return false;
		});
	
	$("#max").click(function(){
		$("#floatingBarOpen").slideToggle('slow', function(){
			$("#floatingBar").slideToggle('slow')});	
		return false;
		});


});

// side navigation - higlight current page
function link_scanner(link_list, string_to_compare, class_to_add)
	{
		this.link_list = link_list
		this.string_to_compare = string_to_compare
					
		
		//create function variables
		var index_of_querystring = string_to_compare.indexOf("?");
		
		//Set str to the correct value depending on whether or not there's a querystring.
		index_of_querystring == -1 ? str = string_to_compare.substr(string_to_compare.lastIndexOf("/") + 1, string_to_compare.length - 1) : str = string_to_compare.substr(index_of_querystring + 1, string_to_compare.length - 1)
		
		
		//Scan the link_list
		$.each(link_list, function(key, value)
		{
			$(this).removeClass("sn_active");
			var address = $(this).attr('href')
			var last_slash = address.lastIndexOf("/")
			var qs_index = address.indexOf("?")
			
			if(last_slash == -1)
			{
				if(str == address)
				{
					$(this).addClass(class_to_add)
					return false
				}
			}
			
			if(qs_index == -1)
			{
					var sanitized = address.substr(last_slash + 1, address.length -1)
				
					if(str == sanitized)
					{
						$(this).addClass(class_to_add)
						return false
					}
			}
			else
			{
				var sanitized = address.substr(qs_index + 1, address.length - 1)
				
				if(str == sanitized)
				{
					$(this).addClass(class_to_add)
					return false
				}
				
			}
		})
	}
