var $j = jQuery.noConflict();
     
     // Use jQuery via $j(...)
     $j(document).ready(function(){
      	fnOurWork()
     	});

// Global Variables
var iepc,firefox,ns7,ns8,mozilla,safari,OS
function fnBrowser() {	
	var ua = navigator.userAgent.toLowerCase();

	iepc = (((ua.indexOf("msie 7") != -1)||(ua.indexOf("msie 6") != -1)||(ua.indexOf("msie 5.5") != -1))&&(ua.indexOf("windows") != -1)&&(ua.indexOf("opera") == -1))? true:false;
	ie7 = ua.indexOf("msie 7") != -1 ? true:false;
	firefox = ua.indexOf("firefox") != -1 ? true:false; // pc or mac
	ns7 = ua.indexOf("netscape/7") != -1 ? true:false; // firefox mode
	ns8 = ua.indexOf("netscape/8") != -1 ? true:false; // firefox mode
	mozilla = (ua.indexOf("gecko") != -1) && (ua.indexOf("netscape") == -1) ? true:false; 
	safari = ua.indexOf("safari") != -1 ? true:false;
	OS = ua.indexOf("windows") != -1? "PC":"MAC";		
	opera = ua.indexOf("opera/9") != -1 ? true:false;
	if (iepc||firefox||ns7||ns8||mozilla||safari||opera) {
		return true;
	} else {
		return false;
	}
}
fnBrowser(); // run on load;


function fnTextSize(textSize) {											
	document.body.className = textSize;			
	var menuLinks = document.getElementById("menu").getElementsByTagName("A");
	for(i=0;i<menuLinks.length;i++) {
		menuLinks[i].href = menuLinks[i].href.split("?")[0]+"?tSize="+textSize;
	}			
} 

function fnPrint() {	
	window.print();			
}

function fnBodyId(newID) {	
	document.body.id = newID;		
}

function fnNews(target) {
	var oArticles = document.getElementById("articles").getElementsByTagName("DIV");
	var oNewsMenuList = document.getElementById("newsMenu").getElementsByTagName("LI");
	
	// If a specific article is referenced and it exists
	if(target!='' && document.getElementById(target)) { 
		for(i=0;i<oNewsMenuList.length;i++) {	
			oNewsMenuList[i].className = "none";
		}	
		for(i=0;i<oArticles.length;i++) {			
			if (oArticles[i].className == "textBoxPadding") {
				oArticles[i].style.display = "none";
				if (oArticles[i].id == target) {
					document.getElementById(target).style.display = "block";	
					document.getElementById(target+"Link").className = "selected";
				}
			}
		}
		 document.getElementById("newsTopImg").src = "images/pageSpecific/news/"+target+".jpg";
	} 
	// if not show leading article
	else { 
		for(i=0;i<oArticles.length;i++) {		
			if (oArticles[i].className == "textBoxPadding") {				
				oArticles[i].style.display = "block";
				oNewsMenuList[0].className = "selected";				
				document.getElementById("newsTopImg").src = "images/pageSpecific/news/"+oArticles[i].id+".jpg";
				break;
			}
		}				
	}	
}

function fnCareers(target) {		
	
	var oCareers = document.getElementById("content").getElementsByTagName("DIV");
	var oCareersMenuList = document.getElementById("careersMenu").getElementsByTagName("LI");
	
	if(target!='') {
		for(i=0;i<oCareersMenuList.length;i++) {	
			oCareersMenuList[i].className = "none";
		}	
		for(i=0;i<oCareers.length;i++) {			
			if (oCareers[i].className == "featureBlock3") {
				oCareers[i].style.display = "none";
				if (oCareers[i].id == target) {
					document.getElementById(target).style.display = "block";	
					document.getElementById(target+"Link").className = "selected";
				}
			}
		}
			
	} else { // find first career and show
		for(i=0;i<oCareers.length;i++) {		
			if (oCareers[i].className == "featureBlock3") {				
				oCareers[i].style.display = "block";
				oCareersMenuList[0].className = "selected";
				break;
			}
		}				
	}	
}

contact1 = new Image();
contact2 = new Image();
contact1.src = "images/pageSpecific/contactUs/topBgBris.jpg";
contact2.src = "images/pageSpecific/contactUs/topBgLon.jpg";

function fnContact(target) {			
	// get source HTML
	var sHTML = document.getElementById("directions"+target).innerHTML;
	// DOM push HTML
	document.getElementById("target").innerHTML = sHTML;	
	
	// Loop through menu's and clear classes
	var oContactMenuList = document.getElementById("menus").getElementsByTagName("LI")	;
	for(i=1;i<=oContactMenuList.length;i++) {
		oContactMenuList[i-1].className = "none";	
	}
	
	// add class to selected link in menu
	oContactMenuList[target-1].className = "selected";
	
	// Switch hero image
	document.getElementById("heroPic").src = target<3? contact1.src  :contact2.src 
	
	/* Only print selected  */
	/*document.getElementById("printSection").innerHTML = sHTML;	*/
	document.getElementById("wrapper").className = "hideFromPrint";
	
}

