function navRoll(navName,navState) {
	if (document.images) {
			document.images[navName].src = eval(navState + ".src");
	}
}

function tabRoll(navName, src) {
	if (document.images) {
		img = document.images[navName];
		if(img.src != src){
			img.src = src;
		}
	}
}

var menuwidth='' //default menu width
var menubgcolor=0  //menu bgcolor
var disappeardelay=300  //menu disappear speed onMouseout (in miliseconds)
var hidemenu_onclick="yes" //hide menu when user clicks within menu?
var	current_nav = null;
/////No further editting needed

var ie4=document.all
var ns6=document.getElementById&&!document.all

//if (ie4||ns6)
//	document.write('<div id="dropmenudiv" class="" style="visibility:hidden;width:'+menuwidth+';background-color:'+menubgcolor+'" onMouseover="clearhidemenu()" onMouseout="dynamichide(event)"></div>')

function getposOffset(what, offsettype){
	var totaloffset=(offsettype=="left")? what.offsetLeft : what.offsetTop;
	var parentEl=what.offsetParent;
	while (parentEl!=null){
		totaloffset=(offsettype=="left")? totaloffset+parentEl.offsetLeft : totaloffset+parentEl.offsetTop;
		parentEl=parentEl.offsetParent;
	}
	return totaloffset;
}


function showhide(obj, e, visible, hidden, menuwidth, page){
	if (ie4||ns6)
		dropmenuobj.style.left=dropmenuobj.style.top="-500px"
		dropmenuobj.className = page
	if (menuwidth!=""){
		dropmenuobj.widthobj=dropmenuobj.style
		dropmenuobj.widthobj.width=menuwidth
	}
	if (e.type=="click" && obj.visibility==hidden || e.type=="mouseover"){
		obj.visibility=visible;
	}	
	else if (e.type=="click"){
		obj.visibility=hidden;
	}
}

function iecompattest(){
	return (document.compatMode && document.compatMode!="BackCompat")? document.documentElement : document.body
}

function clearbrowseredge(obj, whichedge){
	var edgeoffset=0
	if (whichedge=="rightedge"){
		var windowedge=ie4 && !window.opera? iecompattest().scrollLeft+iecompattest().clientWidth-15 : window.pageXOffset+window.innerWidth-15

		dropmenuobj.contentmeasure=dropmenuobj.offsetWidth
		if (windowedge-dropmenuobj.x < dropmenuobj.contentmeasure)
			edgeoffset=dropmenuobj.contentmeasure-obj.offsetWidth
	}
	else{
		var topedge=ie4 && !window.opera? iecompattest().scrollTop : window.pageYOffset
		var windowedge=ie4 && !window.opera? iecompattest().scrollTop+iecompattest().clientHeight-15 : window.pageYOffset+window.innerHeight-18
		dropmenuobj.contentmeasure=dropmenuobj.offsetHeight
/*		if (windowedge-dropmenuobj.y < dropmenuobj.contentmeasure){ //move up?
			edgeoffset=dropmenuobj.contentmeasure+obj.offsetHeight
			alert("up");
			if ((dropmenuobj.y-topedge)<dropmenuobj.contentmeasure) //up no good either?
				edgeoffset=dropmenuobj.y+obj.offsetHeight-topedge
		}*/
	}
	
	return edgeoffset
}

function populatemenu(what){
	if (ie4||ns6)
		dropmenuobj=what;
}


