//<![CDATA[
 
/////////////////////////////////////////////////////////////////
// JS Object: IE_computedStyle
// Returns the computed style, expressed in pixels or as auto, for the given element
// 
// Usage:
// IE_computedStyle.get(elementNode, CSS-Style);
//
// Examples:
// IE_computedStyle.get(el, "width");
// IE_computedStyle.get(el, "margin-top");
/////////////////////////////////////////////////////////////////
var IE_computedStyle = {
    isIE : /*@cc_on true || @*/false,
    styleEl : Object,
    borderRegex : /thin|medium|thick/i, // regex for css border width keywords
    
    // GET /////////////////////////////////////////////////////////////////
    get : function(el, styleProp) {   
        var rValue;
        this.styleEl = (typeof(el) == "string") ? document.getElementById(el) : el;	
        var styleProp = (typeof(styleProp) == "string") ? styleProp.toLowerCase() : "";
        styleProp = styleProp.replace(/\-/g, "");
        
        if(!this.isIE || !/block/i.test(this.styleEl.currentStyle["display"]))
            return;
        
        switch(styleProp) { // run through the valid css properties, return undefined if none match
            case "top": rValue = this.getPos("top"); break;
            case "right": rValue = this.getPos("right"); break;
            case "bottom": rValue = this.getPos("bottom"); break;
            case "left": rValue = this.getPos("left"); break;
            case "margintop": rValue = this.getMargin("Top"); break;
            case "marginright": rValue = this.getMargin("Right"); break;
            case "marginbottom": rValue = this.getMargin("Bottom"); break;
            case "marginleft": rValue = this.getMargin("Left"); break;
            case "bordertopwidth": rValue = this.getBorderWidth("Top"); break;
            case "borderrightwidth": rValue = this.getBorderWidth("Right"); break;
            case "borderbottomwidth": rValue = this.getBorderWidth("Bottom"); break;
            case "borderleftwidth": rValue = this.getBorderWidth("Left"); break;
            case "paddingtop": rValue = this.getPadding("Top"); break;
            case "paddingright": rValue = this.getPadding("Right"); break;
            case "paddingbottom": rValue = this.getPadding("Bottom"); break;
            case "paddingleft": rValue = this.getPadding("Left"); break;
            case "width": rValue = this.getWidth(); break;
            case "height": rValue = this.getHeight(); break;
        }
        
        return rValue;
    },
    
    // GET POS 
    getPos : function(which) {
        if(/auto/i.test(this.styleEl.currentStyle[which])) {
            return "auto";
        } else {
            return this.grabLength(this.styleEl.currentStyle[which]) + "px";
        }
    },
    
    // GET MARGIN 
    getMargin : function(which) {
        if(/auto/i.test(this.styleEl.currentStyle["margin" + which])) {
            return "0px";
        } else {
            return this.grabLength(this.styleEl.currentStyle["margin" + which]) + "px";
        }
    },
    
    // GET BORDER WIDTH 
    getBorderWidth : function(which) {
        var borderWidth = this.styleEl.currentStyle["border" + which + "Width"];
        if(this.styleEl.currentStyle["border" + which + "Style"] != "none" && 
                ((/Top|Bottom/i.test(which) && this.styleEl.offsetHeight > this.styleEl.clientHeight) || 
                (/Right|Left/i.test(which) && this.styleEl.offsetWidth > this.styleEl.clientWidth))) {
            if(!this.borderRegex.test(borderWidth)) {
                return this.grabLength(borderWidth) + "px";
            } else if(this.borderRegex.test(borderWidth)) {
                var temp = document.createElement("DIV");
                temp.style.width = "10px";
                temp.style.border = borderWidth + " " + this.styleEl.currentStyle["border" + which + "Style"] + " #000000";
                this.styleEl.parentNode.appendChild(temp);
                borderWidth = Math.round((temp.offsetWidth-10)/2);
                this.styleEl.parentNode.removeChild(temp);
                return borderWidth + "px";
            }
        } else {
            return "0px";
        }
    },
    
    // GET PADDING 
    getPadding : function(which) {
        return this.grabLength(this.styleEl.currentStyle["padding" + which]) + "px";
    },
    
    // GET WIDTH 
    getWidth : function() {
        var width = this.styleEl.offsetWidth; // currently the width including padding + border
        width -= parseInt(this.getPadding("Right"));
        width -= parseInt(this.getPadding("Left"));
        width -= parseInt(this.getBorderWidth("Right"));
        width -= parseInt(this.getBorderWidth("Left"));
        return width + "px";
    },
    
    // GET HEIGHT    
    getHeight : function() {
        var height = this.styleEl.offsetHeight; // currently the height including padding + border
        height -= parseInt(this.getPadding("Top"));
        height -= parseInt(this.getPadding("Bottom"));
        height -= parseInt(this.getBorderWidth("Top"));
        height -= parseInt(this.getBorderWidth("Bottom"));
        return height + "px";
    },
    
    // GRAB LENGTH 
    grabLength : function(length) {
        var temp = document.createElement("DIV");
        temp.style.width = length;
        this.styleEl.parentNode.appendChild(temp);
        length = Math.round(temp.offsetWidth);
        this.styleEl.parentNode.removeChild(temp);
        return length;
    }
}



