//[['link','scope','scope',(...)],...]
var arr_scopes=[
['/CM/Custom/TOCPracticeAreaDescriptions.asp','PracticeAreas/index.html','/CM/PracticeAreaDescriptions'],
['/CM/Custom/Attorneys.asp','Bio/index.html','/CM/AttorneyBios/'],
['/','/CM/Custom/Home.asp']
];

var at = document.getElementsByTagName('a'), it = document.getElementsByTagName('img'),i=0;
var uc = '!@#$';
re = new RegExp(/^.+\('([^']+)'.+'\/(.+\/)+(.+)',.\)$/m);
fp = document.location + '--+';
rp = fp.replace(/^http:\/\/[^\/]+(\/.*)$/,'$1');
dn = fp.replace(rp,'')+'/';
rf = rp.replace(/^(\/(.+\/)+).+$/,'$1');
fn = rp.replace(rf,'');

fp = fp.replace('--+','');
rp = rp.replace('--+','');
fn = fn.replace('--+','');

//Make '/' something unique
rp=(rp=='index.html')?uc:rp;
for(i=0;i<arr_scopes.length;i++){
	for(j=0;j<arr_scopes[i].length;j++){
		arr_scopes[i][j] = (arr_scopes[i][j]=='index.html')?uc:arr_scopes[i][j];
	}
}

for(i=0;i<at.length;i++){
	at_hr = at[i].getAttribute('href');	
	at_hr=(at_hr==dn)?uc:at_hr;	

	if((at_hr.indexOf(rp)>-1||scopes(at_hr))&&at[i].getAttribute('onmouseover')!=null){			
	
			m = re.exec(at[i].getAttribute('onmouseover')+'');

			for(j=0;j<it.length;j++){
				if(it[j].getAttribute('name')==m[1]){
					m[3] = m[3].replace('-o.','-a.');
					it[j].src = '/Includes/Templates/Active/images/' + m[3];					
				}
			}		
		
	}
}


function scopes(hr){	
	var i=0,j=0;
	//alert('*' + hr + '* - *' + dn + '*');
	mod_fp=(fn=='')?uc:fp;
	mod_fn=(fn=='')?uc:fn;
	
	for(i=0;i<arr_scopes.length;i++){
		//Do scopes of current link fit the current file path? 
		if(hr.indexOf(arr_scopes[i][0])>-1){
			for(j=1;j<arr_scopes[i].length;j++){
				//alert(fp + ' - ' + arr_scopes[i][j] + ' - ' + i);
				
				if(mod_fp.indexOf(arr_scopes[i][j])>-1){
					return true;
				}
			}
		}
		
		//Do any combination of scopes and present file name in address bar fit current link?
		for(j=1;j<arr_scopes[i].length;j++){
			if(hr.indexOf(arr_scopes[i][j])>-1&&hr.indexOf(mod_fn)>-1){
				//alert('db');
				return true;
			}	
		}	
	}
	return false;
}
