
(function()
{
	var namespace = function(namespace)
	{
		var ns = namespace.split('.');
	    var obj = window;
	    var i, len;
	    
	    for(i=0; i<ns.length; i++)
	    {
	    	obj = obj[ns[i]] = obj[ns[i]] || {};
	  	}
	  
	  	return obj;
	};
	
	
	
	var registerClass=function (nsName, className, clazz)
	{
		var ns = namespace(nsName);
		ns[className]=clazz;
	};
	
	
	
	//Name space our utils that are needed.
	var ns=namespace("com.zero42.util");
	
	ns["namespace"]=namespace;
	ns["registerClass"]=registerClass;
	
	
	var GAS=namespace("GAS");
	
	GAS.data=null;
	GAS.onLoad=function(){}; // handler to be overidden for async loads
	GAS.load=function(path,sync)
	{
		//load the path, either sync or async and pass the callback handler to process the data.
		if(sync==null)
			sync=true;
			
	 	com.zero42.galleryAdmin.model.LoadGalleryXML(path,sync,dataLoaded);
	};
	
	function dataLoaded(data)
	{
		GAS.data = new com.zero42.galleryAdmin.model.vo.GASDataVO(data.galleries, data.photographers, data.images, data.tags, data.pages);
	 	
	 	//add data to proxies
	 	GAS.galleryProxy = new com.zero42.galleryAdmin.model.GalleryProxy( data.galleries );
	 	GAS.imageProxy = new com.zero42.galleryAdmin.model.ImageProxy( data.images );
	 	GAS.photographerProxy = new com.zero42.galleryAdmin.model.PhotographerProxy( data.photographers );
		
		GAS.pageProxy = new com.zero42.galleryAdmin.model.PageProxy( data.pages );
		GAS.tagsProxy = new com.zero42.galleryAdmin.model.TagsProxy( data.tags );
		
		//Fire handler to inform we have laoded
		GAS.onLoad();
	};
	
	
	
	//UTILS
	
	
	
	
	/**
	 *  Array#indexOf(item[, offset = 0]) -> Number
	 *  - item (?): A value that may or may not be in the array.
	 *  - offset (Number): The number of initial items to skip before beginning the
	 *      search.
	 *
	 *  Returns the position of the first occurrence of `item` within the array &mdash; or
	 *  `-1` if `item` doesn't exist in the array.
	**/
	function indexOf(item, i) 
	{
	  i || (i = 0);
	  var length = this.length;
	  if (i < 0) i = length + i;
	  for (; i < length; i++)
	    if (this[i] === item) return i;
	  return -1;
	};
	

	
	if (!Array.prototype.indexOf) Array.prototype.indexOf = indexOf;
	
		
}());


