//Common functions/variables

var undefined;		//used for IE 5.5 Flash
var SERVICE_URL = "../services/public/publiccontent.asmx";

//var SERVICE_URL = "http://stage.qa.optimedia-us.moxieinteractive.com/services/public/publiccontent.asmx";

function rollOn(elem, classid) {
	elem.className = classid;
}

function swapImage(elem, imgName) {
	elem.src = imgName;
}

function email(address) {
	location=('mailto:'+address.replace('||at||','@'));
}
///Google analytics
_uacct = "UA-2262347-1";
urchinTracker();
///Second Google analytics
var pageTracker = _gat._getTracker("UA-3401987-2");
pageTracker._initData();
pageTracker._trackPageview();

//Sort an array by the orderNumber property
function sortByOrderNumber(a, b) {
	return parseInt(a.orderNumber)-parseInt(b.orderNumber);
}

//Randomize an array
function randomizeArray(arrayElements,arraySize) {//Generate random array
	var newArray = new Array();

	for (i=1;i<=arraySize-1;i++) {
		var newElement = arrayElements.random();
		newArray.push(newElement);
		newArray = newArray.unique();
		if (newArray.length != i+1) {i-=1;}
	}

	return newArray;
}

//Rotates through a series of images
function rotateImages(imageID,imageArray,startPosition,maximum) {
	if (typeof imageArray != 'object') {imageArray = imageArray.split(',');}
	$(imageID).src = imageArray[startPosition];
	startPosition = startPosition==maximum ? 0 : startPosition+1;

	setTimeout('rotateImages(\''+imageID+'\',\''+imageArray+'\','+startPosition+','+maximum+')',5000);
}

//Navigation generation
///Top navigation
function writeHeader(rootPath,inPage) {
	document.write('<div id="header">');
	var menuImage = new Array();
	var menuURL  = new Array();

	menuImage[0] = '<img src="'+rootPath+'publishedFiles/images/menu_home_INOUT.gif" alt="HOME" />';
	menuURL[0] = rootPath + 'index.html';

	menuImage[1] = '<img src="'+rootPath+'publishedFiles/images/menu_inside_INOUT.gif" alt="INSIDE OPTIMEDIA" />';
	menuURL[1] = rootPath + 'inside/index.html';

	menuImage[2] = '<img src="'+rootPath+'publishedFiles/images/menu_extra_INOUT.gif" alt="EXTRA BITS" />';
	menuURL[2] = rootPath + 'extra/index.html';

	menuImage[3] = '<img src="'+rootPath+'publishedFiles/images/menu_careers_INOUT.gif" alt="CAREERS" />';
	menuURL[3] = rootPath + 'careers/index.html';

	menuImage[4] = '<img src="'+rootPath+'publishedFiles/images/menu_contact_INOUT.gif" alt="CONTACT US" />';
	menuURL[4] = rootPath + 'contact/index.html';

	document.write('<div id="headerFlash" style="float:left;margin-top:14px;margin-left:15px;"></div>');

	document.write('<div id="top_menu">');
	for (i=0;i<=menuImage.length-1;i++) {
		if (i==inPage) {
			document.write(menuImage[i].replace('_INOUT','_in'));
		} else {
			document.write('<a href="'+menuURL[i]+'">'+menuImage[i].replace('_INOUT','')+'</a>');
		}
	}
	document.write('</div>');

	document.write('</div>');

	var fo = new FlashObject(rootPath+'flash/logo.swf', 'flsh_movie', '196', '45', '7');
	fo.addParam('quality', 'high');
	fo.addParam('wmode', 'transparent');
	fo.setAltContent('<img src="'+rootPath+'publishedFiles/images/optimedialogo.gif"  alt="Optimedia - never settle, never stop..." />');
	fo.write('headerFlash');
}
///Popup header
function writePopupHeader(rootPath) {
	document.write('<div id="popupheader">');
	document.write('<img src="'+rootPath+'publishedFiles/images/optimedialogo_popup.gif" style="float:left;margin-top:10px;margin-left:10px;" alt="Optimedia - never settle, never stop..." />');
	document.write('<div style="float:right;margin-right:10px;margin-top:10px;"><a href="javascript:window.close();"><img src="'+rootPath+'publishedFiles/images/btn_close.gif" alt="X" /></a></div>');
	document.write('</div>');
}

///Sub navigation
////Inside Optimedia secondary navigation
function writeInsideSubNav(inPage) {
	document.write('<div id="subnav">');
	var menuText = new Array();
	var menuURL  = new Array();

	menuText[0] = 'Team';
	menuURL[0] = 'index.html';

	menuText[1] = 'Philosophy';
	menuURL[1] = 'philosophy.html';

	menuText[2] = 'Our Approach';
	menuURL[2] = 'approach.html';

	menuText[3] = 'Our Services';
	menuURL[3] = 'services.html';

	menuText[4] = 'Our Clients';
	menuURL[4] = 'clients.html';

	menuText[5] = 'News';
	menuURL[5] = 'news.html';

	menuText[6] = 'Our Work';
	menuURL[6] = 'work.html';

	for (i=0;i<=menuText.length-1;i++) {
		if (i != 0) {document.write('|');}
		if (i==inPage) {
			document.write('<span class="in">'+menuText[i]+'</span>');
		} else {
			document.write('<a href="'+menuURL[i]+'">'+menuText[i]+'</a>');
		}
	}

	document.write('</div>');
}

/////Our Services tertiary navigation
function writeServicesSubNav(inPage) {
	var htmlString = '';
	var menuText = new Array();
	var menuURL  = new Array();

	menuText[0] = 'Strategies';
	menuURL[0] = 'javascript:updateServices(0);';

	menuText[1] = 'Activation &amp; Implementation';
	menuURL[1] = 'javascript:updateServices(1)';

	for (i=0;i<=menuText.length-1;i++) {
		if (i==inPage) {
			htmlString += '<img class="subsubnavarrow" src="../publishedFiles/images/icon_subsubnav_in.gif" alt="&gt;" /><span class="in">'+menuText[i]+'</span>';
		} else {
			htmlString += '<img class="subsubnavarrow" src="../publishedFiles/images/icon_subsubnav_out.gif" alt="&gt;" /><a href="'+menuURL[i]+'">'+menuText[i]+'</a>';
		}
	}

	$('subsubnav').innerHTML = htmlString;
}

