function UberProfile(hWin, user){
	this.hWin = hWin; //handle of window to draw in
	this.user = user; //user object to get data from
	this.rating = null;
	this.sendToFriend = true; //set to false if profile is being shown to anonymous user
}
	
UberProfile.prototype.starsigns = new Array("", "Capricorn", "Aquarius", "Pisces", "Aries", "Taurus", "Gemini", "Cancer", "Leo", "Virgo", "Libra", "Scorpio", "Sagittarius");
UberProfile.prototype.bodyTypes = new Array("", "I'm sleek and slim", "I'm just right", "I'm beefed up", "I'm supersized", "I'm all curves", "I'm a double scoop");
UberProfile.prototype.rStatus = new Array("", "I'm single, not desperate", "I want to fool around", "I can look but can't touch", "I'm on the rebound");
UberProfile.prototype.hair = new Array("", "I have brown hair", "I have blonde hair", "I have black hair", "I have red hair", "I have grey hair", "I have coloured hair", "I have no hair", "I have hair all over");
UberProfile.prototype.eyes = new Array("", "I have brown eyes", "I have blue eyes", "I have green eyes", "I have black eyes", "I have grey eyes", null, null, "I have deep eyes", "I have wandering eyes", "I have bloodshot eyes", "I have starry eyes");
UberProfile.prototype.flirting = new Array("", "I am up for light flirting", "I want someone to hold", "I'm up for anything");
UberProfile.prototype.positions = new Array("", "I like it on all fours", "I like wearing high heels", "I like it before breakfast", "I like it with friends", "I like it on a train", "I like taking my time", "I like unbuttoning", "I like being on top", "I like leaving room for dessert");
	
UberProfile.prototype.rateFlirt = function(){
		if(this.rating != null && this.rating > 0){
			var u = 'xml/rateflirt.jsp?ghost=' + stateWindow.getSession() + '&id=' + this.user.id + '&r=' + this.rating;
			stateWindow.loadXML(u);
		} else {
			alert('Please select a rating');
		}
	}
	
UberProfile.prototype.updateRating = function(val, num){
		this.user.rating = Math.round(10*val)/10;
		this.user.ratedBy = num;
		stateWindow.cascadeUserChange(this.user, {rating: 'rating', ratedBy : 'ratedBy'});
		alert('Thank you, your rating has been recorded');
	}
	
UberProfile.prototype.drawBlockStatus = function()
	{
		var elt = this.hWin.document.getElementById("blockAction") ;
		if(!elt)return;
		switch (this.user.block)
		{
		case 1: // We blocked them
		case 3: // We blocked each other!!
			elt.innerHTML = '<A href="javascript:uberProfile.changeUberBlock()" class="FlirtActionLink"><IMG src="http://' + stateWindow.staticHost() + '/images/profile/block_icon.gif" border="0" align="absmiddle">&nbsp;<SPAN id="block"><H3><span class="FALBlock">Unblock</SPAN></H3></SPAN></A>';
			break ;
		case 2: // They blocked us
			elt.innerHTML = '<IMG src="http://' + stateWindow.staticHost() + '/images/profile/block_icon.gif" border="0" align="absmiddle">&nbsp;<SPAN id="block"><H3>Blocked</H3></SPAN>';
			break ;
		default:
			elt.innerHTML = '<A href="javascript:uberProfile.changeUberBlock()" class="FlirtActionLink"><IMG src="http://' + stateWindow.staticHost() + '/images/profile/block_icon.gif" border="0" align="absmiddle">&nbsp;<SPAN id="block"><H3>Block</H3></SPAN></A>';
			break ;
		}
	}

