﻿var contactMinimized = true;
var homepageBlockVisible = -1;

$(document).ready(function(){
	$('div.navLinkNotActive').bind("mouseenter",function() {
		$(this).removeClass("navLinkNotActive");
		$(this).addClass("navLinkRollover");
	});
	
	$('div.navLinkNotActive').bind("mouseleave",function() {
		$(this).removeClass("navLinkRollover");
		$(this).addClass("navLinkNotActive");
	});	
	
	$("a[@href^=http]").each(
		function(){  
			if(this.href.indexOf(location.hostname) == -1) {
				$(this).attr('target', '_blank');}
		});
});


function preLoadImage(imgSource)
{
	img = new Image();
	img.src = imgSource;
}
function embedFlash(width, height, image, flv, allowEmbed, embedString, renderDivId)
{
	var flashvars = {};
	flashvars.width 	= width;
	flashvars.height 	= height;
	flashvars.image		= image;
	flashvars.flv 		=  flv; 
	flashvars.embed		= "false";
	flashvars.embedText = embedString;
	var params = { allowScriptAccess: "always", base: "", wmode:"opaque", allowFullScreen:"true"};
	var attributes = {id: "main"};

	swfobject.embedSWF(flashVideoPath, renderDivId, width, height, "9.0.0", express, flashvars, params, attributes);
}

function insertDropDown(list, urls, targets, renderDivId, title, height)
{
	if( !(list instanceof Array))
		return;
	if( !(urls instanceof Array))
		return;
	if( !(targets instanceof Array))
		return ;
	
	var flashvars = {};
	flashvars.view = title;
	flashvars.list = list;
	flashvars.urls = urls;
	flashvars.tars = targets;
			
	var params = { allowScriptAccess: "always", base: "", wmode:"transparent"};
	var attributes = {id: "main"};

	swfobject.embedSWF(flashDropDownPath, renderDivId, "280", "300", "9.0.0", express, flashvars, params, attributes);

}

function showHomepageDiv(divNumberToShow)
{
	if(divNumberToShow != homepageBlockVisible)
	{
		//hide all roll over states
		for(hide = 0; hide < 12; hide++)
		{			
			try
			{
				document.getElementById('mainPageImageBack' + hide).style.display = "none";
				document.getElementById('mainPageImage' + hide).style.display = "block";
			}
			catch(exception)
			{ }

		}
		
		if(divNumberToShow != "-1")
		{
			var overImage = null;
			overImage = document.getElementById('mainPageImageBack' + divNumberToShow);
			
			if(overImage != null)
			{
				document.getElementById('mainPageImage' + divNumberToShow).style.display = "none";
				overImage.style.display = "block";
			}
		}
			
		homepageBlockVisible = divNumberToShow;
	}
	

}

function toggleContact(expandImage, contractImage)
{
    if(contactMinimized)
    {
        document.getElementById("FancyGettingInTouch").className = "expand smallWhite";
        document.getElementById("FancyGettingInTouchImageButton").src = expandImage;
		document.getElementById("FancyGettingInTouchImageButton").setAttribute("alt", 'Collapse panel');
        document.getElementById("FancyGettingInTouchTitle").style.display = "none";
        document.getElementById("FancyGettingInTouchContent").style.display = "inline";        
        document.getElementById("Clock").style.visibility = "hidden";        
        document.getElementById("Clock").style.display = "none";  
		
		try
		{
			Cufon.replace('#FancyGettingInTouchContent a, #FancyGettingInTouchTitle a', { fontFamily: 'GothamMedium' });
			Cufon.now();
		}
		catch(err){}
    }
    else
    {
        document.getElementById("FancyGettingInTouch").className = "minimized smallWhite";
        document.getElementById("FancyGettingInTouchImageButton").src = contractImage;
		document.getElementById("FancyGettingInTouchImageButton").setAttribute("alt", 'Expand panel');
        document.getElementById("FancyGettingInTouchTitle").style.display = "inline";
        document.getElementById("FancyGettingInTouchContent").style.display = "none";        
        document.getElementById("Clock").style.visibility = "visible";        
        document.getElementById("Clock").style.display = "block";      
    }

    contactMinimized = !contactMinimized;
}

function togglePressRelease(teaserId, expandId, collapseId, fullStoryId, topScroll)
{
	if(document.getElementById(fullStoryId).style.display == "block")
	{
		document.getElementById(fullStoryId).style.display = "none";
		document.getElementById(teaserId).style.display = "block";
		document.getElementById(expandId).style.display = "block";		
		document.getElementById(collapseId).style.display = "none";	
		document.getElementById(topScroll).scrollIntoView(true); 
	}
	else
	{
		document.getElementById(fullStoryId).style.display = "block";
		document.getElementById(teaserId).style.display = "none";
		document.getElementById(expandId).style.display = "none";		
		document.getElementById(collapseId).style.display = "block";		
	}
}
function swapImage(mainImageId, source)
{
	document.getElementById(mainImageId).src = source;
}
function removeWordStyles(newContent)
{
	//get rid of the comments at the top
	while(newContent.indexOf("<!--") > -1)
	{
		intStart = newContent.indexOf("<!--");
		intEnd = newContent.indexOf("-->");
		strReplace = newContent.substring(intStart, intEnd + 3);
		newContent = newContent.replace(strReplace, "")
	}

	return newContent;
	try
	{
		tinymce.EditorManager.activeEditor.setContent(newContent, {format : 'raw'});
	}
	catch(err)
	{
		alert(newContent);
	}
}
function removeInlineStyles(content)
{
	//get rid of inline styles
	styleReplace = new RegExp(".*(style=\".*\").*");
	//citesReplace = new RegExp(".*(<ins.*>.*</ins>).*");

	while(styleReplace.exec(content)!= null)
		content = content.replace(styleReplace.exec(content)[1], "");
	//while(citesReplace.exec(content)!= null)
		//content = content.replace(citesReplace.exec(content)[1], "");
	
	//get rid of the class
	while(content.indexOf("MsoNormal") > -1)
		content = content.replace("MsoNormal", "");
	while(content.indexOf("MsoNoSpacing") > -1)
		content = content.replace("MsoNoSpacing", "");
	while(content.indexOf("msoIns") > -1)
		content = content.replace("msoIns", "");
	while(content.indexOf('<p>&nbsp;<\/p>') > -1)
		content = content.replace('<p>&nbsp;<\/p>', "");
		
	tinymce.EditorManager.activeEditor.setContent(content, {format : 'raw'});
}
function removeWordFormattingThatHasBeenEncoded(content)
{
	if(content.indexOf("&lt;!--") > -1)
	{					
		if(confirm("Microsoft Word formatting has been HTML encoded into your document.  This tool can attempt to remove the extra text.  Do you want to proceed?"))
		{
			do
			{
				msWordReplaced = false;
				while(content.indexOf("&lt;!--") > -1)
				{
					endSearch = "endif] ><\/p>"
					intStart = content.indexOf("&lt;!--");
					intEnd = content.indexOf(endSearch);
					
					if(intEnd == -1)
					{
						endSearch = "--&gt;<\/p>";
						intEnd = content.indexOf(endSearch);
						
						if(intEnd == -1)
						{
							break;
						}
					}
						
					strReplace = content.substring(intStart, intEnd + endSearch.length);
					content = content.replace(strReplace, "");
					msWordReplaced = true;
				}
			} while (msWordReplaced);

			tinymce.EditorManager.activeEditor.setContent(content, {format : 'raw'});

			alert("The Microsoft Word formatting text has been removed.  Please check your content carefully before saving.");
		}
	}
}