/////Our Work tertiary navigation
function writeWorkSubNav(inPage) {
	var htmlString = '';

	for (i=0;i<=examples.length-1;i++) {
		if (examples[i].exampleID==inPage) {
			htmlString += '<img class="subsubnavarrow" src="../publishedFiles/images/icon_subsubnav_in.gif" alt="&gt;" /><span class="in">'+examples[i].exampleName+'</span>';
		} else {
			htmlString += '<img class="subsubnavarrow" src="../publishedFiles/images/icon_subsubnav_out.gif" alt="&gt;" /><a href="javascript:writeWorkSubNav('+examples[i].exampleID+')">'+examples[i].exampleName+'</a>';
		}
	}

	$('subsubnav').innerHTML = htmlString;
	GetSingleContent(inPage, updateWork);
}

////Careers secondary navigation
function writeCareersSubNav(inPage) {
	var htmlString = '';
	var menuText = new Array();
	var menuURL  = new Array();

	for (j=0;j<cities.length;j++) {
		if (j != 0) {htmlString += '|';}
		if (cities[j].id==inPage) {
			htmlString += '<span class="in">'+cities[j].name+'</span>';
		} else {
			htmlString += '<a href="javascript:updateCareers('+cities[j].id+')">'+cities[j].name+'</a>';
		}
	}

	$('subnav').innerHTML = htmlString;
}

////Extra Bits secondary navigation
function writeExtraBitSubNav(inPage) {
	var htmlString = '';

	for (i=0;i<=extrabitsections.length-1;i++) {
		if (extrabitsections[i].extrabitID==inPage) {
			htmlString += '<p class="in">'+extrabitsections[i].extrabitName+'</p>';
		} else {
			htmlString += '<p><a href="javascript:updateExtra('+extrabitsections[i].extrabitID+');">'+extrabitsections[i].extrabitName+'</a></p>';
		}
	}

	$('verticalnav').innerHTML = htmlString;
}

///Footer
function writeFooter(rootPath) {
	document.write('<div id="footer">');
	document.write('<img src="'+rootPath+'publishedFiles/images/spacer.gif" style="width:1px;height:21px;vertical-align:middle;" />Copyright &copy 2007 Optimedia<img src="'+rootPath+'publishedFiles/images/spacer.gif" style="width:1px;height:21px;vertical-align:middle;" />');
	document.write('</div>');
}

//XML Objects
///Homepage pods
function homepod(PodTitle, PodText, PodLink, PodOrderNumber, PodImages, PodActive) {
	this.podTitle = PodTitle;
	this.podText = PodText;
	this.podLink = PodLink;
	this.orderNumber = PodOrderNumber;
	this.podImages = PodImages;
	this.podActive = PodActive;
}

///Our Clients
function client(OrderNumber, ClientName, ImageName, LinkURL) {
	this.orderNumber = OrderNumber;
	this.clientName = ClientName;
	this.imageName = ImageName;
	this.linkURL = LinkURL;
}

///Careers cities
function city(ObjectID, CityName) {
	this.id = ObjectID;
	this.name = CityName;
}

///Careers job postings
function openposition(CityID, JobID, JobTitle, JobSummary, JobDescription, JobOrderNumber, Disabled) {
	this.cityID = CityID;
	this.jobID = JobID;
	this.jobTitle = JobTitle;
	this.jobSummary = JobSummary;
	this.jobDescription = JobDescription;
	this.orderNumber = JobOrderNumber;
	this.disabled = Disabled;
}

///Executive Team
function execteam(ExecID, ExecName, ExecTitle, ExecSmallThumb, ExecOrderNumber) {
	this.execID = ExecID;
	this.execName = ExecName;
	this.execTitle = ExecTitle;
	this.execSmallThumb = ExecSmallThumb;
	this.orderNumber = ExecOrderNumber;
}

///Contacts
function contact(ContactTitle, ContactEmail, ContactBody, ContactOrderNumber) {
	this.contactTitle = ContactTitle;
	this.contactEmail = ContactEmail;
	this.contactBody = ContactBody;
	this.orderNumber = ContactOrderNumber;
}

///Work Examples
function example(ExampleID, ExampleName, ExampleOrderNumber) {
	this.exampleID = ExampleID;
	this.exampleName = ExampleName;
	this.orderNumber = ExampleOrderNumber;
}

///Extrabit sections
function extrabitsection(ExtraBitID, ExtraBitName) {
	this.extrabitID = ExtraBitID;
	this.extrabitName = ExtraBitName;
}

///Extrabits
function extrabit(ExtraBitID, ExtraBitTitle, ExtraBitBody, ExtraBitImage, ExtraBitLinks, ExtraBitActive, ExtraBitOrderNumber) {
	this.extrabitID = ExtraBitID;
	this.extrabitTitle = ExtraBitTitle;
	this.extrabitBody = ExtraBitBody;
	this.extrabitImage = ExtraBitImage;
	this.extrabitLinks = ExtraBitLinks;
	this.extrabitActive = ExtraBitActive;
	this.orderNumber = ExtraBitOrderNumber;
}

///Extrabit Links
function extrabitlink(ExtraBitLinkID, ExtraBitLinkText, ExtraBitLinkURL, ExtraBitLinkPopupType, ExtraBitLinkHeight, ExtraBitLinkWidth, ExtraBitLinkOrderNumber) {
	this.extrabitlinkID = ExtraBitLinkID;
	this.extrabitlinkText = ExtraBitLinkText;
	this.extrabitlinkURL = ExtraBitLinkURL;
	this.extrabitlinkPopupType = ExtraBitLinkPopupType;
	this.extrabitlinkHeight = ExtraBitLinkHeight;
	this.extrabitlinkWidth = ExtraBitLinkWidth;
	this.orderNumber = ExtraBitLinkOrderNumber;
}

