﻿var _already_did_domready = false;

if (document.addEventListener) {
    document.addEventListener("DOMContentLoaded", function() {
        _already_did_domready = true;
        bedazzle();
    }, false);
} else if (document.all && !window.opera) {
    document.write('<script type="text/javascript" id="_httpbedazzler_domready" defer="defer" src="javascript:void(0)"><\/script>')
    var _httpbedazzler_domready = document.getElementById("_httpbedazzler_domready");
    _httpbedazzler_domready.onreadystatechange = function() {
        if (this.readyState == "complete") {
            _already_did_domready = true;
            bedazzle();
        }
    }
}

//window.onload = function() {
//    setTimeout(function () {
//        if (!_already_did_domready)
//            bedazzle();
//    }, 0);
//}

//window.onreadystatechange = function() {
//    //if (this.readyState == "complete")
//    //    bedazzle();
//}

function bedazzle() {
    // Suppress javascript errors
    function stopError() {
        return true;
    }
    window.onerror = stopError;

    // Find the <body> tag
    var elements = document.getElementsByTagName("body");
    if (elements.length <= 0)
        return;
    var body = elements[0];
    
    // Get window size
    var window_x, window_y;
    window_x = window.innerWidth;
    window_y = window.innerHeight;
    if (window_x == null || window_y == null) {
        window_x = body.offsetWidth;
        window_y = body.offsetHeight;
    }
    // Add some exclamation points
    var elements = document.getElementsByTagName("h1");
    for (var i=0; i<elements.length; i++) {
        var element = FindChildNodeContainingText(elements[i]);
        if (element != null)
            element.nodeValue = element.nodeValue + "!!!";
    }
    
    // Element to hover between the body background & the page content
    //var bg_layer = document.createElement("div");
    //bg_layer.id = "httpbedazzler_background_layer";
    //bg_layer.style.width = window_x + "px";
    //bg_layer.style.height = window_y + "px";
    //bg_layer.style.opacity = 0.25;        
    //if (body.hasChildNodes())
    //    body.insertBefore(bg_layer, body.childNodes[0]);
    //else
    //    body.appendChild(bg_layer);
    
    // Rainbow
    /*var rainbow = document.createElement("img");
    rainbow.src = "/_images/rainbow.png";
    rainbow.style.position = "fixed";
    rainbow.style.top = "0px";
    rainbow.style.left = "0px";
    rainbow.style.width = (window_x / 2) + "px";
    rainbow.style.height = (window_x / 2) + "px";
//    rainbow.style.top = "0px";
//    rainbow.style.left = "0px";
//    rainbow.style.width = "500px";
//    rainbow.style.height = "500px";
    
    body.appendChild(rainbow);*/
    
    // Run through all elements in the document and find any that have
    // the same background color as <body>
    // ...
    
    // Sprites
    //var sprite = document.createElement("div");
    //sprite.className = "background_sprite";
    //bg_layer.appendChild(sprite);
}

function FindChildNodeContainingText(node) {
    var returnNode = null;
    
    switch (node.nodeType) {
        case 3: // Text node
            if (trim(node.nodeValue, "").length > 0)
                returnNode = node;
            break;
        
        default:
            for (var i=0; i<node.childNodes.length; i++) {
                returnNode = FindChildNodeContainingText(node.childNodes[i]);
                if (returnNode != null)
                    break;
            }
            break;
    }
    
    return returnNode;
}

function trim(str, chars) {
    return ltrim(rtrim(str, chars), chars);
}

function ltrim(str, chars) {
    chars = chars || "\\s";
    return str.replace(new RegExp("^[" + chars + "]+", "g"), "");
}

function rtrim(str, chars) {
    chars = chars || "\\s";
    return str.replace(new RegExp("[" + chars + "]+$", "g"), "");
}


// [NAK] - Adding Gems

/*********************************************************
     * You may use this code for free on any web page provided that 
     * these comment lines and the following credit remain in the code.
     * Floating Div from http://www.javascript-fx.com
     ********************************************************/
