
//relative positions 1-8 [1 = north, 2 = north east, 3 = east, etc....]
var objHelp = {
orginalLoadTime: new Date(), 
context: [ { 	"lightboxPreview" : [{"posX":"145","posY":"280","blanker":"lightboxPreview_blanker","lastClicked": "", "location": "notSet", "detailImportance": 1, 'relativePostion':2, 'icon':'/_img/pressassociation/bubble/lightboxIcon.jpg','htmlTitle':'Lightbox Functionality','htmlToDisplay': 'The lightbox provides a way of storing images and video so you can return to them later.' }],
		"simpleDateSection" : [{"posX":"430","posY":"155","blanker":"simpleDateSection_blanker","lastClicked": "", "location": "notSet", "detailImportance": 2, 'relativePostion':5, 'icon':'/_img/pressassociation/bubble/simpleSearchIcon.jpg', 'htmlTitle': 'Date searching','htmlToDisplay': 'This function allows you to refine your search by date.'  }],
		"inactivetabs"  : [{"posX":"480","posY":"90","blanker":"inactivetabs_blanker","lastClicked": "onload", "location": "notSet", "detailImportance":2, 'relativePostion':5, 'icon':'/_img/pressassociation/bubble/tabsIcon.jpg', 'htmlTitle': 'Tabbed browsing','htmlToDisplay': 'This allows you to quickly switch between sections of the website. You can run a search then compare these results to our collections or latest event section. Just with one click. '}],
		"toolbar_blanker" :[{"posX":"400","posY":"188","blanker":"toolbar_blanker","lastClicked": "onload", "location": "notSet", "detailImportance":2, 'relativePostion':5, 'icon':'/_img/pressassociation/bubble/toolbarIcon.jpg', 'htmlTitle': 'The Toolbar','htmlToDisplay': 'The toolbar allows you to change your viewing preferences and save searches.' }],
		"advSearch_blanker" :[{"posX":"notSet","posY":"notSet","blanker":"advSearch_blanker","lastClicked": "onload", "location": "notSet", "detailImportance":2, 'relativePostion':7, 'icon':'/_img/pressassociation/bubble/toolbarIcon.jpg', 'htmlTitle': 'Advanced search','htmlToDisplay': 'The advance search gives you the ability to select more options to refine your search.' }]
} ]
};


var theBubble = '<div id="theBubble" class="bubble"><div class="headerTxt">$title</div><div class="contentTxt">$content</div></div></div>'

var theBubble = '<div id="theBubble" class="bubble"><div class="contentTxt">$img<h1>$title</h1>$content<div class="helpFooter">These features are activated once logged in</div></div></div>'

imgTag = '<img src="$url" align="right" />'
var oldBubble = "";
var activeBubble = "";

function showBubble(objTrigger){

	objHelper = document.getElementById('helpHolder');
	if(objHelper.style.display == "block"){
		changeOpac(70,objHelp.context[0][activeBubble][0].blanker)	
	}
	
	
	if(document.getElementById("dynamicHelpSwitch")){
		if(document.getElementById("dynamicHelpSwitch").checked!=true){
			return;
		}
	}
	
	objHelper = document.getElementById('helpHolder');
	tempStr = theBubble;
	tempStr = theBubble.replace("$title", objHelp.context[0][objTrigger.id][0].htmlTitle);
	tempStr2 = tempStr.replace("$content", objHelp.context[0][objTrigger.id][0].htmlToDisplay);
	tempStr3 = imgTag.replace("$url", objHelp.context[0][objTrigger.id][0].icon)
	helpContents = tempStr2.replace("$img", tempStr3)
	
	
	objHelper.innerHTML = helpContents;
	objHelper.style.display = "block";
	
	if(objHelp.context[0][objTrigger.id][0].posX == "notSet"){
		
		wait = positionHelper(objHelper, objTrigger);
	}else{
		
		objHelper.style.left = objHelp.context[0][objTrigger.id][0].posX + "px";
		objHelper.style.top = objHelp.context[0][objTrigger.id][0].posY + "px";
		switchBubbleBG(document.getElementById("theBubble"),objHelp.context[0][objTrigger.id][0].relativePostion);
		
		if(objHelp.context[0][objTrigger.id][0].blanker!=""){
			changeOpac(40,objHelp.context[0][objTrigger.id][0].blanker)
		}
	}
	
	document.getElementById("theBubble").style.display="block";
	oldBubble = activeBubble;
	activeBubble = objTrigger.id;
}