/////////////////////////////////////////////////////////////////
// JS function: isIE
// Returns: True if browser is IE 
// 
// Usage:
// isIE(no argument is required);
//
// Examples:
// isIE();
// 
// Todo:
// Get browser agent not by appName but by MS object like MSXML
/////////////////////////////////////////////////////////////////
function isIE() {
	var brw = (navigator.appName == "Microsoft Internet Explorer") ? true : false;
	return (brw);
}

/////////////////////////////////////////////////////////////////
// JS function: sortfunction
// Returns: causes an array to be sorted numerically and ascending
// 
// Usage:
// sortfunction(no argument is required)  
// 
// Note: use it in a sort function and make sure the array to be sorted
// is numerical integer
//
// Examples:
// MyobjectArray.sort(sortfunction)
/////////////////////////////////////////////////////////////////
function sortfunction(a, b){
	return (a - b) 
}

/////////////////////////////////////////////////////////////////
// JS function: setDivsHeight
// Returns: Set the height of containers with the highest Height
// 
// Usage:
// setDivsHeight(resetFlag, elementNode);
//
// Note: resetFlag is OPTIONAL and used to clear the height of the container before
//			 setting the height.  This situation is most used for ajax
//			 calls that updates content
// !important: resetFlag must be equal to 1  
//
// Examples (Normal):
// setDivsHeight('#myDiv');
// setDivsHeight('#myDiv1','#myDiv2');
// setDivsHeight('#myDiv1','#myDiv2','#myDiv3');
// 
// Examples (With reset flag):
// setDivsHeight(1, '#myDiv');
// setDivsHeight(1, '#myDiv1','#myDiv2');
// setDivsHeight('#myDiv1','#myDiv2','#myDiv3', 1);
//
// Javascript framework:
// DOMAssistant is required (but you can use any kind of javascript
// framework .. just use the framework namespace and its equivalent method
// to retrieve the object styles
/////////////////////////////////////////////////////////////////
function setDivsHeight() {
	var intReset = 0;
	var tmpArr = new Array();

	// Check resetFlag
	for (i=0; i<setDivsHeight.arguments.length;i++) {
		if (setDivsHeight.arguments[i] == 1) {
			intReset = 1;			
		}
	}

	// Reset height if required
	if (intReset == 1) {
		for (var i=0; i<setDivsHeight.arguments.length;i++) {
			DOMAssistant.$(setDivsHeight.arguments[i]).setStyle("height","auto");
		}
	}

	// Get Container height
	var y = 0;
	for (var i=0; i<setDivsHeight.arguments.length;i++) {
		if (isIE()) {
			tmpArr[y] = IE_computedStyle.get(DOMAssistant.$(setDivsHeight.arguments[i])[0], "height").replace("px","");
		} else {
			tmpArr[y] = parseInt(DOMAssistant.$(setDivsHeight.arguments[i]).getStyle("height")[0].replace("px",""));
		}
		y++;
	}

	// Set Container Height
	tmpArr.sort(sortfunction);
	var maxHeight = tmpArr[tmpArr.length - 1] + "px";
	for (var i=0; i<setDivsHeight.arguments.length;i++) {
		DOMAssistant.$(setDivsHeight.arguments[i]).setStyle("height",maxHeight);
	}
}

