/*

Universal Viewer
Injection Script

Copyright (c) 2007-2008 View 22. All rights reserved.

*/
function UniversalViewerEmbed(projectId, server)
{
	this.projectId 		= projectId;
	this.server 		= server;
	
	//dimensions of the iframe
	this.frameWidth 	= 400;
	this.frameHeight 	= 300;
	
	//dimensions of the viewer itself
	this.viewerWidth 	= 400;
	this.viewerHeight 	= 300;
	
	this.commerceBar 		= 1;
	this.showWebStores		= 1;
	this.allowFullScreen 	= 1;
	this.type 				= "flash";
	this.metrics			= 1;
	
	this.COMMERCE_BAR_HEIGHT = 128;
}

UniversalViewerEmbed.prototype.Draw = function()
{
	var source = this.server+'/web/UniversalViewer_v2/embed.php?p='+this.projectId+'&cb='+this.commerceBar+'&stores='+this.showWebStores+'&type='+this.type+'&refUrl='+escape(location.href)+'&height='+this.viewerHeight+'&width='+this.viewerWidth+'&fullscreen='+this.allowFullScreen+'&m='+this.metrics;
	var embed = '<iframe ';
	
	if(typeof(this.id) !== 'undefined')
		embed += 'id="' + this.id + '" ';
	
	if(typeof(this.classNames) !== 'undefined')
	{
		embed += 'class="';
		for(var i = 0; i < this.classNames.length; i++)
		{
			if(i != 0)
				embed += ' ';
			embed += this.classNames[i];
		}
		embed += '" ';
	}		
	
	embed += 'src="' + source + '" frameborder="0" scrolling="no" ';
	embed += 'width="'+this.frameWidth+'" height="' + this.frameHeight + '"></iframe>';
	
	document.write(embed);
}

UniversalViewerEmbed.prototype.SetViewType = function(type)
{
	switch (type)
	{
		case "2d":
			if(this.type == "2d")
				return this;
				
			this.type = "2d";
			this.viewerWidth 	= this.frameWidth - 10;
			this.viewerHeight 	= this.frameHeight - 10;
			
			if(this.commerceBar == 1)
				this.viewerHeight -= this.COMMERCE_BAR_HEIGHT;
			break;
		
		case "flash":
			if(this.type == "flash")
				return this;
				
			this.type = "flash";
			this.viewerWidth 	= this.frameWidth;
			this.viewerHeight 	= this.frameHeight;
			break;
	}
	return this;
}

UniversalViewerEmbed.prototype.SetDimensions = function(width, height)
{
	this.frameWidth 	= width;
	this.frameHeight 	= height;
	this.viewerWidth 	= width;
	this.viewerHeight 	= height;
	
	//make room for grey boarder (5px per side)
	if(this.type == "2d")
	{
		this.viewerWidth 	-= 10;
		this.viewerHeight 	-= 10;
		
		//make room for commerce bar if visible	
		if(this.commerceBar == 1)
			this.viewerHeight -= this.COMMERCE_BAR_HEIGHT;
	}
	return this;
}

UniversalViewerEmbed.prototype.ShowCommerceEngine = function(show)
{
	if(show)
	{
		if(this.commerceBar == 1)
			return this;
		
		if(this.type == "2d")
			this.viewerHeight -= this.COMMERCE_BAR_HEIGHT; 	
		
		this.commerceBar = 1;		
		return this;
	}
	
 	if(this.commerceBar == 0)
 		return this;
 	
 	if(this.type == "2d")
 		this.viewerHeight += this.COMMERCE_BAR_HEIGHT;
 	
 	this.commerceBar = 0;
	return this;
}

UniversalViewerEmbed.prototype.ShowWebStores = function(show)
{
	if(show)
		this.showWebStores = 1;
	else
		this.showWebStores = 0;
	
	return this;
}

UniversalViewerEmbed.prototype.AllowFullScreen = function(allow)
{
	if(allow)
		this.allowFullScreen = 1;
	else
		this.allowFullScreen = 0;
	
	return this;
}

UniversalViewerEmbed.prototype.SetId = function(id)
{
	this.id = id;
	
	return this;
}

UniversalViewerEmbed.prototype.AddClassName = function(className)
{
	if(typeof(this.classNames) === 'undefined')
		this.classNames = new Array();
	
	this.classNames.push(className);
	
	return this;
}

UniversalViewerEmbed.prototype.EnableMetrics = function(enable)
{
	if(enable)
		this.metrics = 1;
	else
		this.metrics = 0;
	
	return this;
}

//////////////////////////////////////////////////////////////////////////////////
//																				//
//    				Old embed code lives below this line. 						//
//    		This code has been depricated and should not be editted. 			//
//    					Consider yourself warned!								//
//																				//
//////////////////////////////////////////////////////////////////////////////////
/* old embed */
function SCWEmbedViewer(projectId, commerceBar, type, locHost, width, height){
	
	var viewer_width = (typeof width =="undefined") ? 400 : width;
	var viewer_height = (typeof height =="undefined") ? 227 : height;
	
	if (typeof locHost =="undefined") {
		locHost = type;
		type= "2d";
	}

	if(type != 'flash')
	{
		swv_height = viewer_height + 10;
		
		if(commerceBar == 1)
			swv_height += 128;
			
		swv_width = 411;
		//swv_height += 73;
		//viewer_height = 414;
	}
	else
	{
		if(typeof height =="undefined") {
			swv_height = 310;
			viewer_height = 310;
		}
		else {
			swv_height = viewer_height;
		}
		if(typeof height =="undefined"){
			swv_width = 411;
			viewer_width = 411;	
		}
		else{
			swv_width = viewer_width;
		}
	}
	
	var curUrl = escape(location.href);
	document.write('<iframe id="SCWContainer" src="'+locHost+'/web/UniversalViewer/embed.php?p='+projectId+'&cb='+commerceBar+'&type='+type+'&refUrl='+curUrl+'&height='+viewer_height+'&width='+viewer_width+'" frameborder="0" scrolling="no" width="'+swv_width+'" height="'+swv_height+'"></iframe>');
}

/* newer embed, Oct 28, 2008 */
function SCWEmbedViewer2(projectId, commerceBar, type, locHost, width, height){
	
	var viewer_width = (typeof width =="undefined") ? 400 : width;
	var viewer_height = (typeof height =="undefined") ? 227 : height;
	
	if (typeof locHost =="undefined") {
		locHost = type;
		type= "2d";
	}
	
	if(type != 'flash')
	{
		swv_height = (commerceBar==0) ? 237 : 365;
		swv_width = 411;
		//swv_height += 73;
		//viewer_height = 414;
	}
	else
	{
		swv_height = viewer_height;
		swv_width = viewer_width;
	}
	
	var curUrl = escape(location.href);
	document.write('<iframe id="SCWContainer" src="'+locHost+'/web/UniversalViewer/embed.php?p='+projectId+'&cb='+commerceBar+'&type='+type+'&refUrl='+curUrl+'&height='+viewer_height+'&width='+viewer_width+'" frameborder="0" scrolling="no" width="'+swv_width+'" height="'+swv_height+'"></iframe>');
}


function SCWResizeContainer(container_type, commerce_bar){
	var swv_height = (commerce_bar==0) ? 237 : 365;
	
	if (container_type=='flash')
		swv_height += 73;
		
	document.getElementById('SCWContainer').height = swv_height;
}