var Gallery = {
	
	// Dom Object
	imageFull : null,
	title : null,
	divContent : null,
	spanDisplay : null, 
	
	// Base Path for this hotel
	basePath : null,
	
	// Current Gallery, Current Image
	cg : [0,0],
	
	isQtvr : false,
	
	// Detect QuickTime
	asQtvr : false,

	// Init the Dom Object
	init : function() {
		this.title = document.getElementById("image-title");
		this.imageFull = document.getElementById("image-full");
		this.divContent = document.getElementById("gallery-nav-content");
		this.display = document.getElementById("gallery-display");

		if(haveqt) this.asQtvr = haveqt;
		},

	// Set a Category	
	set : function(g) {
		if(this.isQtvr) this.setQtvr();
		
		this.cg[0] = g;
		this.cg[1] = 0;
		this.render();
		},
	
	// Next Image
	next : function() {
		var maxImages = PhotoGalleries.Category[this.cg[0]].Images.length-1;
		if(this.cg[1]+1 > maxImages) {
			var maxCategory = PhotoGalleries.Category.length-1;
			if(this.cg[0]+1 > maxCategory) {
				this.cg[0] = 0;
				this.cg[1] = 0;				
			} else {
				this.cg[0] = this.cg[0]+1;
				this.cg[1] = 0;
				}
		} else {
			this.cg[1] = this.cg[1]+1;
			}
		this.render();
		},
	
	// Previous Image
	previous : function() {
		if(this.cg[1]-1 < 0) {
			if(this.cg[0]-1 < 0) {
				this.cg[0] = PhotoGalleries.Category.length-1;
				this.cg[1] = PhotoGalleries.Category[this.cg[0]].Images.length-1;				
			} else {
				this.cg[0] = this.cg[0]-1;
				this.cg[1] = PhotoGalleries.Category[this.cg[0]].Images.length-1;
				}
		} else {
			this.cg[1] = this.cg[1]-1;
			}
		this.render();
		},
		
	// Render the current Image
	render : function() {
		
		var elementID = PhotoGalleries.Category[this.cg[0]].Images[this.cg[1]].Title;
    	var elementCategory = PhotoGalleries.Category[this.cg[0]].Name;
    	COREMETRICS.utils.cmCreatePageElementTag(escape(elementID),escape(elementCategory),COREMETRICS.tagging.pageName,COREMETRICS.tagging.categoryID,null);
		
		this.title.innerHTML = PhotoGalleries.Category[this.cg[0]].Images[this.cg[1]].Title;
		
		setTimeout("Gallery.imageFull.src = Gallery.basePath + PhotoGalleries.Category[Gallery.cg[0]].Images[Gallery.cg[1]].ImageUrl;",100);
		this.imageFull.alt = PhotoGalleries.Category[this.cg[0]].Images[this.cg[1]].ImageAlternateText;
		
		if(PhotoGalleries.Category[this.cg[0]].VirtualTourUrl) {
			this.divContent.className = "vr";
		} else { 
			this.divContent.className = "";
			}	
		},

	
		
	setQtvr : function() {
		if(this.isQtvr) {
			this.divContent.className = "vr";
			this.display.innerHTML = "<img id='image-full' />";
			this.isQtvr = false;
			this.init();
			this.render();
			
			YAHOO.util.Event.removeListener('checkAvailability', 'click', Gallery.resetQtvr);
			
		} else {
    		var elementID = PhotoGalleries.Category[this.cg[0]].Images[this.cg[1]].Title;
    		var elementCategory = PhotoGalleries.Category[this.cg[0]].Name;
    		COREMETRICS.utils.cmCreatePageElementTag(escape(elementID),escape(elementCategory),COREMETRICS.tagging.pageName,COREMETRICS.tagging.categoryID,null);
			this.divContent.className = "tour";
			if(this.asQtvr) {
				this.display.innerHTML = '<embed width="581" height="387" controller="false" target="myself" '
					+ 'src="' + Gallery.basePath + PhotoGalleries.Category[this.cg[0]].VirtualTourUrl +'" '
					+ 'bgcolor="ffffff" border="0" pluginspage="http://www.apple.com/quicktime/download/"></embed>';
			} else {
				if(Culture == 'fr') this.display.innerHTML = '<p class="error">Vous devez installer la derni&egrave;re version du plugiciel Quicktime pour appr&eacute;cier pleinement votre exp&eacute;rience sur loewshotels.com. <a href="http://www.apple.com/ca/fr/quicktime/download/win.html" target="_blank">Cliquez ici</a> pour t&eacute;l&eacute;charger Quicktime.<p>';
				else  this.display.innerHTML = '<p class="error">You need the latest Quicktime plug-in to fully experience loewshotels.com. <a href="http://www.apple.com/quicktime/download/win.html" target="_blank">Click here</a> to download it.<p>';
				}
			this.isQtvr = true;				
			YAHOO.util.Event.on('checkAvailability', 'click', Gallery.resetQtvr, Gallery, true);
			}
		},
		
	resetQtvr : function() {
		Gallery.setQtvr();
		}

	}
	
YAHOO.util.Event.addListener(window, "load", Gallery.init, Gallery, true);