document.getElementsByClassName = function(clsName){
	var retVal = new Array();
	var elements = document.getElementsByTagName("*");
	for(var i = 0;i < elements.length;i++){
		if(elements[i].className.indexOf(" ") >= 0){
			var classes = elements[i].className.split(" ");
			for(var j = 0;j < classes.length;j++){
				if(classes[j] == clsName)
					retVal.push(elements[i]);
			}
		}
		else if(elements[i].className == clsName)
			retVal.push(elements[i]);
	}
	return retVal;
}

function panel_move_vertical(linkname) {
	var $target = $(linkname);
	$target = $target.length && $target
	|| $('[name=' + linkname.slice(1) +']');
	
	if ($target.length) {
	  var targetOffset = $target.offset().top - 46;
	  $('html,body')
	  .animate({scrollTop: targetOffset}, 1000, 'swing');
	 return false;
	}
}

// PUT a 1 for each Coda Slider you are gonna use this sets the default position
var panel_no = new Array(1,1,1,1,1,1,1);
		
function panel_move(pane,direction,tab){
	//put the width of each coda slider you are gonna use
	//var widths = new Array('984','500');
	var widths = document.getElementById('panelContainer'+pane).clientWidth;
	var panelCount = document.getElementsByClassName("panel"+pane).length;
	widths = widths / panelCount;
	//var totalWidth = widths[pane] * panelCount;
	var panel = null;
	
	if(direction == 'left'){
		if(panel_no[pane] == 1){
			panel_no[pane] = panelCount;
			
			if(pane == 3 || pane == 5){
				panel = - (widths * (panelCount - 2));
				panel_no[pane] = panelCount - 1;
			} else {
				
				panel = - (widths * (panelCount - 1));
			}
			jQuery("div.panelContainer"+pane).animate({ left: panel}, 750, "expoinout");
		} else {
			panel_no[pane] = panel_no[pane] - 1;
			panel = - ((panel_no[pane] - 1) * widths);
			jQuery("div.panelContainer"+pane).animate({ left: panel}, 750, "expoinout");
			
		}
		
		if(tab != ""){
			tabs(tab,panel_no[pane]);
		} 
	} else if(direction == 'right'){
		if(panel_no[pane] == panelCount || (pane == 3 && panel_no[pane] == (panelCount -1)) || (pane == 5 && panel_no[pane] == (panelCount -1))){
			panel_no[pane] = 1;
			panel = 0;
			jQuery("div.panelContainer"+pane).animate({ left: panel}, 750, "expoinout");
		} else {
			panel = - (panel_no[pane] * widths);
			jQuery("div.panelContainer"+pane).animate({ left: panel}, 750, "expoinout");
			panel_no[pane] = panel_no[pane] + 1;
		}
		
		if(tab != ""){
			tabs(tab,panel_no[pane]);
		}
		if (pane == 4) {
			preloadImage(panel_no[pane]);
		}
	} else {
		if(direction == 'detail' || direction == 'thankyou'){
			direction = panelCount;
			spawn_detail('on',pane);
		} 
		
		if((pane == 3 || pane == 5) && direction == 1){
			spawn_detail('off',pane);
		}
		
		panel = - ((direction - 1) * widths);
		jQuery("div.panelContainer"+pane).animate({ left: panel}, 750, "expoinout");
		panel_no[pane] = direction;
		
		if(tab != ""){
			tabs(tab,panel_no[pane]);
		}
		if (pane == 4) {
			preloadImage(direction);
		}
	}
	
	if(pane == 3){
		currworkplace = panel_no[pane];
	}
}

function spawn_detail(theswitch,thepane){
	if(thepane == 3){
		if(theswitch == 'on'){
			document.getElementById('next_work').style.display = 'none';
			document.getElementById('prev_work').style.display = 'none';
			document.getElementById('back_to_list').style.display = 'block';
			document.getElementById('next_detail').style.display = 'block';
		} else {
			document.getElementById('next_work').style.display = 'block';
			document.getElementById('prev_work').style.display = 'block';
			document.getElementById('back_to_list').style.display = 'none';
			document.getElementById('next_detail').style.display = 'none';
		}
	}
}

var sel_about = 'background';
var sel_services = 'strategy';
var sel_contact = 'getting';
		
