﻿var baseURL = 'http://www.weetbix.com.au/tryathlon/';
if (location.hostname.toLowerCase().indexOf("localhost") == 0)
    baseURL = "/tryathlon2009/";
else if (location.hostname.toLowerCase().indexOf("staging1") == 0)
    baseURL = "/TryAthlon2009/";
else if (location.hostname.toLowerCase().indexOf("http://www.weetbix.com.au/tryathlon/staging/") == 0)
    baseURL = 'http://www.weetbix.com.au/tryathlon/staging/';
    
function popUp(URL)
{
    day = new Date();
    id = day.getTime();
    eval("page" + id + " = window.open(URL, '" + id + "', 'toolbar=0,scrollbars=1,location=0,statusbar=0,menubar=0,resizable=1,width=800,height=600,left=25,top=25');");
}

/* Scroll function */
var msecBetweenJump = 150;
var scrollBoxHeight;
var scrollContainerHeight = 79; // matches the CSS values
var topMarginValue = 0;
var pxJump = 2;
var intervalID;
var newsList;

function scrollMove() 
{
    if (newsList)
    {
        topMarginValue = topMarginValue - pxJump;
        newsList.style.marginTop = topMarginValue + "px";
        if ((topMarginValue * -1) > scrollBoxHeight)
            topMarginValue = scrollContainerHeight;
    }
}

function scrollPause()
{
    window.clearInterval(intervalID);
}

function scrollResume()
{
    intervalID = window.setInterval(scrollMove, msecBetweenJump);
}

function initScroll() 
{
    if (document.getElementById)
    {
        newsList = document.getElementById("newsList");
        newsList.onmouseover = scrollPause;
        newsList.onmouseout = scrollResume;
        scrollBoxHeight = newsList.offsetHeight;
        scrollResume();
    }
}

sfHover = function() {
	var sfEls = document.getElementById("mainNavLinks").getElementsByTagName("LI");
	for (var i=0; i<sfEls.length; i++) {
		sfEls[i].onmouseover=function() {
			this.className+=" sfhover";
		}
		sfEls[i].onmouseout=function() {
			this.className=this.className.replace(new RegExp(" sfhover\\b"), "");
		}
	}
}

/* A logo of the sponsor appears when hovering over the link */

    
function linkLogoHoverInit()
{
	var myLinks = document.links;
	for (i = 0; i < myLinks.length; i++) {
	    if (myLinks[i].className.indexOf("sponsor") == 0) {
            if (myLinks[i].className.indexOf("newbalance") > 0) {
                linkLogoHoverSettings(myLinks[i], "Images/Logos/nb_logo.gif");
            }
            else if (myLinks[i].className.indexOf("eyeline") > 0) {
                linkLogoHoverSettings(myLinks[i], "Images/Logos/eyeline_logo.png");
            }
            else if (myLinks[i].className.indexOf("malvernStar") > 0) {
                linkLogoHoverSettings(myLinks[i], "Images/Logos/mal_logo.jpg");
            }            
            else if (myLinks[i].className.indexOf("rosebank") > 0) {
                linkLogoHoverSettings(myLinks[i], "Images/Logos/rosebank_logo.gif");
            }
            else if (myLinks[i].className.indexOf("kennards") > 0) {
                linkLogoHoverSettings(myLinks[i], "Images/Logos/kennards_logo.gif");
            }
        }
	}	
}

function linkLogoHoverSettings(linkElem, logoPath)
{    
    var linkText = linkElem.innerHTML;
	var className = linkElem.className;

    // for IE6 and IE5.5
    if (document.all && document.getElementById && (navigator.appVersion.indexOf("MSIE 6.0") > 0 || navigator.appVersion.indexOf("MSIE 5.5") > 0))
	{
        linkElem.onmouseover = function()
        {
            linkElem.innerHTML = linkText + '<span><img src="' + baseURL + logoPath + '" alt="" /></span>';
        }
        linkElem.onmouseout = function()
        {
			//var t = setTimeout('linkLogoHoverOff("' + className + '", "' + linkText + '")', 2000);
			linkElem.innerHTML = linkText;
        }
	}
	else
		linkElem.innerHTML = linkText + '<span><img src="' + baseURL + logoPath + '" alt="" /></span>';
}

function linkLogoHoverOff(className, linkText)
{
	var myLinks = document.links;
	for (i = 0; i < myLinks.length; i++) {
		if (myLinks[i].className.indexOf("sponsor") == 0) {
            if (myLinks[i].className == className) {
				myLinks[i].innerHTML = linkText;
            }
        }
	}
}

function LoadMap()
{
    var elem = document.getElementById("ausmap");
    if(elem!=undefined && elem!=null)
    {
        var flashvars = {width:"400", height:"300"}
        var params = {allowScriptAccess:"always"};
        var attributes = {};
        var expressInstallURL = "Flash/expressInstall.swf";
        var swfURL = "Flash/map.swf";
        swfobject.embedSWF(baseURL+swfURL, "ausmap", "400px", "300px", "9.0.28", baseURL+expressInstallURL, flashvars, params, attributes);
    }
}

init = function()
{
	// load sponsors
	var flashvars = {width:"895", height:"61"}
    var params = {};
    var attributes = {};
    var expressInstallURL = "Flash/expressInstall.swf";
    var swfURL = "Flash/tryathlon2009_sponsors.swf";
    swfobject.embedSWF(baseURL+swfURL, "sponsors", "895px", "61px", "9.0.28", baseURL+expressInstallURL, flashvars, params, attributes);

	// news scroller
	//initScroll();
	if(location.href.toUpperCase().indexOf("DATESANDVENUES"))
	    LoadMap();
	
	linkLogoHoverInit();
}

if (window.attachEvent) window.attachEvent("onload", sfHover);

window.onload = init;