///News postings
function newsitem(NewsID, NewsHeadline, NewsSubHeadline, NewsBody, Disabled, OrderNumber) {
	this.newsID = NewsID;
	this.newsHeadline = NewsHeadline;
	this.newsSubHeadline = NewsSubHeadline;
	this.newsBody = NewsBody;
	this.disabled = Disabled;
	this.orderNumber = OrderNumber;
}

//Content population
///Service calls
////GetSingleContent(id attribute of Object, function to pass control to)
function GetSingleContent(contentId, completionFunction) {
	var params = "contentId="+contentId;
	var uri = SERVICE_URL+"/GetSingleContent";
    
	var request = new Ajax.Request(uri,{
		method: 'post',
		parameters: params,
		onComplete: completionFunction
	});
	
}

////GetContentByParent(id attribute of parent object, function to pass control to)
function GetContentByParent(parentContentId, completionFunction) {
	var params = "parentContentId="+parentContentId;
	var uri = SERVICE_URL+"/GetContentByParent";
	var request = new Ajax.Request(uri,{
		method: 'post',
		parameters: params,
		onComplete: completionFunction
	});
}

////GetContentByParentByLevel(id attribute of parent object, number of levels to traverse, function to pass control to)
function GetContentByParentByLevel(parentContentId, nbrOfLevels, completionFunction) {
	var params = "parentContentId="+parentContentId;
		params += "&" + "nbrOfLevels="+nbrOfLevels;
	var uri = SERVICE_URL+"/GetContentByParentByLevel";
	var request = new Ajax.Request(uri,{
		method: 'post',
		parameters: params,
		onComplete: completionFunction
	});
}

////GetSummaryContentByParent(id attribute of parent object, function to pass control to)
function GetSummaryContentByParent(parentContentId, completionFunction) {
	var params = "parentContentId="+parentContentId;
	var uri = SERVICE_URL+"/GetSummaryContentByParent";
	var request = new Ajax.Request(uri,{
		method: 'post',
		parameters: params,
		onComplete: completionFunction
	});
}

///Helper function to handle FF vs IE vs Safari issues
function getText(node) {
/*
	if (typeof node.text != 'undefined') {		//IE
		return node.text;
	} else if (typeof node.textContent != 'undefined') {		//FireFox
		return node.textContent;
	} else {								//Safari
		return node.firstChild.nodeValue;
	}
*/
	if (typeof node.text != 'undefined') {		//IE
		return node.text;
	} else if (typeof node.textContent != 'undefined') {		//FireFox
		return node.textContent;
	}
}

///Populate title & body objects to headline & topcopy <div>s - Used primary for Page Blobs
function TitleBody(response) {
	var XMLresponse = response.responseXML;
	var headline = '';
	var topcopy = '';

	var properties = XMLresponse.getElementsByTagName('property');
	for (var i=0;i<properties.length;i++) {
		if (properties[i].getAttribute("name") == 'Title') {headline = getText(properties[i]);}
		if (properties[i].getAttribute("name") == 'Body') {topcopy = getText(properties[i]);}
	}
	$('headline').innerHTML = headline;
	$('topcopy').innerHTML = topcopy;
}

///Put all XML content in scrollablearea div
function FillScrollable(response) {
	var XMLresponse = response.responseXML;
	var headline = '';
	var topcopy = '';

	var properties = XMLresponse.getElementsByTagName('property');
	for (var i=0;i<properties.length;i++) {
		if (properties[i].getAttribute("name") == 'Title') {headline = getText(properties[i]);}
		if (properties[i].getAttribute("name") == 'Body') {topcopy = getText(properties[i]);}
	}

	$('scrollablearea').innerHTML = '<h4>'+headline+'</h4>';
	$('scrollablearea').innerHTML += topcopy;
}

///Populate Homepage pods
function HomePagePods() {
	var params = "parentContentId=317";
	var uri = SERVICE_URL+"/GetContentByParent";
	var request = new Ajax.Request(uri,{
		method: 'get',
		parameters: params,
		asynchronous: false
	});

	var XMLresponse = request.transport.responseXML;
	var HPpods = new Array();

	var objects = XMLresponse.getElementsByTagName('object');
	for (var obj=0;obj<objects.length;obj++) {
		var properties = objects[obj].getElementsByTagName('property');
		var podTitle = '';
		var podText = '';
		var podLink = '';
		var podOrderNumber = '';
		var podActive = '';
		var podImageURLs = new Array();
		podImageURLs.clear();
		for (var i=0;i<properties.length;i++) {
			if (properties[i].getAttribute("name") == 'Title') {podTitle = getText(properties[i]);}
			if (properties[i].getAttribute("name") == 'Text') {podText = getText(properties[i]);}
			if (properties[i].getAttribute("name") == 'Link') {podLink = getText(properties[i]);}
			if (properties[i].getAttribute("name") == 'Order Number') {podOrderNumber = getText(properties[i]);}
			if (properties[i].getAttribute("name") == 'Image') {podImageURLs.push(getText(properties[i]));}
			for (var imgNum=2;imgNum<=20;imgNum++) {
				if (properties[i].getAttribute("name") == 'Image'+imgNum) {podImageURLs.push(getText(properties[i]));}
			}
			if (properties[i].getAttribute("name") == 'Active') {podActive = getText(properties[i]);}
		}
		if (podActive==1) {
			podImageURLs = podImageURLs.purge('');
			HPpods.push(new homepod(podTitle, podText, podLink, podOrderNumber, podImageURLs, podActive));
		}
	}

	HPpods.sort(sortByOrderNumber);

	var podLoc = 'left';
	for (j=0;j<HPpods.length;j++) {
		var HTMLstring = '';

		HTMLstring += '<div class="podTitle">'+HPpods[j].podTitle+'</div>';
		HTMLstring += '<div class="image_holder">';
//		HTMLstring += '<img src="'+HPpods[j].podImageURL+'" alt="'+HPpods[j].podTitle+'" />';
		HTMLstring += '<img id="podimage_'+podLoc+'" src="publishedFiles/images/spacer.gif" alt="'+HPpods[j].podTitle+'" />';
		HTMLstring += '</div>';
		HTMLstring += HPpods[j].podText;

		$('pods_'+podLoc).innerHTML += HTMLstring;
		$('pods_'+podLoc+'_url').href = HPpods[j].podLink;
		$('pods_'+podLoc+'_url').style.display='inline';

		var startPoint = HPpods[j].podImages.random();
		rotateImages('podimage_'+podLoc,HPpods[j].podImages,HPpods[j].podImages.indexOf(startPoint),HPpods[j].podImages.length-1);

		if (podLoc == 'center') { podLoc = 'right'; }
		if (podLoc == 'left') { podLoc = 'center'; }
	}

}

