/*
	Packshotlive®
	http://www.packshotlive.com
	
*/

/*
	Packshotlive Object
*/

Packshotlive = function () {
	this._plugIns = new Array();
	this._images = new Array();
	this._params = new Array();	
}
Packshotlive.prototype = {
	width: 450,
	height: 500,
	clientID: '',
	serverName: 'http://images.packshotlive.com',
	appPath: '/html/zoomapp/',
	plugInPath: '/html/zoomapp/plugins/',
	servletPath: '/servlet/ImageData',
	bgColor: '#ffffff',
	
	addImage: function (img, url) {
		if (url == undefined) url = "";
		this._images.push({name: img, url: url});
	},
	
	addPlugIn: function (plug){
		this._plugIns.push(plug);
	},
	
	addParam: function(name, value){
		// compatible to prototype
		this._params[name] = {value: value, zv: true};
	},
	
	getEmbedCode: function() {
		var imageURL = this.serverName + this.servletPath +'?clientId='+this.clientID;
		imageURL += this._getImages();
		
		var zvParameter = 'imageURL='+escape(imageURL)
		var itsme = "&referrer=" + encodeURIComponent(document.referrer);
		zvParameter += escape( itsme );
		zvParameter += this._getPlugIns() + this._getParams();
		
		var protocol = "http://";
		if ( this.serverName.indexOf( "https" ) == 0 )
			protocol = "https://"; 
		
		var code = '';
		code += ('<object classid="clsid:d27cdb6e-ae6d-11cf-96b8-444553540000" codebase="' + protocol + 'fpdownload.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=6,0,0,0" width="'+this.width+'" height="'+this.height+'" id="zoomoviewer" align="middle">');
		code += ('<param name="movie" value="' + this.serverName + this.appPath + 'zoomo07.swf?'+ zvParameter +'" />');
		code += ('<param name="allowScriptAccess" value="always"><param name="bgcolor" value="'+this.bgColor+'">');
		code += ('<embed src="' + this.serverName + this.appPath + 'zoomo07.swf?'+zvParameter+'" quality="high" width="'+this.width+'" height="'+this.height+'" bgcolor="'+this.bgColor+'" name="zoomoviewer" align="middle" type="application/x-shockwave-flash" pluginspage="' + protocol + 'www.macromedia.com/go/getflashplayer" allowScriptAccess="always" swliveconnect="true" />');
		code += ('</object>');
		
		return code;
	},
	
	start: function () {
		var code = this.getEmbedCode();
		document.write(code);
	},
	
	_getImages: function () {
		var str = "";
		for (var i = 0; i < this._images.length; i++) {
			str += "&image=" + this._images[i].name;
			str += "&url=" + this._images[i].url;
		}
		return str;
	},
	
	_getPlugIns: function () {
		var str = "&plugIns=";
		for (var i = 0; i < this._plugIns.length; i++) {
			str += this.serverName + this.plugInPath + this._plugIns[i] + "|";
		}
		return str.substring(0, str.length - 1);
	},
	
	_getParams: function () {
		var str = "";
		for (var p in this._params) {
			if (this._params[p].zv) 
				str += "&" + p + "=" + this._params[p].value;
		}
		return str;
	},
	
	startSWFObject: function (divID) {
		var imageURL = this.serverName + this.servletPath +'?clientId='+this.clientID;
		imageURL += this._getImages();
		
		var zvParameter = 'imageURL='+escape(imageURL)
		zvParameter += this._getPlugIns() + this._getParams();
	
		var so = new SWFObject(this.serverName + this.appPath + "zoomo07.swf?" + zvParameter, "ZoomoViewer", this.width, this.height, "6", "#FFFFFF");
		so.addParam("allowScriptAccess", "always");
		so.addParam('bgcolor', this.bgColor);
		so.write(divID);
	}
}
