
var _tickerGroups=new Array();
var newMenu;

top.Initialize=function()
{
    try
    {
        document.execCommand("BackgroundImageCache", false, true);
    }
    catch(e)
    {}
    
    top.AddTickerGroup(top.CreateTickerGroup("RouteOne","products-routeone.html",new Array("Create electronic forms and PDFs")));
    top.AddTickerGroup(top.CreateTickerGroup("ShowMe","products-showme.html",new Array("Executive dashboards")));
    top.AddTickerGroup(top.CreateTickerGroup("PCiRoute","products-pciroute.html",new Array("Upload data automatically from external sites")));
    top.AddTickerGroup(top.CreateTickerGroup("ProFiler","products-profiler.html",new Array("File all outgoing iSeries documents without manual intervention")));
    top.AddTickerGroup(top.CreateTickerGroup("ProActive","products-proactive.html",new Array("Build audit trails of changed iSeries data")));
    top.AddTickerGroup(top.CreateTickerGroup("DataArchiver","products-dataarchiver.html",new Array("Boost performance by removing historical data")));
    top.AddTickerGroup(top.CreateTickerGroup("QueryManager","products-querymanager.html",new Array("Will recommend access path builds to increase performance")));

    top.AddTickerGroup(top.CreateTickerGroup("RouteOne","products-routeone.html",new Array("Fast transfer of volume data to other platforms")));
    top.AddTickerGroup(top.CreateTickerGroup("ShowMe","products-showme.html",new Array("Browser based enquiries and drill downs")));
    top.AddTickerGroup(top.CreateTickerGroup("PCiRoute","products-pciroute.html",new Array("Accept incoming orders via XML")));
    top.AddTickerGroup(top.CreateTickerGroup("ProFiler","products-profiler.html",new Array("Conforms to SAF-T standard")));
    top.AddTickerGroup(top.CreateTickerGroup("ProActive","products-proactive.html",new Array("Add extra functionality to existing applications")));
    top.AddTickerGroup(top.CreateTickerGroup("DataArchiver","products-dataarchiver.html",new Array("Can archive to SQL server, iSeries files, Access or spreadsheets")));
    top.AddTickerGroup(top.CreateTickerGroup("QueryManager","products-querymanager.html",new Array("Automatically change libraries within Query definition")));

    top.AddTickerGroup(top.CreateTickerGroup("RouteOne","products-routeone.html",new Array("Deliver spreadsheets and reports by email")));
    top.AddTickerGroup(top.CreateTickerGroup("ShowMe","products-showme.html",new Array("Business intelligence cubes with slice and dice")));
    top.AddTickerGroup(top.CreateTickerGroup("PCiRoute","products-pciroute.html",new Array("Transfer spreadsheet data to iSeries table")));
    top.AddTickerGroup(top.CreateTickerGroup("ProFiler","products-profiler.html",new Array("Send copy invoices by email")));
    top.AddTickerGroup(top.CreateTickerGroup("ProActive","products-proactive.html",new Array("Monitor events and respond immediately")));
    top.AddTickerGroup(top.CreateTickerGroup("DataArchiver","products-dataarchiver.html",new Array("Easily restore data as and when required")));
    top.AddTickerGroup(top.CreateTickerGroup("QueryManager","products-querymanager.html",new Array("Provides complete visibility of Query usage on the system")));




}