function dropdownmenu(obj, e, menucontents, menuwidth, cnav, page){
	menucontents = document.getElementById(menucontents);

	if(cnav != current_nav){
		offmainnav();
		hidemenu();
	}
	
	if (window.event) event.cancelBubble=true
	else if (e.stopPropagation) e.stopPropagation()
	clearhidemenu()

	dropmenuobj=document.getElementById? document.getElementById("dropmenudiv") : dropmenudiv
	populatemenu(menucontents);

	if (ie4||ns6){
		// Change tabs status if menu is a tab dropdown
		if(window.tabsMouseOver){
			tabsMouseOver(cnav);
		}
		
		showhide(dropmenuobj.style, e, "visible", "hidden", menuwidth, page)
		if ((cnav=="nav_innovation") && (page!="home")){
			dropmenuobj.x=getposOffset(obj, "left") - 90;
			dropmenuobj.style.borderLeftWidth = "0px";
		}else if ((cnav=="nav_practice") && (page!="home")){
			dropmenuobj.x=getposOffset(obj, "left") - 115;
			dropmenuobj.style.borderLeftWidth = "0px";
		}else if ((cnav=="nav_blog")){
			dropmenuobj.x=getposOffset(obj, "left") - 66;
			dropmenuobj.style.borderLeftWidth = "0px";
		}else{
			dropmenuobj.x=getposOffset(obj, "left")
		}
		dropmenuobj.y=getposOffset(obj, "top");
		dropmenuobj.style.left=dropmenuobj.x-clearbrowseredge(obj, "rightedge")+"px"
		dropmenuobj.style.top=dropmenuobj.y-clearbrowseredge(obj, "bottomedge")+obj.offsetHeight+"px"
	}

	current_nav = cnav;

	return clickreturnvalue()
}

function clickreturnvalue(){
	if (ie4||ns6) return false
	else return true
}

function contains_ns6(a, b) {
	while (b.parentNode)
		if ((b = b.parentNode) == a)
			return true;
	
	return false;
}

function dynamichide(e){
	if (ie4&&!dropmenuobj.contains(e.toElement))
		delayhidemenu()
	else if (ns6&&e.currentTarget!= e.relatedTarget&& !contains_ns6(e.currentTarget, e.relatedTarget))
		delayhidemenu()
}

function hidemenu(e){
	if (typeof dropmenuobj!="undefined"){
		if (ie4||ns6){
			dropmenuobj.style.visibility="hidden";
			offmainnav();
		}
	}
}

function offmainnav(){
	cnav = document.getElementById(current_nav);
	if(window.tabsMouseOut){
		tabsMouseOut(current_nav);
	}
	if(cnav){
		navRoll(current_nav, current_nav+'_off');
	}			
}

function delayhidemenu(){
	if (ie4||ns6)
		delayhide=setTimeout("hidemenu()",disappeardelay)
}

function clearhidemenu(){
	if (typeof delayhide!="undefined")
		clearTimeout(delayhide)
}

if (hidemenu_onclick=="yes")
document.onclick=hidemenu

function subnavRoll(navName) {
	document.getElementById(navName).className="selected";
}

function subnavRollOut(navName) {
	document.getElementById(navName).className="subnav";
}


util_home_on=new Image();
util_home_on.src="/images/util_home_over.jpg";
util_home_off=new Image();
util_home_off.src="/images/util_home_off.jpg";

util_about_on=new Image();
util_about_on.src="/images/util_about_over.jpg";
util_about_off=new Image();
util_about_off.src="/images/util_about_off.jpg";

util_offices_on=new Image();
util_offices_on.src="/images/util_offices_over.jpg";
util_offices_off=new Image();
util_offices_off.src="/images/util_offices_off.jpg";

util_careers_on=new Image();
util_careers_on.src="/images/util_careers_over.jpg";
util_careers_off=new Image();
util_careers_off.src="/images/util_careers_off.jpg";

util_move_on=new Image();
util_move_on.src="/images/util_move_over.jpg";
util_move_off=new Image();
util_move_off.src="/images/util_move_off.jpg";

util_contact_on=new Image();
util_contact_on.src="/images/util_contact_over.jpg";
util_contact_off=new Image();
util_contact_off.src="/images/util_contact_off.jpg";

util_login_on=new Image();
util_login_on.src="/images/util_client_over.jpg";
util_login_off=new Image();
util_login_off.src="/images/util_client_off.jpg";


/* Offices */

var office_current = null;

function officeRoll(office_id, over) {
	var map = document.getElementById("map");

	if(map && office_id != office_current){
		if(over){
			if(!office_current){
				map.src = eval('office_'+office_id+'.src');
			}
		}else{
			if(!office_current){
				map.src = '/images/s.gif';
			}
		}
	}
}

