/* Reference
 
*/

/* Flash API */
function GenericFlash()
{
	this.name = "GenericFlashObject";			// Name for class - for easy detection during inheritance
	this.instanceID = "";						// Unique name of js object in DOM (document[instanceID])
	this.containerId =	"";						// Id for the container that will house the flash
	this.flashMinVer = "8";						// Default Minimum flash version
	this.flashDir = "/gui/flash/swf/";			// Default Location of SWF files
//	this.flashDir = "gui/flash/swf/"			// when running without server
	this.flashFile = "";						// Name of SWF file to use
	this.flashHeight = "";						// Height of OBJECT/EMBED element
	this.flashWidth = "";						// Width of OBJECT/EMBED element
	this.flashObj = {};							// The SWFObject Object
	this.init = function (ArgObj) {
		//import arguments from html page
		for(var x in ArgObj){
			this[ x ] = ArgObj[x];
		}
		//insert to DOM for easy access
		document[this.instanceID] = this;
		//Assign a unique ID for the Flash plugin
		this.id = ArgObj["instanceID"] + "_Flash";
		// create the flash HTML wrapper
		this.containerId = this.instanceID + "_Container";
		this.createFlashContainer();
		// create the flash swf object
		this.createFlashObject(ArgObj);
		
	};
	this.SWFObject = function(swf,id,w,h,ver,c,quality,xiRedirectUrl,redirectUrl,detectKey)
	{
		/**
		* SWFObject v1.5: Flash Player detection and embed - http://blog.deconcept.com/swfobject/
		*
		* SWFObject is (c) 2007 Geoff Stearns and is released under the MIT License:
		* http://www.opensource.org/licenses/mit-license.php
		*
		*/
		if(typeof deconcept == "undefined") var deconcept = new Object();
		if(typeof deconcept.util == "undefined") deconcept.util = new Object();
		if(typeof deconcept.SWFObjectUtil == "undefined") deconcept.SWFObjectUtil = new Object();
		deconcept.SWFObject = function(swf, id, w, h, ver, c, quality, xiRedirectUrl, redirectUrl, detectKey) {
			if (!document.getElementById) { return; }
			this.DETECT_KEY = detectKey ? detectKey : 'detectflash';
			this.skipDetect = deconcept.util.getRequestParameter(this.DETECT_KEY);
			this.params = new Object();
			this.variables = new Object();
			this.attributes = new Array();
			if(swf) { this.setAttribute('swf', swf); }
			if(id) { this.setAttribute('id', id); }
			if(w) { this.setAttribute('width', w); }
			if(h) { this.setAttribute('height', h); }
			if(ver) { this.setAttribute('version', new deconcept.PlayerVersion(ver.toString().split("."))); }
			this.installedVer = deconcept.SWFObjectUtil.getPlayerVersion();
			if (!window.opera && document.all && this.installedVer.major > 7) {
				// only add the onunload cleanup if the Flash Player version supports External Interface and we are in IE
				deconcept.SWFObject.doPrepUnload = true;
			}
			if(c) { this.addParam('bgcolor', c); }
			var q = quality ? quality : 'high';
			this.addParam('quality', q);
			this.setAttribute('useExpressInstall', false);
			this.setAttribute('doExpressInstall', false);
			var xir = (xiRedirectUrl) ? xiRedirectUrl : window.location;
			this.setAttribute('xiRedirectUrl', xir);
			this.setAttribute('redirectUrl', '');
			if(redirectUrl) { this.setAttribute('redirectUrl', redirectUrl); }
		}
		deconcept.SWFObject.prototype = {
			useExpressInstall: function(path) {
				this.xiSWFPath = !path ? "expressinstall.swf" : path;
				this.setAttribute('useExpressInstall', true);
			},
			setAttribute: function(name, value){
				this.attributes[name] = value;
			},
			getAttribute: function(name){
				return this.attributes[name];
			},
			addParam: function(name, value){
				this.params[name] = value;
			},
			getParams: function(){
				return this.params;
			},
			addVariable: function(name, value){
				this.variables[name] = value;
			},
			getVariable: function(name){
				return this.variables[name];
			},
			getVariables: function(){
				return this.variables;
			},
			getVariablePairs: function(){
				var variablePairs = new Array();
				var key;
				var variables = this.getVariables();
				for(key in variables){
					variablePairs[variablePairs.length] = key +"="+ variables[key];
				}
				return variablePairs;
			},
			getSWFHTML: function() {
				var swfNode = "";
				if (this.getAttribute("doExpressInstall")) {
					this.addVariable("MMplayerType", "ActiveX");
					this.setAttribute('swf', this.xiSWFPath);
				}
				swfNode = '<object id="'+ this.getAttribute('id') +'" classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000" width="'+ this.getAttribute('width') +'" height="'+ this.getAttribute('height') +'" style="'+ this.getAttribute('style') +'">';
				swfNode += '<param name="movie" value="'+ this.getAttribute('swf') +'" />';
				var params = this.getParams();
				for(var key in params) {
				 swfNode += '<param name="'+ key +'" value="'+ params[key] +'" />';
				}
				var pairs = this.getVariablePairs().join("&");
				if(pairs.length > 0) {swfNode += '<param name="flashvars" value="'+ pairs +'" />';}
				
					if (this.getAttribute("doExpressInstall")) {
						this.addVariable("MMplayerType", "PlugIn");
						this.setAttribute('swf', this.xiSWFPath);
					}
					swfNode += '<embed type="application/x-shockwave-flash" src="'+ this.getAttribute('swf') +'" width="'+ this.getAttribute('width') +'" height="'+ this.getAttribute('height') +'" style="'+ this.getAttribute('style') +'"';
					swfNode += ' id="'+ this.getAttribute('id') +'" name="'+ this.getAttribute('id') +'" ';
					var params = this.getParams();
					 for(var key in params){ swfNode += [key] +'="'+ params[key] +'" '; }
					var pairs = this.getVariablePairs().join("&");
					 if (pairs.length > 0){ swfNode += 'flashvars="'+ pairs +'"'; }
					swfNode += '/>';
				
				swfNode += "</object>";
				return swfNode;
			},
			write: function(elementId){
				if(this.getAttribute('useExpressInstall')) {
					// check to see if we need to do an express install
					var expressInstallReqVer = new deconcept.PlayerVersion([6,0,65]);
					if (this.installedVer.versionIsValid(expressInstallReqVer) && !this.installedVer.versionIsValid(this.getAttribute('version'))) {
						this.setAttribute('doExpressInstall', true);
						this.addVariable("MMredirectURL", escape(this.getAttribute('xiRedirectUrl')));
						document.title = document.title.slice(0, 47) + " - Flash Player Installation";
						this.addVariable("MMdoctitle", document.title);
					}
				}
				if(this.skipDetect || this.getAttribute('doExpressInstall') || this.installedVer.versionIsValid(this.getAttribute('version'))){
					var n = (typeof elementId == 'string') ? document.getElementById(elementId) : elementId;
					n.innerHTML = this.getSWFHTML();
					return true;
				}else{
					if(this.getAttribute('redirectUrl') != "") {
						document.location.replace(this.getAttribute('redirectUrl'));
					}
				}
				return false;
			}
		}

		/* ---- detection functions ---- */
		deconcept.SWFObjectUtil.getPlayerVersion = function(){
			var PlayerVersion = new deconcept.PlayerVersion([0,0,0]);
			if(navigator.plugins && navigator.mimeTypes.length){
				var x = navigator.plugins["Shockwave Flash"];
				if(x && x.description) {
					PlayerVersion = new deconcept.PlayerVersion(x.description.replace(/([a-zA-Z]|\s)+/, "").replace(/(\s+r|\s+b[0-9]+)/, ".").split("."));
				}
			}else if (navigator.userAgent && navigator.userAgent.indexOf("Windows CE") >= 0){ // if Windows CE
				var axo = 1;
				var counter = 3;
				while(axo) {
					try {
						counter++;
						axo = new ActiveXObject("ShockwaveFlash.ShockwaveFlash."+ counter);
						//document.write("player v: "+ counter);
						PlayerVersion = new deconcept.PlayerVersion([counter,0,0]);
					} catch (e) {
						axo = null;
					}
				}
			} else { // Win IE (non mobile)
				// do minor version lookup in IE, but avoid fp6 crashing issues
				// see http://blog.deconcept.com/2006/01/11/getvariable-setvariable-crash-internet-explorer-flash-6/
				try{
					var axo = new ActiveXObject("ShockwaveFlash.ShockwaveFlash.7");
				}catch(e){
					try {
						var axo = new ActiveXObject("ShockwaveFlash.ShockwaveFlash.6");
						PlayerVersion = new deconcept.PlayerVersion([6,0,21]);
						axo.AllowScriptAccess = "always"; // error if player version < 6.0.47 (thanks to Michael Williams @ Adobe for this code)
					} catch(e) {
						if (PlayerVersion.major == 6) {
							return PlayerVersion;
						}
					}
					try {
						axo = new ActiveXObject("ShockwaveFlash.ShockwaveFlash");
					} catch(e) {}
				}
				if (axo != null) {
					PlayerVersion = new deconcept.PlayerVersion(axo.GetVariable("$version").split(" ")[1].split(","));
				}
			}
			return PlayerVersion;
		}
		deconcept.PlayerVersion = function(arrVersion){
			this.major = arrVersion[0] != null ? parseInt(arrVersion[0]) : 0;
			this.minor = arrVersion[1] != null ? parseInt(arrVersion[1]) : 0;
			this.rev = arrVersion[2] != null ? parseInt(arrVersion[2]) : 0;
		}
		deconcept.PlayerVersion.prototype.versionIsValid = function(fv){
			if(this.major < fv.major) return false;
			if(this.major > fv.major) return true;
			if(this.minor < fv.minor) return false;
			if(this.minor > fv.minor) return true;
			if(this.rev < fv.rev) return false;
			return true;
		}
		/* ---- get value of query string param ---- */
		deconcept.util = {
			getRequestParameter: function(param) {
				var q = document.location.search || document.location.hash;
				if (param == null) { return q; }
				if(q) {
					var pairs = q.substring(1).split("&");
					for (var i=0; i < pairs.length; i++) {
						if (pairs[i].substring(0, pairs[i].indexOf("=")) == param) {
							return pairs[i].substring((pairs[i].indexOf("=")+1));
						}
					}
				}
				return "";
			}
		}
		/* fix for video streaming bug */
		deconcept.SWFObjectUtil.cleanupSWFs = function() {
			var objects = document.getElementsByTagName("OBJECT");
			for (var i = objects.length - 1; i >= 0; i--) {
				objects[i].style.display = 'none';
				for (var x in objects[i]) {
					if (typeof objects[i][x] == 'function') {
						objects[i][x] = function(){};
					}
				}
			}
		}
		// fixes bug in some fp9 versions see http://blog.deconcept.com/2006/07/28/swfobject-143-released/
		if (deconcept.SWFObject.doPrepUnload) {
			if (!deconcept.unloadSet) {
				deconcept.SWFObjectUtil.prepUnload = function() {
					__flash_unloadHandler = function(){};
					__flash_savedUnloadHandler = function(){};
					window.attachEvent("onunload", deconcept.SWFObjectUtil.cleanupSWFs);
				}
				window.attachEvent("onbeforeunload", deconcept.SWFObjectUtil.prepUnload);
				deconcept.unloadSet = true;
			}
		}
		/* add document.getElementById if needed (mobile IE < 5) */
		if (!document.getElementById && document.all) { document.getElementById = function(id) { return document.all[id]; }}

		/* add some aliases for ease of use/backwards compatibility */
		var getQueryParamValue = deconcept.util.getRequestParameter;
		var FlashObject = deconcept.SWFObject; // for legacy support
		var SWFObject = deconcept.SWFObject;

		var FlashObject=deconcept.SWFObject;
		var SWFObject=deconcept.SWFObject;
		SWFObject.getQueryParamValue=deconcept.util.getRequestParameter;
		
		return new SWFObject(swf,id,w,h,ver,c,quality,xiRedirectUrl,redirectUrl,detectKey);
	}
	this.createFlashContainer = function()
	{
		wrapper = document.createElement("DIV");
		flashContainer = document.createElement("DIV");
		
		flashContainer.id = this.containerId;
		flashContainer.className = "FlashContainer";
		flashPlaceHolder = document.createElement("IMG");
		flashPlaceHolder.src = "gui/flash/images/need_flash.jpg";
		flashPlaceHolder.alt = "This site Requires Adobe&copy; Flash ";
		flashDownload = document.createElement("A");
		flashDownload.appendChild(flashPlaceHolder);
		flashDownload.href = "http://www.adobe.com/shockwave/download/download.cgi?P1_Prod_Version=ShockwaveFlash&promoid=BIOW";
		flashDownload.target = "_blank";
		flashDownload.innerHTML += "<br/>";
		flashDownload.innerHTML += "You need to get or update flash";
		
		flashContainer.appendChild(flashDownload);
		wrapper.appendChild(flashContainer);
		document.write(wrapper.innerHTML);
		this.container = document.getElementById(this.containerId);
	}
	
	this.createFlashObject = function(variables, bgcolor)
	{
		this.flashObj =  new this.SWFObject(this.flashDir+this.flashFile,this.id,this.flashWidth,this.flashHeight,this.flashMinVer,null);
		
		if(bgcolor) {
			this.flashObj.addParam("bgcolor",bgcolor);
		} else {
			this.flashObj.addParam("wmode","window");
		}
		this.flashObj.addParam("allowScriptAccess","always");
		this.flashObj.addVariable("allowScriptAccess","always");
		this.flashObj.addVariable("instanceID",this.instanceID);
		this.flashObj.addVariable("iconSize",this.iconSize);
		this.flashObj.addVariable("flashWidth",this.flashWidth);
		this.flashObj.addVariable("flashHeight",this.flashHeight);
		this.flashObj.addVariable("language",this.language);
		this.flashObj.addVariable("langDir",this.langDir);
		this.flashObj.addVariable("debug",this.debug);
		this.flashObj.addVariable("zlFieldIconAnimation","yes");
		for(v in variables){
			this.flashObj.addVariable(v,variables[v]);
		}
		this.isFlashRendered = this.flashObj.write(this.containerId);
	}
		
	/* Resizing the OBJECT/EMBED element */
	/* Resizing the OBJECT/EMBED element */
	this.resizeTo = function (targetHeight,targetWidth,steps,interval,powr)
	{
		// flash calls this to resize to new height 
		var oSrc = document[this.id];
		
		/**/
		var noAnim = true;
		if(noAnim == true)
		{
			if(targetWidth != null)
			{
				oSrc.style.width = targetWidth + "px";
				oSrc.width = targetWidth;
			}
			if(targetHeight != null)
			{
 				oSrc.style.height = targetHeight + "px";
				oSrc.height = targetHeight;
			}
			oSrc.resizeComplete(oSrc.height);
			setMainSize();
			return;
		}
		/**/
		
		window.clearInterval(oSrc.resizer);
		var targetHeight = parseInt(targetHeight);
		var targetWidth = parseInt(targetWidth);
		var startHeight = parseInt(oSrc.height);
		var startWidth = parseInt(oSrc.width);
		var rowHeight = this.iconSize*2;
		var delta = parseInt(targetHeight - startHeight);
		if(delta<0)
		{
			var direction = "collapse";
		}else if(delta>0)
		{
			var direction = "expand";
		}
		var absDelta = Math.abs(parseInt(targetHeight - startHeight));
		if(targetHeight == startHeight || (absDelta <= 20) || isNaN(targetHeight) )
		{
			targetHeight = null;
		}
		if(targetWidth == startWidth || isNaN(targetWidth))
		{
			targetWidth = null;
		}
		if(targetHeight == null && targetWidth == null)
		{
			oSrc.resizeComplete(oSrc.height);
			return;
		}
		/***************
		this.container.style.height = targetHeight + "px";
		document[this.id].style.height = targetHeight + "px";
		document[this.id].resizeComplete(targetHeight);
		***************/
		/***************/
		//Setting defaults for undefined params
		if(steps == null || steps == ""){
			steps = 10;
		}
		if(interval == null || intervalinterval == ""){
			interval = 10;
		}
		if(powr == null || powr == ""){
			powr = 0.5;
		}
		if(oSrc.currentWidth == null){
			var startWidth =  parseInt(oSrc.width);
		}else{
			var startWidth =  oSrc.currentWidth;
		}
		if(oSrc.currentHeight == null){
			var startHeight = parseInt(oSrc.height);
		}else{
			var startHeight =  oSrc.currentHeight;
		}
		var currentStep = 0;
		oSrc.currentWidth = startWidth;
		oSrc.currentHeight = startHeight;
		oSrc.resizer = window.setInterval(
			function(){
				//debugger;
				/*
				if(typeof(ddd) == "undefined"){
				ddd = document.createElement("DIV");
				document.body.appendChild(ddd);
				ddd.style.position = "absolute";
				ddd.style.backgroundColor = "white";
				ddd.style.padding = "5px";
				ddd.style.border = "1px solid black";
				ddd.style.top = "0px";
				
				}*/
				/**/
				if(targetWidth != null){
					oSrc.currentWidth = oSrc.easeInOut(startWidth,targetWidth,steps,currentStep,powr);
					oSrc.style.width = oSrc.currentWidth+ "px";
					oSrc.width = oSrc.currentWidth;
				}
				if(targetHeight != null){
					oSrc.currentHeight = oSrc.easeInOut(startHeight,targetHeight,steps,currentStep,powr);
					oSrc.style.height = oSrc.currentHeight+ "px";
					oSrc.height = oSrc.currentHeight;
				}
				if(currentStep > steps){
					if(targetWidth != null){
						oSrc.style.width = targetWidth+ "px";
						oSrc.width = oSrc.targetWidth;
					}
					if(targetHeight != null){
						oSrc.style.height = targetHeight+ "px";
						oSrc.height = targetHeight;
					}
					window.clearInterval(oSrc.resizer);
					oSrc.resizeComplete(targetHeight);
				}
				currentStep++;
			},
			interval
		)
		oSrc.easeInOut = function(minValue,maxValue,totalSteps,actualStep,powr) { 
			var _delta = maxValue - minValue; 
			var stepp = minValue+(Math.pow(((1 / totalSteps) * actualStep), powr) * _delta); 
			return Math.ceil(stepp) ;
		}
		/***************/
		
	}
}