/* SCRIPT USED FOR FLOATY GEMS, NOT NEEDED?
var ns = (navigator.appName.indexOf("Netscape") != -1);
var d = document;
function JSFX_FloatDiv(id, sx, sy)
{
	var el=d.getElementById?d.getElementById(id):d.all?d.all[id]:d.layers[id];
	var px = document.layers ? "" : "px";
	window[id + "_obj"] = el;
	if(d.layers)el.style=el;
	el.cx = el.sx = sx;el.cy = el.sy = sy;
	el.sP=function(x,y){this.style.left=x+px;this.style.top=y+px;};

	el.floatIt=function()
	{
		var pX, pY;
		pX = (this.sx >= 0) ? 0 : ns ? innerWidth : 
		document.documentElement && document.documentElement.clientWidth ? 
		document.documentElement.clientWidth : document.body.clientWidth;
		pY = ns ? pageYOffset : document.documentElement && document.documentElement.scrollTop ? 
		document.documentElement.scrollTop : document.body.scrollTop;
		if(this.sy<0) 
		pY += ns ? innerHeight : document.documentElement && document.documentElement.clientHeight ? 
		document.documentElement.clientHeight : document.body.clientHeight;
		this.cx += (pX + this.sx - this.cx)/8;this.cy += (pY + this.sy - this.cy)/8;
		this.sP(this.cx, this.cy);
		setTimeout(this.id + "_obj.floatIt()", 40);
	}
	return el;
}*/

//var numOfGems = 30;
//addgems(0,0, numberOfGems);
function getImageFile()
{
    return "rhinestone_" + rand(1,27) + ".png";
}


function addgems(minW, minH, gems, url)
{ 
    for(var j=0; j < gems; j++)
    {
        var randX = rand(minW, f_clientWidth());
        var randY = rand(minH, f_clientHeight());
        
        document.write('<div id="gemdockcontent' + j + '" class="gemdock" style="position:fixed;visibility:visible;left:' + randX + 'px;top:' + randY + 'px;z-index:1000;"><img src="'+ url + getImageFile() + '" border="0"></div>');
        //JSFX_FloatDiv("gemdockcontent" + j, randX, randY).floatIt();
    }
    document.write('<div id="badge" class="badgedock" style="position:fixed;visibility:visible;right:0px;top:0px;z-index:1000;"><a href="mailto:?subject=I took the AMAZE-IT e-Challenge.  Check it out!&body=Hey, have you heard of the Amazing Amazer? I just used it on the Internets! Take a look: http://www.amazingamazer.com/" ><img src="http://onyx.amazingamazer.clc/_images/badge.png" border="0" /></a></div>');
}



function rand(minVal, maxVal)
{
  var randVal = minVal+(Math.random()*(maxVal-minVal));
  return Math.floor(randVal);
}

function f_clientWidth() {
	return f_filterResults (	
    	window.innerWidth ? window.innerWidth : 0,
		document.documentElement ? document.documentElement.clientWidth : 0,
		document.body ? document.body.clientWidth : 0);
}
function f_clientHeight() {   
    window_y = window.innerHeight;
    if (window_y == null) {
	    return f_filterResults (
		    document.documentElement ? document.documentElement.clientWidth : 0,
		    document.body ? document.body.clientWidth : 0);
    }
    else
    {
        return window_y;
    }
	//return f_filterResults (
		//window.innerHeight ? window.innerHeight : 0,
		//document.documentElement ? document.documentElement.clientHeight : 0,
		//document.body ? document.body.clientHeight : 0
	//);
}
function f_scrollLeft() {
	return f_filterResults (
		window.pageXOffset ? window.pageXOffset : 0,
		document.documentElement ? document.documentElement.scrollLeft : 0,
		document.body ? document.body.scrollLeft : 0
	);
}
function f_scrollTop() {
	return f_filterResults (
		window.pageYOffset ? window.pageYOffset : 0,
		document.documentElement ? document.documentElement.scrollTop : 0,
		document.body ? document.body.scrollTop : 0
	);
}
function f_filterResults(n_win, n_docel, n_body) {
	var n_result = n_win ? n_win : 0;
	if (n_docel && (!n_result || (n_result > n_docel)))
		n_result = n_docel;
	return n_body && (!n_result || (n_result > n_body)) ? n_body : n_result;
}



/********* [NAK] - Sparkle!!!  *********************/