///Populate Our Clients page
function PopulateOurClients(response) {
	var XMLresponse = response.responseXML;
	var clients = new Array();
	var imagename = '';
	var clientname = '';
	var ordernumber = '';
	var linkurl = '';
	var HTMLstring = '';

	var clientsXML = XMLresponse.getElementsByTagName('object');

	for (var i=0;i<clientsXML.length;i++) {
		var properties = clientsXML[i].getElementsByTagName('property');
		for (var j=0;j<properties.length;j++) {
			if (properties[j].getAttribute("name") == 'Image') {imagename = getText(properties[j]);}
			if (properties[j].getAttribute("name") == 'Name') {clientname = getText(properties[j]);}
			if (properties[j].getAttribute("name") == 'Order Number') {ordernumber = getText(properties[j]);}
			if (properties[j].getAttribute("name") == 'LinkURL') {linkurl = getText(properties[j]);}
		}
		clients[i] = new client(ordernumber, clientname, imagename, linkurl);
	}

	clients.sort(sortByOrderNumber);

	for (i=0;i<clients.length;i++) {
		HTMLstring += '<div class="client">';
		HTMLstring += clients[i].linkURL != '' ? '<a href="'+clients[i].linkURL+'" target="_blank">' : '';
		HTMLstring += '<img class="clientImage" src="../'+clients[i].imageName+'" alt="'+clients[i].clientName+'" />';
		HTMLstring += clients[i].linkURL != '' ? '</a>' : '';
		HTMLstring += '<p class="clientName">'+clients[i].clientName+'</p>';
		HTMLstring += '</div>';
	}

	$('scrollablearea').innerHTML+=HTMLstring;
}

///Populate Careers home
function CareersHome(response) {
	var XMLresponse = response.responseXML;
	var headline = '';
	var copy = '';
	var HTMLstring = '';

	var properties = XMLresponse.getElementsByTagName('property');
	for (var i=0;i<properties.length;i++) {
		if (properties[i].getAttribute("name") == 'Title') {headline = getText(properties[i]);}
		if (properties[i].getAttribute("name") == 'Body') {copy = getText(properties[i]);}
	}

	HTMLstring += '<div id="topcopy" class="bold" style="margin-bottom:0;">'+headline+'</div>';
	HTMLstring += '<div id="blurb1" class="blurb bg_white">';
	HTMLstring += '<div class="blurbtext careershome">'+copy+'</div>';
	HTMLstring += '</div>';

	$("scrollablearea").innerHTML = HTMLstring;
	GetContentByParentByLevel(336, 0, FillCities);
}

///Get list of cities and their jobs
function FillCities(response) {
	var XMLresponse = response.responseXML;
	var htmlString = '';

	var objects = XMLresponse.getElementsByTagName('object');
	for (var i=0;i<objects.length;i++) {
		cities[i] = new city(objects[i].getAttribute("id"),objects[i].getAttribute("name"));
		BuildJobs(cities[i].id);
	}
	writeCareersSubNav(-1);
}

///Get list of jobs based on city's id
var numOfPositions = 0;
function BuildJobs(parentContentId) {
	var params = "parentContentId="+parentContentId;
	var uri = SERVICE_URL+"/GetContentByParent";
	var request = new Ajax.Request(uri,{
		method: 'get',
		parameters: params,
		asynchronous: false
	});

	var responseText = request.transport.responseText;
	var XMLresponse = request.transport.responseXML;
	var jobListings = XMLresponse.getElementsByTagName('children');
	var positions = jobListings[0].getElementsByTagName('object');

	for (var i=0;i<positions.length;i++) {
		var cityid = parentContentId;
		var jobid = positions[i].getAttribute("id");
		var jobtitle = '';
		var jobsummary = '';
		var jobdescription = '';
		var jobordernumber = '';
		var disabled = '';
		var properties = positions[i].getElementsByTagName('property');
		for (var j=0;j<properties.length;j++) {
			if (properties[j].getAttribute("name") == 'Title') {jobtitle = getText(properties[j]);}
			if (properties[j].getAttribute("name") == 'Summary') {jobsummary = getText(properties[j]);}
			if (properties[j].getAttribute("name") == 'Body') {jobdescription = getText(properties[j]);}
			if (properties[j].getAttribute("name") == 'Order Number') {jobordernumber = getText(properties[j]);}
			if (properties[j].getAttribute("name") == 'Disabled') {disabled = getText(properties[j]);}
		}
		if (disabled=='0') {
			openpositions.push(new openposition(cityid, jobid, jobtitle, jobsummary, jobdescription, jobordernumber, disabled));
		}
	}
}