UberProfile.prototype.drawFavStatus = function()
	{
		var elt = this.hWin.document.getElementById('favAction');
		if(elt)
		{
			if (this.user.favourite & 1)
				elt.innerHTML = '<A class="FlirtActionLink" href="javascript:uberProfile.changeUberFav(1)"><IMG src="http://' + stateWindow.staticHost() + '/images/profile/add_fav_icon.jpg" border="0" align="absmiddle">&nbsp;<SPAN id="favourite"><H3><SPAN class="FALFavourite">Favourite!</SPAN></H3></SPAN></A>' ;
			else
				elt.innerHTML = '<A class="FlirtActionLink" href="javascript:uberProfile.changeUberFav(1)"><IMG src="http://' + stateWindow.staticHost() + '/images/profile/add_fav_icon.jpg" border="0" align="absmiddle">&nbsp;<SPAN id="favourite"><H3>Add&nbsp;favourite</H3></SPAN></A>' ;
		}
			
		elt = this.hWin.document.getElementById('priAction');
		if(elt)
		{
			if (this.user.favourite & 2)
				elt.innerHTML = '<A class="FlirtActionLink" href="javascript:uberProfile.changeUberFav(2)"><IMG src="http://' + stateWindow.staticHost() + '/images/profile/add_pri_icon.gif" border="0" align="absmiddle">&nbsp;<SPAN id="private"><H3><SPAN class="FALBackstagePass">Backstage!</SPAN></H3></SPAN></A>' ;
			else
				elt.innerHTML = '<A class="FlirtActionLink" href="javascript:uberProfile.changeUberFav(2)"><IMG src="http://' + stateWindow.staticHost() + '/images/profile/add_pri_icon.gif" border="0" align="absmiddle">&nbsp;<SPAN id="private"><H3>Invite&nbsp;backstage</H3></SPAN></A>' ;
		}
			
		elt = this.hWin.document.getElementById('alertAction');
		if(elt)
		{
			if (this.user.favourite & 4)
				elt.innerHTML = '<A class="FlirtActionLink" href="javascript:uberProfile.changeUberFav(4)"><IMG src="http://' + stateWindow.staticHost() + '/images/profile/add_alert_icon.gif" border="0" align="absmiddle">&nbsp;<SPAN id="private"><H3><SPAN class="FALBackstagePass">Alert! (remove)</SPAN></H3></SPAN></A>' ;
			else
				elt.innerHTML = '<A class="FlirtActionLink" href="javascript:uberProfile.changeUberFav(4)"><IMG src="http://' + stateWindow.staticHost() + '/images/profile/add_alert_icon.gif" border="0" align="absmiddle">&nbsp;<SPAN id="private"><H3>Alert&nbsp;Me!</H3></SPAN></A>' ;
		}
			
		elt = this.hWin.document.getElementById('buzzAction');
		if(elt)
		{
			elt.innerHTML = '<A class="FlirtActionLink" href="javascript:stateWindow.doBuzz('+this.user.id+')"><IMG src="http://' + stateWindow.staticHost() + '/images/profile/add_buzz_icon.gif" border="0" align="absmiddle">&nbsp;<SPAN id="private"><H3>BUZZ!</H3></SPAN></A>' ;
		}
	}
	
UberProfile.prototype.drawOnlineStatus = function()
	{
		var elt = this.hWin.document.getElementById("chatAction") ;
		if(elt){
			if (this.user.canChat==1 && this.user.online==3 && this.user.block==0)
			{
				elt.className = "FlirtAction" ;
				elt.innerHTML = '<A class="FlirtActionLink" href="javascript:uberProfile.uberChat()"><IMG src="http://' + stateWindow.staticHost() + '/images/profile/chat_icon.jpg" border="0" align="absmiddle">&nbsp;<H3>Chat&nbsp;invite</H3></A>' ;
			}
			else
			{
				elt.className = "FlirtNoAction" ;
				elt.innerHTML = '<IMG src="http://' + stateWindow.staticHost() + '/images/profile/nochat_icon.jpg" border="0" align="absmiddle">&nbsp;<H3>Chat&nbsp;invite</H3>' ;
			}
		}
		var onlineStatus = '';
		if(this.user.online == 2){
			onlineStatus = '<H3>On&nbsp;mobile&nbsp;</H3>';
		} else if(this.user.online == 3){
			onlineStatus = '<H3>Online&nbsp;</H3>';
		}
		onlineStatus += '<IMG id="onlineIcon' + this.user.id + '" src="http://' + stateWindow.staticHost() + '/images/userstatus/online' + this.user.online + '.gif" align="absmiddle">';
		this.hWin.document.getElementById('onlineStatus').innerHTML = onlineStatus;
	}
	