function fnWhatWeDo(targ) {	
	document.getElementById("whatWeDoTopImg").src = "images/pageSpecific/whatWeDo/"+targ+"BG.jpg"
	switch (targ) {
		case "clientServices":										
	    	document.getElementById("clientServicesLink").className = "selected";
			document.getElementById("creativeLink").className = "none";
			document.getElementById("technicalLink").className = "none";
			document.getElementById("clientServicesDetail").style.display = "block";
			document.getElementById("creativeDetail").style.display = "none";
			document.getElementById("technicalDetail").style.display = "none";
	    break
		case "creative":										
	    	document.getElementById("clientServicesLink").className = "none";
			document.getElementById("creativeLink").className = "selected";
			document.getElementById("technicalLink").className = "none";
			document.getElementById("clientServicesDetail").style.display = "none";
			document.getElementById("creativeDetail").style.display = "block";
			document.getElementById("technicalDetail").style.display = "none";
	    break
		case "technical":										
	    	document.getElementById("clientServicesLink").className = "none";
			document.getElementById("creativeLink").className = "none";
			document.getElementById("technicalLink").className = "selected";
			document.getElementById("clientServicesDetail").style.display = "none";
			document.getElementById("creativeDetail").style.display = "none";
			document.getElementById("technicalDetail").style.display = "block";
	    break
	}				
				document.getElementById(targ+"Link").className = "selected";	
				/*document.getElementById(targ+"Detail").display = "block";*/	
}


// Popup
function fnPopUp(filePath,height,width,attributes){
	var sScreenX = screen.width
	var sScreenY = screen.height
	var x = sScreenX - width
	var y = sScreenY - height
	var winLeft = x/2
	var winTop =  y/2 
	window.open(filePath,"","width=" + width + ",height=" + height + "," + attributes + ",left=" + winLeft + ",top=" + winTop)
}

// Popup Map
function fnPopupMap(targ){
	var width = 750;
	var height = 550;
	var obj = targ.href;
	var sScreenX = screen.width;
	var sScreenY = screen.height;
	var x = sScreenX - width;
	var y = sScreenY - height;
	var winLeft = x/2;
	var winTop =  y/2;	
	window.open(obj,"","width=" + width + ",height="+ height + ",scrollbars=no,left=" + winLeft + ",top=" + winTop);	
	}




/**********************************************************

Name: 			$
Description:	Generic function for returning a reference to an object based on it's ID or
				An array of object references based on a specific class
@param  a 		String representing the ID or Class to be matched
@param 	b 		leave null if matching an ID, else set to 
				the element you wish to look for the matching class in.
      
**********************************************************/
function $(a,b) {
	if(b) {
		var classArray  = new Array;
		var objects  = document.getElementsByTagName(b);
		for(i=0;i<objects.length;i++) {
			if(objects[i].className==a) {
				classArray.push(objects[i]);
			}
		}
		return classArray;
	} 
	else {
		return document.getElementById(a);
	}
}
	
	
/********************************************************************************
 
Name:     Flash plugin detect
 
*********************************************************************************/
/* Create new object called flash */
var flash = new Object();	

/* set flash installed to false by default */
flash.installed = false;

if (navigator.plugins && navigator.plugins.length) {
	for (x=0; x < navigator.plugins.length; x++) {
		
		if (navigator.plugins[x].name.indexOf('Shockwave Flash') != -1) {		
			flash.installed = true;								
			flash.version = eval(navigator.plugins[x].description.split('Shockwave Flash ')[1].split('.')[0]);					
			break;
		}
	}
}
else if (window.ActiveXObject) {
	for (x = 2; x <= 20; x++) {
		try {
			oFlash = eval("new ActiveXObject('ShockwaveFlash.ShockwaveFlash." + x + "');");
			if(oFlash) {		
				flash.installed = true;	
				flash.version = x;
			}
		}
		catch(e) {}
	}
}


/********************************************************************************
 
Name:     			Flash embed
Description:  		Writeout flash code. Fixes Eolas update for IE as well.
@param swf  		String path to swf file
@param width     	Number value of movie width
@param height    	Number value of movie height
@param alternate	Content String of HTML to be served if flash is not installed
@param args			Any extra arguments. Must be a properly formatted string
 
*********************************************************************************/
 
flash.insert = function(swf,width,height,args) {
	swf = swf.replace(/\./g,"%2E") // encode periods as %2e	
	if(!args){
		args="";
	}
 if(flash.installed) {
 	flashObject = '<embed src="'+swf+'" menu="false" quality="high" width="'+width+'px" height="'+height+'px" type="application/x-shockwave-flash" salign="T" pluginspage="http://www.macromedia.com/go/getflashplayer" '+args+' />'
 	document.write(flashObject);
	if(document.getElementById("flashContent")) {
		document.getElementById("flashContent").style.display = "block";
	}
	if(document.getElementById("flashContent1")) {
		document.getElementById("flashContent1").style.display = "block";
	}
	if(document.getElementById("flashContent2")) {
		document.getElementById("flashContent2").style.display = "block";
	}
	
	
 } 
 else {
  	//flashObject = alternateContent;
	fnShowNoFlash();
 }
 
 
}





