function imagePoster(parentDivName) {

	var mySelf = this;

	this.parentDivName = parentDivName;
	this.addImageDiv = null;
	this.addImageIframe = null;
	this.addAlbumDiv = null;

	//public functions
	//----------------------------------
	this.addAlbum = addAlbum;
	this.addMedia = addMedia;
	this.uploadPhoto = uploadPhoto;
	this.postAlbum = postAlbum;
	this.closeDiv = closeDiv;
	//----------------------------------

	function addAlbum() {	    if (mySelf.addAlbumDiv == null) {
	    	contentDiv = document.getElementById(mySelf.parentDivName);
	        mySelf.addAlbumDiv = createPopupDiv(document.body.offsetWidth/2 - 150, 100, 300, 320);
	        document.body.appendChild(mySelf.addAlbumDiv);
	        addPhpToDiv(mySelf.addAlbumDiv, 'includes/ajaxPages/addAlbum.php', true);
	        fadePageOn();
	    }

	}

	//shows an addImage box with a text and url box.
	//if the writeDiv has selected text, then this text goes into the "text" textfield
	function addMedia() {
	    if (mySelf.addImageDiv == null) {
	    	contentDiv = document.getElementById(mySelf.parentDivName);
	        mySelf.addImageDiv = createPopupDiv(document.body.offsetWidth/2 - 150, 100, 300, 160);
	        document.body.appendChild(mySelf.addImageDiv);

		this.addImageIframe = document.createElement('iframe');
	        this.addImageIframe.src = 'includes/ajaxPages/addPhoto.php';
	        this.addImageIframe.id = 'imageIframe';
	        this.addImageIframe.scrolling = "NO";
	        this.addImageIframe.frameBorder = "0";
	        this.addImageIframe.width = "300";
	        this.addImageIframe.height = "160";
	        mySelf.addImageDiv.appendChild(this.addImageIframe);
	        var errorDiv = document.createElement('div');
	        errorDiv.id = "addImageErrorDiv";
	        errorDiv.className = "errorDiv";
	        mySelf.addImageDiv.appendChild(errorDiv);
	        fadePageOn();
	    }
	}

	function uploadPhoto() {
		var file = document.getElementById('ifile');
   		var iframe = this.addImageIframe;
		iframe.contentDocument.getElementById('iform').submit();
		albumIndex = iframe.contentDocument.getElementById('iform').album.value;
		addPhpToDiv(document.getElementById('content'), '../../includes/photosPage.php?album=' + albumIndex, true);
	}

	function postAlbum(id, albumName, descriptionText, allowComments) {
		var query = "../includes/submits/albumSubmit.php";

		var poststr = albumName+"=" + encodeURI( document.getElementById(albumName).value )+"&"+descriptionText+"=" + encodeURI( document.getElementById(descriptionText).value )+"&"+allowComments+"=" + encodeURI( document.getElementById(allowComments).value );
		if (id != "")
			poststr +=  "&id=" + encodeURI(id);
		var successFunction = function() {
			fadePageOff();
			showPhotos(new Object());
		};
		submitToPhp(query, document.getElementById('addAlbumErrorDiv'), successFunction, poststr);

	}


	function closeDiv() {
	    if (mySelf.addImageDiv != null) {
	        document.body.removeChild(mySelf.addImageDiv);
	        mySelf.addImageDiv = null;
	        fadePageOff();
	    }
	    else if (mySelf.addAlbumDiv != null) {
	        document.body.removeChild(mySelf.addAlbumDiv);
	        mySelf.addAlbumDiv = null;
	        fadePageOff();
	    }
	}

}