(function()
{
	com.zero42.util.registerClass("com.zero42.galleryAdmin.model", "GalleryProxy", GalleryProxy);
	
	
	function GalleryProxy( data )
	{
		this.galleries=data;
		this.data=data;
	}
	
	var clazz = "com.zero42.galleryAdmin.model.GalleryProxy::";
		
	/**
	* True if the gallery passed contains the image passed
	*/	
	GalleryProxy.prototype.galleryHasImage=function( image, gallery )
	{
		if (!image) throw new Error(clazz+"galleryHasImage: no image specified");
		if (!gallery) throw new Error(clazz+"galleryHasImage: no gallery specified");
		
		
		for (var i = 0; i < gallery.images.length; i++)
			if (gallery.images[i] == image.id)
				return true;
		
		
		return false;
	};
	
	/**
	* Returns an array of galleries who contain the image passed
	*/	
	GalleryProxy.prototype.getGalleriesByImage=function( image )
	{
		if(!image) throw new Error(clazz+"getGalleriesByImage: no image specified");
		
		var assignedGalleries = new Array();
		
		for ( var i = 0; i < this.galleries.length; i++)
		{
			var gallery = this.galleries[i];
			imageLoop :
			for (var j = 0; j < gallery.images.length; j++)
			{
				if (gallery.images[j] == image.id)
				{
					assignedGalleries.push(gallery);
					break imageLoop;
				}
			}
		}
		
		return assignedGalleries;
	};
		
	
	/**
	* Returns an array of galleries who contain the tag passed
	*/	
	GalleryProxy.prototype.getGalleriesByTag=function( tag )
	{
		if(!tag) throw new Error(clazz+"getGalleriesByTag: no tag specified");
		
		var assignedGalleries = new Array();
		
		for ( var i = 0; i < this.galleries.length; i++)
		{
			var gallery = this.galleries[i];
			tagLoop :
			for (var j = 0; j < gallery.tags.length; j++)
			{
				if (gallery.tags[j] == tag.id)
				{
					assignedGalleries.push(gallery);
					break tagLoop;
				}
			}
		}
		
		return assignedGalleries;
		
	};
		
	
	/**
	* Returns an array of all the unique tags across all galleries
	*/
		
	GalleryProxy.prototype.getAllUniqueTags=function()
	{
		var allTags = new Array();
		
		for ( var i = 0; i < this.galleries.length; i++)
		{
			var gallery = this.galleries[i];
			
			for (var j = 0; j < gallery.tags.length; j++)
			{
				var tag = gallery.tags[j];
				if ( allTags.indexOf(tag) == -1 )
					allTags.push(tag);
				
			}
			
		}
			 
		
		allTags.sort();
			    
		return allTags;
	};
	
}());
(function()
{
	com.zero42.util.registerClass("com.zero42.galleryAdmin.model", "ImageProxy", ImageProxy);
	
	
		function ImageProxy( data )
		{
			this.data = data;
			this.images= this.data;
		
		} 
		
		
		var clazz = "com.zero42.galleryAdmin.model.ImageProxy::";
	
				
		// determine if the photographer already has this image
		ImageProxy.prototype.imageHasPhotographer=function( image, photographer )
		{
			if(!image) throw new Error(clazz+"imageHasPhotographer: no image specified");
			if(!photographer) throw new Error(clazz+"imageHasPhotographer: no photographer specified");
			
			if (image.photographerID == photographer.id)
				return true;
			
			return false;
		};


		ImageProxy.prototype.getImagesByPhotograpaher=function( photographer ) 
		{
			if (!photographer) throw new Error(clazz+"getImagesByPhotograpaher: no photographer specified");
			
			var photographersImages = new Array();
			
			for (var i=0; i < photographer.images.length; i++)
			{
				imagesLoop:
				for (var j = 0 ; j < this.images.length; j++)
				{
					if ( photographer.images[i] == this.images[j].id )
					{
						photographersImages.push( this.images[j] );
						break imagesLoop;
					}
				}
			}
			
			return photographersImages;
			
		};
		
		ImageProxy.prototype.getImagesByGallery=function( gallery )
		{
			if (!gallery) throw new Error(clazz+"getImagesByGallery: no gallery specified");
			
			var galleryImages = new Array();
			
			for (var i = 0; i < gallery.images.length; i++)
			{
				imagesLoop:
				for (var j = 0 ; j < this.images.length; j++)
				{
					if ( gallery.images[i] == this.images[j].id)
					{
						galleryImages.push(this.images[j]);
						break imagesLoop;
					}
				}
			}
			
			return galleryImages;
		};
		
		ImageProxy.prototype.getImagesByTag=function( tag ) 
		{
			if (!tag) throw new Error(clazz+"getImagesByTag: no tag specified");
			
			var assignedImages = new Array();
			
			for ( var i = 0; i < this.images.length; i++)
			{
				var image = this.images[i];
				tagLoop :
				for (var j = 0; j < image.tags.length; j++)
				{
					if (image.tags[j] == tag.id)
					{
						assignedImages.push(image);
						break tagLoop;
					}
				}
			}
			
			return assignedImages;
			
		};
		
		ImageProxy.prototype.getImagesByPage=function( page )
		{
			if (!page) throw new Error(clazz+"getImagesByPage: no page specified");
			
			var pageImages = new Array();
			
			for (var i = 0; i < page.images.length; i++)
			{
				imagesLoop:
				for (var j = 0 ; j < this.images.length; j++)
				{
					if ( page.images[i] == this.images[j].id)
					{
						pageImages.push(this.images[j]);
						break imagesLoop;
					}
				}
			}
			
			return pageImages;
		};
		
	
		
	
}());