///Update what is shown on the Careers page
var displayedDescription = -1;
var positionsToShow = new Array();
function updateCareers(inPage) {
	var htmlString = '';

	displayedDescription = -1;
	positionsToShow = filterByCity(openpositions, inPage);
	positionsToShow.sort(sortByOrderNumber);
	switch (inPage) {
		case -1:
			GetSingleContent(341, CareersHome);
			break;
		case 337:		//New York
			htmlString += '<h2 style="margin-bottom:15px;">I &hearts; NY</h2>';
			break;
		case 419:		//San Fran
			htmlString += '<h2 style="margin-bottom:15px;">Rice-A-Roni</h2>';
			break;
		case 480:		//Dallas
			htmlString += '<h2 style="margin-bottom:15px;">Who Shot JR?</h2>';
			break;
		case 484:		//Seattle
			htmlString += '<h2 style="margin-bottom:15px;">Sleepless</h2>';
			break;
		case 489:		//Indianpolis
			htmlString += '<h2 style="margin-bottom:15px;">500</h2>';
			break;
	}

	var bgtoggle = 1;
	var bg_color = new Array();

	bg_color[1] = 'bg_grey';
	bg_color[0] = '';
	bg_color[-1] = 'bg_white';

	if (positionsToShow.length > 0 ) {
		for (i=0;i<=positionsToShow.length-1;i++) {
			htmlString += '<div id="blurb'+i+'" class="blurb '+bg_color[bgtoggle]+' joblisting">';
			htmlString += '<a class="jobtitle" href="javascript:showDescription('+i+');">'+positionsToShow[i].jobTitle+'</a><br /><br />';
			htmlString += positionsToShow[i].jobSummary;
			htmlString += '</div>';
			bgtoggle = -bgtoggle;
		}
	} else {
		if (inPage != -1) {htmlString += 'No current positions open at this time';}
	}

	$('scrollablearea').innerHTML = htmlString;
	writeCareersSubNav(inPage);
}

///Toggle for job posting description
function showDescription(index) {
	var additionalText = '<p style="margin-top:15px;">If you are interested in this position please <a style="color:#333300;" href="javascript:email(&#39;careers||at||optimedia-us.com&#39;);">email your resume</a>. No phone calls please, we will contact candidates whose education and experience meets the requirements for one of our job openings.</p>';
	for (i=0;i<=positionsToShow.length-1;i++) {
		if (i==index) {
			if (index==displayedDescription) {
				$('blurb'+i).innerHTML = '<a class="jobtitle" href="javascript:showDescription('+i+');">'+positionsToShow[i].jobTitle+'</a><br /><br /><p class="blurbtext" id="blurb'+i+'_text">'+positionsToShow[i].jobSummary+'</p>';
				displayedDescription = -1;
			} else {
				$('blurb'+index).innerHTML = '<a class="jobtitle" href="javascript:showDescription('+i+');">'+positionsToShow[i].jobTitle+'</a><br /><br /><p class="blurbtext" id="blurb'+index+'_text"><span class="bold">Overview:</span> '+positionsToShow[i].jobSummary+positionsToShow[i].jobDescription+'</p>';
				$('blurb'+index).innerHTML += additionalText;
				displayedDescription = index;
			}
		} else {
			$('blurb'+i).innerHTML = '<a class="jobtitle" href="javascript:showDescription('+i+');">'+positionsToShow[i].jobTitle+'</a><br /><br /><p class="blurbtext" id="blurb'+i+'_text">'+positionsToShow[i].jobSummary+'</p>';
		}
	}
}

///Filters openPositions array to only display jobs for given CityID
function filterByCity(OP, CityID) {
	var returnPositions = new Array();
	for (i=0;i<OP.length;i++) {
		if (OP[i].cityID == CityID) {returnPositions.push(OP[i])};
	}

	return returnPositions;
}

///Populate Team/Inside Optimedia page
function PopulateExecTeam(response) {
	var XMLresponse = response.responseXML;
	var execs = new Array();
	var execname = '';
	var exectitle = '';
	var execbio = '';
	var smallthumb = '';
	var largethumb = '';
	var ordernumber = '';
	var HTMLstring = '';

	var execsXML = XMLresponse.getElementsByTagName('object');

	for (var i=0;i<execsXML.length;i++) {
		var properties = execsXML[i].getElementsByTagName('property');
		execid = execsXML[i].getAttribute("id");
		for (var j=0;j<properties.length;j++) {
			if (properties[j].getAttribute("name") == 'Name') {execname = getText(properties[j]);}
			if (properties[j].getAttribute("name") == 'Title') {exectitle = getText(properties[j]);}
			if (properties[j].getAttribute("name") == 'Image') {smallthumb = getText(properties[j]);}
			if (properties[j].getAttribute("name") == 'Order Number') {ordernumber = getText(properties[j]);}
		}
		execs[i] = new execteam(execid, execname, exectitle, smallthumb, ordernumber);
	}

	execs.sort(sortByOrderNumber);

	for (i=0;i<execs.length;i++) {
		var withTop = '';
		if (i==0 || i==1) {withTop = ' withTop';}

		HTMLstring += '<div class="teammember'+withTop+'">';
		HTMLstring += '<img class="teamphoto" src="../'+execs[i].execSmallThumb+'" />';
		HTMLstring += '<a class="teamname" href="javascript:void(window.open(\'memberpage.html?id='+execs[i].execID+'\',\'member\',\'width=635,height=575,status=0,dependent=0,directories=0,menubar=0,resizable=1,scrollbars=1,toolbar=0\'));">'+execs[i].execName+'</a>';
		HTMLstring += '<p class="teamtitle">'+execs[i].execTitle+'</p>';
		HTMLstring += '</div>';
	}

	$('teammembers').innerHTML+=HTMLstring;
}

///Write Exec Team member bio
function writeBio() {
	var index = location.search.substring(1).toQueryParams()['id'];
	GetSingleContent(index, PopulateBioContent);
}

///Populates the popup content
function PopulateBioContent(response) {
	var XMLresponse = response.responseXML;
	var headline = '';
	var topcopy = '';

	var properties = XMLresponse.getElementsByTagName('property');
	for (var i=0;i<properties.length;i++) {
		if (properties[i].getAttribute("name") == 'Name') {$('personname').innerHTML = getText(properties[i]);}
		if (properties[i].getAttribute("name") == 'Title') {$('persontitle').innerHTML = getText(properties[i]);}
		if (properties[i].getAttribute("name") == 'Body') {$('biography').innerHTML += getText(properties[i]);}
		if (properties[i].getAttribute("name") == 'LargeImage') {$('personphoto').src = '../'+getText(properties[i]);}
	}
}

