
var operativeExampleLink = null;
var operativeExampleLinkIsAdvertiserSpecific = false;

/*******************************************************/
/********** BEHAVIOUR CODE FOR ATTACHING JSCRIPT *******/
/**********  TO HTML WITH SPECIAL FUNCTIONALITY	********/
/*******************************************************/
var linkToUsRules = {
	
	'DIV.exampleLinkActuator': function(link){
		link.onclick = function(){
				var destination = '/contentManaged/linkToUs/linkSourceCode.htm';
				var windowRef = window.open(destination, 'sourceCode', 'height=350,width=600,location=no,scrollbars=yes,menubar=no,resizable=no,status=no,statusbar=no,toolbar=no,directories=no');
				windowRef.focus();
				operativeExampleLink = getExampleLink(link);
				
				//windowRef.document.getElementById('sourceCodeContainer').value = exampleLink.innerHTML;				
			};
		link.onmouseover = function(){link.style.textDecoration = 'underline';};
		link.onmouseout = function(){link.style.textDecoration = 'none';};
	},
	
	
	'A.exampleLinkActuator': function(link){
		link.onclick = function(){
				var destination = link.href;
				var windowRef = window.open(destination, 'sourceCode', 'height=600,width=640,location=no,menubar=no,resizable=yes,status=no,scrollbars=yes,statusbar=no,toolbar=no,directories=no');
				windowRef.focus();
				operativeExampleLink = getExampleLink(link);
				
				return false;
				//windowRef.document.getElementById('sourceCodeContainer').value = exampleLink.innerHTML;				
			};
		link.onmouseover = function(){link.style.textDecoration = 'underline';};
		link.onmouseout = function(){link.style.textDecoration = 'none';};
	}
	
};



try{
	Behaviour.register(linkToUsRules);
}catch(e){
	//Happened because the behaviour script is not loaded yet
	//Attempt to register after the page finishes loading
	if(document.attachEvent){
		document.attachEvent('onload', new Function('try{Behaviour.register(linkToUsRules);}catch(e){}'));
	}else{
		document.addEventListener('load', new Function('try{Behaviour.register(linkToUsRules);}catch(e){}'), true);
	}
}
	
	
	
	
	

/*******************************************************/
/***************** UTILITY FUNCTIONS *******************/
/*******************************************************/
	
	
function getExampleLink(link){
	var subSectionContainer = findSubSectionContainer(link);	
	var exampleLink = document.getSubElementsByClassName(subSectionContainer, 'exampleLink');
	
	if(exampleLink.length > 0){
		return exampleLink[0];
	}else{
		exampleLink = document.getSubElementsByClassName(subSectionContainer, 'exampleAdvertiserLink');
		if(exampleLink.length > 0){
			operativeExampleLinkIsAdvertiserSpecific = true;
			return exampleLink[0];
		}else{
			throw ('Failed to find the exampleLink or exampleAdvertiserLink in the HTML.  The HTML for this link is not properly constructed.');
		}
	}	
}


function findSubSectionContainer(element){
	if(element.className.toLowerCase() == 'subsectioncontainer'){
		return element;
	}else{
		return findSubSectionContainer(element.parentNode);
	}	
}

