var curleft = 0;
var curtop = 0;

sfHover = function() {
	var sfEls = document.getElementById("navigation").getElementsByTagName("LI");
	for (var i=0; i<sfEls.length; i++) {
		
		if (sfEls[i].className=="tlmi") {
			sfEls[i].onmouseover=function() {
				this.className+=" sfhover";
				this.firstChild.firstChild.src = this.firstChild.firstChild.src.replace(".gif","-over.gif");
				}
			sfEls[i].onmouseout=function() {
				this.className=this.className.replace(new RegExp(" sfhover\\b"), "");
				this.firstChild.firstChild.src = this.firstChild.firstChild.src.replace("-over.gif",".gif");
				}
		
		} else {
			sfEls[i].onmouseover=function() {
				this.className+=" sfhover";
				}
			sfEls[i].onmouseout=function() {
				this.className=this.className.replace(new RegExp(" sfhover\\b"), "");
				}
		}
	}
}



if (window.attachEvent) window.attachEvent("onload", sfHover);
if (window.addEventListener) window.addEventListener("load",sfHover,false);
if (document.addEventListener) document.addEventListener("load",sfHover,false);

function findPosX(obj){
	var curleft = 0;
	if (obj.offsetParent)
	{
		while (obj.offsetParent)
		{
			curleft += obj.offsetLeft
			obj = obj.offsetParent;
		}
	}
	else if (obj.x)
		curleft += obj.x;
	return curleft;
}

function findPosY(obj){
	var curtop = 0;
	if (obj.offsetParent)
	{
		while (obj.offsetParent)
		{
			curtop += obj.offsetTop
			obj = obj.offsetParent;
		}
	}
	else if (obj.y)
		curtop += obj.y;
	return curtop;
}

function defn(obj,lyr){
	var iWidth = (window.innerWidth) ? window.innerWidth : document.body.offsetWidth;
	var iHeight = (window.innerHeight) ? window.innerHeight : document.body.offsetHeight;
	var newX = findPosX(obj);
	var newY = findPosY(obj);
	var x = document.getElementById(lyr);
	var xspaceAvail = iWidth - newX;
	var yspaceAvail = iHeight - newY;

	if (xspaceAvail > 341){
		var newX = newX + 20;
		x.style.left = newX + 'px';
	} else {
		var newX = newX - 321;
		x.style.left = newX + 'px';
	}

	if (yspaceAvail > 160){
		var newY = newY - 100;
		x.style.top = newY + 'px';
	} else {
		x.style.top = newY + 'px';
	}

	x.style.display = "block";
}

function fade(obj){
	setTimeout('hide("'+obj+'");',4000);
}

function hide(lyr){
	var y = document.getElementById(lyr);
	y.style.display = "none";
}



// Return an element by name.
function getElement(objectName)
{
    if (document.getElementById) return document.getElementById(objectName);
    if (document.all) return document.all[objectName].style.display=value;
    return null;
}

var flashValid = false;

function insertFlash(filename, width, height, backgroundColour, minVersion, alternateType, alternate)
{
	var plugin = (navigator.mimeTypes && navigator.mimeTypes["application/x-shockwave-flash"]) ? navigator.mimeTypes["application/x-shockwave-flash"].enabledPlugin : 0;
	if (plugin) {
		var words = navigator.plugins["Shockwave Flash"].description.split(" ");
		for (var i = 0; i < words.length; ++i)
		{
			if (isNaN(parseInt(words[i])))
			continue;
			var MM_PluginVersion = words[i]; 
		}
		flashValid = (MM_PluginVersion >= minVersion);
	}
	else if (navigator.userAgent && navigator.userAgent.indexOf("MSIE")>=0 
	&& (navigator.appVersion.indexOf("Win") != -1)) {
		document.write('<SCR' + 'IPT LANGUAGE="VBScript"\>\n'); //FS hide this from IE4.5 Mac by splitting the tag
		document.write('on error resume next \n');
        document.write('flashValid = ( IsObject(CreateObject("ShockwaveFlash.ShockwaveFlash.'+minVersion+'")))\n');
		document.write('</SCR' + 'IPT\> \n');
	}
	if (flashValid && document.location.search.substring(1)!='noflash') {
		document.write('<object classid="clsid:d27cdb6e-ae6d-11cf-96b8-444553540000"');
		document.write('    codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab"');
		document.write('    id="FlashMain" width="' + width + '" height="' + height + '" align="middle">');
		document.write('	  <param name="allowScriptAccess" value="sameDomain" />');
		document.write('    <param name="movie" value="' + filename + '">');
		document.write('    <param name="menu" value="false" />');
		document.write('    <param name="quality" value="high" />');
		document.write('    <param name="wmode" value="transparent">');
		document.write('    <param name="bgcolor" value="' + backgroundColour + '">');
		document.write('    <embed src="' + filename + '" quality="high" align="middle" bgcolor="' + backgroundColour + '" wmode="transparent"');
		document.write('        swLiveConnect="FALSE" allowScriptAccess="sameDomain" width="' + width + '" height="' + height + '" name="Main"');
		document.write('        type="application/x-shockwave-flash" pluginspage="http://www.macromedia.com/go/getflashplayer">');
		document.write('    </embed>');
		document.write('</object>');
	} else {
		switch (alternateType)
		{
			case 'image':
				document.write('<img src="'+alternate+'" width="'+width+'" height="'+height+'" border="0" /><br />');
				break;
			case 'flashRequired':
				document.write('<p>Macromedia Flash version '+minVersion+' or above is required to view this content.</p>');
				document.write('<p><a href="http://www.macromedia.com/go/getflashplayer" target="_blank"><img src="http://www.macromedia.com/images/shared/download_buttons/get_flash_player.gif" border="0" width="88" height="31"/></a></p>');
				break;
			case 'showElement':
				getElement(alternate).style.display='block';
				break;
			case 'javascript':
				eval(alternate);
				break;
			default:
				document.write(alternate);
				break;
		}
	}
}

// external link disclaimer 

function disclaimer() { 
	alert("You are about to leave www.bipolar.com.au and open a new website.\n\nThe information you are about to access is not provided by Lilly and may not\ncomply with the Australian regulatory environment.\n\nThis link is provided for information only and does not constitute advice from Lilly. \n\nAny information should be discussed with your health care professional and does\nnot replace their advice.");
	}

// popup window

function openWindow(theURL) {
	var width = '354';
	var height = '480';
	var screenY = screen.height;
	var screenX = screen.width;
	var topvar = (screenY - height) / 2 - 50;
	var leftvar = (screenX - width) / 2;
	window.open(theURL,'','resizable=no,scrollbars=yes,toolbar=no,menubar=no,location=no,status=no,top='+topvar+',left='+leftvar+',width='+width+',height='+height+'');
}


// preload

var refs=['questionnaire','submit','story'];
for(var i=0;i<refs.length;i++){ preload(refs[i]);}
function preload(ref)
{
   var im=new Image();
   im.src="/common/images/btn_"+ref+"_hover.gif";
}

function imageOver(ob,ref)
{
 ob.src="/common/images/btn_"+ref+"_hover.gif";
}

function imageOut(ob,ref)
{
 ob.src="/common/images/btn_"+ref+".gif";
}



// return an element by name

function getElement(objectName)
{
    if (document.getElementById) return document.getElementById(objectName);
    return null;
}

<!--
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];}
}
//-->