function tabs(section,panes){
	var about_arr = new Array('','background','process','team');
	var services_arr = new Array('','strategy','branding','creative','development','marketing','products');
	var contact_arr = new Array('','getting','request','where');
		
	if(section == 'about'){
		if(sel_about != about_arr[panes]){
			var old_main_menu = document.getElementById(''+section+'_menu_'+sel_about+'_div');
			var old_roll_menu = document.getElementById(''+section+'_menu_'+sel_about+'_div_r');
			var old_sel_menu = document.getElementById(''+section+'_menu_'+sel_about+'_div_s');
			var new_main_menu = document.getElementById(''+section+'_menu_'+about_arr[panes]+'_div');
			var new_sel_menu = document.getElementById(''+section+'_menu_'+about_arr[panes]+'_div_s');
			
			old_main_menu.style.top = '0px';
			old_sel_menu.style.top = '33px';
			old_roll_menu.style.top = '33px';
			new_main_menu.style.top = '33px';
			new_sel_menu.style.top = '0px';
			
			sel_about = about_arr[panes];
		}
		sel_about = about_arr[panes];
		pageTracker._trackPageview('ABOUT/'+about_arr[panes]+'');
		
	} else if(section == 'services'){			
		if(sel_services != services_arr[panes]){
			var old_main_menu = document.getElementById(''+section+'_menu_'+sel_services+'_div');
			var old_roll_menu = document.getElementById(''+section+'_menu_'+sel_services+'_div_r');
			var old_sel_menu = document.getElementById(''+section+'_menu_'+sel_services+'_div_s');
			var new_main_menu = document.getElementById(''+section+'_menu_'+services_arr[panes]+'_div');
			var new_sel_menu = document.getElementById(''+section+'_menu_'+services_arr[panes]+'_div_s');
			
			old_main_menu.style.top = '0px';
			old_sel_menu.style.top = '33px';
			old_roll_menu.style.top = '33px';
			new_main_menu.style.top = '33px';
			new_sel_menu.style.top = '0px';
			
			sel_services = services_arr[panes];
			
		}
		sel_services = services_arr[panes];
		pageTracker._trackPageview('SERVICES/'+services_arr[panes]+'');
		
	} else if(section == 'contact'){			
		if(sel_contact != contact_arr[panes]){
			var old_main_menu = document.getElementById(''+section+'_menu_'+sel_contact+'_div');
			var old_roll_menu = document.getElementById(''+section+'_menu_'+sel_contact+'_div_r');
			var old_sel_menu = document.getElementById(''+section+'_menu_'+sel_contact+'_div_s');
			var new_main_menu = document.getElementById(''+section+'_menu_'+contact_arr[panes]+'_div');
			var new_sel_menu = document.getElementById(''+section+'_menu_'+contact_arr[panes]+'_div_s');
			
			old_main_menu.style.top = '0px';
			old_sel_menu.style.top = '33px';
			old_roll_menu.style.top = '33px';
			new_main_menu.style.top = '33px';
			new_sel_menu.style.top = '0px';
			
			sel_contact = contact_arr[panes];
		}
		sel_contact = contact_arr[panes];
		pageTracker._trackPageview('CONTACT/'+contact_arr[panes]+'');
	}
}
		
function smart_roll(thesection, themenu, theswitch){
	var roll_menu = document.getElementById(''+thesection+'_menu_'+themenu+'_div_r');
	var main_menu = document.getElementById(''+thesection+'_menu_'+themenu+'_div');
	
	if(thesection == 'about'){
		if(sel_about != themenu){
			if(theswitch == 'on'){
				main_menu.style.top = '33px';
				roll_menu.style.top = '0px';
			} else {
				main_menu.style.top = '0px';
				roll_menu.style.top = '33px';
			}
		}
	}
	
	if(thesection == 'services'){
		if(sel_services != themenu){
			if(theswitch == 'on'){
				main_menu.style.top = '33px';
				roll_menu.style.top = '0px';
			} else {
				main_menu.style.top = '0px';
				roll_menu.style.top = '33px';
			}
		}
	}
	
	if(thesection == 'contact'){
		if(sel_contact != themenu){
			if(theswitch == 'on'){
				main_menu.style.top = '33px';
				roll_menu.style.top = '0px';
			} else {
				main_menu.style.top = '0px';
				roll_menu.style.top = '33px';
			}
		}
	}	
}
var portnumber_img = new Array();
var portnumbers = new Array();

