function ImageClass() {
	this.holder;
	this.img;
	this.p;
	
	this.construct();
	
	return (this);
}

ImageClass.prototype.construct = function () {
	this.holder = document.createElement('div');
	this.holder.id = "scene_image";
	this.img = document.createElement('img');
	this.p = document.createElement('p');
	this.holder.appendChild(this.img);
	this.holder.appendChild(this.p);
}

function SceneClass() {
	var parent;

	var image;
	var video;
	var slideshow;

	this.id;
	var loading;

	var xmlHttp;
	var xmlDoc;

	var comments;
	
	this.construct();

	return (this);
}

SceneClass.prototype.construct = function () {
	this.parent = objId('viewable');
	this.comments = new Comments(objId('comments_list'),'scene');
	this.loading = new LoadingClass();
}

SceneClass.prototype.updateXML = function () {
	
	xmlHttp = GetXmlHttpObject();
	var url = urlc+"?id="+this.id;

	xmlHttp.open("GET",url,false);
	xmlHttp.send(null);
	
	xmlDoc = xmlHttp.responseXML;
}
	
SceneClass.prototype.displayItem = function (id_) {
	var this_ = this;
	this.id = id_;
	
	var scene_header = objId('scene_header');
	scene_header.style.visibility = "hidden";
	
	this.xmlHttp = GetXmlHttpObject();
	var url = urlc+"?id="+this.id;

	this.xmlHttp.open("GET",url,true);
	this.xmlHttp.onreadystatechange = function () { this_.displayingItem(); };
	this.xmlHttp.send(null);
	
	//this.loading.set();  // append the Loading message to the element
	this.parent.appendChild(this.loading.element);
}

SceneClass.prototype.displayingItem = function () {
	if (this.xmlHttp.readyState == 4) {
		
		//this.loading.remove();  // remove the Loading message
		this.parent.removeChild(this.loading.element);
		//alert(this.xmlHttp.responseText);
		this.xmlDoc = this.xmlHttp.responseXML;	

		var scene_header = objId('scene_header');
		scene_header.style.visibility = "";
	
		/* Set Scene Header Information **/
		var scene_title = this.xmlDoc.getElementsByTagName('title')[0].childNodes[0].nodeValue;
		var scene_submitterId = this.xmlDoc.getElementsByTagName('submitterId');
		var scene_submitterName = this.xmlDoc.getElementsByTagName('submitterName');
		var scene_submitterCity = this.xmlDoc.getElementsByTagName('submitterCity');
		var scene_submitterProvince = this.xmlDoc.getElementsByTagName('submitterProvince');
		var scene_submitDate = this.xmlDoc.getElementsByTagName('submitDate');
		var scene_likedthis = this.xmlDoc.getElementsByTagName('votes')[0].childNodes[0].nodeValue;
				
		var image_info = objId('image_info');
		image_info.innerHTML = "<h3>"+scene_title+"</h3>";
		image_info.innerHTML += "<p class=\"credit\">";
		 
		try { image_info.innerHTML += "<span class=\"province_abbr\">"+scene_submitterProvince[0].childNodes[0].nodeValue+"</span> "; } catch(err) {}
		try { image_info.innerHTML += "<a href=\""+urlp+"?id="+scene_submitterId[0].childNodes[0].nodeValue+"\">"+scene_submitterName[0].childNodes[0].nodeValue+"</a>";
			try { image_info.innerHTML += " "+fromm+" "+scene_submitterCity[0].childNodes[0].nodeValue; } catch(err) {}
			try { image_info.innerHTML += ", "+scene_submitDate[0].childNodes[0].nodeValue; } catch(err) {}
		} catch(err) {}
		image_info.innerHTML += "</p>";
		
		
		this.ilikethis_msg(scene_likedthis);
		
		var button = objId('ilikethis_vote');
		button.style.display = "";
		
		/* Show comments */
		//build comments
		var comments_xml = this.xmlDoc.getElementsByTagName('comment');
		this.comments.id = this.id;
		this.comments.commentsXML = comments_xml;
		this.comments.show_comments(true);
		
		var f = objId('comment_form');
		if (f != null) {
			f.style.display = "";
		}
		
		/* Set Scene for Image/Video/Slideshow */
		var scene_type = this.xmlDoc.getElementsByTagName('type')[0].childNodes[0].nodeValue;

		if (this.parent.firstChild != null) {
			this.parent.removeChild(this.parent.firstChild); // remove current scene item from the viewable space
		}
		
		if (scene_type == "image") {
			this.setImage(this.xmlDoc);
		}
		else if (scene_type == "video") {
			this.setVideo(this.xmlDoc);
		}
		else if (scene_type == "slideshow") {
			this.setSlideshow(this.xmlDoc);
		}
		//this.parent.style.height = "auto";
	}
}

