var body = document.body;
var doc  = document;      //make it quicker to write

var initEvents = new Array( mailToFix );

window.location.oldHash = window.location.hash;

function $( e ) { return document.getElementById( e ); }

function $n( e ) { return document.getElementsByTagName( e ); }

// generate an element
function e( type, attrib, txt )
{
    var el = document.createElement( type );

    if (el)
    {
        for (var name in attrib)
	{
	    /*@cc_on @*/
            /*@if (@_win32 || @_win64)
	    if (name == "style")
	    {
                el.style.cssText = attrib[name];
	    }
	    
	    else
            {
            /*@end @*/
	        el.setAttribute( name, attrib[name] );
	    /*@cc_on @*/
            /*@if (@_win32 || @_win64)
	    }
	    /*@end @*/
	}

	if (txt)
	{
            el.appendChild( document.createTextNode( txt ) );
	}

	return el;
    }
    
    return null;
}

var CONFIG =
{
    fontsFile: "http://cdn.absolutewebhosting.com.au/script/fonts.swf"

}

var FLAGS = {
    w3: function() {
        return !!(document.getElementById && document.createElement);
    }(),
    ie: function() {
        return /*@cc_on!@*/0;
    }(),
    /*@cc_on @*/
    /*@if (@_win32 || @_win64)
    ieVersion: function() { var arVersion = navigator.appVersion.split( "MSIE" ); return parseFloat( arVersion[1] ); }(),
    /*@end @*/
    fonts: null,
    ssl: function() {
     return (("https:" == document.location.protocol) ? true : false);
    }(),
    queryStringVars: function()
    {
       var vars = new Array();
       var loc  = window.location.toString();
       if (loc.indexOf( "?" ) != -1)
       {
           loc = loc.substr( loc.indexOf( "?" )+1, loc.length );
	   loc = loc.split( "&" );
	   
	   for (var i = 0; i < loc.length; i++)
	   {
               var temp =  loc[i].split( "=" );
	       
	       vars[temp[0]] = temp[1];
	   }
       }

       return vars;
    }(),
    baseURL: function() { return "http://" + window.location.hostname.toString() + "/"; }(),
    pageURL: function() { return window.location.toString(); }(),
    callbackURL: function() { return "http"+(("https:" == document.location.protocol) ? "s" : "")+"://" + window.location.hostname.toString() + "/callback/ajax.php"; }()
};

function getCookie( name )
{
    var nameEQ = name + "=";
    var ca = document.cookie.split(';');

    for (var i=0; i < ca.length;i++) 
    {
        var c = ca[i];
        while (c.charAt(0)==' ')
        {
            c = c.substring(1,c.length);
	}
	if (c.indexOf(nameEQ) == 0) return decodeURIComponent( c.substring( nameEQ.length, c.length ) );
    }
    return null;
}

function setCookie( name, value, days ) 
{
    if (days) 
    {
        var date = new Date();
        date.setTime( date.getTime() + (days*24*60*60*1000) );
        var expires = "; expires="+date.toGMTString();
    }
    else
    {
        var expires = "";
    }
    document.cookie = name + "=" + encodeURIComponent( value ) + expires + "; path=/";
}

function removeCookie( name ) {
    setCookie( name, "" , -1 );
}


function getFontList()
{

    var fonts = getCookie( "fonts" );
    
    if (!fonts)
    {
        var flash = e( "object", { type: "application/x-shockwave-flash", data: CONFIG["fontsFile"], style: "visibility: hidden;", width: "1", height: "1", id: "flashobj", name: "flashobj" } );
        flash.appendChild( e( "param", { name: "movie", value: CONFIG["fontsFile"] } ) );
        document.body.appendChild( flash );
    }
    else
    {    
        FLAGS["fonts"] = fonts.split(",").sort();
    }

}

function mailToFix()
{
    var links   = $n( "a" );

    for (var i = 0; i < links.length; i++)
    {
       var href          = links[i].href.toString(  );
       if (href.indexOf( "contact/" ))
       {
           var address   = href.replace( /.*contact\/([a-z0-9._%-]+)\+([a-z0-9._%-]+)\+([a-z.]+)/i, "mailto:$1@$2.$3" );
           links[i].href = address;   
       }
    }
}

// sun.com
var hasClass = (function(){
  var c={};
  return function(el, cls){
    if(!c[cls]){c[cls]=new RegExp("(^|\\s)"+cls+"($|\\s)");}
    return el.className && c[cls].test(el.className);
  }
})();