/////////////////////////////////////////////////////////////////
// JS function: setListHeight
// Returns: Nothing =>Sets the height of containers list with the highest Height
// 
// Usage:
// setDivsHeight(resetFlag,elementNode);
//
// Note: resetFlag is OPTIONAL and used to clear the height of the list before
//			 setting the height.  This situation is most used for ajax
//			 calls that updates the content of the list  
//
// !important: resetFlag must be equal to 1
//
// Examples (normal):
// setListHeight('#myDivContainingA_UL_List');
// setListHeight('#myDivContainingA_UL_List','#my_UL');
// setListHeight('#myDivContainingA_UL_List','#my_UL1','#my_UL2');
// 
// Examples (with reset flag):
// setListHeight(1, '#myDivContainingA_UL_List');
// setListHeight(1, '#myDivContainingA_UL_List','#my_UL');
// setListHeight('#myDivContainingA_UL_List','#my_UL1','#my_UL2', 1);
//
// Javascript framework:
// DOMAssistant is required (but you can use any kind of javascript
// framework .. just use the framework namespace and its equivalent method
// to retrieve the object styles
/////////////////////////////////////////////////////////////////

function setListHeight() {
	var intReset = 0;

	// Check resetFlag
	for (var i=0; i<setListHeight.arguments.length;i++) {
		if (setListHeight.arguments[i] == 1) {
			intReset = 1;			
		}
	}
	for (var i=0; i<setListHeight.arguments.length;i++) {
		// Get array of list
		var tmpList = new Array();
		var tmpHeight = new Array();
		
		tmpList = DOMAssistant.$(setListHeight.arguments[i] + " > li");
		if (tmpList.length == 0) {
			tmpList = DOMAssistant.$(setListHeight.arguments[i] + " > ul > li");
		}
		if (tmpList.length == 0) {		
			tmpList = DOMAssistant.$(setListHeight.arguments[i]);
		}
		
		// Reset height if required
		if (intReset == 1) {
			DOMAssistant.$(tmpList).setStyle("height","auto");
		}

		// Get each li height
		for (var y=0; y<tmpList.length; y++) {
			if (isIE()) {
				tmpHeight[y] = IE_computedStyle.get(DOMAssistant.$(tmpList[y]),"height").replace("px","");
			} else {
				tmpHeight[y] = parseInt(DOMAssistant.$(tmpList[y]).getStyle("height").replace("px",""));
			}
		}
		tmpHeight.sort(sortfunction);
		var maxHeight = tmpHeight[tmpHeight.length - 1] + "px";
		for (var z=0; z<tmpList.length;z++) {
			DOMAssistant.$(tmpList[z]).setStyle("height",maxHeight);
		}
	}
}
/////////////////////////////////////////////////////////////////
// JS function: setHomePageWallpaper
// Returns: Nothing => Will show or hide a wallpaper in the homepage
// 
// Usage:
// setHomePageWallpaper(pStatus, pTimer)
//
// Note: pTimer is OPTIONAL and used to define a timer before hiding
//		 the wallpaper
//
// !important: pTimer must greater than 100
//
// Examples (normal):
// setHomePageWallpaper(true);
// setHomePageWallpaper(false);
// setHomePageWallpaper(true, 1000); // hide wallpaper after 1 sec
/////////////////////////////////////////////////////////////////
function setHomePageWallpaper(pStatus, pTimer){
	// Check for timeout value
	for (i=0; i<setHomePageWallpaper.arguments.length;i++) {
		if (setHomePageWallpaper.arguments[i] > 100) {
			setTimeout("setHomePageWallpaper(false)", setHomePageWallpaper.arguments[i]);
		}
	}
	if (pStatus) {
		DOMAssistant.$("#home").addClass("wallpaper");
	} else {
		DOMAssistant.$("#home").removeClass("wallpaper");
	}
}

//]]>