(function()
{
	//Register the LoadGallery
	com.zero42.util.registerClass("com.zero42.galleryAdmin.model", "LoadGalleryXML", LoadGalleryXML);
	
	
	function LoadGalleryXML(path,sync,callback)
	{
		//if sync, then return data
		loadXML(path,sync,callback);
		
	};
	
	
	function parseGASXML(xml)
	{	
		var i;
		//import classes
		var TagVO = com.zero42.galleryAdmin.model.vo.TagVO;
		var PageVO = com.zero42.galleryAdmin.model.vo.PageVO;
		var ImageVO = com.zero42.galleryAdmin.model.vo.ImageVO;
		var PhotographerVO = com.zero42.galleryAdmin.model.vo.PhotographerVO;
		var GalleryVO = com.zero42.galleryAdmin.model.vo.GalleryVO;
				
		//define XML top level nodes
		var tagsXML=[];
		var photogXML=[];
		var galleryXML=[];
		var imageXML=[];
		var pageXML=[];
		
		
		//Parse top level XML nodes (dont simply getElementsByTagname as some child nodes share same names
		if (xml && xml.documentElement && xml.documentElement.childNodes)
		{
			var galleryData= xml.documentElement.childNodes;
			
			for (i=0; i<galleryData.length; i++)
			{
				switch(galleryData[i].nodeName)
				{
					case "galleries" 		: 	galleryXML=galleryData[i].getElementsByTagName("gallery"); break;
					case "photographers" 	: 	photogXML=galleryData[i].getElementsByTagName("photographer"); break;
					case "images" 			: 	imageXML=galleryData[i].getElementsByTagName("image"); break;
					case "pages" 			: 	pageXML=galleryData[i].getElementsByTagName("page"); break;;	
					case "tags" 			:	tagsXML=galleryData[i].getElementsByTagName("tag"); break;
				}	
			}
		
		}
		
		
		//***************************//
		// Tags
		//***************************//
		var tags = new Array();
		
		for(i=0; i<tagsXML.length; i++)
		{
			//id, lavel
			var tag=new TagVO( 
							getAttribute(tagsXML[i], "id"), 
							getValue(tagsXML[i],"label") 
							);
			
			tags.push(tag);		
		}
		
		
		
		
		
		
		
		
		//***************************//
		// Images
		//***************************//
		var images = new Array();
		for(i=0; i<imageXML.length; i++)
		{
			//id, src, thumb, photographerID, title, caption, date, location, tags, other1, other2, other3
			var image=new ImageVO( 
							getAttribute( imageXML[i], "id" ), 
							getValue( imageXML[i], "src" ),
							getValue( imageXML[i], "thumb" ),
							getValue( imageXML[i], "photographerID" ),
							getValue( imageXML[i], "title" ),
							getValue( imageXML[i], "caption" ),
							getValue( imageXML[i], "date" ),
							getValue( imageXML[i], "location" ),
							getArray( imageXML[i], "tags" ),
							getValue( imageXML[i], "other1" ),
							getValue( imageXML[i], "other2" ),
							getValue( imageXML[i], "other3" )
							);
			//set the width, height and mime types...
			image.width = getValue( imageXML[i], "width" );
			image.height = getValue( imageXML[i], "height" );
			image.mime = getValue( imageXML[i], "mime" );
			
			images.push(image);		
		}
		
		
		
		
		//***************************//
		// Photog
		//***************************//
		var photogs = new Array();
		for(i=0; i<photogXML.length; i++)
		{
			//id, fname, lname, email, link, description, tags, other1, other2, other3, images
			var photo=new PhotographerVO( 
							getAttribute( photogXML[i], "id" ), 
							getValue( photogXML[i], "fname" ),
							getValue( photogXML[i], "lname" ),
							getValue( photogXML[i], "email" ),
							getValue( photogXML[i], "link" ),
							getValue( photogXML[i], "description" ),
							getArray( photogXML[i], "tags" ) ,
							getValue( photogXML[i], "other1" ),
							getValue( photogXML[i], "other2" ),
							getValue( photogXML[i], "other3" ),
							getArray( photogXML[i], "images" ) 
							);
			
			photogs.push(photo);		
		}


		
		
		//***************************//
		// Pages
		//***************************//
		var pages = new Array();
		for(i=0; i<pageXML.length; i++)
		{
			//id, title, body, images, tags, other1, other2, other3
			var page=new PageVO( 
							getAttribute( pageXML[i], "id" ), 
							getValue( pageXML[i], "title" ),
							getValue( pageXML[i], "body" ),
							getArray( pageXML[i], "images" ) ,
							getArray( pageXML[i], "tags" ) ,
							getValue( pageXML[i], "other1" ),
							getValue( pageXML[i], "other2" ),
							getValue( pageXML[i], "other3" )
							);
			
			pages.push(page);		
		}
		
		
		
		
		//***************************//
		// galleries
		//***************************//
		var galleries = new Array();
		for(i=0; i<galleryXML.length; i++)
		{
			//id, name, description, images, tags, other1, other2, other3
			var gallery=new GalleryVO( 
							getAttribute( galleryXML[i], "id" ), 
							getValue( galleryXML[i], "name" ),
							getValue( galleryXML[i], "description" ),
							getArray( galleryXML[i], "images" ) ,
							getArray( galleryXML[i], "tags" ) ,
							getValue( galleryXML[i], "other1" ),
							getValue( galleryXML[i], "other2" ),
							getValue( galleryXML[i], "other3" )
							);
			
			galleries.push(gallery);		
		}
		
		
		
		
		//Create gas data
		var gasData = {
			galleries:galleries,
			photographers:photogs,
			images:images,
			tags:tags,
			pages:pages
			};
			
			
		
		//Return data
		return gasData;
		
	};
	
	
	function getItemById(group, id)
	{
		for (var i=0; i<group.length; i++)
			if(group[i].id == id)
				return group[i];
				
	}
	
	
	function getAttribute(node, name)
	{
		try { return node.attributes.getNamedItem(name).nodeValue;  }
		catch(e){}
		
		return "";	
	}
	
	//Returns value as an array of items.
	function getArray(node, name)
	{
		return getValue(node, name, true);
	}
	
	//Private get node value
	function getValue(node, name, forceArray)
	{
		var res="";
		var val;
		try { 
			val = node.getElementsByTagName(name); 
			
			//If one node, return the value, else convert to array of values
			if (val.length == 1)
			{
				if (forceArray) 
				{
					res = new Array();
					res.push( val[0].childNodes[0].nodeValue );
				}
				else 
				{
					res = val[0].childNodes[0].nodeValue;
				}	
			}
			else
			{
			 	res = new Array();
				
				for (var j=0; j<val.length; j++)
					res.push( val[j].childNodes[0].nodeValue );
				
			}
		}
		catch(e)
		{
		}
		
		return res;
	}
	
	//Private - load XML
	function loadXML(path,sync,callback)
	{
		var xhttp;
		
		if (window.XMLHttpRequest)
		{
			xhttp=new XMLHttpRequest();
		}
		else // Internet Explorer 5/6
		{
			xhttp=new ActiveXObject("Microsoft.XMLHTTP");
		}
		
		if(sync==false)
		{
			xhttp.onreadystatechange=function()
    		{ 
    			if(xhttp.readyState==4)
		        	callback( parseGASXML( xhttp.responseXML ) );
		    };
		}
		
		xhttp.open("GET",path,!sync);
		xhttp.send(null);
		
		if(sync!==false)
			callback( parseGASXML( xhttp.responseXML ));
	}
	
	
		
		
}());


