
//parseUri 1.2 <stevenlevithan.com>; MIT License
// http://blog.stevenlevithan.com/archives/parseuri
var parseUri=function(d){var o=parseUri.options,value=o.parser[o.strictMode?"strict":"loose"].exec(d);for(var i=0,uri={};i<14;i++){uri[o.key[i]]=value[i]||""}uri[o.q.name]={};uri[o.key[12]].replace(o.q.parser,function(a,b,c){if(b)uri[o.q.name][b]=c});return uri};parseUri.options={strictMode:false,key:["source","protocol","authority","userInfo","user","password","host","port","relative","path","directory","file","query","anchor"],q:{name:"queryKey",parser:/(?:^|&)([^&=]*)=?([^&]*)/g},parser:{strict:/^(?:([^:\/?#]+):)?(?:\/\/((?:(([^:@]*):?([^:@]*))?@)?([^:\/?#]*)(?::(\d*))?))?((((?:[^?#\/]*\/)*)([^?#]*))(?:\?([^#]*))?(?:#(.*))?)/,loose:/^(?:(?![^:@]+:[^:@\/]*@)([^:\/?#.]+):)?(?:\/\/)?((?:(([^:@]*):?([^:@]*))?@)?([^:\/?#]*)(?::(\d*))?)(((\/(?:[^?#](?![^?#\/]*\.[^?#\/.]+(?:[?#]|$)))*\/?)?([^?#\/]*))(?:\?([^#]*))?(?:#(.*))?)/}};

function openmypage(expertID, practiceID, name) { 
	//if (expertID==1){
	ajaxwin=dhtmlwindow.open("ajaxbox", "ajax", cmspeoplepath + "html/people.html?name="+name, "", "width=300px,height=300px,left=55px,top=150px,resize=0,scrolling=0");
	//	}
	//if (expertID==2){
	//	ajaxwin=dhtmlwindow.open("ajaxbox", "ajax", cmspeoplepath + "html/people2.html?name="+name, "", "width=300px,height=300px,left=55px,top=150px,resize=0,scrolling=0");
	//	}
	//ajaxwin=dhtmlwindow.open("ajaxbox", "ajax", "../../html/background.jsp?expert=" + expertID, "", "width=300px,height=300px,left=55px,top=150px,resize=0,scrolling=0");
	//http://www.bcg.com/impact_expertise/expert_background.jsp?expert=" + expertID + "&practice=" + practiceID
}

Event.observe(window,'load',function() { 
	var anchor = parseUri(document.location.href).anchor;
	if (!anchor) return; // no anchor found.. nothing special.
	
	if (anchor.indexOf('tab=') == 0){
		var tabid = anchor.substr(4,anchor.length);
		expandtab(tabid, 0); //anchor should be the ID of the tab LI that we want to view.
	}
	if (anchor.indexOf('bio=') == 0){
		var bioid = anchor.substr(4,anchor.length);
		var query = parseUri(document.location.href).query;
		var practiceid = 0
		if (query.indexOf('practice=') == 0) {
			practiceid = query.substr(9,query.length);
		}
		openmypage(bioid,practiceid);   //open the dhtmlwindow with the specific bio.
		var biolink = null;
		var openmypagestr = 'openmypage('+bioid+','+practiceid+');';
		$$('a').each( function(el){
			if (el.readAttribute('onclick'))
				if (el.readAttribute('onclick').indexOf(openmypagestr) != -1) 
					biolink = el;     // got the link to the bio.
		});
		var arr = document.body.getElementsByTagName('a');
		var openmypagestr = 'openmypage('+bioid+','+practiceid+');';
		//alert (openmypagestr);

		if (biolink == null) return; // quit if you didnt find it.
		
		var par = biolink.parentNode; // we are gonna walk up the DOM until we find the tabcontent div.

		//while (par.className != 'tabcontent'){
		while (par.className != 'tabcontentpractice'){
			par = par.parentNode;
		};
		// at this point.. parent.className == 'tabcontentpractice'
		
		var tabheadera;
		for (var i = 0; i < arr.length; i++) { 
			if (arr[i].getAttribute('rel'))
				if (arr[i].getAttribute('rel').indexOf(par.id) != -1) 
					tabheadera = arr[i];     // got the link to the bio.
		}
		var parli = tabheadera.parentNode;
		while (parli.nodeName != 'LI'){
			parli = parli.parentNode;
		};
		// we got the LI!
		
		expandtab(parli.id, 0); // ID of the tab that it's in..

	}
	});
