var ArtistBioPage = Class.create( {
	ArtistPhotoDivClassName : 'artist_image_div',
	ArtistsPageContentClassName : 'artists_page_content',
	HeadingClassName : 'heading',
	DetailsClassName : 'details',
	ArtistPhotoDivClassName : 'artist_photo_div',
	FormColumnDivClassName : 'form_column_div',
	
	initialize : function(artistsPageDiv, artist) {	
		this.Artist = artist;
		//this.ArtistNameHeading = new Element('h1').addClassName(this.ArtistNameHeadingClassName).update(this.Artist.name);
		this.ArtistsPageContent = new Element('div').addClassName(this.ArtistsPageContentClassName);//.insert(this.ArtistNameHeading);
		this.ArtistsPageDiv = $(artistsPageDiv).insert({top: this.ArtistsPageContent});

		var columnWrapper = this.CreateColumn();
		var rightColumn = this.CreateColumn().setStyle({
			'width': '75%'
		});
		var clearDiv = new Element('div').addClassName('clear');
		
		this.ArtistsPageContent.insert(columnWrapper).insert(rightColumn).insert(clearDiv);
		
		if (this.Artist.photo_src != null && this.Artist.photo_src != '') {				
			this.ArtistPhoto = $(new Image()).hide();
			this.ArtistPhoto.src = this.Artist.photo_src;
			this.ArtistPhoto.observe('load', function() {
				this.ResizeArtistPhoto();
				this.ArtistPhoto.show();
			}.bind(this));
			
			this.ArtistPhotoDiv = new Element('div').addClassName(this.ArtistPhotoDivClassName).update(this.ArtistPhoto);
			
			columnWrapper.insert(this.ArtistPhotoDiv);
		}
		
		if (this.Artist.photos != undefined && this.Artist.photos != null && this.Artist.photos.length > 0) {
			var photoGalleryDiv = new Element('div');
			columnWrapper.insert(photoGalleryDiv);
			this.PhotoGallery = new PhotoGallery(photoGalleryDiv, this);
		}
		
		if (this.Artist.videos != undefined && this.Artist.videos != null && this.Artist.videos.length > 0) {
			var videoGalleryDiv = new Element('div');
			columnWrapper.insert(videoGalleryDiv);
			this.VideoGallery = new VideoGallery(videoGalleryDiv, this);
		}
		
		if (parseInt(this.Artist.is_group)) {
			this.ArtistNameHeading = Element.wrap(new Element('span').update('Group: '), 'p').addClassName(this.HeadingClassName).insert(this.Artist.name);
		} else {
			this.ArtistNameHeading = Element.wrap(new Element('span').update('Artist: '), 'p').addClassName(this.HeadingClassName).insert(this.Artist.name);
		}
		
		rightColumn.insert(this.ArtistNameHeading);
		
		if (this.Artist.area != undefined && this.Artist.area != null && this.Artist.area != '') {
			this.ArtistAreaDetails = Element.wrap(new Element('span').update('Area: '), 'p').addClassName(this.DetailsClassName).insert(this.Artist.area);
			rightColumn.insert(this.ArtistAreaDetails);
		}
		
		if (this.Artist.label != undefined && this.Artist.label != null && this.Artist.label != '') {
			this.ArtistLabelDetails = Element.wrap(new Element('span').update('Label: '), 'p').addClassName(this.DetailsClassName).insert(this.Artist.label);
			rightColumn.insert(this.ArtistLabelDetails);
		}
		
		if (this.Artist.website != undefined && this.Artist.website != null && this.Artist.website != '') {
			var websiteAnchor = new Element('a').update(this.Artist.website);
			websiteAnchor.href = this.Artist.website;
			websiteAnchor.target = '_blank';
			this.ArtistWebsiteDetails = Element.wrap(new Element('span').update('Home Page: '), 'p').addClassName(this.DetailsClassName).insert(websiteAnchor);
			rightColumn.insert(this.ArtistWebsiteDetails);
		}
		
		if (this.Artist.myspace != undefined && this.Artist.myspace != null && this.Artist.myspace != '') {
			var myspaceAnchor = new Element('a').update(this.Artist.myspace);
			myspaceAnchor.href = this.Artist.myspace;
			myspaceAnchor.target = '_blank';
			this.ArtistMySpaceDetails = Element.wrap(new Element('span').update('MySpace: '), 'p').addClassName(this.DetailsClassName).insert(myspaceAnchor);
			rightColumn.insert(this.ArtistMySpaceDetails);
		}
		
		if (this.Artist.twitter != undefined && this.Artist.twitter != null && this.Artist.twitter != '') {
			var twitterAnchor = new Element('a').update(this.Artist.twitter);
			twitterAnchor.href = this.Artist.twitter;
			twitterAnchor.target = '_blank';
			this.ArtistTwitterDetails = Element.wrap(new Element('span').update('Twitter: '), 'p').addClassName(this.DetailsClassName).insert(twitterAnchor);
			rightColumn.insert(this.ArtistTwitterDetails);
		}
		
		if (this.Artist.group_members != undefined && this.Artist.group_members != null && this.Artist.group_members.length > 0) {
			this.ArtistsInGroupDetails = Element.wrap(new Element('span').update('Group Members: '), 'p').addClassName(this.DetailsClassName);
			
			for (var i = 0; i < this.Artist.group_members.length; i++) {
				var artistAnchor = new Element('a').update(this.Artist.group_members[i].name);
				artistAnchor.href = '/artists?q=' + this.Artist.group_members[i].name;
				this.ArtistsInGroupDetails.insert(artistAnchor).insert('&nbsp;&nbsp;');
			}
			
			rightColumn.insert(this.ArtistsInGroupDetails);
		}
		
		if (this.Artist.group_affiliation != undefined && this.Artist.group_affiliation != null && this.Artist.group_affiliation.length > 0) {
			this.ArtistGroupAffiliationDetails = Element.wrap(new Element('span').update('Group Affiliations: '), 'p').addClassName(this.DetailsClassName);
			
			for (var i = 0; i < this.Artist.group_affiliation.length; i++) {
				var artistAnchor = new Element('a').update(this.Artist.group_affiliation[i].name);
				artistAnchor.href = '/artists?q=' + this.Artist.group_affiliation[i].name;
				this.ArtistGroupAffiliationDetails .insert(artistAnchor).insert('&nbsp;&nbsp;');
			}
			
			rightColumn.insert(this.ArtistGroupAffiliationDetails);
		}
		
		if (this.Artist.biography != undefined && this.Artist.biography != null && this.Artist.biography != '') {
			this.ArtistBiographyDetails = Element.wrap(new Element('span').update('Biography: '), 'p').addClassName(this.DetailsClassName).insert(new Element('p').update(this.Artist.biography));
			rightColumn.insert(this.ArtistBiographyDetails);
		}
		
		if (this.Artist.albums != undefined && this.Artist.albums != null && this.Artist.albums.length > 0) {
			/*var albumGalleryDiv = new Element('div');
			rightColumn.insert(albumGalleryDiv);
			this.AlbumGallery = new AlbumGallery(albumGalleryDiv, this);*/
			var artistAlbumsList = new Element('ul');
			this.ArtistAlbumsDetails = Element.wrap(new Element('span').update('Albums: '), 'p').addClassName(this.DetailsClassName).insert(artistAlbumsList);
			rightColumn.insert(this.ArtistAlbumsDetails);
			this.ArtistAlbumPhotos = new Array();
			
			for (var i = 0; i < this.Artist.albums.length; i++) {
				var albumNameAnchor = new Element('a').update(this.Artist.albums[i].name);
				albumNameAnchor.target = '_blank';
				albumNameAnchor.href = this.Artist.albums[i].location == '' ? '#' : this.Artist.albums[i].location;
				
				var listElement = new Element('li').insert(albumNameAnchor);
				artistAlbumsList.insert(listElement);
				
				if (this.Artist.albums[i].photo_location != undefined && this.Artist.albums[i].photo_location != null && this.Artist.albums[i].photo_location != '') {
					var albumPhoto = $(new Image());
					albumPhoto.src = this.Artist.albums[i].photo_location;
					this.ArtistAlbumPhotos.push(albumPhoto);
					listElement.insert(albumPhoto.hide());
				
					var showAlbumPhoto = function(photo) {
						var eventHandler = function(e) {
							var ratio = (75 / photo.width) < (75 / photo.height) ? 75 / photo.width : 75 / photo.height;
							
							if (photo.width <= 75 && photo.height <= 75) {
								ratio = 1;
							}
							
							photo.setStyle({
								'position': 'absolute',
								'top': e.pointerY() - (Math.floor(photo.height * ratio) + 10) + 'px',
								'left': e.pointerX() + 10 + 'px',
								'width': Math.floor(photo.width * ratio) + 'px',
								'height': Math.floor(photo.height * ratio) + 'px'
							}).show();
						};
						
						return eventHandler;
					};
					
					albumNameAnchor.observe('mousemove', showAlbumPhoto(this.ArtistAlbumPhotos[i]));
					albumNameAnchor.observe('mouseout', function(e){this.up().down('img').hide()});
				}
			}
		}
		
		var rightDoubleArrow = new Element('span').update('&nbsp;&raquo;');
		this.ViewArtistArticlesLink = new Element('a').update('View posts mentioning ' + this.Artist.name).insert(rightDoubleArrow);
		this.ViewArtistArticlesLink.href = '/?s=' + this.Artist.name;
		rightColumn.insert(this.ViewArtistArticlesLink);
		rightDoubleArrow.setStyle({
			fontSize: '1.2em'
		});
		
		if (this.Artist.additional_artists != undefined && this.Artist.additional_artists != null && this.Artist.additional_artists.length > 0) {
			this.OtherArtistsDetails = Element.wrap(new Element('span').update('Also check out these artists: '), 'p').addClassName(this.DetailsClassName);
			rightColumn.insert(this.OtherArtistsDetails);
			this.OtherArtistsDetails.style.marginTop = '2em';
			
			for (var i = 0; i < this.Artist.additional_artists.length; i++) {
				var artistAnchor = new Element('a').update(this.Artist.additional_artists[i].name);
				artistAnchor.href = '/artists?q=' + this.Artist.additional_artists[i].name;
				this.OtherArtistsDetails.insert(artistAnchor).insert('&nbsp;&nbsp;');
			}
		}
	},
	
	CreateColumn : function() {
		return new Element('div').addClassName(this.FormColumnDivClassName);
	},
	
	ResizeArtistPhoto : function() {
		if (this.ArtistPhoto.width > 185 || this.ArtistPhoto.height > 185) {
			var ratio = (185 / this.ArtistPhoto.width) < (185 / this.ArtistPhoto.height) ? 185 / this.ArtistPhoto.width : 185 / this.ArtistPhoto.height;
			
			this.ArtistPhoto.writeAttribute({
				style: ''
			}).setStyle({
				width: Math.floor(this.ArtistPhoto.width * ratio) + 'px',
				height: Math.floor(this.ArtistPhoto.height * ratio) + 'px'
			});
		}
	},
	
	SetArtistPhoto : function(image) {
		if (image != null) {
			this.ArtistPhoto = image;
			this.ResizeArtistPhoto();
			this.ArtistPhotoDiv.update(this.ArtistPhoto);
		}
	}
});