function officeClick(office_id, office_location){
	if(office_current){
		var office_old = document.getElementById(office_current);
		var office_old_arrow = document.getElementById('arrow_' + office_current);
		office_old.style.color = '#90B403';
		office_old_arrow.style.color = '#90B403';
	}

	var office = document.getElementById(office_id);
	var office_arrow = document.getElementById('arrow_' + office_id);
	if(office){
		office_current = office_id;
		office.style.color = '#006600';
		office_arrow.style.color = '#006600';
	
		var map = document.getElementById("map");
		map.src = eval('office_'+office_id+'.src');
		
		officeShowInfos(office_id);
	}	
	
	if(window.urchinTracker){
		//alert('/offices/' + office_location);
		urchinTracker('/offices/' + office_location);
	}
	return false;
}

function officeShowInfos(office_id){
	var office_header = document.getElementById('office_hdr');
	var office_infos = document.getElementById('office_infos');
	var office_infos_trick = document.getElementById('office_infos_trick');
	var office_blurb = document.getElementById('office_blurb');

	office_header.style.display = '';
	office_header.src = eval('office_'+office_id+'_hdr.src');;
	office_infos.style.display = '';
	
	var infos = '<div class="details">';
	eval('infos += office_'+office_id+'_infos;');
//		eval(' alert(office_'+office_id+'_infos);')
	var infos_trick = infos;
	infos += '</div><img src="/images/cinfo_bottom.jpg" width="220" height="9" alt="" />';
	office_infos.innerHTML = infos;

	infos_trick += '</div><img src="/images/s.gif" width="220" height="9" alt="" />';
	eval('infos_trick += office_'+office_id+'_visit;');


	office_infos_trick.style.display = '';
	office_infos_trick.innerHTML = infos_trick;

	eval('office_blurb.innerHTML = office_'+office_id+'_blurb;');

}


var email_current = 'enter your email address';

function email_QueryFieldOnFocus(fname){
  if(document.getElementById){
	field = document.getElementById(fname);
	if (fname == 'email'){
		 if(field.value == email_current){
         	field.value=''; 
         }
	}
	field.style.color='#000000';	
  }
}

function email_QueryFieldOnBlur(fname) {
if (document.getElementById) {
	field = document.getElementById(fname);
	if (fname == 'email') {
    	if (field.value=='') {
    	    field.style.color='#999999';
    		field.value= email_current;
        }
	}
  }
}


// Urchin tracking code for documents and external links
function setupUrchinTracking() {
	var links       = document.getElementsByTagName('a');

	var setup_link;
	for (var i = links.length; i != 0; i--) {
		setup_link = false;
		var a = links[i-1];
		if (!a.href) continue;
		
		// Track external links
		if(a.href.indexOf('http') != -1 &&  a.href.indexOf(window.location.hostname) == -1){
			setup_link = true;
		}else if(a.href.indexOf('mailto:') != -1){
			setup_link = true;
		}else{
			// Track documents
			setup_link = isDocument(a.href);
		}
		
		if (setup_link){
			a.onclick = function() {
                track_url(this.href);
                return true;
            }
            
		}
	}
}

function isDocument(href){
	var track_files = new Array('.pdf', '.doc', '.PDF', '.DOC');
	for(var f = 0; f < track_files.length; f++){
		if(href.indexOf(track_files[f]) == (href.length - track_files[f].length)){
			return true;
		}
	}

	return false;
}

function removeDomain(href){
	if(href.indexOf('http') != -1 && href.indexOf(window.location.hostname) != -1){
		href = href.substring((window.location.hostname.length + 7));
	}
	return href;
}

function removeHTTP(href){
	if(href.indexOf('http') != -1){
		href = href.substring(7);
	}
	return href;
}

function track_url(href) {
	if(window.urchinTracker){
		// If is document, remove http://www.domainname.com
		if(isDocument(href)){
			href = removeDomain(href);
		}else if(href.indexOf('mailto:') != -1){
			href = '/mailto/' + href.substring(7);
		}else{
		// If is external link, remove http:// and track the link under /external/
			href = '/external/' + removeHTTP(href);
		}
		//alert(href);
		urchinTracker(href);
	}
}


function setupExternalLinks() {
  var links = document.getElementsByTagName('a');
  for (var i = links.length; i != 0; i--) {
    var a = links[i-1];
    if (!a.href) continue;

    if (a.href.indexOf('http') != -1 &&
            a.href.indexOf(window.location.hostname) == -1 &&
      !excludeUrl(a.href)
        ) {
        a.target = "_blank";

    }
  }
}

