/* 	asp.js
		Example V-1. A custom API for positionable elements
		DHTMLapi3.js custom API for cross-platform
		object positioning by Danny Goodman (http://www.dannyg.com).
		Release 3.0. Supports NN4, IE, and W3C DOMs.
		Modified by Mark Willner, Angel Station Corporation, 2008
		Version 1.1 - 12/23/2008
*/		
		


// Globals
// aPics is ordinal and chronological for each picture produced
var aPics = new Array("1_Skull_2000.jpg","2_MyMiracle_2000.jpg","3_CW_2001.jpg","4_Taped_2001.jpg","5_TD_2001.jpg","6_WS_2001.jpg","7_IP_2002.jpg","8_AI_2003.jpg","9_IWIMW_2003.jpg","10_SF_2006.jpg");
var aLen = aPics.length;


var DHTMLAPI = {
	browserClass : new Object( ),
	init : function ( ) {
	this.browserClass.isCSS = ((document.body && document.body.style) ? true : false);
	this.browserClass.isW3C = ((this.browserClass.isCSS && document.getElementById) ? true : false),
	this.browserClass.isIE4 = ((this.browserClass.isCSS && document.all) ? true : false),
	this.browserClass.isNN4 = ((document.layers) ? true : false),
	this.browserClass.isIECSSCompat = 	((document.compatMode && document.compatMode.indexOf("CSS1") >= 0) ? true : false),
	this.browserClass.isIE6 = (navigator.appName.indexOf("Microsoft") != -1 && navigator.appVersion.indexOf("6.0") != -1)
	},

// Convert element name string or object reference
// into a valid element object reference
getRawObject : function (elemRef) {
	var elem;
	if (typeof elemRef == "string") {
	if (this.browserClass.isW3C) {
		elem = document.getElementById(elemRef);
	} else if (this.browserClass.isIE4) {
		elem = document.all(elemRef);
	} else if (this.browserClass.isNN4) {
		elem = this.seekLayer(document, elemRef);
	}
	} else {
		// pass through object reference
		elem = elemRef;
	}
	return elem;
    },

// Convert element name string or object reference
// into a valid style (or NN4 layer) object reference
getStyleObject : function (elemRef) {
	var elem = this.getRawObject(elemRef);
	if (elem && this.browserClass.isCSS) {
		elem = elem.style;
	}
	return elem;
   }  ,

// Position an element at a specific pixel coordinate
moveTo : function (elemRef, x, y) {
	var elem = this.getStyleObject(elemRef);
	if (elem) {
		if (this.browserClass.isCSS) {
			// equalize incorrect numeric value type
			var units = (typeof elem.left == "string") ? "px" : 0;
			elem.left = x + units;
			elem.top = y + units;
		} else if (this.browserClass.isNN4) {
				elem.moveTo(x,y);
		}
	}
   },

// Move an element by x and/or y pixels
moveBy : function (elemRef, deltaX, deltaY) {
	var elem = this.getStyleObject(elemRef);
	if (elem) {
		if (this.browserClass.isCSS) {
			// equalize incorrect numeric value type
			var units = (typeof elem.left == "string") ? "px" : 0;
			elem.left = this.getElementLeft(elemRef) + deltaX + units;
			elem.top = this.getElementTop(elemRef) + deltaY + units;
		} else if (this.browserClass.isNN4) {
			elem.moveBy(deltaX, deltaY);
		}
	}
    },

// Set the z-order of an object
setZIndex : function (obj, zOrder) {
	var elem = this.getStyleObject(obj);
	if (elem) {
			elem.zIndex = zOrder;
	}
    },

// Set the background color of an object
setBGColor : function (obj, color) {
	var elem = this.getStyleObject(obj);
	if (elem) {
			if (this.browserClass.isCSS) {
				elem.backgroundColor = color;
			}  else if (this.browserClass.isNN4) {
				elem.bgColor = color;
			}
	}
    },

// Set the visibility of an object to visible
show : function (obj) {
	var elem = this.getStyleObject(obj);
	if (elem) {
			elem.visibility = "visible";
	}
    },

// Set the visibility of an object to hidden
hide : function (obj) {
	var elem = this.getStyleObject(obj);
	if (elem) {
			elem.visibility = "hidden";
	}
    },

// return computed value for an element's style property
getComputedStyle : function (elemRef, CSSStyleProp) {
	var elem = this.getRawObject(elemRef);
	var styleValue, camel;
	if (elem) {
			if (document.defaultView) {
					// W3C DOM version
					var compStyle = document.defaultView.getComputedStyle(elem, "");
					styleValue = compStyle.getPropertyValue(CSSStyleProp);
			} else if (elem.currentStyle) {
					// make IE style property camelCase name from CSS version
					var IEStyleProp = CSSStyleProp;
					var re = /-\D/;
					while (re.test(IEStyleProp)) {
						camel = IEStyleProp.match(re)[0].charAt(1).toUpperCase( );
						IEStyleProp = IEStyleProp.replace(re, camel);
					}
					styleValue = elem.currentStyle[IEStyleProp];
			}
	}
	return (styleValue) ? styleValue : null;
    },

// Retrieve the x coordinate of a positionable object
getElementLeft : function (elemRef) {
	var elem = this.getRawObject(elemRef);
	var result = null;
	if (this.browserClass.isCSS || this.browserClass.isW3C) {
		result = parseInt(this.getComputedStyle(elem, "left"));
	} else if (this.browserClass.isNN4) {
		result = elem.left;
	}
	return result;
},
// Retrieve the y coordinate of a positionable object
getElementTop : function (elemRef) {
	var elem = this.getRawObject(elemRef);
	var result = null;
	if (this.browserClass.isCSS || this.browserClass.isW3C) {
		result = parseInt(this.getComputedStyle(elem, "top"));
	} else if (this.browserClass.isNN4) {
		result = elem.top;
	}
	return result;
    },

// Retrieve the rendered height of an element
getElementHeight : function (elemRef) {
	var result = null;
	var elem = this.getRawObject(elemRef);
	if (elem) {
			// W3C DOM supporters
			result = parseInt(this.getComputedStyle(elemRef, "height"));
			// others, including "auto" results
			if (result == null || isNaN(parseInt(result))) {
				if (elem.offsetHeight) {
					result = elem.offsetHeight;
				} else if (elem.clip && elem.clip.height) {
					result = elem.clip.height;
				}
				return parseInt(result);
			}
	}
	return result;
    },

// Return the available content width space in browser window
getInsideWindowWidth : function ( ) {
	if (window.innerWidth) {
		return window.innerWidth;
	} else if (this.browserClass.isIECSSCompat) {
		// measure the html element's clientWidth
		return document.body.parentElement.clientWidth;
	} else if (document.body && document.body.clientWidth) {
		return document.body.clientWidth;
	}
	return null;
    },

// Return the available content height space in browser window
getInsideWindowHeight : function ( ) {
	if (window.innerHeight) {
		return window.innerHeight;
	} else if (this.browserClass.isIECSSCompat) {
		// measure the html element's clientHeight
		return document.body.parentElement.clientHeight;
	} else if (document.body && document.body.clientHeight) {
		return document.body.clientHeight;
	}
		return null;
    },

// Retrieve the rendered width of an element
getElementWidth : function (elemRef) {
	var result = null;
	var elem = this.getRawObject(elemRef);

	if (elem) {
		// W3C DOM supporters
		result = parseInt(this.getComputedStyle(elemRef, "width"));
		if (result == null || isNaN(parseInt(result))) {
			if (elem.offsetWidth) {
				if (elem.scrollWidth && (elem.offsetWidth != elem.scrollWidth)) {
					result = elem.scrollWidth;
				}
				else { result = elem.offsetWidth; }
	/* 10-09-08 Error	else if (elem.clip && elem.clip.width) {
					// Netscape 4 positioned elements
					result = elem.clip.width;
				}*/
			}
		}

	}
	return result;
     } ,

// Seek nested NN4 layer from string name
seekLayer : function (doc, name)  {
			var elem;
			for (var i = 0; i < doc.layers.length; i++) {
				if (doc.layers[i].name == name) {
					elem = doc.layers[i];
					break;
				}
				// dive into nested layers if necessary
				if (doc.layers[i].document.layers.length > 0) {
					elem = this.seekLayer(doc.layers[i].document, name);
					if (elem) {break;}
				}
			}
		return elem;
    }

}