///Populates Contact Us page
function PopulateContacts(response) {
	var XMLresponse = response.responseXML;
	var contacts = new Array();
	var contacttitle = '';
	var contactemail = '';
	var contactbody = '';
	var contactordernumber = '';
	var HTMLstring = '';

	var contactsXML = XMLresponse.getElementsByTagName('object');

	for (var i=0;i<contactsXML.length;i++) {
		var properties = contactsXML[i].getElementsByTagName('property');
		for (var j=0;j<properties.length;j++) {
			if (properties[j].getAttribute("name") == 'Title') {contacttitle = getText(properties[j]);}
			if (properties[j].getAttribute("name") == 'Email') {contactemail = getText(properties[j]);}
			if (properties[j].getAttribute("name") == 'Body') {contactbody = getText(properties[j]);}
			if (properties[j].getAttribute("name") == 'Order Number') {contactordernumber = getText(properties[j]);}
		}
		contacts[i] = new contact(contacttitle, contactemail, contactbody, contactordernumber);
	}

	contacts.sort(sortByOrderNumber);

	for (i=0;i<contacts.length;i++) {
		HTMLstring += '<div class="contactlocation">';
		HTMLstring += '<a class="cityname" href="javascript:email(\''+contacts[i].contactEmail.replace('@','||at||')+'\');">'+contacts[i].contactTitle+'</a>';
		HTMLstring += contacts[i].contactBody;
		HTMLstring += '</div>';
	}

	$('contacts').innerHTML = HTMLstring;
}

///Build Our Work tertiary nav
function BuildOurWorkNav(response) {
	var XMLresponse = response.responseXML;
	var exampleid = '';
	var examplename = '';
	var exampleordernumber = '';

	var navXML = XMLresponse.getElementsByTagName('object');

	for (var i=0;i<navXML.length;i++) {
		var properties = navXML[i].getElementsByTagName('property');
		exampleid = navXML[i].getAttribute("id");
		for (var j=0;j<properties.length;j++) {
			if (properties[j].getAttribute("name") == 'Name') {examplename = getText(properties[j]);}
			if (properties[j].getAttribute("name") == 'Order Number') {exampleordernumber = getText(properties[j]);}
		}
		examples[i] = new example(exampleid, examplename, exampleordernumber);
	}

	examples = examples.sort(sortByOrderNumber);

	writeWorkSubNav(examples[0].exampleID);
}

///Build Extra Bits tertiary nav
function BuildExtraBitsNav(response) {
	ebXML = response.responseXML;
	var extrabitid = '';
	var extrabitname = '';

	var navXML = ebXML.getElementsByTagName('object');

	for (var i=0;i<navXML.length;i++) {
		if (navXML[i].getAttribute("parentId")=='412') {
			extrabitid = navXML[i].getAttribute("id");
			extrabitname = navXML[i].getAttribute("name");
			extrabitsections.push(new extrabitsection(extrabitid, extrabitname));
		}
	}

	updateExtra(extrabitsections[0].extrabitID);
}

///Builds the grid of Extra Bit items
function updateExtra(section) {
	var ebID = '';
	var ebTitle = '';
	var ebBody = '';
	var ebImage = '';
	var ebActive = '';
	var ebOrderNumber = '';

	writeExtraBitSubNav(section);
	extrabits.clear();

	var contentXML = ebXML.getElementsByTagName('object');
	for (var i=0;i<contentXML.length;i++) {
		if (contentXML[i].getAttribute("parentId")==section) {
			ebID = contentXML[i].getAttribute("id");
			var dataNode = contentXML[i].getElementsByTagName('data');
			var properties = dataNode[0].getElementsByTagName('property');
			for (var j=0;j<properties.length;j++) {
				if (properties[j].getAttribute("name") == 'Title') {ebTitle = escape(getText(properties[j]));}
				if (properties[j].getAttribute("name") == 'Body') {ebBody = escape(getText(properties[j]));}
				if (properties[j].getAttribute("name") == 'Image') {ebImage = getText(properties[j]);}
				if (properties[j].getAttribute("name") == 'Active') {ebActive = getText(properties[j]);}
				if (properties[j].getAttribute("name") == 'OrderNumber') {ebOrderNumber = getText(properties[j]);}
			}

			var ebLinks = new Array();
			var ebLinkID = '';
			var ebLinkText = '';
			var ebLinkURL = '';
			var ebLinkPopUpType = '';
			var ebLinkHeight = '';
			var ebLinkWidth = '';
			var ebLinkURLOrderNumber = '';

			var childrenNode = contentXML[i].getElementsByTagName('children');
			var childrenItems = childrenNode[0].getElementsByTagName('object');
			ebLinks.clear();
			if (childrenItems.length) {
				for (var k=0;k<childrenItems.length;k++) {
					ebLinkID = childrenItems[k].getAttribute("id");
					var properties_links = childrenItems[k].getElementsByTagName('property');
					for (var z=0;z<properties_links.length;z++) {
						if (properties_links[z].getAttribute("name") == 'LinkText') {ebLinkText = escape(getText(properties_links[z]));}
						if (properties_links[z].getAttribute("name") == 'LinkURL') {ebLinkURL = getText(properties_links[z]);}
						if (properties_links[z].getAttribute("name") == 'PopupType') {ebLinkPopUpType = getText(properties_links[z]);}
						if (properties_links[z].getAttribute("name") == 'Height') {ebLinkHeight = getText(properties_links[z]);}
						if (properties_links[z].getAttribute("name") == 'Width') {ebLinkWidth = getText(properties_links[z]);}
						if (properties_links[z].getAttribute("name") == 'OrderNumber') {ebLinkURLOrderNumber = getText(properties_links[z]);}
					}
					ebLinks.push(new extrabitlink(ebLinkID, ebLinkText, ebLinkURL, ebLinkPopUpType, ebLinkHeight, ebLinkWidth, ebLinkURLOrderNumber));
				}
				ebLinks = ebLinks.sort(sortByOrderNumber);
			}
			if (ebActive==1) {
				extrabits.push(new extrabit(ebID, ebTitle, ebBody, ebImage, ebLinks, ebActive, ebOrderNumber));
			}
		}
	}

	extrabits = extrabits.sort(sortByOrderNumber);

	var htmlString = '';
	for (i=0;i<extrabits.length;i++) {
		var eb_image = extrabits[i].extrabitImage;
		var eb_title = extrabits[i].extrabitTitle;
		var eb_body = badCharacters(extrabits[i].extrabitBody);
		var eb_links = '';
		for (j=0;j<extrabits[i].extrabitLinks.length;j++) {
			var ebl_text = extrabits[i].extrabitLinks[j].extrabitlinkText;
			var ebl_url = extrabits[i].extrabitLinks[j].extrabitlinkURL;
			var ebl_poptype = extrabits[i].extrabitLinks[j].extrabitlinkPopupType;
			var ebl_height = extrabits[i].extrabitLinks[j].extrabitlinkHeight;
			var ebl_width = extrabits[i].extrabitLinks[j].extrabitlinkWidth;
			eb_links += escape('<br />'+buildEBlink(ebl_text, ebl_url, ebl_poptype, ebl_height, ebl_width));
		}
		htmlString += '<div class="extrabit" onmouseover="hiliteEB(this);" onmouseout="unhiliteEB(this);" onclick="showExtraBit(&#39;'+eb_title+'&#39;, &#39;'+eb_body+'&#39;, &#39;'+eb_links+'&#39;);">';
		htmlString += '<img class="extrabitImage" onmouseover="showtooltip(\''+eb_title+'\');" onmouseout="hidetooltip()"; src="../'+eb_image+'" />';
		htmlString += '</div>';
	}

	htmlString += '<div id="eb_Detail"></div>';

	$('scrollablearea').innerHTML = htmlString;
}

