﻿/*
Copyright Decode Studios All Rights Reserved
2008
*/
var cHeight;//Page Height
var cWidth;//Page Width
var scrollPos;//Y Scroll Position
var loadBoxID = "loadingBox";
var screenID = "blackOutScreen";//ID Name for Screener
var windowOptionsID = "windowBoxOptions";//ID Name for Options
var maximizePadding = 15;//Padding for Maximize

function screenSize(){ //setting the big variables
	if (self.innerHeight) {	// all except IE
		cWidth = self.innerWidth;
		cHeight = self.innerHeight;
	} else if (document.documentElement && document.documentElement.clientHeight) { // IE 6 Strict Mode
		cWidth = document.documentElement.clientWidth;
		cHeight = document.documentElement.clientHeight;
	} else if (document.body) { // other IE
		cWidth = document.body.clientWidth;
		cHeight = document.body.clientHeight;
	}
	if (self.pageYOffset) {
		scrollPos = self.pageYOffset;
	} else if (document.documentElement && document.documentElement.scrollTop){	 // Explorer 6 Strict
		scrollPos = document.documentElement.scrollTop;
	} else if (document.body) {// all other Explorers
		scrollPos = document.body.scrollTop;	
	}
}
function createLoadBox(bWidth, bHeight) {
    var loadBox = document.createElement('div');
    loadBox.setAttribute('id', loadBoxID);
    document.body.appendChild(loadBox);
    createWindow(loadBoxID, bWidth, bHeight, false, true);
}
function createWindow(boxID, bWidth, bHeight, restoreAllow, wOption) {
    if (restoreAllow == "true") restoreAllow = true;
    else restoreAllow = false;
    if (wOption == 'true') wOption = true;
    else wOption = false;
    screenSize(); //Get the Page Dimentions
	var screener = document.createElement('div');//Create the Screener Div
	screener.setAttribute('id', screenID);//Giv the Screener its ID
	screener.style.height = (cHeight + scrollPos + "px");//Set the Height To the  Full Page Height
    screener.style.width = (cWidth + "px");//Set the Screener to full Page Width
	screener.style.position = "absolute";//Position the Screener
	screener.style.left = "0px";//Position the Screener
	screener.style.top = "0px";//Position the Screener
	screener.style.backgroundColor = "#000000"; //Set the Screener Color
	setOpacity(screener, 6);//Set the Opacity
	document.body.appendChild(screener); //Add the Screener to the Page
	var windowOptions;
	if (wOption) windowOptions = generateOptions(boxID, bWidth, bHeight, false, restoreAllow, true);
	var windowBox = document.getElementById(boxID); //Get the Box
	var tempHTML = windowBox.innerHTML;//Get the Options HTML
	if (wOption) windowBox.innerHTML = ""; //Clear the HTML
	if (wOption) windowBox.appendChild(windowOptions); //Add the Window Options
	if (wOption) windowBox.innerHTML += tempHTML; //Add the Original HTML
    windowBox.style.position = "absolute";//Set the Box to Abosolute
    windowBox.style.margin = "auto";//Set the Margin to Auto
    windowBox.style.zIndex = "999";//Set the Z-Index
    centerElement(boxID, bWidth, bHeight);
	windowBox.style.display = "block";//Display the Block
	//Element.setOpacity(windowBox, 0.0 );//Hide
	//new Effect.Opacity(windowBox, {duration:0.5, from:0.2, to:1});//Fade in Box
}
function createBox(boxID, bWidth, bHeight, restoreAllow, wOption) {
    if (restoreAllow == "true") restoreAllow = true;
    else restoreAllow = false;
    if (wOption == 'true') wOption = true;
    else wOption = false;
    screenSize(); //Get the Page Dimentions
    var windowOptions;
    if (wOption) windowOptions = generateOptions(boxID, bWidth, bHeight, false, restoreAllow, true, true);
    var windowBox = document.getElementById(boxID); //Get the Box
    var tempHTML = windowBox.innerHTML; //Get the Options HTML
    if (wOption) windowBox.innerHTML = ""; //Clear the HTML
    if (wOption) windowBox.appendChild(windowOptions); //Add the Window Options
    if (wOption) windowBox.innerHTML += tempHTML; //Add the Original HTML
    windowBox.style.position = "absolute"; //Set the Box to Abosolute
    windowBox.style.margin = "auto"; //Set the Margin to Auto
    windowBox.style.zIndex = "999"; //Set the Z-Index
    centerElement(boxID, bWidth, bHeight);
    windowBox.style.display = "block"; //Display the Block
    //Element.setOpacity(windowBox, 0.0); //Hide
    //new Effect.Opacity(windowBox, { duration: 0.5, from: 0.2, to: 1 }); //Fade in Box
}
function replaceLoadWindow(boxID, bWidth, bHeight, restoreAllow, wOption) {
    document.body.removeChild(document.getElementById(loadBoxID)); //Destroy the Load BOx
    if (restoreAllow == "true") restoreAllow = true;
    else restoreAllow = false;
    if (wOption == 'true') wOption = true;
    else wOption = false;
    screenSize();
    var windowOptions;
    if (wOption) windowOptions = generateOptions(boxID, bWidth, bHeight, false, restoreAllow, true);
    var windowBox = document.getElementById(boxID); //Get the Box
    var tempHTML = windowBox.innerHTML; //Get the Options HTML
    if (wOption) windowBox.innerHTML = ""; //Clear the HTML
    if (wOption) windowBox.appendChild(windowOptions); //Add the Window Options
    if (wOption) windowBox.innerHTML += tempHTML; //Add the Original HTML
    windowBox.style.position = "absolute"; //Set the Box to Abosolute
    windowBox.style.margin = "auto"; //Set the Margin to Auto
    windowBox.style.zIndex = "999"; //Set the Z-Index
    centerElement(boxID, bWidth, bHeight);
    windowBox.style.display = "block"; //Display the Block
    //Element.setOpacity(windowBox, 0.0); //Hide
    //new Effect.Opacity(windowBox, { duration: 0.5, from: 0.2, to: 1 }); //Fade in Box

}
function destroyWindow(boxID){
	var windowBox = document.getElementById(boxID);//Get the Box
	windowBox.style.display = "none"; //Hide the Block
	var temp = document.getElementById(windowOptionsID);
	if (temp != null) windowBox.removeChild(temp); //Destroy the window box options
	document.body.removeChild(document.getElementById(screenID));//Destroy the Screen
}
function destroyBox(boxID) {
    var windowBox = document.getElementById(boxID); //Get the Box
    windowBox.style.display = "none"; //Hide the Block
    var temp = document.getElementById(windowOptionsID);
    if (temp != null) windowBox.removeChild(temp); //Destroy the window box options
}
function maximizeWindow(boxID, bWidth, bHeight) {
	screenSize();//Get the Screen Sizes
	var windowBox = document.getElementById(boxID);//get the Window Box
	windowBox.removeChild(document.getElementById(windowOptionsID)); //Destroy the window box options
	var windowOptions = generateOptions(boxID, bWidth ,bHeight, true, false, true);//Generate the window Options
	var tempHTML = windowBox.innerHTML; //Get the Options HTML
	windowBox.innerHTML = ""; //Clear the HTML
	windowBox.appendChild(windowOptions); //Add the Window Options
	windowBox.innerHTML += tempHTML; //Add the Original HTML
	centerElement(boxID, cWidth - (2 * maximizePadding) - 25, cHeight - (2 * maximizePadding) - 25);
}
function restoreWindow(boxID,bWidth,bHeight){
	screenSize();//Get the Screen Sizes
	var windowBox = document.getElementById(boxID); //Get the Window Box
	windowBox.removeChild(document.getElementById(windowOptionsID)); //Destroy the window box options
	var windowOptions = generateOptions(boxID, bWidth, bHeight, false, true, true); //Generate the window Options
	var tempHTML = windowBox.innerHTML; //Get the Options HTML
	windowBox.innerHTML = ""; //Clear the HTML
	windowBox.appendChild(windowOptions); //Add the Window Options
	windowBox.innerHTML += tempHTML; //Add the Original HTML
	centerElement(boxID, bWidth, bHeight);
}
function generateOptions(boxID, bWidth, bHeight, restore, maximize, close, box) {
    if (box == 'true' || box == 'True' || box == true) box = true; else box = false;
    var windowOptions = document.createElement('div'); //Create the Options Box
    windowOptions.setAttribute('id', windowOptionsID); //Set the ID of the Options box
    windowOptions.setAttribute('style', 'text-align:right;'); //Set the Style of the Box
    if (restore == "true" || restore == true) {
        var restoreButton = document.createElement('a'); //Create the Restore Button
        restoreButton.setAttribute('href', "#restoreWindow"); //Create the Hred
        restoreButton.setAttribute('onclick', "restoreWindow('" + boxID + "','" + bWidth + "','" + bHeight + "')"); //Create the Onlcick
        restoreButton.setAttribute('style', 'padding:2px 5px 2px 5px;text-decoration:none;'); //Set the Style
        restoreButton.innerHTML = "-"; //Set the Text
        windowOptions.appendChild(restoreButton);}
    if (maximize == "true" || maximize == true) {
        var maximizeButton = document.createElement('a'); //Create the Maximize Button
        maximizeButton.setAttribute('href', "#maximizeWindow"); //Create the href
        maximizeButton.setAttribute('onclick', "maximizeWindow('" + boxID + "','" + bWidth + "','" + bHeight + "')"); //Create the Onlcick
        maximizeButton.setAttribute('style', 'padding:2px 5px 2px 5px;text-decoration:none;'); //Set the Style
        maximizeButton.innerHTML = "[]"; //Set the Text
        windowOptions.appendChild(maximizeButton);} 
    if (close == "true" || close == true) {
        var closeButton = document.createElement('a'); //Create the Close Button
        if (box) closeButton.setAttribute('href', "#closeBox"); //Create the Hred
        else closeButton.setAttribute('href', "#closeWindow"); //Create the Hred
        if (box) closeButton.setAttribute('onclick', "destroyBox('" + boxID + "')"); //Create the OnClick
        else closeButton.setAttribute('onclick', "destroyWindow('" + boxID + "')"); //Create the OnClick
        closeButton.setAttribute('style', 'padding:2px 5px 2px 5px;text-decoration:none;'); //Set the Style
        closeButton.innerHTML = "X"; //Set the Text
        windowOptions.appendChild(closeButton);}
    return windowOptions;
}
function centerElement(boxID, bWidth, bHeight) {
    var windowBox = document.getElementById(boxID); //Get the Window Box
    var boxTop = ((((cHeight / 2) - (bHeight / 2)) - 20) + scrollPos); //Create a Variable to Store the Box Height
    var boxLeft = ((cWidth / 2) - (bWidth / 2)); //Create a Variable to Store the Box Width
    if (boxTop < 10) boxTop = 10; //If the Top Is less the 10 Then Set it to 10
    if (boxLeft < 10) boxLeft = 10; //If the left Is less the 10 Then Set it to 10
    windowBox.style.height = (bHeight + "px"); //Set the Box Height To the Inputed Height
    windowBox.style.width = (bWidth + "px"); //Set the Box Width To the Inputed width
    windowBox.style.top = boxTop + "px"; //Set the Box Top Value
    windowBox.style.left = boxLeft + "px"; //Set the Box Left Value
}

function setOpacity(element,value){
    element.style.filter = 'alpha(opacity=' + value * 10 + ')'; //Set the Opacity if IE
    element.style.opacity = '0.' + value;//Set for Everything Else
}

function getY(oElement) {
    var iReturnValue = 0;
    alert("running");
    while (oElement != null) {
        iReturnValue += oElement.offsetTop;
        oElement = oElement.offsetParent;
    }
    return iReturnValue;
} 