function excludeUrl(url){
  var excludeUrls = Array(
              'http://www.rfinteractive.com',
              'http://www.rfistudios.com',
              'http://www.rfinnovations.com',
              'http://www.rfwest.com',
              'http://www.rfasia.com',
              'http://www.ruderfinn.fr',
              'http://www.ruderfinn.co.uk',
              'http://www.ruderfinn.co.il',
              'http://www.mrpicassohead.com',
              'http://www.plannedtvarts.com',
              'http://www.plannedtelevisionarts.com',
              'http://rfinteractive.com',
              'http://rfinnovations.com',
              'http://rfwest.com',
              'http://rfasia.com',
              'http://ruderfinn.fr',
              'http://ruderfinn.co.uk',
              'http://ruderfinn.co.il',
              'http://mrpicassohead.com',
              'http://plannedtvarts.com',
              'http://plannedtelevisionarts.com'
              );

  for(var l = 0; l < excludeUrls.length; l++){
    if(url.indexOf(excludeUrls[l]) == 0){
      return true;
    }
  }

  return false;
}

var tab_innovation_img = new Image();
tab_innovation_img.src = '/images/tab_innovation_sound_on.jpg?2009-03-10';
var tab_practice_img = new Image();
tab_practice_img.src = '/images/tab_specialty_sound_off.jpg?2009-03-10';

var homeCurrentArea = 'practice';
var homePreviousArea = 'practice';

function homeSetArea(area){
//    if(area != homeCurrentArea){
        obj_features = document.getElementById('home-features');

        tab_innovation = document.getElementById('tab-innovation');
        tab_practice = document.getElementById('tab-practice');
        tab_blogs = document.getElementById('tab-blogs');

        footer_container = document.getElementById('footer-container');
        home_container = document.getElementById('main-container-home');

        callouts_innovation = document.getElementById('callouts-innovation');
        callouts_practice = document.getElementById('callouts-practice');
        callouts_blog = document.getElementById('callouts-blog');
        
        sshadow = document.getElementById('shadow');

        nav_innovation = document.getElementById('nav-innovation');
        nav_practice = document.getElementById('nav-practice');
        if(area == 'innovation'){
            sshadow.className = 'pad-top-0px';

            obj_features.className = 'home-features-innovation';
            footer_container.className = 'footer-innovation';

            tab_blogs.src = '/images/tab_blog_on.jpg?2009-03-10';
            if(homePreviousArea == 'practice'){
            	tab_practice.src = '/images/tab_specialty_sound_on.jpg?2009-03-10';
            	tab_innovation.src = '/images/tab_innovation_blog_sound_off.jpg?2009-03-10';
            }else{
            	tab_innovation.src = '/images/tab_innovation_blog_off.jpg?2009-03-10';
            	tab_practice.src = '/images/tab_specialty_sound_off.jpg?2009-03-10';
            }  

            callouts_practice.style.display = 'none';
            callouts_innovation.style.display = 'inline';
            callouts_blog.style.display = 'none';

            nav_practice.style.display = 'none';
            nav_innovation.style.display = 'block';
           
        }else if(area == 'practice'){
            sshadow.className = 'pad-top-5px';

            obj_features.className = 'home-features';
            footer_container.className = 'footer-sound';

            tab_practice.src = '/images/tab_specialty_sound_on.jpg?2009-03-10';
            if(homePreviousArea == 'blogs'){
            	tab_innovation.src = '/images/tab_innovation_sound_off.jpg?2009-03-10';
            }else{
            	tab_innovation.src = '/images/tab_innovation_blog_sound_off.jpg?2009-03-10';
            }  

            callouts_practice.style.display = 'block';
            callouts_innovation.style.display = 'none';
            callouts_blog.style.display = 'none';

            
            nav_practice.style.display = 'block';
            nav_innovation.style.display = 'none';

        }else if(area == 'blogs'){
            sshadow.className = 'pad-top-0px';

            obj_features.className = 'home-features-blog';
            footer_container.className = 'footer-blog';

            tab_innovation.src = '/images/tab_innovation_sound_on.jpg?2009-03-10';
            tab_practice.src = '/images/tab_specialty_sound_off.jpg?2009-03-10';
            tab_blogs.src = '/images/tab_blog_off.jpg?2009-03-10';

            callouts_practice.style.display = 'none';
            callouts_innovation.style.display = 'none';
            callouts_blog.style.display = 'block';

            nav_practice.style.display = 'none';
            nav_innovation.style.display = 'none';
        }
    	homePreviousArea = area;
        homeCurrentArea = area;
        
        setSiteBackground();
//    }

}

