	// Variables
	var cols = 2;
	
	function Album (id, title, artist, artist_id,  release, tags)
	{
		this.id = id;
		this.title = title;
		this.artist = artist;
		this.artist_id = artist_id;
		this.release = release;
		this.tags = tags;
		this.is_tagged_id = function (id_tag)
		{
			var i;
			
			for (i = 0; i < this.tags.length; ++i)
				if (this.tags[i]['id'] == id_tag)
					return true;
			return false;
		}
		this.is_almost_tagged_name = function (name_tag)
		{
			var i;
			
			for (i = 0; i < this.tags.length; ++i)
				if (this.tags[i]['name'].toLowerCase ().indexOf (name_tag.toLowerCase ()) >= 0)
					return true;
			return false;
		}
		this.filter = function (word)
		{
			if (this.title.toLowerCase ().indexOf (word.toLowerCase ()) >= 0)
				return true;
			if (this.release.toLowerCase ().indexOf (word.toLowerCase ()) >= 0)	
				return true;
			if (this.artist.toLowerCase ().indexOf (word.toLowerCase ()) >= 0)	
				return true;
			if (this.is_almost_tagged_name (word))	
				return true;
			return false;
		}
		this.toHTML_picture = function (current)
		{
			var res = "";
			var i;
			
			if (current % cols == 0)
			{
				if (current > 0)
					res += "</tr>";
				res += "<tr>";
			}
			res += "<td width=\"" + Math.round (100 / cols) + "%\" valign=\"top\">";
			res += "	<table cellpadding=\"4\" cellspacing=\"0\" width=\"100%\" class=\"movie\" onmouseover=\"this.className='movie over';\" onmouseout=\"this.className='movie';\">";
			res += "		<tr>";
			res += "			<td valign=\"top\" width=\"130\">";
			res += "				<img src=\"images/albums/" + this.id + ".jpg\" border=\"0\">";
			res += "			</td>";
			res += "			<td valign=\"top\">";
			res += "				<span class=\"title dark_grey\">" + this.title + "</span><br>";
			res += "				<a href=\"#\" onclick=\"javascript:loadArtist (" + this.artist_id + ");\" class=\"artist_link\">" + this.artist + "</a><br>";
			res += "				<br>";
			res += "				<span class=\"light_grey\">Sortie : </span><span class=\"dark_grey\">" + this.release + "</span><br>";			
			res += "				<span class=\"light_grey\">Tags : </span><span class=\"dark_grey\">";
			
			for (i = 0; i < this.tags.length; ++i)
			{
				if (i > 0)
					res += ", ";
				res += "<a href=\"#\" onclick=\"javascript:loadTag (" + this.tags[i]['id'] + ");\" class=\"tag_link\">" + this.tags[i]['name'] + "</a>";
			}
			
			res += "				</span><br><br>";
			res += "				<a href=\"http://www.lastfm.com/music/" + this.artist.replace (/ /g, "+") + "/" + this.title.replace (/ /g, "+") + "\" target=\"_blank\"><img src=\"images/icon_lastfm.gif\" border=\"0\"></a>";
			res += "			</td>";
			res += "		</tr>";
			res += "	</table>";
			res += "</td>";
			return res;
		}
	}
	
	function searchMusic (words)
	{
		var layer_content = document.getElementById ("content");
		var res = "";
		var k = 0;
		var i;
		
		for (i = 0; i < music.length; ++i)
			if (music[i].filter (words))
				res += music[i].toHTML_picture (k++);
		while (k % cols)
		{
			res += "<td width='" + Math.round (100 / cols) + "%'></td>";
			++k;
		}
		layer_content.innerHTML = "<table cellpadding=\"3\" cellspacing=\"0\" width=\"100%\">" + res + "</table>";
	}
	
	function loadAllMusic ()
	{
		var layer_content = document.getElementById ("content");
		var res = "";
		var i;
		
		for (i = 0; i < music.length; ++i)
			res += music[i].toHTML_picture (i);
		if (i % cols > 0)
		{	
			while (i % cols)
			{
				res += "<td width='" + Math.round (100 / cols) + "%'></td>";
				++i;
			}
			res += "</tr>";
		}
		layer_content.innerHTML = "<table cellpadding=\"3\" cellspacing=\"0\" width=\"100%\">" + res + "</table>";
	}
	
	function loadTag (id_tag)
	{
		var layer_content = document.getElementById ("content");
		var res = "";
		
		j = 0;
		for (i = 0; i < music.length; ++i)
		{
			if (music[i].is_tagged_id (id_tag))
				res += music[i].toHTML_picture (j++);
		}
		if (j % cols > 0)
		{	
			while (j % cols)
			{
				res += "<td width='" + Math.round (100 / cols) + "%'></td>";
				++j;
			}
			res += "</tr>";
		}
		layer_content.innerHTML = "<table cellpadding=\"3\" cellspacing=\"0\" width=\"100%\">" + res + "</table>";
	}
	
	function loadArtist (id_artist)
	{
		var layer_content = document.getElementById ("content");
		var res = "";
		
		j = 0;
		for (i = 0; i < music.length; ++i)
		{
			if (music[i].artist_id == id_artist)
				res += music[i].toHTML_picture (j++);
		}
		if (j % cols > 0)
		{	
			while (j % cols)
			{
				res += "<td width='" + Math.round (100 / cols) + "%'></td>";
				++j;
			}
			res += "</tr>";
		}
		layer_content.innerHTML = "<table cellpadding=\"3\" cellspacing=\"0\" width=\"100%\">" + res + "</table>";
	}
	
	function setCookie (variable, value)
	{
		var expire = new Date();
		var year = expire.getTime() + (365 * 24 * 60 * 60 * 1000);
		
		expire.setTime (year);
		document.cookie = variable + "=" + value + "; expires=" + expire.toGMTString() + "; path=/music";
	}
	
	function colorToggle (color)
  	{
		var layer_main = document.getElementById ("main");
		
		layer_main.className = "main_" + color;
		setCookie ("color", color);
 	}