(function()
{
	com.zero42.util.registerClass("com.zero42.galleryAdmin.model", "PageProxy", PageProxy);
	
	
	function PageProxy( data )
	{
		this.data = data;
		this.pages = data;
	}
	
	
	var clazz = "com.zero42.galleryAdmin.model.PageProxy::";
	
		
	PageProxy.prototype.getPagesByTag=function( tag ) 
	{
		if (!tag) throw new Error(clazz+"getPagesByTag no tag passed");
		
		var assignedPages = new Array();
		
		for ( var i = 0; i < this.pages.length; i++)
		{
			var page = this.pages[i];
			tagLoop :
			for (var j = 0; j < page.tags.length; j++)
			{
				if (page.tags[j] == tag.id)
				{
					assignedPages.push(page);
					break tagLoop;
				}
			}
		}
		
		return assignedPages;
	};
		
				
	PageProxy.prototype.getAllUniqueTags=function()
	{
		var allTags = new Array();
		
		for ( var i = 0; i < this.pages.length; i++)
		{
			var page = this.pages[i];
			
			for (var j = 0; j < page.tags.length; j++)
			{
				var tag = page.tags[j];
				if ( allTags.indexOf(tag) == -1 )
				{
					allTags.push(tag);
				}
			}
			
		}
		 
		allTags.sort();
		
		return allTags;
	};
		
			
	
}());
(function()
{
	com.zero42.util.registerClass("com.zero42.galleryAdmin.model", "PhotographerProxy", PhotographerProxy);
	
	function PhotographerProxy( data )
	{
		this.data = data;
		this.photographers = data;
	}
				
	var clazz = "com.zero42.galleryAdmin.model.PhotographerProxy::";
		
		
	PhotographerProxy.prototype.getItemById=function( id)
	{
		if (!id) throw new Error(clazz+"getItemById no id specificed");
		
		for ( var i=0; i<this.photographers.length; i++ )
		{
			if ( this.photographers[i].id == id ) {
				return this.photographers[i];
			}
		}
		
		return null;
	};
		
	PhotographerProxy.prototype.getPhotographerByName=function( name, caseSensitive )
	{
		if (!name) throw new Error(clazz+"getPhotographerByName no name specificed");
		
		
		var res;
		
		if (caseSensitive===null)
			caseSensitive=false;
			
		for ( var i=0; i<this.photographers.length; i++ )
		{
			if (caseSensitive)
				res = (this.photographers[i].value == name);
			else
				res = (this.photographers[i].value.toLowerCase() == name.toLocaleLowerCase());
				
			if ( res )
				return this.photographers[i];
		}
		
		return null;
		
	};
		
	PhotographerProxy.prototype.getPhotographersByTag=function( tag)
	{
		if (!tag) throw new Error(clazz+"getPhotographersByTag no tag specificed");
		
		
		var assignedPhotographers = new Array();
		
		for ( var i = 0; i < this.photographers.length; i++)
		{
			var photographer = this.photographers[i];
			tagLoop :
			for (var j = 0; j < photographer.tags.length; j++)
			{
				if (photographer.tags[j] == tag.id)
				{
					assignedPhotographers.push(photographer);
					break tagLoop;
				}
			}
		}
		
		return assignedPhotographers;	
	};
	
		
		
	
}());