UberProfile.prototype.drawRating = function(withLink){
		var ratingElt = this.hWin.document.getElementById('rating') ;
		if (!ratingElt)
			return ;	// Missing uberprofile (admin user?)
		var ratingHTML = '';
		if(this.user.ratedBy && this.user.rating){
			var avg = this.user.rating;
			//alert(this.user.rating);
			var n = Math.round(avg);
//			var rating = stateWindow.ratingCategories[n - 1];
			var img = 'http://' + stateWindow.staticHost() + '/images/profile/rating/r' +  n + ".gif";
			ratingHTML = '<DIV><IMG src="' + img + '" align="absmiddle"><P> rated <STRONG>' + avg + ' out of 10</STRONG> by ';
			var s = this.user.ratedBy + ' people</P>';
			if(withLink){
				s = '<A href="ratedby.jsp?ghost=' + stateWindow.getSession() + '&tab=ratedby">' + s + '</A>';
			}
			ratingHTML += s + '</DIV>';
		} else {
			ratingHTML = '<P> Not rated </P>';	
		}
		//supersnogs and gifts
		ratingHTML += '<TABLE cellspacing="0" cellpadding="0" border="0"><TR><TD>';
		ratingHTML += '<IMG src="http://' + stateWindow.staticHost() + '/images/profile/rating/supersnog_19x19.gif" align="absmiddle"> <P><b>' + this.user.snogged + '</b> supersnogs</P>';
		ratingHTML += '</TD><TD>&nbsp;&nbsp;';
		ratingHTML += '<IMG src="http://' + stateWindow.staticHost() + '/images/profile/giftbox.gif" align="absmiddle"> <P><STRONG>' + this.user.gifts + '</STRONG> gifts</P>';
		ratingHTML += '</TD><TR></TABLE>';
		if(this.user.id != stateWindow.meMyself.id && this.user.points > 150){
			ratingHTML += '<DIV style="margin-top: 2px"><IMG src="http://' + stateWindow.staticHost() + '/images/profile/fp.gif" align="absmiddle"> <P><b>I\'m loaded!</b></P></DIV>';
		} else if(this.user.id == stateWindow.meMyself.id){
			ratingHTML += '<DIV style="margin-top: 2px"><IMG src="http://' + stateWindow.staticHost() + '/images/profile/fp.gif" align="absmiddle"> <P><b>' + this.user.points + '</b> Flirt Points</P></DIV>';
		}
		ratingElt.innerHTML = ratingHTML;
	}
	