// Global 'corrector' for IE/Mac et al., but doesn't hurt others
var fudgeFactor = {top:-1, left:-1};
// Center a positionable element whose name is passed as
// a parameter in the current window/frame, and show it
function centerIt(layerName) {
	// 'obj' is the positionable object
	var obj = DHTMLAPI.getRawObject(layerName);
	// set fudgeFactor values only first time

	if (fudgeFactor.top == -1) {
		if ((typeof obj.offsetTop == "number") && obj.offsetTop > 0) {
			fudgeFactor.top = obj.offsetTop;
			fudgeFactor.left = obj.offsetLeft;
		} else {
				fudgeFactor.top = 0;
				fudgeFactor.left = 0;
		}
		if (obj.offsetWidth && obj.scrollWidth) {
			if (obj.offsetWidth != obj.scrollWidth) {
				obj.style.width = obj.scrollWidth;
			}
		}
	}
	var x = Math.round((DHTMLAPI.getInsideWindowWidth( )/2) - (DHTMLAPI.getElementWidth(obj)/2));
	var y = Math.round((DHTMLAPI.getInsideWindowHeight( )/2) - (DHTMLAPI.getElementHeight(obj)/2));
	DHTMLAPI.moveTo(obj, x - fudgeFactor.left, y - fudgeFactor.top);
	//DHTMLAPI.show(obj);
}


