/*************************************************************************
*
* ADOBE CONFIDENTIAL
* ___________________
*
*  Copyright 2008 Adobe Systems Incorporated
*  All Rights Reserved.
*
* NOTICE:  All information contained herein is, and remains
* the property of Adobe Systems Incorporated and its suppliers,
* if any.  The intellectual and technical concepts contained
* herein are proprietary to Adobe Systems Incorporated and its
* suppliers and may be covered by U.S. and Foreign Patents,
* patents in process, and are protected by trade secret or copyright law.
* Dissemination of this information or reproduction of this material
* is strictly forbidden unless prior written permission is obtained
* from Adobe Systems Incorporated.
*
* AdobePatentID="B564"
* AdobePatentID="B565"
*
**************************************************************************/

if (!AdminPanel) {
	var AdminPanel = {};
};

// Local variable that is used to cache the value
AdminPanel.swfElement = null;

/**
 * This function returns the SWF movie element. If it has been read once, then the value is cached and
 * returned directly during next calls.
 *
 * @return DocumentElement The SWF movie element 
 */
AdminPanel.getSWFElement = function() {
	if (!AdminPanel.swfElement) {
		AdminPanel.swfElement = document.getElementById("portal");
	}
	return AdminPanel.swfElement;
};

/**
 * This function sets the width of the SWF object in the page
 *
 * @param String value The new SWF width expressed either in "px" or "%"
 */
AdminPanel.setSWFWidth = function(value) {
	el = AdminPanel.getSWFElement();
	if (el) {
		el.style.width = value;
	}
};

/**
 * This function sets the height of the SWF object in the page
 *
 * @param String value The new SWF height expressed either in "px" or "%"
 */
AdminPanel.setSWFHeight = function(value){
	el = AdminPanel.getSWFElement();
	if (el) {
		el.style.height = value;
	}
};

/**
 * This function is called from Flex when app loads and each time the language changes. It updates the flash movie min dimenstions
 * that are used to determine whether or not to add browser scrollbars. After setting the width/height min values this function also
 * triggers a call to AdminPanel.onWindowResize() to make sure the scrolls are displayed properly and registers a listener to the
 * window.onresize event.
 *
 * @param Number width New min width of Flash movie
 * @param Number height New min height of Flash movie
 */
AdminPanel.setFlashMinDimensions = function(width, height) {
	AdminPanel.flashMinDimensions = new Object();
	AdminPanel.flashMinDimensions.width = width;
	AdminPanel.flashMinDimensions.height = height;

	// Attach the onResize handler to the window object
	window.onresize = AdminPanel.onWindowResize;

	// Manually call the AdminPanel.onWindowResize() so that we can be sure the app is correctly displayed
	AdminPanel.onWindowResize();
};

/**
 * This function resizes the SWF movie to either a fixed size or 100%, depending on the browser size
 */
AdminPanel.onWindowResize = function() {
	var clientWidth = (!Kore.is.mozilla ? document.documentElement.clientWidth : document.width);
	var clientHeight = (!Kore.is.mozilla ? document.documentElement.clientHeight : document.height);

	if (clientWidth <= AdminPanel.flashMinDimensions.width) {
		AdminPanel.setSWFWidth(AdminPanel.flashMinDimensions.width + "px");
	} else {
		AdminPanel.setSWFWidth("100%");
	}
	if (clientHeight <= AdminPanel.flashMinDimensions.height) {
		AdminPanel.setSWFHeight(AdminPanel.flashMinDimensions.height + "px");
	} else {
		AdminPanel.setSWFHeight("100%");
	}
};