function printStackTrace() { 

    var callstack = []; 

    var isCallstackPopulated = false; 

    try { 

        i.dont.exist+=0; //does not exist - that's the point 

    } catch(e) { 

        if (e.stack) { //Firefox 

            var lines = e.stack.split("\n"); 

            for (var i = 0, len = lines.length; i < len; i++) { 

                if (lines[i].match(/^\s*[A-Za-z0-9\-_\$]+\(/)) { 

                    callstack.push(lines[i]); 

                } 

            } 

            //Remove call to printStackTrace() 

            callstack.shift(); 

            isCallstackPopulated = true; 

        } 

        else if (window.opera && e.message) { //Opera 

            var lines = e.message.split("\n"); 

            for (var i = 0, len = lines.length; i < len; i++) { 

                if (lines[i].match(/^\s*[A-Za-z0-9\-_\$]+\(/)) { 

                    var entry = lines[i]; 

                    //Append next line also since it has the file info 

                    if (lines[i+1]) { 

                        entry += " at " + lines[i+1]; 

                        i++; 

                    } 

                    callstack.push(entry); 

                } 

            } 

            //Remove call to printStackTrace() 

            callstack.shift(); 

            isCallstackPopulated = true; 

        } 

    } 

    if (!isCallstackPopulated) { //IE and Safari 

        var currentFunction = arguments.callee.caller; 

        while (currentFunction) { 

            var fn = currentFunction.toString(); 

            //If we can't get the function name set to "anonymous" 

            var fname = fn.substring(fn.indexOf("function") + 8, fn.indexOf("(")) || "anonymous"; 

            callstack.push(fname); 

            currentFunction = currentFunction.caller; 

        } 

    } 

    alert(callstack.join("\n\n")); 
} 

function generateQueryString( vars )
{
    var queryString = "?";
    
    var j = 0;
    for (var i in vars)
    {
        if (j > 0) queryString += "&";
	queryString += i + "=" + vars[i];
        j++;
    }
    return queryString;
}

var addEvent = function() {
    if ( window.addEventListener ) {
        return function(el, type, fn) {
            el.addEventListener(type, fn, false);
        };
    } else if ( window.attachEvent ) {
        return function(el, type, fn) {
            var f = function() {
                fn.call(el, window.event);
            };
            el.attachEvent('on'+type, f);
        };
    } else {
        return function(el, type, fn) {
            element['on'+type] = fn;
        }
    }
}();

function cancelEvent( e )
{
    if (e.preventDefault) e.preventDefault();
    if (e.cancelBubble) e.cancelBubble = true;
    return false; 
}


function init() {
	if (arguments.callee.done) return;

	arguments.callee.done = true;

	if (_timer) clearInterval(_timer);

	if (initEvents)
        {
            for (var i = 0; i < initEvents.length; i++)
            {
                initEvents[i]();
            }
        }

}

/* for Internet Explorer */
/*@cc_on @*/
/*@if (@_win32)
function pngFix()
{
var arVersion = navigator.appVersion.split("MSIE")
var version = parseFloat(arVersion[1])

if ((version >= 5.5) && (document.body.filters) && version < 7) 
{
   for(var i=0; i<document.images.length; i++)
   {
      var img = document.images[i]
      var imgName = img.src.toUpperCase()
      if (imgName.substring(imgName.length-3, imgName.length) == "PNG")
      {
         var imgID = (img.id) ? "id='" + img.id + "' " : ""
         var imgClass = (img.className) ? "class='" + img.className + "' " : ""
         var imgTitle = (img.title) ? "title='" + img.title + "' " : "title='" + img.alt + "' "
         var imgStyle = "display:inline-block;" + img.style.cssText 
         if (img.align == "left") imgStyle = "float:left;" + imgStyle
         if (img.align == "right") imgStyle = "float:right;" + imgStyle
         if (img.parentElement.href) imgStyle = "cursor:hand;" + imgStyle
         var strNewHTML = "<span " + imgID + imgClass + imgTitle
         + " style=\"" + "width:" + img.width + "px; height:" + img.height + "px;" + imgStyle + ";"
         + "filter:progid:DXImageTransform.Microsoft.AlphaImageLoader"
         + "(src=\'" + img.src + "\', sizingMethod='scale');\"></span>" 
         img.outerHTML = strNewHTML
         i = i-1
      }
   }
}
}

/*@end @*/


{
var initAttached = false;

/* for Mozilla/Opera9 */
if (document.addEventListener) {
	addEvent( document, "DOMContentLoaded", init);
        initAttached = true;
}

/* for Internet Explorer */
/*@cc_on @*/
/*@if (@_win32 || @_win64)
	if (!initAttached)
	{
                document.write('<script type="text/javascript" defer="defer" src="//:" onreadystatechange="if(this.readyState == \'complete\') { init(); }"></script>');
        	initAttached = true;
	}
/*@end @*/

/* for Safari */
if (/KHTML|WebKit/i.test(navigator.userAgent) && !initAttached) // sniff
{ 
	var _timer = setInterval(function() {
		if (/loaded|complete/.test(document.readyState)) {
			init(); // call the onload handler
		}
	}, 10);
        initAttached = true;
}

if (!initAttached)
{
    window.onload = init;
}

};

function XHR() { };
XHR.prototype = 
{
    transport: 
	      function() 
              { 
                  var trans;
  
                  /*@cc_on @*/
                  /*@if (@_win32 || @_win64)
                  try
                  {
                      trans = new ActiveXObject("MSXML2.XMLHTTP.6.0");  
                  }
                  catch( e ){ }
                  try
                  {
                      if( !trans ) trans = new ActiveXObject("MSXML2.XMLHTTP");  
                  }
                  catch( e ){ }

                  if (0)
                  {
                  /*@end @*/

                      trans = new XMLHttpRequest();
  
                  /*@cc_on @*/
                  /*@if (@_win32 || @_win64)
                  }
                  /*@end @*/

                  return trans;
               }(),

     post:
	      function( url, vars, callback, headers )
	      {
		  var t = this.transport;
                  t.open( "POST", url, true );
                  t.setRequestHeader("Content-Type", "application/x-javascript;");
                  t.onreadystatechange = function() 
		  {
                      if (t.readyState == 4 && t.status == 200) 
		      {
                          if (t.responseText) 
			  {
                              callback( t.responseText );
                          }
                      }
                  };

		  t.send( vars );
	      },

    get:
	      function( url, callback, headers )
	      {
		  var t = this.transport;
                  t.open( "GET", url, true );
                  t.setRequestHeader("Content-Type", "application/x-javascript;");
                  t.onreadystatechange = function() 
		  {
                      if (t.readyState == 4 && t.status == 200) 
		      {
                          if (t.responseText) 
			  {
                              callback( t.responseText );
                          }
                      }
                  };
		  t.send( null );
	      }
};

function getOffsetTop (el)
{
var ot = el.offsetTop;
while ( ( el = el.offsetParent ) != null )
{
ot += el.offsetTop;
}
return ot;
}