function chgImg(direc, ident) {
	// aPics = array of imge files stored ordinally and chronologically starting at index 0
	var aComp;
	var found;
	var aVal;
	var iFile = "images/" ; 
	var aIndx = Number(aLen) + 1;
	
	//image file path and name
	var eIdSrc = document.getElementById(ident).src;
	var eIdOnly = document.getElementById(ident);
	if (eIdSrc == null) {
			alert("eId == null. Error on page.");
			return;
}

		
	//remember that the index is 0 - arrylength -1
//What image is currently displaying? Get the array value
	for (i=0; i < aLen; i++) {
		aComp = aPics[i];
		found = eIdSrc.match(aComp);
		aVal = i;
		if (found != null) {
			break;
		}
	}

	switch(direc) {
		case "N":
			// array maxed out, start back at zero
			if (aVal == (aLen-1)) {
				eIdOnly.src = iFile + aPics[0];
				break;
			}
			if(aVal < aLen) {
				eIdOnly.src = iFile + aPics[aVal + 1];
				break;
			}
			break;
		case "P":
			// array maxed out, start back at zero
			if (aVal == 0) {
				eIdOnly.src = iFile + aPics[(aLen-1)];
				break;
			}
			if(aVal < aLen && aVal != 0) {
				eIdOnly.src = iFile + aPics[aVal - 1];
				break;
			}
			break;
	}
	
}

// Special handling for CSS-P redraw bug in Navigator 4
function handleResize( ) {
	if (DHTMLAPI.browserClass.isNN4) {
		// causes extra re-draw, but gotta do it to get banner object color drawn
		location.reload( );
	} else {
		centerIt("asp01");
	}
}
function init( ) {
	
	DHTMLAPI.init( );		 

	if (DHTMLAPI.browserClass.isW3C) {	
		//load most current release image at web page start
		var eId = document.getElementById("ImgBrdr");
		if (eId != null) {
			var iFile = "images/" + aPics[aLen-1]; 
			eId.src = iFile;
		}
		if (!DHTMLAPI.browserClass.isIE6) { centerIt("asp01");  }
		
		if (DHTMLAPI.browserClass.isIE6) { 
			
			location.href = "ie6/ie6_asp01.shtml"
			
		}
		
		curDate("asOf");
		
	}

		DHTMLAPI.show("asp01");

}

function curDate(elemID) {
	var arMon = new Array ("01","02","03","04","05","06","07","08","09","10","11","12");
	var arMtxt = new Array ("Jan","Feb","Mar","Apr","May","Jun","Jul","Aug","Sep","Oct","Nov","Dec");
	var Today = new Date();
	var CurYear = Today.getFullYear();
	var CurMo		= arMon[Today.getMonth()];
	var CurDay  = Today.getDate();
	var strDate = fmtDate(CurMo,CurDay,CurYear);
	var elId = document.getElementById(elemID);

if (elId != null) { elId.innerHTML = "No casting notices as of " + strDate; }

}

function fmtDate(mon,dy,yr) {
// format a date string
	var dStrg = new String();

	dStrg = mon + "/" + dy +"/" + yr;

	return dStrg;
	
}


window.onresize = handleResize;
window.onload = init;