UberProfile.prototype.drawUberProfile = function(photoLink,width,height,ratingLink){
		if (width==null || this.user.photoSrc=="") width="92" ;
		if (height==null || this.user.photoSrc=="") height="92" ;
		if (!this.hWin.document.getElementById('flirtyFace')) return ; // Missing profile

		this.hWin.document.getElementById('flirtyFace').src = this.user.faceIconURL() ;
		var heading = "<H1>" + this.user.flirtname + " (" + (this.user.gender == 'MALE' ? 'M' : 'F') + ',' + this.user.age + ")</H1><H2><br>"+this.user.getLocationMarkup()+"</h2>" ;

		this.hWin.document.getElementById('flirtname').innerHTML = heading ;
		
		this.drawRating(ratingLink);
		if(this.hWin.document.getElementById('chatupLine')){
			this.hWin.document.getElementById('chatupLine').innerHTML = "<H2>" + this.user.chatupLine + "</H2>";	
		}
		if(this.hWin.document.getElementById('flirtsWith')){
			this.hWin.document.getElementById('flirtsWith').innerHTML = "<H2>Flirts with " + (this.user.target_gender == 'MALE' ? 'men' : (this.user.target_gender == 'FEMALE' ? 'women' : 'men and women')) + "</H3>";
		}
		if(this.user.ageVerified && this.hWin.document.getElementById('ageVerified')){
			this.hWin.document.getElementById('ageVerified').innerHTML = '<IMG src="http://' + stateWindow.staticHost() + '/images/userstatus/ageverified.gif" align="absmiddle"><H3>&nbsp;Age verified</H2>';
		}
		var imgPath = 'http://' + stateWindow.staticHost() + '/images/';
		var moodSrc = imgPath + 'profile/' + this.user.mood.toLowerCase() + '_' + this.user.gender.toLowerCase() + '.gif';
		this.hWin.document.getElementById('photoLink').href = photoLink ? photoLink : "javascript:stateWindow.openUberProfile(" + this.user.id + ",'" + this.user.flirtname + "')";
		var eltPhoto = this.hWin.document.getElementById('photo') ;
		if (eltPhoto)
		{
			eltPhoto.width = width;
			eltPhoto.height = height;
			eltPhoto.src = this.user.photoImgSrc;
		}
		this.hWin.document.getElementById('mood').src = moodSrc;

		var dropDetailsHTML = this.starsigns[this.user.starsign] ? '<DIV class="DropDetailItem"><P>I\'m ' + this.starsigns[this.user.starsign] + '</P></DIV>' : '';
		dropDetailsHTML += this.rStatus[this.user.status] ? '<DIV class="DropDetailItem"><P>' + this.rStatus[this.user.status] + '</P></DIV>' : '';
		dropDetailsHTML += this.flirting[this.user.flirting] ? '<DIV class="DropDetailItem"><P>' + this.flirting[this.user.flirting] + '</P></DIV>' : '';
		dropDetailsHTML += this.bodyTypes[this.user.bodyType] ? '<DIV class="DropDetailItem"><P>' + this.bodyTypes[this.user.bodyType] + '</P></DIV>' : '';
		dropDetailsHTML += this.hair[this.user.hairColour] ? '<DIV class="DropDetailItem"><P>' + this.hair[this.user.hairColour] + '</P></DIV>' : '';
		dropDetailsHTML += this.eyes[this.user.eyeColour] ? '<DIV class="DropDetailItem"><P>' + this.eyes[this.user.eyeColour] + '</P></DIV>' : '';
		dropDetailsHTML += this.positions[this.user.position] ? '<DIV class="DropDetailItem"><P>' + this.positions[this.user.position] + '</P></DIV>' : '';
		var elt = this.hWin.document.getElementById("dropDetails");
		if(elt)elt.innerHTML = dropDetailsHTML;
		
		
		var moreAboutMeHTML = '<DIV class="MoreAboutMeItem"><H3>More about me:&nbsp;</H3> <P>' + this.user.description + '</P></DIV>';
		moreAboutMeHTML += '<DIV class="MoreAboutMeItem"><H3>Listening:&nbsp;</H3> <P>' + this.user.interests[1] + '</P></DIV>';
		moreAboutMeHTML += '<DIV class="MoreAboutMeItem"><H3>Eating:&nbsp;</H3> <P>' + this.user.interests[2] + '</P></DIV>';
		moreAboutMeHTML += '<DIV class="MoreAboutMeItem"><H3>Watching:&nbsp;</H3> <P>' + this.user.interests[0] + '</P></DIV>';	
		elt = this.hWin.document.getElementById('moreAboutMe');
		if(elt)elt.innerHTML = moreAboutMeHTML;
		this.drawOnlineStatus() ;
		this.drawBlockStatus() ;
		this.drawFavStatus() ;
		elt = this.hWin.document.getElementById('flirtlink');
		var flirtlink = 'http://'+stateWindow.serverName()+'/'+ this.user.flirtname.replace(/ /g,"_");
		var lnk = this.sendToFriend ? "javascript:stateWindow.openEmailPopup('uberprofile', "  + this.user.id + ")" : flirtlink;
		if (elt && this.user.private_flirtlink == 0){
			elt.innerHTML = '<H3>FlirtLink: </H3> <A href="' + lnk + '"><P>' + flirtlink + '</P></A>' ;
		}
		if(this.sendToFriend && this.user.private_flirtlink == 0){
			elt = this.hWin.document.getElementById('sendFriendBtnCtn');
			var srcPath = 'http://' + stateWindow.staticHost() + '/images/buttons/';
			if(elt){
				elt.innerHTML = '<A href="' + lnk + '"><IMG src="' + srcPath + 'sendfriend_off.gif" border="0" onmouseover="this.src=\'' + srcPath + 'sendfriend_on.gif\'" onmouseout="this.src=\'' + srcPath + 'sendfriend_off.gif\'"></A>';
			}
		}
	}
	
UberProfile.prototype.uberChat = function()
	{
		if (this.user.canChat==1 && this.user.online>0 && this.user.block==0)
			stateWindow.openChat(this.user.id,this.user.flirtname,0);
	}
	
UberProfile.prototype.changeUberFav = function(type)
	{
		this.user.toggleFavourite(type);
	}
	
UberProfile.prototype.changeUberBlock = function()
	{
		this.user.toggleBlock();
	}

