// holder object for one profile
function Profile(imageTag, boxText1, boxText2, boxText3) {
	this.imageTag = imageTag;
	this.boxText1 = boxText1;
	this.boxText2 = boxText2;
	this.boxText3 = boxText3;
}

// holder object for one profile hotspot
function ProfileHotspot(number, link, imageTag) {
	this.number = number;		   
	this.link = link;	
	this.imageTag = imageTag;
}


// controller for a random profile
function ProfileController(parNum) {

	// list of all hotspots
	this.hotspotList = new Array();

	// list of all profiles
	this.profileList = new Array();
	
	// hotspot template
	this.hotspotTemplate = new Template('<div class="profile_link#{number}"><a href="#{link}">#{imageTag}</a></div>');

	// get main container that contains all the profile stuff)
	this.profileContainer = $("profileContainer_"+parNum);

	// get corresponding div element where the profile image shall be displayed
	this.imgContainer = $("profileimageContainer_"+parNum);

	// get div elements where the box texts shall be displayed
	this.boxContainer1 = $("profilebox1_"+parNum);
	this.boxContainer2 = $("profilebox2_"+parNum);
	this.boxContainer3 = $("profilebox3_"+parNum);

	// add one hotspot to the list
	this.addHotspot = function(hotspot) {
		this.hotspotList.push(hotspot);
	}

	// add one profile to the list
	this.addProfile = function(profile) {
		this.profileList.push(profile);
	}
	
	// choose a random profile and update the corresponding tags
	this.randomize = function() {

		// get a random profile number
		var randomProfileNumber = this.getRandomProfileNumber();

		// set the box texts for the randomly chosen profile
		this.boxContainer1.update(this.profileList[randomProfileNumber].boxText1);
		this.boxContainer2.update(this.profileList[randomProfileNumber].boxText2);
		this.boxContainer3.update(this.profileList[randomProfileNumber].boxText3);

		// create the real image tag using the template and one randomly chosen profile from the profileList
		var imgTag = this.profileList[randomProfileNumber].imageTag;

		// display the image
		this.imgContainer.update(imgTag);

		// add profile class to image
		this.imgContainer.firstDescendant().addClassName("profile_img");

		// add hotspots, if hotspots are enabled
		if (this.hotspotList.size() > 0) {

			// loop all hotspots, use template to create hotspot div and add the div
			this.hotspotList.each( function(hotspot) {
				this.profileContainer.insert(this.hotspotTemplate.evaluate(hotspot), {position: "bottom" });
			}, this);

		}

	}
	
	// returns the index of the profile to be displayed
	// (a number between 0 and imageList.length-1)
	this.getRandomProfileNumber = function() {
		return Math.floor(Math.random()*this.profileList.size());
	}

}