function preloadImage(portnum) {
	var imagename = document.getElementById('imgname_' + portnum).value;
	portnumber_img[portnum] = imagename;
	portnumbers.push(portnum);

	var img = document.createElement("img");
	img.onload = function() {
		for(var i = 0;i<portnumbers.length;i++) {
			if (portnumber_img[portnumbers[i]] == this.src) {
				MM_setTextOfLayer('work_details_pic_' + portnumbers[i], '', '<img src="' + this.src + '" width="577" height="393" border="0" />');

				MM_setTextOfLayer('work_details_pic_' + portnumbers[i] + '_b1', '', '&nbsp;');
				MM_setTextOfLayer('work_details_pic_' + portnumbers[i] + '_b2', '', '&nbsp;');

			}
		}
	}
	img.src = imagename;
}

function MM_preloadImages() { //v3.0
  var d=document; if(d.images){ if(!d.MM_p) d.MM_p=new Array();
    var i,j=d.MM_p.length,a=MM_preloadImages.arguments; for(i=0; i<a.length; i++)
    if (a[i].indexOf("#")!=0){ d.MM_p[j]=new Image; d.MM_p[j++].src=a[i];}}
}

function MM_swapImgRestore() { //v3.0
  var i,x,a=document.MM_sr; for(i=0;a&&i<a.length&&(x=a[i])&&x.oSrc;i++) x.src=x.oSrc;
}

function MM_findObj(n, d) { //v4.01
  var p,i,x;  if(!d) d=document; if((p=n.indexOf("?"))>0&&parent.frames.length) {
    d=parent.frames[n.substring(p+1)].document; n=n.substring(0,p);}
  if(!(x=d[n])&&d.all) x=d.all[n]; for (i=0;!x&&i<d.forms.length;i++) x=d.forms[i][n];
  for(i=0;!x&&d.layers&&i<d.layers.length;i++) x=MM_findObj(n,d.layers[i].document);
  if(!x && d.getElementById) x=d.getElementById(n); return x;
}

function MM_swapImage() { //v3.0
  var i,j=0,x,a=MM_swapImage.arguments; document.MM_sr=new Array; for(i=0;i<(a.length-2);i+=3)
   if ((x=MM_findObj(a[i]))!=null){document.MM_sr[j++]=x; if(!x.oSrc) x.oSrc=x.src; x.src=a[i+2];}
}


var thistimerin = new Array();
var thistimerout = new Array();

function start_move(thebutton,theswitch) {
	var thebut = document.getElementById(thebutton);
	var thetarget;
	var currbut = thebut.offsetTop;
	if(theswitch == 'on'){
		thetarget = 155;
		//make sure timer out interval is cleared, if its not, recall this function in 50ms
		
		if (thistimerin[thebutton] && thistimerin[thebutton] > 0) {
			// button is entering page, do nothing
		} else if (thistimerout[thebutton] && thistimerout[thebutton] > 0) {
			// button is leaving page
			clearInterval(thistimerout[thebutton]);
			thistimerout[thebutton] = 0;
			thistimerin[thebutton] = setInterval("learn_more('"+thebutton+"','"+theswitch+"')", 10);
		} else {
			// button is just hanging out off-page
			thistimerin[thebutton] = setInterval("learn_more('"+thebutton+"','"+theswitch+"')", 10);
		}
	} else {
		if (thistimerout[thebutton] && thistimerout[thebutton] > 0) {
			// button is leaving page, do nothing
		} else if (thistimerin[thebutton] && thistimerin[thebutton] > 0) {
			// button is entering page
			clearInterval(thistimerin[thebutton]);
			thistimerin[thebutton] = 0;
			thistimerout[thebutton] = setInterval("learn_more('"+thebutton+"','"+theswitch+"')", 10);
		} else {
			// button is just chilling on the page
			thistimerout[thebutton] = setInterval("learn_more('"+thebutton+"','"+theswitch+"')", 10);
		}
	}
}
function learn_more(thebutton,theswitch){
	var thebut = document.getElementById(thebutton);
	var thetarget;
	var currbut = thebut.offsetTop;
	if(theswitch == 'on'){
		thetarget = 155;
	} else {
		thetarget = 125;
	}
	if(thetarget > currbut){
		thebut.style.top = currbut + 3;
	}
	if(thetarget < currbut){
		thebut.style.top = currbut - 3;
	}
	if((theswitch == 'on' && thetarget < currbut) || (theswitch != 'on' && thetarget > currbut) || (thetarget == currbut)){
		if(theswitch == 'on'){
			clearInterval(thistimerin[thebutton]);
			thistimerin[thebutton] = 0;
		} else {
			clearInterval(thistimerout[thebutton]);
			thistimerout[thebutton] = 0;
		}
	}
}