
/**
 * Dialog singleton
 */
if (typeof rrcms == "undefined") var rrcms = {};
if (typeof rrcms.classes == "undefined") rrcms.classes = {};
if (typeof rrcms.classes.CMS == "undefined") rrcms.classes.CMS = new function () {
	/*
	 * Private Members
	 */
	var isSafari = navigator.userAgent.toLowerCase().indexOf('safari') != -1;
	var isSafari3 = (!window.devicePixelRatio) ? false : true;
	var view = "form";
	var xhtml = "";
	function dims () {
		var x,y;
		if (self.innerHeight) { // all except Explorer
			x = self.innerWidth;
			y = self.innerHeight;
		} else if (document.documentElement &&document.documentElement.clientHeight) { // Explorer 6 Strict Mode
			x = document.documentElement.clientWidth;
			y = document.documentElement.clientHeight;
		} else if (document.body) { // other Explorers
			x = document.body.clientWidth;
			y = document.body.clientHeight;
		}
		return ([x, y]);
	};
	function height (num) {
		var dim = dims();
		if (num=="0") window.scrollTo(0, 0);
		num = parseInt(num, 10) + 291;
		num = Math.max(600, num);
		num = Math.min(2880, num);
		if (num<dim[1]) num = "100%";
		else num = num + "px";
		var element = document.getElementById("cms_container");
		element.style.height = num;
		var element = document.getElementById("cms_swf");
		element.style.height = num;
	};
	function boot () {
		rrcms.classes.Cookie.set("AuthID", "6e7b5c210d55be7b660e85e3a979da21");
		off();
	};
	function validate () {
		var AuthID = rrcms.classes.Cookie.get("AuthID");
		if (AuthID==""||AuthID=="6e7b5c210d55be7b660e85e3a979da21") {
			boot();
			return false;
		}
		return true;
	};
	function on () {
		if (view=="form") {
			var element = document.getElementById("cms_container");
			xhtml = element.innerHTML;
			element.innerHTML = '<div id="cms_container_inner"></div>';
			var att = {
				data:"assets/movies/loader.swf",
				id: "cms_swf",
				width:"100%",
				height:"100%"
			};
			var par = {
				wmode: "opaque",
				quality: "high",
				allowScriptAccess: true
			};
			var id = "cms_container_inner";
			var so = swfobject.createSWF(att, par, id);
			document.body.style.height = "100%";
			height(0);
			view = "cms";
		}
	};
	function off () {
		if (view=="cms") {
			var element = document.getElementById("cms_container");
			element.innerHTML = xhtml;
			document.body.style.height = "auto";
			element.style.height = "auto";
			view = "form";
		}
	};
	function init () {
		if (validate()==true) on();
	};
	/**
	 * Constructor
	 */
	if (isSafari==true&&isSafari3==false) {
		window.location = "assets/errors/no-safari-support.html";
	} else {
		swfobject.addDomLoadEvent(init);
	}
	/**
	 * Public
	 */
	this.resize = function(num) {
		height(num);
	};
	this.logout = function() {
		boot();
	};
	this.session = function() {
		var AuthID = rrcms.classes.Cookie.get("AuthID");
		var swf = document.getElementById("cms_swf");
		swf.SetVariable("AuthID", AuthID);
	};
	this.close = function() {
		$.closeDOMWindow();
	};
	this.upload = function(multiple) {
		$.openDOMWindow({
			overlayOpacity: 10,
			positionType: 'centered',
			overlay: 1,
			loader:0,
			windowPadding: 0,
			windowSource:'iframe',
			windowSourceURL: "http://www.redrocketcms.com/display/upload/" + (multiple?"multiple":"single"),
			width: 500,
			modal:1,
			height: (multiple?300:220)
		});
	};
	this.publish = function(style, id) {
		$.openDOMWindow({
			overlayOpacity: 10,
			positionType: 'centered',
			overlay: 1,
			loader:0,
			windowPadding: 0,
			windowSource:'iframe',
			windowSourceURL: "http://www.redrocketcms.com/publish/site/" + style + "/" + rrcms.classes.Cookie.get("SiteID") + (style=="single"?"/"+id:""),
			width: 600,
			modal:1,
			height: 300
		});
	};
};