function Zlango_Flash()
{
	this.name = "ZlagoFlashMain";		//
	this.isFlashReady = false;			// Bool - flash is ready to get data
	this.language = "en";				// Default writing language
	this.langDir = "ltr";				// Default writing direction of language
	this.iconFolder = "zlicons/";			// Default location core icons
	
	this.zlangoFlashInit = function(){
		//this.loadDictionary();
	};
	//check if flash is ready to recieve commands and data
	this.flashReady = function(bool) {
		// flash calls this when it's ready.
		// now you can start pushing statements to the viewer.
		//alert("isFlashReady = "+ b);
		this.isFlashReady = true;
	}
	/* Static Core Icon Dictionary */
	this.dictionary = {};
	this.dictionary.icons = {};
	this.loadDictionary = function(lang)
	{
		if(!lang || lang == ""){
			dictionaryFile = "Zlango_Language_Default_index_1.0.3.2_Template.xml";
		}else{
			dictionaryFile = "Zlango_Language_"+lang+"_index_1.0.3.2_Template.xml";
		}
		this.dictionary["xmlDoc"] = xmlDoc(dictionaryFile);
		
		IconColl = this.dictionary.xmlDoc.getElementsByTagName("Icon");
		this.dictionary.icons.length = IconColl.length;
		for(var i=0; i<IconColl.length; i++ )
		{
			this.dictionary.icons[IconColl[i].getAttribute("ID")] = {
				"file" : IconColl[i].getAttribute("file"),
				"description" : IconColl[i].getAttribute("description")
			}
		}
	}
	
	/* Generate Icon URL based in size and ID */
	this.getIconUrl = function (_IconId,_Size)
	{
		if(_IconId > 0){
			IconUrl = "show.img?id=" + _IconId + "&size=" + _Size;
			return IconUrl;
		}
		
	}
	
	/* Generate Icon URL based in size and ID */
	this.getFullIconUrl = function (_IconId,_Size)
	{
		var server = getServerPath();
		if(_IconId > 0){
			alert("zlango_flash.js, line 508");
			IconUrl = server + "/" + this.iconFolder + _Size + "/" + this.dictionary.icons[_IconId].file;
			return IconUrl;
		}
		
	}
	
	/* Getting Statements */
	this.getStatement = function (_statementId)
	{
		/* This retrives statments form the server */
		if(true)
		{
			oStatement = new xmlDoc(jsonrpc.daoStatement.getXmlById(_statementId));
		}else{
			/* This retrives statments from local files */
			oStatement = xmlDoc("/api/"+_statementId+".xml");
		}
		if(oStatement == null || oStatement.getElementsByTagName("word").length < 1){
			oStatement = xmlDoc("/api/notFound.xml");
		}
		return oStatement;
	}
	/*Into Viewer*/
	this.loadStatement = function (_statementId,i,n){
		if(i == null || i == ""){i = 0};
		if(n == null || n == ""){n = 1};
		// strXML contains id of statement
		oStatement = this.getStatement(_statementId);

		/* this adds iconURL nodes to the xml */
		cWords = oStatement.getElementsByTagName("word");
		for(w = 0; w < cWords.length; w++){
			if(cWords[w].getElementsByTagName("iconId").length > 0){
				if(cWords[w].getElementsByTagName("iconId")[0].text){
					intIconId = cWords[w].getElementsByTagName("iconId")[0].text;
				}else
				if(cWords[w].getElementsByTagName("iconId")[0].textContent){
					intIconId = cWords[w].getElementsByTagName("iconId")[0].textContent;
				}
				if(intIconId != -1){
					IconUrl = oStatement.createTextNode( this.getIconUrl(intIconId,this.iconSize) );
					IconUrlNode = oStatement.createElement('iconURL');
					IconUrlNode.appendChild(IconUrl);
					cWords[w].appendChild(IconUrlNode);
				}
			}
		}
		
		strXML = oStatement.xml;
		try{
			if(this.isFlashReady){
				//document.getElementById(this.instanceID + "_gigyaShare").className = "Hidden";
				document[this.id].loadStatement(strXML,i,(n - 1));
			}else{
				return false;
			}
		}
		catch(e){
			
		}
	}
	
	this.getStatementXml = function(_statementId) {
		oStatement = this.getStatement(_statementId);
		
		/* this adds iconURL nodes to the xml */
		cWords = oStatement.getElementsByTagName("word");
		for(w = 0; w < cWords.length; w++){
			if(cWords[w].getElementsByTagName("iconId").length > 0){
				if(cWords[w].getElementsByTagName("iconId")[0].text){
					intIconId = cWords[w].getElementsByTagName("iconId")[0].text;
				}else
				if(cWords[w].getElementsByTagName("iconId")[0].textContent){
					intIconId = cWords[w].getElementsByTagName("iconId")[0].textContent;
				}
				if(intIconId != -1){
					IconUrl = oStatement.createTextNode( this.getIconUrl(intIconId,this.iconSize) );
					IconUrlNode = oStatement.createElement('iconURL');
					IconUrlNode.appendChild(IconUrl);
					cWords[w].appendChild(IconUrlNode);
				}
			}
		}
		
		return oStatement.xml;
	}
	
	this.getComposerStatementXml = function(_statementId) {
		oStatement = this.getStatement(_statementId);
		return oStatement.xml;
	}
	
	this.zlangoFlashInit();
}
Zlango_Flash.prototype = new GenericFlash;