(function()
{
	com.zero42.util.registerClass("com.zero42.galleryAdmin.model", "TagsProxy", TagsProxy);
	
	
	function TagsProxy( data )
	{
		this.data = data;
		this.tags = data;
	}
		
	var clazz = "com.zero42.galleryAdmin.model.TagsProxy::";
		
		
	TagsProxy.prototype.getItemTags=function(item)
	{
		if(!item) throw new Error(clazz+"getItemTags no item specified");
		
		var itemTags = new Array();
		var tagIds = item.tags;
		
		for ( var i = 0; i < this.tags.length; i++)
		{
			var tag= this.tags[i];
			
			for ( var j = 0; j < tagIds.length; j++)
			{
				if (tagIds[j] == tag.id)
				{
					itemTags.push(tag);
				}
			}
		}
		
		itemTags.sort();
		
		return itemTags;
	};
		
	TagsProxy.prototype.getItemTagIndex=function(item, tag)
	{
		if(!item) throw new Error(clazz+"getItemTagIndex no item specified");
		if(!tag) throw new Error(clazz+"getItemTagIndex no tag specified");
		
		if (item.tags)
		{
			var itemTags = item.tags;
		
			if (itemTags != null)
			{
				for (var i = 0; i < itemTags.length; i++)
				{
					if (itemTags[i] == tag.id)
						return i;
				}
			}
		}
		
		return -1;
	};
		
		
		
	TagsProxy.prototype.itemHasTag=function(item, tag)
	{
		if(!item) throw new Error(clazz+"itemHasTag no item specified");
		if(!tag) throw new Error(clazz+"itemHasTag no tag specified");
		
		
		if (item.tags)
		{
			var itemTags = item.tags;
		
			if (itemTags != null)
			{
				for (var i = 0; i < itemTags.length; i++)
				{
					if (itemTags[i] == tag.id)
						return true;
				}
			}
		}	
		return false;
	};
		
		
		
		
	TagsProxy.prototype.getTagByLabel=function( label )
	{
		if(!label) throw new Error(clazz+"getTagByLabel no label specified");
		
		
		for ( var i = 0; i < this.tags.length; i++)
		{
			var tag = this.tags[i];
			
			if (tag.label.toLowerCase() == label.toLowerCase())
				return tag;
		}
		
		return null;
	};
		
		
	
}());
(function()
{
	com.zero42.util.registerClass("com.zero42.galleryAdmin.model.vo", "GalleryVO", GalleryVO);
	
	
		function GalleryVO ( id, name, description, images, tags, other1, other2, other3)
		{
			this.id = parseInt(id) || 0;
			
			this.name = name || "";
			this.description = description || "";
			this.tags =  tags || [];
			this.images = images || [];
			this.other1 = other1 || "";
			this.other2 = other2 || "";
			this.other3 = other3 || "";
			
			
			this.value = this.name || "untitled gallery " + this.id;
			this.label = this.value;
			this.isValid =  !isNaN(this.id) && this.name != '';
		}
		
		
		GalleryVO.prototype.toString=function()
		{
			return this.value;
		};
	
}());
(function()
{
	com.zero42.util.registerClass("com.zero42.galleryAdmin.model.vo", "GASDataVO", GASDataVO);
	
		
		function GASDataVO( galleries, photographers, images, tags, pages) 
		{
			this.galleries = galleries || new Array();
			this.photographers = photographers || new Array();
			this.images = images || new Array();
			this.tags = tags || new Array();
			this.pages = pages || new Array();
			
		}
		
	
	
}());
(function()
{
	com.zero42.util.registerClass("com.zero42.galleryAdmin.model.vo", "ImageVO", ImageVO);
		
		ImageVO.prototype.width=null;
		ImageVO.prototype.height=null;
		ImageVO.prototype.mime="";
		
		
		
		function ImageVO ( id, src, thumb, photographerID, title, caption, date, location, tags, other1, other2, other3 )
		{
			this.id = parseInt(id) || 0;
			this.src = src || "";
			this.thumb = thumb || "";
			this.photographerID = parseInt(photographerID);
			this.title = title || "";
			this.caption = caption || "";
			this.date = date || null;
			this.location = location || "";
			this.tags  =  tags || [];
			this.other1 = other1 || "";
			this.other2 = other2 || "";
			this.other3 = other3 || "";
			
			this.value= this.title;
			this.label = this.value;
			
			this.isValid = !isNaN(this.id) && this.src!='';	
			
		}
		
		ImageVO.prototype.toString=function()
		{
			return this.value;
		};
		
		ImageVO.prototype.isVideo=function()
		{
			switch(this.mime)
			{
				case "image/jpeg" :
				case "image/png" :
				case "image/gif" :
					return false;
				break;
			}
				
			return true;
			
		};
		
		ImageVO.prototype.toHTMLString=function()
		{
			var htmlString = "";
			var vidId="video_"+this.id;
			
			switch(this.mime)
			{
				case "video/x-flv" :
				
					htmlString = "<object id=\""+vidId+"\" type=\"application/x-shockwave-flash\" data=\"flvPlayer.swf?video="+this.src+"\" width=\"100%\" height=\"100%\">";
					htmlString +=	"<param name=\"menu\" value=\"false\">";
					htmlString += 	"<param name=\"scale\" value=\"noScale\">";
					htmlString +=	"<param name=\"allowFullscreen\" value=\"true\">";
					htmlString +=	"<param name=\"allowScriptAccess\" value=\"always\">";
					htmlString +=	"<param name=\"bgcolor\" value=\"#FFFFFF\">";
					htmlString += 	"<embed href=\"flvPlayer.swf?video="+this.src+"\" scale=\"noScale\" quality=\"high\" bgcolor=\"#FFFFFF\" width=\"100%\" height=\"100%\" name=\""+vidId+"\"  type=\"application/x-shockwave-flash\" pluginspage=\"http://www.macromedia.com/go/getflashplayer\"></embed>";
					htmlString +=	"</object>";
					
					return htmlString;
					
				break;
				
				case "video/quicktime" :
				case "video/mpeg"	   :
				case "video/mpg"	   :
				case "video/mp4"	   :
					
					
					htmlString = "<object id=\""+vidId+"\" classid=\"clsid:02BF25D5-8C17-4B23-BC80-D3488ABDDC6B\" codebase=\"http://www.apple.com/qtactivex/qtplugin.cab\" height=\"100%\" width=\"100%\">";
					htmlString += "	<param name=\"src\" value=\""+this.src+"\">";
					htmlString += "	<param name=\"autoplay\" value=\"false\">";
					htmlString += "	<param name=\"type\" value=\""+this.mime+"\" height=\"100%\" width=\"100%\">";
					htmlString += "	<embed name=\""+vidId+"\" src=\""+this.src+"\" height=\"100%\" width=\"100%\" autoplay=\"false\" type=\""+this.mime+"\" pluginspage=\"http://www.apple.com/quicktime/download/\"></embed>";
					htmlString +=  "</object>";
				
				break;
				
				case "video/x-msvideo" :
				case "video/msvideo" :
					
					htmlString = "<object id=\""+vidId+"\"  CLASSID=\"CLSID:22d6f312-b0f6-11d0-94ab-0080c74c7e95\" codebase=\"http://activex.microsoft.com/activex/controls/mplayer/en/nsmp2inf.cab#Version=5,1,52,701\" standby=\"Loading Microsoft Windows® Media Player components...\" type=\"application/x-oleobject\" width=\"100%\" height=\"100%\">";
					htmlString += "	<param name=\"fileName\" value=\""+this.src+"\"/>";
					htmlString += "	<param name=\"animationatStart\" value=\"true\"/>";
					htmlString += "	<param name=\"transparentatStart\" value=\"true\"/>";
					htmlString += "	<param name=\"autoStart\" value=\"false\"/>";
					htmlString += "	<param name=\"showControls\" value=\"true\"/>";
					htmlString += "	<embed type=\"application/x-mplayer2\" pluginspage=\"http://www.microsoft.com/Windows/MediaPlayer/\" src=\""+this.src+"\" name=\""+vidId+"\" width=\"100%\" height=\"100%\" autostart=0 showcontrols=1></embed>";
					htmlString += "</object>";
									
				break;
				
				default :
				
					htmlString = "<img id=\"img_"+this.id+"\" src='" + this.src + "' width="+ this.width +" height="+ this.height +" alt="+ this.title +" />";
				
				break;
				
			};
			
			return htmlString; 
		};
		
		ImageVO.prototype.toHTMLElement=function()
		{
			var div = document.createElement('div');
			div.innerHTML = this.toHTMLString();
			return div.firstChild;
		}
		
		
	
}());	
(function()
{
	com.zero42.util.registerClass("com.zero42.galleryAdmin.model.vo", "PageVO", PageVO);
	
		function PageVO ( id, title, body, images, tags, other1, other2, other3 )
		{
			this.id = parseInt(id) || 0;
			
			this.title = title || "";
			this.body = body || "";
			this.images =  images || [];
			this.tags =  tags || [];
			this.other1 = other1 || "";
			this.other2 = other2 || "";
			this.other3 = other3 || "";
			
			this.label = this.value;
			this.value = this.title || "untitled page " + this.id;
			
			this.isValid= !isNaN(this.id) && this.title != '';
			
		}
		
		
		PageVO.prototype.toString=function()
		{
			return this.value;
		};
	
}());