flash.insertDrop = function(swf,searchType,xmlFile) {
	swf = swf.replace(/\./g,"%2E") // encode periods as %2e	

	 if(flash.installed) {
	 	flashObject = '<embed src="'+swf+'" FlashVars="sJavascript=fMenuOpen&sTitle='+searchType+'&sJavascriptClose=fMenuClose&sXml='+escape(xmlFile)+'" id="flashDrop_'+searchType+'" menu="false" quality="high" width="100%" height="100%" type="application/x-shockwave-flash" salign="T" pluginspage="http://www.macromedia.com/go/getflashplayer" />'
	 	document.write(flashObject);
		if(document.getElementById("dropNoFlash")) {
			document.getElementById("dropNoFlash").style.display = "none";
		}
		if(document.getElementById("dropFlash")) {
			document.getElementById("dropFlash").style.display = "block";
		}
	 } 
	 else {
	    // flash is already hidden by its class=hide, non flash is already showing.
	  	//flashObject = alternateContent;
		//fnShowNoFlash();
	 }
}




/********************************************************************************
 
Name:     		Show No Flash Content
Description:  	Find all divs with "noFlashContent" in their id, put them back on
				screen.

@param:			N/A

Notes:			Use an ID attribute of noFlashContent+number sequentially for 
				any non-flash code sections. 
				
*********************************************************************************/
function fnShowNoFlash() {	
	/* set the function up */
	var divs = document.getElementsByTagName("DIV"); 	// get array of html DIV's
	var id = "noFlashContent";							// set the ID to find
	
	for(i=0;i<=divs.length-1;i++) {						// loop through divs
		if (divs[i].id.match(id)) {						// match object ID to var id
			x = $(divs[i].id);		
			x.style.display = "block";					// use $() to reference ID
			/* 
			x.style.position = "absolute";				// put the div back on screen
			x.style.top = 0;
			x.style.left = 0; 							
			*/
		}
	}
}








/********************************************************************************
 
Name:     		Flash Dropdowns
				
*********************************************************************************/

var sJustClicked = "none";
var sDropCurrentlyOpen = "none";
	


/* Called by Flash when flash dropdown is clicked on */	
function fMenuOpen(arg_bState,sType){

	/* Identify which dropdown has just been clicked */
	sJustClicked = sType;
	
	myMovieId = "flashDrop_" + sDropCurrentlyOpen;		
	myMovie = document.getElementById(myMovieId);	
	
	/* Close currently open flash dropdown */
	if(document.getElementById(myMovieId)) {		
		if(arg_bState == true) {
			myMovie.SetVariable("closedropdown", "erwer");
		}		
	}
	
	/* Update currently Open variable */
	sDropCurrentlyOpen = sJustClicked;
	
	
	targetId = "drop" + sType;

	fnCloseDrop();
	
	if(arg_bState == true) {
		document.getElementById(targetId).style.height = "147px";
	}
	if(arg_bState == false) {
		document.getElementById(targetId).style.height = "22px"
	}	

}
	
function fnBodyClick() {
	if(!safari){
		fCloseFlash();
	}
}

/* Called by flash */
function fMenuClose() {
	fnCloseDrop();
	}

/* Close all flash dropdows */	
/* This needs refactoring! */
function fCloseFlash() {
	myMovieId = document.getElementById("flashDrop_sector");		
	myMovieId.SetVariable("closedropdown", "sector");
	
	myMovieId = document.getElementById("flashDrop_client");		
	myMovieId.SetVariable("closedropdown", "client");
	
	myMovieId = document.getElementById("flashDrop_type");		
	myMovieId.SetVariable("closedropdown", "type");
	
	fnCloseDrop();
}

/* Close Div wrappers */	
/* This needs refactoring! */
function fnCloseDrop() {
	document.getElementById("dropsector").style.height = "19px";
	document.getElementById("dropclient").style.height = "19px";
	document.getElementById("droptype").style.height = "19px";
}	

/*********************************************************************************/
/** end flash dropdowns **/
/*********************************************************************************/

function fnOurWork(){
	//are we on the our work page?
	if($j('#ourWorkContent').length>0) {
		
		$j('#ourWorkTop .main').append('<p>Rollover the logos to find out what we do for each of them.</p>');
		
		$j('#ourWorkContent .row .txtWrap').hide();
		
		$j('#ourWorkContent .row .imgWrap img').tooltip({
   bodyHandler: function() {
     return $j(this).parents('.col').find('.txtWrap').html();
   },
   showURL: false
}
			
		)
		
		
	};
	
	
	
}