function Zlango_Viewer()
{
	/* Viewer default Settings */
	this.name = "FlashViewer";
	this.flashFile = "compositionDisplay.swf";
	this.flashHeight = "97";
	this.flashWidth = "500";
	this.randomize = true;
	this.randomListLength = 1;
	
	/* Default Icon size for most pages */
	this.iconSize = "32";
	
	/* init for viewer flash class */
	this.viewerInit = function (ArgObj){
		/* init for root flash class */
		this.init(ArgObj);
		/*if(this.randomize || typeof daoStatement != "undefined")
		{
			_startPos = Math.floor(Math.random()*100);
			_maxResults = this.randomListLength;
			this.getStatementList(_startPos, _maxResults, -1);
			statmentToLoad = this.getStatement(this.statementList[o].id);
			
			document[this.id].loadStatement( statmentToLoad.xml , 0, _maxResults); 
		}*/
		this.listCounter = {
			"counterBox"	: document.getElementById(this.instanceID + "_CounterArea"),
			"counter"		: document.getElementById(this.instanceID + "_Counter"),
			"IndexField"	: document.getElementById(this.instanceID + "_IndexField"),
			"LengthField"	: document.getElementById(this.instanceID + "_LengthField"),
			"show"			: function(){
				this["counter"].style.display = "block";
			},
			"hide"			: function(){
				this["counter"].style.display = "none";
			},
			"update"		: function (_i,_n){
				this["IndexField"].innerHTML = _i+1;
				this["LengthField"].innerHTML = _n;
			}
		}
		this.titleActions = {
			"box"			: document.getElementById(this.instanceID + "_TitleActions"),
			"show"			: function(){
				this["box"].style.display = "block";
			},
			"hide"			: function(){
				this["box"].style.display = "none";
			}
		}
		this.viewerTabs = {
			"box"			: document.getElementById(this.instanceID + "_ViewerTabs"),
			"show"			: function(){
				this["box"].style.display = "block";
			},
			"hide"			: function(){
				this["box"].style.display = "none";
			}
		}
	}
	
	/* Viewer Specific Methods and Properties */
	this.statementList = {};
	this.listSelectedIndex = 0;
	// Navigate Statement List
	this.nextClick = function()
	{
		if(this.listSelectedIndex < this.statementList["listObj"].length-1)
		{
			this.loadStatementFromList(this.listSelectedIndex+1);
		}
		if( typeof selectRow != "undefined" )
		{
			statementId = this.statementList[this.listSelectedIndex+1].id;
			oTR = document.getElementById("TR_" + statementId);
			selectRow(oTR);
		}
	}
	this.prevClick = function()
	{
		if(this.listSelectedIndex > 0)
		{
			this.loadStatementFromList(this.listSelectedIndex-1);
		}
		if( typeof selectRow != "undefined" )
		{
			statementId = this.statementList[this.listSelectedIndex-1].id;
			oTR = document.getElementById("TR_"+statementId);
			selectRow(oTR);
		}
	}
	this.getStatementList = function (_startPos, _maxResults, _orderType,oBool)
	{
		if(_startPos==null||_startPos==""){_startPos = 0};
		if(_maxResults==null||_maxResults==""){_maxResults = 10};
		if(_orderType==null||_orderType==""){_orderType = -1};
		/*	Order Types
		 	
		 	ORDER_NONE=0
			ORDER_PICK=1
			ORDER_DATE=2
			ORDER_RANK=4
			ORDER_USED=8 
		 */
		var R = this.statementList;
		var load = oBool;
		var caller = this;
		if(typeof daoStatement != "undefined"){
			 daoStatement.getStatements( _startPos,_maxResults,_orderType,function(Result)
				{
					R["listObj"] = Result;
					for (x in Result)
					{
						R[Result[x].id] = Result[x];
						R[Result[x].id].index = x;
						
					}
					if(load == true)
					{
						caller.loadStatementFromList(0);
					}
				}
			)
		}
	}
	this.loadStatementFromList = function(_index,_id)
	{
		if(_index == null){
			_index = this.statementList[_id].index;
		}
		if(_id == null){
			_id = this.statementList["listObj"][_index].id;
		}
		_n = this.statementList["listObj"].length;
		this.listSelectedIndex = _index;
		this.loadStatement(_id,_index,_n);
		this.loadStatement(_id,_index,_n);
		
		//Counter
		//SelectedIndex
		//ListLength
		this.listCounter.show();
		this.listCounter.update(_index,_n);
	}
	this.getListAndLoad = function(_startPos, _maxResults, _orderType)
	{
		this.getStatementList(_startPos, _maxResults, _orderType,true);
	}
	/*
	 * var boxCounter = document.getElementById("Counter");
		var boxSelectedIndex = document.getElementById("SelectedIndex");
		var boxListLength = document.getElementById("ListLength");
		if(typeof boxCounter != null)
		{
			boxSelectedIndex.innerHTML = this.listSelectedIndex+1;
			boxListLength.innerHTML = this.statementList["listObj"].length;
		}
	 */
	this.addButton = function(_id,_position,_label,_function)
	{
		switch(_position)
		{
			case "left":
				_theme = "ViewerYellow";
				_target = document.getElementById(this.instanceID + "_LeftButtons");
			break
			case "right":
				_theme = "ViewerOrangeLarge";
				_target = document.getElementById(this.instanceID + "_RightButtons");
			break;
		}
		oBtn = createButton3Parts(_id,_theme,_label,_function);
		_target.appendChild(oBtn);
		
	}
	this.viewerTitle = {
		//_ViewerTitle
		"viewer" : this,
		"title" : document.getElementById(this.instanceID + "_ViewerTitle"),
		"maxLength" : 50,
		"editTitle" : function(titleStr)
		{
			if(this.title == null){
				this.title = document.getElementById(this.viewer.instanceID + "_ViewerTitle");
			}
			if(titleStr.length > this.maxLength)
			{
				titleStr = titleStr.substr(0,this.maxLength) + "...";
			}
			this.title.innerHTML = titleStr;
		}
	}
	this.viewerButtons = {
		"viewer" : this, 
		"show" : function (intId)
		{
			oBtn = document.getElementById(this.viewer.instanceID + "_Btn" + intId);
			oBtn.style.display = "inline";
		},
		"hide" : function (intId)
		{
			oBtn = document.getElementById(this.viewer.instanceID + "_Btn" + intId);
			oBtn.style.display = "none";
		},
		"editLabel" : function (intId,_labelText)
		{
			oBtn = document.getElementById(this.viewer.instanceID + "_Btn" + intId);		
			oBtn.rows[0].cells[1].innerHTML = _labelText;
		},
		"editFunction" : function (intId,_function)
		{
			oBtn = document.getElementById(this.viewer.instanceID + "_Btn" + intId);		
			oBtn.onclick = _function;
		}
	}
	this.gigyaLinks = {
		"viewer" : this,
		"showPost" : function()
		{
			this.hideShare();
			this.hideEmbed();
			
			var serverPath = getServerPath();
			var sconf = { emailSubject : "Zlango Message For You", 
						  emailTemplate : this.viewer.instanceID + "_emailContentPost",
						  cssURL: serverPath + "/gui/viewer/gigyaShare2.css",
						  cornerRoundness: 2,
						  commentTemplate : this.viewer.instanceID + "_commentContentPost",
						  initialMessageType: "hi5"
						  /*,
						  domainForCallback : "zlango.com" */} 
			Wildfire.initShare("Zlango", this.viewer.instanceID + "_divWildfireSharePost", 400, 350,sconf);
			//document.getElementById(this.viewer.instanceID + "_divWildfireSharePost").style.width = "100%";
			document.getElementById(this.viewer.instanceID + "_gigyaPost").className = "";
			document.getElementById(this.viewer.instanceID + "_postActionLink").className = "Action_Link_Active";
			
		},
		"showEmbed" : function()
		{
			this.hideShare();
			this.hidePost();
			
			var serverPath = getServerPath();
			var pconf = { defaultContent : this.viewer.instanceID + "_postContent",
						  cssURL: serverPath + "/gui/viewer/gigyaPost.css"}
			Wildfire.initPost("Zlango", this.viewer.instanceID + "_divWildfirePost", 400, 120,pconf);
			document.getElementById(this.viewer.instanceID + "_divWildfirePost").style.width = "100%";
			
			document.getElementById(this.viewer.instanceID + "_gigyaEmbed").className = "";
			document.getElementById(this.viewer.instanceID + "_embedActionLink").className = "Action_Link_Active";
			
		},
		"showShare" : function()
		{
			this.hidePost();
			this.hideEmbed();
			
			var isUserLogedIn = document.getElementById(this.viewer.instanceID + "_isLogedIn").value;
			var displayUserEmail = document.getElementById(this.viewer.instanceID + "_userEmail").value;
			var userId = document.getElementById(this.viewer.instanceID + "_userId").value;
			if(isUserLogedIn == "true") {
				var userAddressBookEnteries = jsonrpc.daoAddressBook.getAddressEntry(userId).list;
				createUserAddressBook(userAddressBookEnteries);
				document.getElementById(this.viewer.instanceID + "_toLabel").innerHTML ="Add more:";
				document.getElementById(this.viewer.instanceID + "_fromEmail").value = displayUserEmail;
			}
			
			//document.getElementById(this.viewer.instanceID + "_divWildfireShare").style.width = "100%";
			document.getElementById(this.viewer.instanceID + "_gigyaShare").className = "";
			document.getElementById(this.viewer.instanceID + "_shareActionLink").className = "Action_Link_Active";
			
		},
		"hideShare" : function()
		{
			document.getElementById(this.viewer.instanceID + "_gigyaShare").className = "Hidden";
			document.getElementById(this.viewer.instanceID + "_shareActionLink").className = "Action_Link";
		},
		"hidePost" : function()
		{
			document.getElementById(this.viewer.instanceID + "_gigyaPost").className = "Hidden";
			document.getElementById(this.viewer.instanceID + "_postActionLink").className = "Action_Link";
		},
		"hideEmbed" : function()
		{
			document.getElementById(this.viewer.instanceID + "_gigyaEmbed").className = "Hidden";
			document.getElementById(this.viewer.instanceID + "_embedActionLink").className = "Action_Link";
		},
		"closeShare" : function()
		{
			clearShareInfo();
		},
		"closePost" : function()
		{
		},
		"closeEmbed" : function()
		{
		},
		"showGigyaLinks" : function()
		{
			document.getElementById(this.viewer.instanceID + "_gigyaLinks").className = "";
		},
		"hideGigyaLinks" : function() 
		{
			document.getElementById(this.viewer.instanceID + "_gigyaLinks").className = "Hidden";
		}
	}
	
	this.viewerInit(arguments[0]);
}
Zlango_Viewer.prototype = new Zlango_Flash;


function Zlango_Composer()
{
	this.name = "FlashComposer";
	//this.flashFile = "bus_slow_me_late.swf";
	this.flashHeight = "500";
	this.flashWidth = "575";
	
	/* Composer Specific Methods and Properties */
	this.composerInit = function(ArgObj){
		var StatementToEdit = this.getStatement(ArgObj["statementId"]).xml;
		ArgObj["statement"] = StatementToEdit;
		this.init(ArgObj);
	}
	this.getNewStatement = function (){
		var newStatement = document[this.id].getStatement();
		alert(newStatement);
		return newStatement;
	}
	this.composerInit(arguments[0]);
}
Zlango_Composer.prototype = new Zlango_Flash;