//  Creates a menu
top.CreateMenu=function(items,x,y,width)
{
    //  If the menu already exists cancel
    if(newMenu!=null)
        return;
        
    //  Create the new menu hold div
    newMenu=document.createElement("div");
    newMenu.style.position="absolute";
    newMenu.style.left=x+"px";
    newMenu.style.top=y+"px";
    newMenu.style.background="#5891B2";
    newMenu.style.width=width+"px";
    newMenu.style.cursor="pointer";
    newMenu.style.paddingLeft="20px";
    document.body.appendChild(newMenu);

    newMenu.onmouseout=function(event)
    {
        top.DestroyMenu(event);
    }
    
    var menuTop=document.createElement("div");
    newMenu.appendChild(menuTop);
    menuTop.style.background="url(images/menutop.gif) no-repeat top right";
    menuTop.style.height="12px";
    menuTop.style.lineHeight="0px";  
    menuTop.style.fontSize="0px";  
    
    //  Loop for all the items
    for(var index in items)
    {
        //  Create the menu item
        var newItem=document.createElement("div");
        newMenu.appendChild(newItem);
        newItem.appendChild(document.createTextNode(index));
        
        newItem.style.font="12px 'arial'";
        newItem.style.color="#f0f0f0";
        newItem.style.padding="1px";
        
        //  Set the link
        newItem.attLink=items[index];
        
        newItem.onmouseover=function()
        {
            this.style.textDecoration="underline";
        }
        newItem.onmouseout=function()
        {
            this.style.textDecoration="none";
        }
        newItem.onclick=function()
        {
            top.document.location.href=this.attLink;
        }
    }
    
    var menuBottom=document.createElement("div");
    newMenu.appendChild(menuBottom);
    menuBottom.style.background="url(images/menubottom.gif) no-repeat bottom right";
    menuBottom.style.height="12px";
    menuBottom.style.lineHeight="0px";  
    menuBottom.style.fontSize="0px";    
}

top.DestroyMenu=function(event)
{
    event=event||window.event;

    //  Get the to element
    var toElement=event.toElement||event.relatedTarget;
    var isChildOfMenu=false;

    while(toElement!=null)
    {
        if(toElement==newMenu)
        {
            isChildOfMenu=true;
            break;
        }
        
        toElement=toElement.parentNode;
    }

    //  If the to element is a child of the parent node we dont want to destroy the menu
    if(isChildOfMenu)
        return;

    if(newMenu!=null)
        if(newMenu.parentNode!=null)
        {
            newMenu.parentNode.removeChild(newMenu);
            newMenu=null;
        }
}

top.CreateProductsMenu=function()
{
    var productsMenu=new Object();
    
    productsMenu["RouteOne"]="products-routeone.html";
    productsMenu["ShowMe"]="products-showme.html";
    productsMenu["PC-iRoute"]="products-pciroute.html";
    productsMenu["ProFiler"]="products-profiler.html";
    productsMenu["ProActive"]="products-proactive.html";
    productsMenu["DataArchiver"]="products-dataarchiver.html";
    productsMenu["QueryManager"]="products-querymanager.html";
    
    var productsMenuLink=document.getElementById("idProductsMenuLink");
    
    top.CreateMenu(productsMenu,top.CalculateOffsetLeft(productsMenuLink)+76,top.CalculateOffsetTop(productsMenuLink)-13,100);
}

top.CreateCaseStudiesMenu=function()
{
    var caseStudiesMenu=new Object();
    
    caseStudiesMenu["RouteOne"]="casestudies-routeone.html";
    caseStudiesMenu["ShowMe"]="casestudies-showme.html";
    caseStudiesMenu["PC-iRoute"]="casestudies-pciroute.html";
    
    var caseStudiesMenuLink=document.getElementById("idCaseStudiesMenuLink");
    
    top.CreateMenu(caseStudiesMenu,top.CalculateOffsetLeft(caseStudiesMenuLink)+76,top.CalculateOffsetTop(caseStudiesMenuLink)-13,80);
}

top.CalculateOffsetTop=function(obj)
{
    var offsetTop=0;
    
    do
    {
        offsetTop+=obj.offsetTop;
        
        obj=obj.offsetParent;
    }
    while(obj!=null);

    return offsetTop;
}

top.CalculateOffsetLeft=function(obj)
{
    var offsetLeft=0;
    
    do
    {
        offsetLeft+=obj.offsetLeft;
        
        obj=obj.offsetParent;
    }
    while(obj!=null);

    return offsetLeft;
}

