var roomList = new Array();

var new_r,dcg_r, dcg_l,loading, dc_gallery, dc_static;

var rooms,content;


//cmuList Structure===================

//cmuList[CODE] = Marketing Name


function init(){
	rooms = getById("rooms");
	dc_static = getById("dc_static");
	dc_gallery = getById("dc_gallery");
	content = getById("content");
	loading = new Image();
	loading.src = "/images/loading.gif";
	renderRooms();	
}

function renderRooms(){
	var newrm = document.createElement("div");
	newrm.id = "rooms";
	
	var rm;
	for (var i=0; i<roomList.length; i++){
		rm = htmlTag("div","<div class='title'>"+roomList[i][0]+"</div><img alt='"+roomList[i][0]+"' src='"+roomList[i][1][0][0]+"'  />");
		rm.className = "rm_holder";
		rm.index = i;
		rm.onmousedown = function(){
			showRoom(this.index);
		}
		newrm.appendChild(rm);
	}
	content.replaceChild(newrm,rooms);
	rooms = getById("rooms");
}

function showRoom(index){
	if (index >= roomList.length)
		index = 0;
	else if (index < 0)
		index = roomList.length - 1;
		
	dc_gallery.style.display = "block";
	dc_static.style.display = "none";
	var new_l = document.createElement("div");
	new_l.id = "dcg_left";
	
	try{
		dcg_l = getById("dcg_left");
	}
	catch(e){
		dcg_l = document.createElement("div");
		dc_gallery.appendChild(dcg_l);
	}
	
	//left content
	var rmt,nrm,prm;
	nrm = htmlTag("a","");
	nrm.className = "right_arrow";
	nrm.href = "javascript:showRoom("+(index+1)+")";

	prm = htmlTag("a","");
	prm.className = "left_arrow";
	prm.href = "javascript:showRoom("+(index-1)+")";

	rmt = htmlTag("h2", roomList[index][0]);
	rmt.className = "centered";
	new_l.appendChild(prm);
	new_l.appendChild(nrm);
	new_l.appendChild(rmt);
	
	var cls = htmlTag("div","<a href='javascript:closeDCG();'>Close Room Gallery</a>");
	cls.className = "dcg_close";
	new_l.appendChild(cls);
	var rm,cl;
	for (var i=0; i<roomList[index][1].length; i++){
		rm = document.createElement("img");
		rm.title = roomList[index][1][i][2];
		rm.src=roomList[index][1][i][0];
		rm.width = 86;
		rm.rmNum = index;
		rm.imgNum = i;
		rm.onmousedown = function(){
			setRmImage(this.rmNum, this.imgNum);
		}
		new_l.appendChild(rm);
		if ((i+1)%3 == 0){
			cl=document.createElement("div");
			cl.className="clearer";
			new_l.appendChild(cl);
		}
	}
	//right content
	setRmImage(index,0);
	
	dc_gallery.replaceChild(new_l,dcg_l);
}

function closeDCG(){
	dc_static.style.display = "block";
	dc_gallery.style.display = "none";
}


function setRmImage(index, num){
	if (num >= roomList[index][1].length)
		num = 0;
	else if (num < 0)
		num = roomList[index][1].length - 1;
	
	new_r = document.createElement("div");
	new_r.id = "dcg_right";
	
	try{
		dcg_r = getById("dcg_right");
	}
	catch(e){
		dcg_r = document.createElement("div");
		dc_gallery.appendChild(dcg_r);
	}
	//right
	var nfpi,pfpi,fpc,fpi,fpt;
	nfpi = htmlTag("a","");
	nfpi.className = "right_arrow";
	nfpi.href = "javascript:setRmImage("+index+","+(num+1)+")";

	pfpi = htmlTag("a","");
	pfpi.className = "left_arrow";
	pfpi.href = "javascript:setRmImage("+index+","+(num-1)+")";


	fpc = htmlTag("div","");
	fpc.className="clearer";
	
	//image.src = "http://getmarquis.dreesteam.com/jsp/cachedImageView.do?key=docid::"+homesList[index][5][num][0];
	
	fpi = htmlTag("div","<img id='rm_image' width='425' src='"+roomList[index][1][num][1]+"' />");
	fpi.id = "image_holder";
	
	fpt = htmlTag("h3",roomList[index][1][num][2]);
	fpt.className = "centered";
	
	new_r.appendChild(fpc);
	new_r.appendChild(fpi);
	new_r.appendChild(nfpi);
	new_r.appendChild(pfpi);
	new_r.appendChild(fpt);
	
	//setTimeout("chkImageLoaded("+index+","+num+")",100);
	dc_gallery.replaceChild(new_r,dcg_r);
}