///Helper function to remove problem characters
function badCharacters(inString) {
	var returnString = '';

	returnString = inString.replace('%0A', '<br />');

	return returnString;
}

//Change the ExtraBit style to highlight it
function hiliteEB(elm, titleText) {
	elm.style.background='url(../publishedFiles/images/extrabits/bg_extrabits_hilite.gif) no-repeat';
	var imageElm = elm.firstChild;
	imageElm.style.marginRight='15px';
	imageElm.style.marginBottom='20px';
	imageElm.style.width='120px';
	imageElm.style.height='79px';
//	showtooltip(titleText);
}

//Change the ExtraBit style to un-highlight it
function unhiliteEB(elm) {
	elm.style.background='';
	var imageElm = elm.firstChild;
	imageElm.style.marginRight='25px';
	imageElm.style.marginBottom='30px';
	imageElm.style.width='110px';
	imageElm.style.height='72px';
//	hidetooltip();
}

////////////////////////
var xOffSet = 10;
var yOffSet = 10;
var xPos = 0;
var yPos = 0;

function createToolTip(elmId) {
	if (document.createElement) {
		var elm = document.createElement('p');
		elm.id = elmId;
		elm.innerHTML = '';
		document.body.appendChild(elm);
	}
}

function mouseposition(e) {
	if (document.all) {
		xPos = event.clientX + document.body.scrollLeft;
		yPos = event.clientY + document.body.scrollTop;
	} else {
		xPos = e.pageX;
		yPos = e.pageY;
	}

	$('eb_tooltip').style.left = xPos+xOffSet-(document.documentElement.clientWidth-874)/2+'px';
	$('eb_tooltip').style.top = yPos+yOffSet+'px';
}
function showtooltip(titleText)
{
	if(!$('eb_tooltip')) createToolTip('eb_tooltip');
	$('eb_tooltip').innerHTML = unescape(titleText) + ' - click for more info';
	document.onmousemove = mouseposition;
	$('eb_tooltip').style.display = 'inline';
}
function hidetooltip()
{
	$('eb_tooltip').style.display = 'none';
}
////////////////////////

///Helper function to create either a popup window or a new browser window
function buildEBlink(text,uri,poptype,h,w) {
	var linkstring = '';

	switch (poptype) {
		case 'External':
			linkstring += '<a href="'+uri+'" target="_blank">';
			break;
		case 'Internal':
			linkstring += '<a href="javascript:void(window.open(&#39;'+uri+'&#39;, &#39;popup&#39;, &#39;width='+w+', height='+h+',status=0,dependent=0,directories=0,menubar=0,resizable=1,scrollbars=1,toolbar=0&#39;));">';
			break;
	}
	linkstring += unescape(text);
	linkstring += '</a>';

	return linkstring;
}

///Displays the Extra Bit purple box
function showExtraBit(title, body, linkList) {
	$('eb_Detail').innerHTML = '<h6>'+unescape(title)+'</h6>';
	$('eb_Detail').innerHTML += unescape(body);
	$('eb_Detail').innerHTML += unescape(linkList);
	$('eb_Detail').style.display='inline';
}

///Toggles the content in the Our Services sub pages
function updateServices(inPage) {
	var htmlString = '';
	var fo = null;

	switch (inPage) {
		case 0:
			GetSingleContent(527, FillScrollable);

			fo = new FlashObject("../flash/open-integ_bubble.swf", "flsh_movie", "275", "587", "7", "#FFFFFF");
			break;
		case 1:
			GetSingleContent(537, FillScrollable);

			fo = new FlashObject("../flash/activation_bubble.swf", "flsh_movie", "275", "587", "7", "#FFFFFF");
			break;
	}

	fo.addParam("quality", "high");
	fo.addParam("wmode", "transparent");
	fo.setAltContent('<img src="../publishedFiles/images/right_side_5.jpg" alt="" />');
	fo.write("Flash");

	writeServicesSubNav(inPage);
}