SceneClass.prototype.setImage = function (xmlDoc) {
	if (this.image == null) {
		this.image = new ImageClass();
	}
	
	var scene_id = xmlDoc.getElementsByTagName('image')[0].getElementsByTagName('id')[0].childNodes[0].nodeValue;
	this.image.img.src = mediapath+"?id="+scene_id+"&maxImgHeight=590&maxImgWidth=320";
	this.image.img.alt = xmlDoc.getElementsByTagName('title')[0].childNodes[0].nodeValue;

	var scene_caption = xmlDoc.getElementsByTagName('caption');
	try { this.image.p.innerHTML = scene_caption[0].childNodes[0].nodeValue; } catch(err) { this.image.p.innerHTML = "&nbsp;" }

	this.parent.appendChild(this.image.holder);
}	

SceneClass.prototype.setSlideshow = function (xmlDoc) {
	if (this.slideshow == null) {
		this.slideshow = new SlideShowClass();
	}
	
	this.parent.appendChild(this.slideshow.getPointer());
	this.slideshow.set(xmlDoc);
}

SceneClass.prototype.getSlideshow = function () {
	return this.slideshow;
}

SceneClass.prototype.setVideo = function (xmlDoc) {
	var video = xmlDoc.getElementsByTagName('video');
	
	var frontvideo = document.createElement('div');
	frontvideo.setAttribute('class','front_video');
	var version = deconcept.SWFObjectUtil.getPlayerVersion();
	if (version['major'] >= 8) { 
		var vid_id = video.item(0).getElementsByTagName("id").item(0).firstChild.nodeValue;
		var vid_caption = (video[0].getElementsByTagName('caption').item(0).firstChild)? (video[0].getElementsByTagName('caption').item(0).firstChild.nodeValue): "";
		frontvideo.innerHTML = this.showVid(vid_id, vid_caption);
	} else {
		var frontvideoText = document.createTextNode('You need the most current Flash Player to watch this movie');
		frontvideo.appendChild(frontvideoText);
	}
	this.parent.appendChild(frontvideo);
	
}

SceneClass.prototype.showVid = function (vidId, vidcap) {
	var moviewidth = 327;
	var movieheight = 293;
	var objinnerhtml = '<object width="'+moviewidth+'" height="'+movieheight+'" codeBase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab" classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000"><param name="movie" value="'+ hiplayer +'" /><param name="loop" value="false" /><param name="quality" value="high" /><param name="bgcolor" value="#333333" /><param name="scale" value="noborder" /><param name="wmode" value="transparent" /><param name="FlashVars" value="moviePath='+mediapath+'?id='+vidId+'&conn_msg='+connmsg+'" /><embed src="'+ hiplayer +'" loop="false" bgcolor="#333333" width="'+ moviewidth +'" height="'+ movieheight +'" align="middle" allowScriptAccess="sameDomain" type="application/x-shockwave-flash" pluginspage="http://www.macromedia.com/go/getflashplayer" FlashVars="moviePath='+mediapath+'?id='+vidId+'&conn_msg='+connmsg+'" play="false" menu="false" quality="high" scale="noborder" wmode="transparent" /></object>';
	if (vidcap != null){
		objinnerhtml = objinnerhtml + '<div class="videocaption">'+vidcap+'</div>';
	}
	return objinnerhtml;
}

SceneClass.prototype.submit_comment = function (f) {
	return this.comments.comment_submit(f);
}

SceneClass.prototype.vote = function () {
	var this_ = this;
	var poststr = "id="+this.id;

	this.xmlHttp = GetXmlHttpObject();
	var url = urlvote; // global

	this.xmlHttp.open("POST",url,true);
	this.xmlHttp.onreadystatechange = function () { this_.voted(); };
	this.xmlHttp.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
	this.xmlHttp.setRequestHeader("Content-length", poststr.length);
	this.xmlHttp.setRequestHeader("Connection", "close");
	this.xmlHttp.send(poststr);
}

SceneClass.prototype.voted = function () {
	if (this.xmlHttp.readyState == 4) {
		var button = objId('ilikethis_vote');
		button.style.display = "none";
		
		var xmlDoc2 = this.xmlHttp.responseXML;
		this.ilikethis_msg(xmlDoc2.getElementsByTagName('votes')[0].childNodes[0].nodeValue);
	}
}

SceneClass.prototype.ilikethis_msg = function (votes) {
	var likedthis = objId('likedthis');
	if (votes == 1) {
		likedthis.innerHTML = "<strong>" + votes + "</strong> "+personlike;
	}
	else if (votes > 1) {
		likedthis.innerHTML = "<strong>" + votes + "</strong> "+peoplelike;
	}
	else {
		likedthis.innerHTML = "";
	}
}