(function()
{
	com.zero42.util.registerClass("com.zero42.galleryAdmin.model.vo", "PhotographerVO", PhotographerVO);
	
	
	function PhotographerVO ( id, fname, lname, email, link, description, tags, other1, other2, other3, images)
	{
		this.id = parseInt(id) || 0;
		this.fname = fname || '';
		this.lname = lname || '';
		this.email = email || '';
		this.link = link || '';
		this.description = description || '';
		this.tags =  tags || [];
		this.other1 = other1 || '';
		this.other2 = other2 || '';
		this.other3 = other3 || '';
		
		this.value = this.fname+' '+this.lname;
		this.label = this.value;
		
		this.isValid=!isNaN(id) && this.fname != '' && this.lname != '';
		
		this.images = images || [];
		
	}
			
	PhotographerVO.prototype.toString=function()
	{
		return this.value;
	};


}());

(function()
{
	com.zero42.util.registerClass("com.zero42.galleryAdmin.model.vo", "TagVO", TagVO);
	
	
	function TagVO( id, label)
	{
		this.id = parseInt(id);
		this.label = label;
		this.value = label;
		
		this.isValid = !isNaN(this.id) && this.label!='';
	}
		
	
	TagVO.prototype.toString=function()
	{
		return this.label;
	};
	
	
	
}());