var colour="#FF2000";
var sparkles=70;
/****************************
* Tinkerbell Magic Sparkle *
* (c) 2005 mf2fm web-design *
* http://www.mf2fm.com/rv *
* DON'T EDIT BELOW THIS BOX *
****************************/
var x=ox=400;
var y=oy=300;
var swide=800;
var shigh=600;
var sleft=sdown=0;
var tiny=new Array();
var star=new Array();
var starv=new Array();
var starx=new Array();
var stary=new Array();
var tinyx=new Array();
var tinyy=new Array();
var tinyv=new Array();
window.onload=function() { if (document.getElementById) {
var i, rats, rlef, rdow;
for (var i=0; i<sparkles; i++) {
var rats=createDiv(3, 3);
rats.style.visibility="hidden";
document.body.appendChild(tiny[i]=rats);
starv[i]=0;
tinyv[i]=0;
var rats=createDiv(5, 5);
rats.style.backgroundColor="transparent";
rats.style.visibility="hidden";
var rlef=createDiv(1, 5);
var rdow=createDiv(5, 1);
rats.appendChild(rlef);
rats.appendChild(rdow);
rlef.style.top="2px";
rlef.style.left="0px";
rdow.style.top="0px";
rdow.style.left="2px";
document.body.appendChild(star[i]=rats);
}
set_width();
sparkle();
}}
function sparkle() {
var c;
if (x!=ox || y!=oy) {
ox=x;
oy=y;
for (c=0; c<sparkles; c++) if (!starv[c]) {
star[c].style.left=(starx[c]=x)+"px";
star[c].style.top=(stary[c]=y)+"px";
star[c].style.clip="rect(0px, 5px, 5px, 0px)";
star[c].style.visibility="visible";
starv[c]=50;
break;
}
}
for (c=0; c<sparkles; c++) {
if (starv[c]) update_star(c);
if (tinyv[c]) update_tiny(c);
}
setTimeout("sparkle()", 40);
}
function update_star(i) {
if (--starv[i]==25) star[i].style.clip="rect(2px, 6px, 6px, 2px)";
if (starv[i]) {
stary[i]+=1+Math.random()*3;
if (stary[i]<shigh+sdown) {
star[i].style.top=stary[i]+"px";
starx[i]+=(i%5-2)/5;
star[i].style.left=starx[i]+"px";
}
else {
star[i].style.visibility="hidden";
starv[i]=0;
return;
}
}
else {
tinyv[i]=50;
tiny[i].style.top=(tinyy[i]=stary[i])+"px";
tiny[i].style.left=(tinyx[i]=starx[i])+"px";
tiny[i].style.width="2px";
tiny[i].style.height="2px";
star[i].style.visibility="hidden";
tiny[i].style.visibility="visible"
}
}
function update_tiny(i) {
if (--tinyv[i]==25) {
tiny[i].style.width="1px";
tiny[i].style.height="1px";
}
if (tinyv[i]) {
tinyy[i]+=1+Math.random()*3;
if (tinyy[i]<shigh+sdown) {
tiny[i].style.top=tinyy[i]+"px";
tinyx[i]+=(i%5-2)/5;
tiny[i].style.left=tinyx[i]+"px";
}
else {
tiny[i].style.visibility="hidden";
tinyv[i]=0;
return;
}
}
else tiny[i].style.visibility="hidden";
}
document.onmousemove=mouse;
function mouse(e) {
set_scroll();
y=(e)?e.pageY:event.y+sdown;
x=(e)?e.pageX:event.x+sleft;
}
function set_scroll() {
if (typeof(self.pageYOffset)=="number") {
sdown=self.pageYOffset;
sleft=self.pageXOffset;
}
else if (document.body.scrollTop || document.body.scrollLeft) {
sdown=document.body.scrollTop;
sleft=document.body.scrollLeft;
}
else if (document.documentElement && (document.documentElement.scrollTop || document.documentElement.scrollLeft)) {
sleft=document.documentElement.scrollLeft;
sdown=document.documentElement.scrollTop;
}
else {
sdown=0;
sleft=0;
}
}
window.onresize=set_width;
function set_width() {
if (typeof(self.innerWidth)=="number") {
swide=self.innerWidth;
shigh=self.innerHeight;
}
else if (document.documentElement && document.documentElement.clientWidth) {
swide=document.documentElement.clientWidth;
shigh=document.documentElement.clientHeight;
}
else if (document.body.clientWidth) {
swide=document.body.clientWidth;
shigh=document.body.clientHeight;
}
}

function randomColorAll()
{
    colors = new Array(14);
    colors[0]="0";
    colors[1]="1";
    colors[2]="2";
    colors[3]="3";
    colors[4]="4";
    colors[5]="5";
    colors[5]="6";
    colors[6]="7";
    colors[7]="8";
    colors[8]="9";
    colors[9]="a";
    colors[10]="b";
    colors[11]="c";
    colors[12]="d";
    colors[13]="e";
    colors[14]="f";

    digit = new Array(5);
    color="";
    for (i=0;i<6;i++){
        digit[i]=colors[Math.round(Math.random()*14)]
        color = color+digit[i]
    }
    return "#" + color;
}

function createDiv(height, width) {
var div=document.createElement("div");
div.style.position="absolute";
div.style.height=height+"px";
div.style.width=width+"px";
div.style.overflow="hidden";
div.style.backgroundColor= colour;
return (div);
}