/* Overlayer general functions */

function getPageScroll(){
     var scrolly = typeof window.pageYOffset != 'undefined' ? window.pageYOffset : document.documentElement.scrollTop;   
     var scrollx = typeof window.pageXOffset != 'undefined' ? window.pageXOffset : document.documentElement.scrollLeft;   
	
	var arrayScroll = new Array(scrollx, scrolly);
	return arrayScroll;	
}

function getPageSize() {
	var xScroll, yScroll;

	if (window.innerHeight && window.scrollMaxY) {
		xScroll = window.innerWidth + window.scrollMaxX;
		yScroll = window.innerHeight + window.scrollMaxY;
	} else if (document.body.scrollHeight > document.body.offsetHeight){ // all but Explorer Mac
		xScroll = document.body.scrollWidth;
		yScroll = document.body.scrollHeight;
	} else { // Explorer Mac...would also work in Explorer 6 Strict, Mozilla and Safari
		xScroll = document.body.offsetWidth;
		yScroll = document.body.offsetHeight;
	}

	var windowWidth, windowHeight;

	if (self.innerHeight) {	// all except Explorer
		if(document.documentElement.clientWidth){
			windowWidth = document.documentElement.clientWidth;
		} else {
			windowWidth = self.innerWidth;
		}
		windowHeight = self.innerHeight;
	} else if (document.documentElement && document.documentElement.clientHeight) { // Explorer 6 Strict Mode
		windowWidth = document.documentElement.clientWidth;
		windowHeight = document.documentElement.clientHeight;
	} else if (document.body) { // other Explorers
		windowWidth = document.body.clientWidth;
		windowHeight = document.body.clientHeight;
	}

	// for small pages with total height less then height of the viewport
	if(yScroll < windowHeight){
		pageHeight = windowHeight;
	} else {
		pageHeight = yScroll;
	}

	// for small pages with total width less then width of the viewport
	if(xScroll < windowWidth){
		pageWidth = xScroll;
	} else {
		pageWidth = windowWidth;
	}

	arrayPageSize = new Array(pageWidth,pageHeight,windowWidth,windowHeight)
	return arrayPageSize;
}


/* 
	Fix for FireFox - make site background stay on the bottom of page 
	
*/
 
function setSiteBackground(section){
	var pagesize  = getPageSize();
	
	var fileref1=document.createElement("link");
	fileref1.setAttribute("rel", "stylesheet");
	fileref1.setAttribute("type", "text/css");
	
	if(pagesize[1] != pagesize[3]){
		fileref1.setAttribute("href", "/css/ff-with-scroll"+ section +".css?2009-05-28");
	}else{
		fileref1.setAttribute("href", "/css/ff-no-scroll"+ section +".css?2009-05-28");
	}
	document.getElementsByTagName('head')[0].appendChild(fileref1);

	
	if(section != 'capabilities'){
		var fileref2=document.createElement("link");
		fileref2.setAttribute("rel", "stylesheet");
		fileref2.setAttribute("type", "text/css");
		fileref2.setAttribute("href", "/css/background.css");
		document.getElementsByTagName('head')[0].appendChild(fileref2);
	}

}


function getInternetExplorerVersion()
// Returns the version of Internet Explorer or a -1
// (indicating the use of another browser).
{
  var rv = -1; // Return value assumes failure.
  if (navigator.appName == 'Microsoft Internet Explorer')
  {
    var ua = navigator.userAgent;
    var re  = new RegExp("MSIE ([0-9]{1,}[\.0-9]{0,})");
    if (re.exec(ua) != null)
      rv = parseFloat( RegExp.$1 );
  }
  return rv;
}