///Toggles the content in the Our Work sub pages
function updateWork(response) {
	var XMLresponse = response.responseXML;
	var htmlString = '';
	var exampleName = '';
	var exampleDescription = '';

	exampleimages.clear();
	examplecaptions.clear();

	var exampleXML = XMLresponse.getElementsByTagName('object');
	exampleDescription = exampleXML[0].getAttribute("description");
	var properties = exampleXML[0].getElementsByTagName('property');

	for (var j=0;j<properties.length;j++) {
		if (properties[j].getAttribute("name") == 'Name') {exampleName = getText(properties[j]);}
		if (properties[j].getAttribute("name") == 'Body') {exampleBody = getText(properties[j]);}

		if (properties[j].getAttribute("name") == 'Image1') {
			if (getText(properties[j])!='') {exampleimages[1] = getText(properties[j]);}
		}
		if (properties[j].getAttribute("name") == 'Image2') {
			if (getText(properties[j])!='') {exampleimages[2] = getText(properties[j]);}
		}
		if (properties[j].getAttribute("name") == 'Image3') {
			if (getText(properties[j])!='') {exampleimages[3] = getText(properties[j]);}
		}
		if (properties[j].getAttribute("name") == 'Image4') {
			if (getText(properties[j])!='') {exampleimages[4] = getText(properties[j]);}
		}
		if (properties[j].getAttribute("name") == 'Image5') {
			if (getText(properties[j])!='') {exampleimages[5] = getText(properties[j]);}
		}

		if (properties[j].getAttribute("name") == 'Caption1') {
			if (getText(properties[j])!='') {examplecaptions[1] = getText(properties[j]);}
		}
		if (properties[j].getAttribute("name") == 'Caption2') {
			if (getText(properties[j])!='') {examplecaptions[2] = getText(properties[j]);}
		}
		if (properties[j].getAttribute("name") == 'Caption3') {
			if (getText(properties[j])!='') {examplecaptions[3] = getText(properties[j]);}
		}
		if (properties[j].getAttribute("name") == 'Caption4') {
			if (getText(properties[j])!='') {examplecaptions[4] = getText(properties[j]);}
		}
		if (properties[j].getAttribute("name") == 'Caption5') {
			if (getText(properties[j])!='') {examplecaptions[5] = getText(properties[j]);}
		}
	}

	htmlString += '<h5>'+exampleName+' - '+exampleDescription+'</h5>';
	htmlString += '<div id="blurb1" class="blurb">';
	htmlString += '<div class="blurbtext" id="blurb1_text">'+exampleBody+'</div>';
	htmlString += '</div>';

	htmlString += '<div id="examples"></div>';

	$('scrollablearea').innerHTML = htmlString;

	$('examples').innerHTML = '<p id="examplecaption">&nbsp;</p>';
	$('examples').innerHTML += '<div id="examplearea"><img id="exampleimage" src="../publishedFiles/images/spacer.gif" /></div>';
	$('examples').innerHTML += '<div id="rollover">rollover for more </div>';

	for (i=1;i<examplecaptions.length;i++) {
		$('rollover').innerHTML += '<a href="#" onmouseover="swapExample('+i+');"><img id="formoreblock'+i+'" src="../publishedFiles/images/spacer.gif" /></a> ';
	}

	swapExample(1);
}

///Swaps the image & caption for the Our Work sub pages
function swapExample(num) {
	$('exampleimage').src = '../'+exampleimages[num];
	$('examplecaption').innerHTML = examplecaptions[num];
}

var displayedArticle = -1;
function showNews(response) {
	var htmlString = '';

	var XMLresponse = response.responseXML;
	var articles = XMLresponse.getElementsByTagName('object');

	for (i=0;i<articles.length;i++)
	{
		var properties = articles[i].getElementsByTagName('property');

		var NewsID = '';
		var NewsHeadline = '';
		var NewsSubHeadline = '';
		var NewsBody = '';
		var disabled = '';
		var OrderNumber = '';

		NewsID = getText(articles[i].getAttribute("id"));
		for (j=0;j<properties.length;j++)
		{
			if (properties[j].getAttribute("name") == 'Headline') {NewsHeadline = getText(properties[j]);}
			if (properties[j].getAttribute("name") == 'Sub Headline') {NewsSubHeadline = getText(properties[j]);}
			if (properties[j].getAttribute("name") == 'Body') {NewsBody = getText(properties[j]);}
			if (properties[j].getAttribute("name") == 'Disabled') {disabled = getText(properties[j]);}
			if (properties[j].getAttribute("name") == 'Order Number') {OrderNumber = getText(properties[j]);}
		}
		if (disabled == '0')
		{
			newsitems.push(new newsitem(NewsID, NewsHeadline, NewsSubHeadline, NewsBody, disabled, OrderNumber));
		}
	}

	//newsitems = newsitems.reverse();
	newsitems = newsitems.sort(sortByOrderNumber)

	var bgtoggle = 1;
	var bg_color = new Array();

	bg_color[1] = 'bg_grey';
	bg_color[0] = '';
	bg_color[-1] = 'bg_white';

	for (i=0;i<=newsitems.length-1;i++)
	{
		htmlString += '<div id="blurb'+i+'" class="blurb '+bg_color[bgtoggle]+' news">';
		htmlString += '<a class="news_headline" href="javascript:showArticle('+i+');">'+newsitems[i].newsHeadline+'</a><br /><br />';
		htmlString += newsitems[i].newsSubHeadline;
		htmlString += '</div>';
		bgtoggle = -bgtoggle;
	}

	$('scrollablearea').innerHTML = htmlString;
}

///Toggle for job posting description
function showArticle(index) {
	for (i=0;i<=newsitems.length-1;i++) {
		if (i==index) {
			if (displayedArticle == index) {
				$('blurb'+i).innerHTML = '<a class="news_headline" href="javascript:showArticle('+i+');">'+newsitems[i].newsHeadline+'</a><br /><br /><p class="blurbtext">'+newsitems[i].newsSubHeadline+'</p>';
				displayedArticle = -1;
			} else {
				$('blurb'+index).innerHTML = '<a class="news_headline" href="javascript:showArticle('+i+');">'+newsitems[i].newsHeadline+'</a><br /><br /><span class="bold">'+newsitems[i].newsSubHeadline+'</span><p class="blurbtext">'+newsitems[i].newsBody+'</p>';
				displayedArticle = index;
			}
		} else {
			$('blurb'+i).innerHTML = '<a class="news_headline" href="javascript:showArticle('+i+');">'+newsitems[i].newsHeadline+'</a><br /><br /><p class="blurbtext">'+newsitems[i].newsSubHeadline+'</p>';
		}
	}
}