function hideBubble(obj){
	
	if(document.getElementById("dynamicHelpSwitch")){
		if(document.getElementById("dynamicHelpSwitch").checked!=true){
			return;
		}
	}	
	
	
	if(!arguments[1]){
		setTimeout("hideBubble('"+arguments[0]+"',true)",300);
		return;
	}
	
	if (keepAlive == false){
		document.getElementById('helpHolder').style.display="none";
		if(document.getElementById(objHelp.context[0][activeBubble][0].blanker)){
			//alert(objHelp.context[0][activeBubble][0].blanker)
			changeOpac(70, objHelp.context[0][activeBubble][0].blanker)
		}
	}
}



function switchBubbleBG(objHelpBubble,relPos){
	if (relPos == 5){
		objHelpBubble.style.backgroundImage = "url(/_img/pressassociation/bubble/bubble2.gif)";
		objHelpBubble.style.width = "273px";
		objHelpBubble.style.height= "163px";
		objHelpBubble.style.paddingTop = "35px";
		objHelpBubble.style.paddingLeft = "10px";
		objHelpBubble.style.marginRight = "0";
	}else if(relPos == 7){
		objHelpBubble.style.paddingleft = "5px";
		objHelpBubble.style.backgroundImage = "url(/_img/pressassociation/bubble/bubble3.gif)";
		objHelpBubble.style.width = "306px";
		objHelpBubble.style.height="130px";
		objHelpBubble.style.paddingTop = "3px";
		objHelpBubble.style.marginRight = "-50px";
	}else{
		objHelpBubble.style.backgroundImage = "url(/_img/pressassociation/bubble/bubble.gif)";
		objHelpBubble.style.width = "306px";
		objHelpBubble.style.height="130px";
		objHelpBubble.style.paddingTop = "3px";
		objHelpBubble.style.paddingLeft = "50px";
		objHelpBubble.style.marginRight = "0";
	}	
}

function positionHelper(objHelper, trigger){

	trigTop = trigger.offsetTop;
	trigLeft = trigger.offsetLeft;
	offWidth = trigger.offsetWidth;
	offHeight = trigger.offsetHeight;
	
	objHelpBubble = document.getElementById("theBubble")
	
	relPos = objHelp.context[0][trigger.id][0].relativePostion
	
	
	
	//need to adjust the background so the pointy bit goes in the right direction
	switchBubbleBG(objHelpBubble,relPos);
	
	helperHeight = objHelper.offsetHeight;
	helperWidth = objHelper.offsetWidth;

	//change to switch
	if(relPos == 1){
		objHelper.style.top = (trigTop - helperHeight) + "px";
		objHelper.style.left = (trigLeft + (trigLeft/2) - (helperWidth/2)) + "px";
	}	
	if(relPos == 2){
		objHelper.style.top = (trigTop  + (offHeight/2) +  (helperHeight/2)) + "px";
		objHelper.style.left = (trigLeft + offWidth) + "px";
	}
	if(relPos == 5){
		objHelper.style.top = (trigTop+offHeight)+"px";	
		objHelper.style.left = (trigLeft - (helperWidth/2)) + "px";
	}
	if(relPos == 7){
		objHelper.style.top = (trigTop + (40))+"px";	
		objHelper.style.left = (trigLeft - (helperWidth) - offWidth) + "px";
	}
	if(objHelp.context[0][trigger.id][0].blanker!=""){
		changeOpac(40,objHelp.context[0][trigger.id][0].blanker)
	}
	
}

function changeOpac(opacity, id) {
	
	//alert(id)
	
	objBlank = document.getElementById(id).style;
	
	objBlank.opacity = (opacity / 100);
	objBlank.MozOpacity = (opacity / 100);
	objBlank.KhtmlOpacity = (opacity / 100);
	objBlank.filter = "alpha(opacity=" + opacity + ")";

} 
var keepAlive = false;
function initHelpers(){
	for(key in objHelp.context[0]){
		if(document.getElementById(key)){
			htmlObj = document.getElementById(key)
			addEvent(document.getElementById(key), 'mouseover', function(evt)
			{
				keepAlive = true;showBubble(this);//showBubble(document.getElementById(key))
			},1);
			addEvent(document.getElementById(key), 'mouseout', function(evt)
			{
				keepAlive = false;hideBubble(this)
			},1);
		}
	}
	
	addEvent(document.getElementById('helpHolder'), 'mouseover', function(evt)
	{
		keepAlive = true;
	},1);	
	addEvent(document.getElementById('helpHolder'), 'mouseout', function(evt)
	{
		keepAlive = false;hideBubble()
	},1);	
}