function loadCorrectShadows(){
	// if it's IE6 don't use any transparent png in bgs  
	/*
	if(getInternetExplorerVersion() == 6){
		var fileref=document.createElement("link");
		fileref.setAttribute("rel", "stylesheet");
		fileref.setAttribute("type", "text/css");
		fileref.setAttribute("href", "/css/ie6.css");
		document.getElementsByTagName('head')[0].appendChild(fileref);
	}
	*/
}

var capabilities_left_src;
var capabilities_right_src;

function capabilitiesOver(left_img_id, right_img_id, view_img_id, is_last, is_first){
	if($(left_img_id)){
		window.capabilities_left_src = $(left_img_id).src;
		$(left_img_id).src = '/images/capabilities/img-border-left.jpg';
	}
	if($(right_img_id)){
		window.capabilities_right_src = $(right_img_id).src;
		if(is_last){
			$(right_img_id).src = '/images/capabilities/img-border-right-last.jpg';
		}else{
			if($(right_img_id).src.indexOf('left-selected') > 0){
				$(right_img_id).src = '/images/capabilities/img-border-right-selected-1.jpg';
			}else{
				$(right_img_id).src = '/images/capabilities/img-border-right.jpg';
			}
		}
	}
	$(view_img_id).show();
}

function capabilitiesOut(left_img_id, right_img_id, view_img_id, is_last, is_first){
	if($(left_img_id)){
		$(left_img_id).src = window.capabilities_left_src;
	}
	if($(right_img_id)){
		$(right_img_id).src = window.capabilities_right_src;
	}

	$(view_img_id).hide();
}

var mouseIsOverFrame = false;
var currentImageCase = null;
var currentBgCase    = null;
var t;

function capabilitiesFrameOver(img_id, bg_id, url, zindex){
	window.clearInterval(t);
	oldbg_id = window.currentBgCase;
	if(oldbg_id){
		$(oldbg_id).style.background = '#F2F2F2';
	}

	pos = Position.cumulativeOffset($(img_id));
	$(bg_id).style.background = '#ffffff';
	$('case-frame-hover').style.zIndex = zindex;
	$('case-frame-hover').style.top = (pos[1])+"px";
	$('case-frame-hover').style.left = (pos[0])+"px";
	$('case-frame-hover').href = url;
	window.currentImageCase = img_id;
	window.currentBgCase    = bg_id;
	window.mouseIsOverFrame = true;
	t = setInterval(function(){mouseOut(); }, 150);
}

function mouseOut(){
//	alert('x');
	capabilitiesFrameOut(window.currentBgCase);	
}

function capabilitiesFrameOut(bg_id){
//	alert(window.mouseIsOverFrame);
	if(window.mouseIsOverFrame == true){
	}else{
		window.clearInterval(t);
		window.mouseIsOverFrame = false;
		if(bg_id){
			$(bg_id).style.background = '#F2F2F2';
			$('case-frame-hover').style.top = "-5000px";
			$('case-frame-hover').style.left = "-5000px";
		}
	}
	
}

function mouseOverFrame(){
	window.mouseIsOverFrame = true;
}

function mouseOutOfFrame(){
	window.mouseIsOverFrame = false;
}

function setSelectedCase(){
	if(window.selectedCase){
		pos = Position.cumulativeOffset($(window.selectedCase));
		$('case-frame-selected').style.top = (pos[1])+"px";
		$('case-frame-selected').style.left = (pos[0])+"px";
	}
}

function showHideContactPracticeArea(){
	if($('contact-practice-area').visible()){
		$('contact-practice-area').hide();
		$('contact-practice-area-li').className = '';
	}else{
		$('contact-practice-area').show();
		$('contact-practice-area-li').className = 'expanded';
	}
}


function showHomeOverlayer(url, width, height){
	hcontainer_left = getposOffset($('header'), "left");

	left_diff = (width-950) / 2 + 68;
	
	window.open(url, url,'toolbar=no, left=' + (hcontainer_left-left_diff) + ', top=100, location=no, directories=no,status=no,menubar=no,scrollbars=no,resizable=no,copyhistory=yes,width='+ width +', height='+height); return false;

}

function setSelectsDisplay(val){
  var s = document.getElementsByTagName('select');
  for (var i = s.length; i != 0; i--) {
    var ss = s[i-1];
    ss.style.display = val;
  }
}