top.CreateTickerGroup=function(groupMessage,url,tickerMessages)
{
    var tickerGroup=new Object();
    
    tickerGroup.groupMessage=groupMessage;
    tickerGroup.tickerMessages=tickerMessages;
    tickerGroup.url=url;
    
    return tickerGroup;
}

top.AddTickerGroup=function(tickerGroup)
{
    _tickerGroups.push(tickerGroup);
}

var _tickerGroupIndex=0;
var _tickerMessageIndex=-1;

var _tickerTextDiv;
var _processTickerMessage=null;
var _nextTickerMessage="";

top.StartTicker=function()
{
    //  Get the values from the cookie
    _tickerGroupIndex=parseInt(GetCookie("tickerGroupIndex"),10);
    _tickerMessageIndex=parseInt(GetCookie("tickerMessageIndex"),10);
    
    //  If the values could not be parse
    if(isNaN(_tickerGroupIndex))
        _tickerGroupIndex=0;
        
    if(isNaN(_tickerMessageIndex))
        _tickerMessageIndex=0;
    
    _tickerTextDiv=document.getElementById("idTickerText");
    top.NextTickerMessage();
    var startTicker=top.setInterval(top.NextTickerMessage,5000);
}

top.NextTickerMessage=function()
{        
    //  Get the ticker group
    var tickerGroup=_tickerGroups[_tickerGroupIndex];
    
     _tickerMessageIndex++;
     
    //  Wrap back around again if the ticker message is at the end
    if(_tickerMessageIndex>=tickerGroup.tickerMessages.length)
    {
        _tickerMessageIndex=0;
        _tickerGroupIndex++;
        
        //  Wrap back around to the first ticker group
        if(_tickerGroupIndex>=_tickerGroups.length)
            _tickerGroupIndex=0;
    }
    
    //  Get the ticker group again
    tickerGroup=_tickerGroups[_tickerGroupIndex];
    
    //  Reset the next ticker message
    _nextTickerMessage="";
    
    //  Process the next ticker message
    _processTickerMessage=setInterval(top.ProcessTickerMessage,10);
    
    //  Set the cookie
    SetCookie("tickerGroupIndex",_tickerGroupIndex);
    SetCookie("tickerMessageIndex",_tickerMessageIndex);
}

top.ProcessTickerMessage=function()
{
    //  Get the ticker message
    var tickerGroupMessage=_tickerGroups[_tickerGroupIndex].groupMessage;
    var tickerMessage=_tickerGroups[_tickerGroupIndex].tickerMessages[_tickerMessageIndex];
    var url=_tickerGroups[_tickerGroupIndex].url;
    
    //  Stop if we are at the end of the current message
    if(_nextTickerMessage.length==tickerMessage.length)
    {
        clearInterval(_processTickerMessage);
        return;
    }
    
    //  Build the next ticker message
    _nextTickerMessage+=tickerMessage.charAt(_nextTickerMessage.length);
    
    //  Update the html
    _tickerTextDiv.innerHTML="<a style=\"color:#0000ff;font-style:italic;\" href=\""+url+"\">"+tickerGroupMessage+"</a>"+" - "+_nextTickerMessage;
}

//  Sets a cookie
top.SetCookie=function(name,value)
{
    //  Set the cookie
    document.cookie=name+"="+escape(value)+";";
}

//  Gets a cookie
top.GetCookie=function(name)
{
    //  If the cookie object is empty, return empty
    if (document.cookie.length==0)
        return "";
        
    //  Get the start of the cookie we are after
    var cookieStart=document.cookie.indexOf(name+"=");
    
    //  If we couldnt find the cookie, return empty
    if(cookieStart==-1)
        return "";
        
    //  Get the terminating semi colon position
    var cookieEnd=document.cookie.indexOf(";",cookieStart);
    
    //  Return the cookie value
    return unescape(document.cookie.substring(cookieStart+name.length+1,cookieEnd));
}