/*

	Javascripts for www.akg.co.uk
	
	author: Phil Balchin
	client: AKG Actuaries & Consultants
	
	(c)2006 Next Century Systems
	(c)2006 AKG Actuaries & Consultants
*/

$(document).ready(function(){
  
  IENavList();
	
	InitializeFeaturesRollover();
	//InitializeFormStyles();
	
	try {
	    // pageload() should be at the top of the html page,
	    // it should contain functions that are only use full to that page
	    pageLoad();  
	}
	catch(e){
	}
	
});

function IENavList(){
	if (document.all&&document.getElementById) {
		navRoot = document.getElementById("nav-list");
		for (i=0; i<navRoot.childNodes.length; i++) {
			node = navRoot.childNodes[i];
			if (node.nodeName=="LI") {
				node.onmouseover=function() {
					this.className+=" over";
				}
				node.onmouseout=function() {
					this.className=this.className.replace(" over", "");
				}
			}
		}
	}
}


/*	Cookie Tools
------------------------------------------------- */

function setCookie(sName,sValue)
{
	document.cookie = sName + "=" + escape(sValue);
}
function getCookie(sName)
{
	// cookies are separated by semicolons
  var aCookie = document.cookie.split("; ");
  for (var i=0; i < aCookie.length; i++)
  {
    // a name/value pair (a crumb) is separated by an equal sign
    var aCrumb = aCookie[i].split("=");
    if (sName == aCrumb[0]) 
      return unescape(aCrumb[1]);
  }

  // a cookie with the requested name does not exist
  return null;

}

/*	DOM Tools
------------------------------------------------- */

function $id(v)
{
    var o;
    if ( document.getElementById )
    {
        o = document.getElementById(v);
    }
    return o;
}


/* Sitewide
------------------------------------------------- */

function InitializeFeaturesRollover(){

    //Do Main Feature
    if ( document.getElementById("feature-main-img"))
    {
        var featureMainImg = document.getElementById("feature-main-img");
        featureMainImg.onmouseover = FeatureImgOver;
        featureMainImg.onmouseout  = FeatureImgOut;
    }
    
    //Do Mini Features
    if ( document.getElementById("feature-minis") )
    {
        var featureMinis = document.getElementById("feature-minis");
        var featureMinisImg = featureMinis.getElementsByTagName("img");
        
        for ( i=0; i<featureMinisImg.length; i++ )
        {
            featureMinisImg[i].onmouseover = FeatureImgOver;
            featureMinisImg[i].onmouseout = FeatureImgOut;
        }
    }
    else if ( document.getElementById("feature-archive") )
    {
        var featureMinis = document.getElementById("feature-archive");
        var featureMinisImg = featureMinis.getElementsByTagName("img");
        
        for ( i=0; i<featureMinisImg.length; i++ )
        {
            featureMinisImg[i].onmouseover = FeatureImgOver;
            featureMinisImg[i].onmouseout = FeatureImgOut;
        }
    }
}

function InitializeFormStyles(){

    //Filter form Moz Browsers to issue correct Styles for Form Elements
    if ( document.addEventListener )
    {
        //Hide Forms
        $("form").hide().end();
        
        $("form").find("li/label").not("nostyle").each( function(i){
            var labelContent = this.innerHTML;
            var labelWidth = document.defaultView.getComputedStyle( this, "").getPropertyValue("width");
            var labelSpan = document.createElement("span");
                labelSpan.style.display = "block";
                labelSpan.style.width = labelWidth;
                labelSpan.innerHTML = labelContent;
            
            this.style.display = "-moz-inline-box";
            this.innerHTML = null;
            this.appendChild(labelSpan);
        }).end();
            
        //Show Forms
        $("form").show().end();
    }
}

function FeatureImgOver()
{
    var orgSource = this.src;
    var newSource = orgSource.replace(".gif", "-over.gif");
    this.src = newSource;
}
function FeatureImgOut()
{
    var orgSource = this.src;
    var newSource = orgSource.replace("-over.gif", ".gif");
    this.src = newSource;
}