// ---------------------------------------------------------------------------
//    Copyright (c) 2007, LiquidPixels, Incorporated. All Rights Reserved.
//
//    This file represents Intellectual Property which is proprietary and
//  confidential to LiquidPixels, Inc. and may be protected under one or more
//  patents. Any disclosure, in whole or in part, is prohibited without express
//  written permission.
// 
//    A non-exclusive License is granted to use this file only in conjunction
//  with a valid, current, LiquiFire Server license or Service subscription.
//  All other use is expressively prohibited.
//
//   $Id: Zoom.js 390 2010-02-19 16:47:34Z mspencer $
// ---------------------------------------------------------------------------

//import org.prototypejs.prototype.Prototype
//import com.liquidpixels.liquifire.LiquiFire
//import com.liquidpixels.liquifire.Command


com.liquidpixels.liquifire.Zoom = Class.create({
	parent:			undefined,
	revision:		'$Revision: 390 $',
	reasons:		new Array(),

	swfbase:		undefined,
	server:			undefined,
	uri:			undefined,
	width:			undefined,
	height:			undefined,
	controls:		'over',

	watermark:		undefined,
	wgravity:		undefined,
	wopacity:		undefined,
	wmargin:		undefined,
	
	zoomToFit:		undefined,
	maxZoom:		undefined,

	cacheEnabled:	true,
	id:				'',


	initialize: function(server, uri) {
		this.revision = this.revision.replace(/[^\d\.]+([\d\.]+).+/, "$1");

//		if(console.log)
//			console.log("Zoom.js Version " + this.revision + "\nCopyright (c) 2007, LiquidPixels, Incorporated. All Rights Reserved.");

		if(server != undefined)
			this.server = server;

		if(uri != undefined)
			this.uri = uri;
	},



	makeViewer: function(id, params) {
		if(params && params.images)
			this.makeComplexViewer(id, params);
		else
			this.makeSimpleViewer(id, params);
	},



	makeSimpleViewer: function(id, params) {
		var e = $(id);
		var swf = "";
		
		for(p in params) {
			this[p] = params[p];
		}

		if(this.validateSimple()) {
			if(this.swfbase != undefined)
				swf = this.swfbase + "/ZAP.swf?";
			else	
				swf = "http://" + this.server + "/zap/ZAP.swf?";

			swf += "&server=" + this.server;
			swf += "&uri=" + this.uri;
			swf += "&controls=" + this.controls;
			swf += "&cacheEnabled=" + this.cacheEnabled;

			if(this.watermark)
				swf += "&watermark=" + this.watermark;
			if(this.wgravity)
				swf += "&wgravity=" + this.wgravity;
			if(this.wopacity)
				swf += "&wopacity=" + this.wopacity;
			if(this.wmargin)
				swf += "&wmargin=" + this.wmargin;
			if(this.zoomToFit)
				swf += "&zoomToFit=" + this.zoomToFit;
			if(this.maxZoom)
				swf += "&maxZoom=" + this.maxZoom;
			if(this.quality)
				swf += "&quality=" + this.quality;
			if(this.hq)
				swf += "&hq=" + this.hq;
			
			if(this.image)
				swf += "&image=" + this.image;
			else
				swf += "&chain=" + this.chain.replace(/&/g, "|");

			e.innerHTML = this.objectElement(this.id, this.height, this.width, swf);
		} else {
			e.innerHTML = "<font color='#F00'>LiquidPixels' LiquiFire: Unable to create Zoom: </font><BR>" +
				this.reasons.join('<br>');
		}
	},



	validateSimple: function() {
		if(this.server == undefined || this.server == "")
			this.reasons.push("Server must be specified");

		if(this.uri == undefined || this.uri == "")
			this.reasons.push("URI must be specified");

		if(this.height == undefined || this.width == undefined)
			this.reasons.push("Height and width must be specified");

		if((this.image == undefined || this.image == "") && (this.chain == undefined || this.chain == ""))
			this.reasons.push("Either image or chain must be specified");
		
		return this.reasons.length == 0;
	},



	makeComplexViewer: function(id, params) {
		var e = $(id);
		var swf = "";
		
		for(p in params) {
			this[p] = params[p];
		}

		if(this.validateComplex()) {
			if(this.swfbase != undefined)
				swf = this.swfbase + "/ZAPm.swf?";
			else	
				swf = "http://" + this.server + "/zap/ZAPm.swf?";

			swf += "&server=" + this.server;
			swf += "&uri=" + this.uri;
			swf += "&cacheEnabled=" + this.cacheEnabled;
			swf += "&images=" + this.images;

			e.innerHTML = this.objectElement(this.id, this.height, this.width, swf);
		} else {
			e.innerHTML = "<font color='#F00'>LiquidPixels' LiquiFire: Unable to create Zoom: </font><BR>" +
				this.reasons.join('<br>');
		}
	},



	validateComplex: function() {
		if(this.server == undefined || this.server == "")
			this.reasons.push("Server must be specified");

		if(this.uri == undefined || this.uri == "")
			this.reasons.push("URI must be specified");

		if(this.height == undefined || this.width == undefined)
			this.reasons.push("Height and width must be specified");

		if(this.images == undefined)
			this.reasons.push("Images must be specified");
		
		return this.reasons.length == 0;
	},



	makeSpinViewer: function(id, params) {
		var e = $(id);
		var swf = "";
		
		for(p in params) {
			this[p] = params[p];
		}

		if(this.validateSpin()) {
			if(this.swfbase != undefined)
				swf = this.swfbase + "/Spin.swf?";
			else	
				swf = "http://" + this.server + "/zap/Spin.swf?";

			swf += "&server=" + this.server;
			swf += "&uri=" + this.uri;
			swf += "&chain=" + this.chain;
			swf += "&frames=" + this.frames;
			swf += "&controls=" + this.controls;

			e.innerHTML = this.objectElement(this.id, this.height, this.width, swf);
		} else {
			e.innerHTML = "<font color='#F00'>LiquidPixels' LiquiFire: Unable to create Spin: </font><BR>" +
				this.reasons.join('<br>');
		}
	},
	
	
	
	validateSpin: function() {
		if(this.server == undefined || this.server == "")
			this.reasons.push("Server must be specified");

		if(this.uri == undefined || this.uri == "")
			this.reasons.push("URI must be specified");

		if(this.height == undefined || this.width == undefined)
			this.reasons.push("Height and width must be specified");

		if(this.chain == undefined)
			this.reasons.push("Chain must be specified");
		
		if(this.frames == undefined)
			this.reasons.push("Frames must be specified");
		
		return this.reasons.length == 0;
	},
	
	
	makeSpazViewer: function(id, params) {
		var e = $(id);
		var swf = "";
		
		for(p in params) {
			this[p] = params[p];
		}

		if(this.validateSpaz()) {
			if(this.swfbase != undefined)
				swf = this.swfbase + "/Spaz.swf?";
			else	
				swf = "http://" + this.server + "/zap/Spaz.swf?";

			swf += "&server=" + this.server;
			swf += "&uri=" + this.uri;
			swf += "&images=" + this.images;
			if(this.chain)
				swf += "&chain=" + this.chain;
			if(this.frames)
				swf += "&frames=" + this.frames;

			e.innerHTML = this.objectElement(this.id, this.height, this.width, swf);
		} else {
			e.innerHTML = "<font color='#F00'>LiquidPixels' LiquiFire: Unable to create Spin: </font><BR>" +
				this.reasons.join('<br>');
		}
	},
	
	
	
	validateSpaz: function() {
		if(this.server == undefined || this.server == "")
			this.reasons.push("Server must be specified");

		if(this.uri == undefined || this.uri == "")
			this.reasons.push("URI must be specified");

		if(this.height == undefined || this.width == undefined)
			this.reasons.push("Height and width must be specified");

		if(this.images == undefined)
			this.reasons.push("Images must be specified");
		
		return this.reasons.length == 0;
	},
	
	
	objectElement: function(id, height, width, swf) {
		return '<object classid="clsid:d27cdb6e-ae6d-11cf-96b8-444553540000" ' +
				'codebase="http://fpdownload.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=7,0,0,0" ' +
				'width="' + width + '" height="' + height + 
				'" id="' + id + '" align="left">' +

				'<param name="allowScriptAccess" value="sameDomain" />' +
				'<param name="movie" value="' + swf + '" />' +
				'<param name="quality" value="high" />' +
				'<param name="bgcolor" value="#ffffff" />' +
				'<param name="wmode" value="opaque" />' +
				'<embed src="' + swf + '" ' +
				'quality="high" bgcolor="#ffffff" ' +
				'wmode="opaque" ' +
				'width="' + width + '" height="' + height + '" ' +
				'name="' + id + '" align="left" ' +
				'allowScriptAccess="sameDomain" ' +
				'type="application/x-shockwave-flash" ' +
				'pluginspage="http://www.macromedia.com/go/getflashplayer" />' +
				
			'</object>';
	}
});







