// JavaScript Document

// JavaScript Document

// start up
  window.onload = function (e) {onLoadInit();};

    function onLoadInit() {   
		mceImg();
		nicePicCaptions();
    }
	

// --------------------------------------------------------

// IMAGE ROTATION
  function MM_preloadImages() {
        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];
                }
            }
        }
    }

    var startcount = 1;

    function changeimg() {
        var imgdelay = 10000;
        window.setTimeout("changeimg()", imgdelay);
        document.getElementById("bannerPhoto").src = "img/hp_rotation/" + startcount + ".jpg";
        startcount++;
        if (startcount > 3) {
            startcount = 1;
        }
    }
	

// --------------------------------------------------------

// CUSTOMISE hr
    function makeHrs() {
        if (!document.getElementsByTagName) {
            return;
        }
        var hr = document.getElementsByTagName("hr");
        for (var i = 0; i < hr.length; i++) {
            var newHr = hr[i];
            newHr.style.visibility = "hidden";
            var wrapDiv = document.createElement("div");
            wrapDiv.className = "javascriptHR";
            newHr.parentNode.replaceChild(wrapDiv, newHr);
            wrapDiv.appendChild(newHr);
        }
    }
	
	    
	
// --------------------------------------------------------


// SHOW/HIDE NICER TOOLTIP
    function doNiceTips() {
        if (!document.getElementsByTagName) {
            return;
        }
        var getLinks = document.getElementsByTagName("a");
        for (var i = 0; i < getLinks.length; i++) {
            var thisLink = getLinks[i];
            if (thisLink.className == "external") {
                if (window.addEventListener) {
                    thisLink.addEventListener("mouseover", showTip, false);
                    thisLink.addEventListener("mouseout", hideTip, false);
                } else if (window.attachEvent) {
                    thisLink.attachEvent("onmouseover", showTip);
                    thisLink.attachEvent("onmouseout", hideTip);
                } else {
                    return null;
                }
            }
        }
    }


    function showTip(e) {
        var thisLink;
        if (window.event && window.event.srcElement) {
            thisLink = window.event.srcElement;
        } else if (e && e.target) {
            thisLink = e.target;
        }
        if (thisLink) {
            document.getElementById("toolTip").style.visibility = "hidden";
            document.getElementById("toolTip").style.display = "block";
            var positions = getPosition(thisLink);
            var ttLeft = positions[0];
            var ttTop = positions[1];
            document.getElementById("tipP2").firstChild.nodeValue = thisLink.href;
			document.getElementById("tipPointer").style.width = document.getElementById("toolTip").offsetWidth + "px";
            var difference = (document.getElementById("toolTip").offsetWidth - thisLink.offsetWidth) / 2;
			if (ttLeft - difference<0){document.getElementById("toolTip").style.left = 0 + "px";}
			else if (ttLeft - difference + document.getElementById("toolTip").offsetWidth>window.innerWidth){document.getElementById("toolTip").style.left = window.innerWidth - document.getElementById("toolTip").offsetWidth + "px";}
			else {document.getElementById("toolTip").style.left = ttLeft - difference + "px";}
            document.getElementById("toolTip").style.top = ttTop - document.getElementById("toolTip").offsetHeight - 4 + "px";
            document.getElementById("toolTip").style.visibility = "visible";
        } else {
            return null;
        }
    }


    function hideTip() {
        document.getElementById("toolTip").style.left = "-2000px";
        document.getElementById("toolTip").style.display = "none";
    }

// -------------------------------------------------------- 


// IMAGE POSITIONING

    function mceImg() {
        if (!document.getElementsByTagName) {
            return;
        }
        var pics = document.getElementsByTagName("img");
        for (var i = 0; i < pics.length; i++) {
            var thisPic = pics[i];
            checkParent = thisPic.parentNode;
            ismainArea = checkParent.id;
            while (ismainArea != "mainArea" && ismainArea != "wrapper") {
                checkParent = checkParent.parentNode;
                ismainArea = checkParent.id;
            }
            if (ismainArea == "mainArea"&&thisPic.className!="floatLeft" &&thisPic.parentNode.tagName=="P") {
				//alert(thisPic.parentNode.tagName);
                thisPic.parentNode.className = "copyImgPara";
                thisPic.parentNode.style.width = thisPic.width + "px";
            }
			else if (ismainArea == "mainArea"&&thisPic.className=="floatLeft" &&thisPic.parentNode.tagName=="P"){
				thisPic.parentNode.className = "copyImgParaLeft";
                thisPic.parentNode.style.width = thisPic.width + "px";
				
			}
        }
    }
	
	
// --------------------------------------------------------



// IMAGE CAPTIONS: to match image width	
	
  function nicePicCaptions() {
        if (!document.getElementsByTagName) {
            return;
        }
        var thisbox = document.getElementById("mainArea");
        var pics = document.getElementsByTagName("img");
        for (var i = 0; i < pics.length; i++) {
            var thisPic = pics[i];
            if (thisPic.title) {
                var theCaption = thisPic.title;
                var capSpan = document.createElement("span");
                var capSpanInner = document.createElement("span");
                var capText = document.createTextNode(theCaption);
                capSpanInner.appendChild(capText);
                capSpan.appendChild(capSpanInner);
                thisPic.parentNode.appendChild(capSpan);
                capSpan.className = "picCaption";
            }
        }
    }

// --------------------------------------------------------

// FIND ELEMENT COORDINATES
    function getPosition(theElement) {
        var positionX = 0;
        var positionY = 0;
        while (theElement != null) {
            positionX += theElement.offsetLeft;
            positionY += theElement.offsetTop;
            theElement = theElement.offsetParent;
        }
        return [positionX, positionY];
    }