var background;
var isCreate = false;
var artist = false;
var share = false;

function myC_addBlock(ident, text, parent)
{
	var newBlock = document.createElement('div');
	if(ident!= "")newBlock.setAttribute('id', ident);
	
	if(text != "")newBlock.innerHTML = text;
	
	parent.appendChild(newBlock);
	
	return newBlock;

	
}

function myC_addTR(parent)
{
	var newTR = document.createElement('tr');
	parent.appendChild(newTR);
	
	return newTR;
}

function myC_addTD(parent)
{
	var newTD = document.createElement('td');
	parent.appendChild(newTD);
	
	return newTD;
}

function myC_addLink(link, class_id, text, parent)
{
	var addLink = document.createElement('a');
	addLink.setAttribute('href', link);
	addLink.setAttribute('target', "_blank");
	addLink.innerHTML = text;
	
	if(class_id != "")addLink.setAttribute('class', class_id);
	
	parent.appendChild(addLink);
	
	return addLink;
}

function myC_addImg(src, ident, ev_onclick, parent)
{
	var newImg = document.createElement('img');
	newImg.setAttribute('src', src);
	
	if(ident !="")newImg.setAttribute('id', ident);
	//if(ev_onclick != "")newImg.setAttribute('onclick', ev_onclick);
	if(ev_onclick != "")newImg.onclick = ev_onclick;
	
	parent.appendChild(newImg);
	
	return newImg;
}

function myC_createPopup(){
	var body = document.getElementsByTagName('body')[0];
	/*
	 * Creation du fond transparent ....
	 */
	
	background = myC_addBlock("background", "", body);
	
		/*
		 * Creation de la div qui va contenir le bock ... 
		 */
		
		var content = myC_addBlock("block", "", background);	
	
			/*
			 * Creation du block pour le haut ...
			 */			
			myC_addBlock("headerBlock", "", content);
			
			/*
			 * Creation du content pour le block
			 */			
			var block = myC_addBlock("contentBlock", "", content);
			
				/*
				 * Ajout de 2 bloc div pour les liens et mettre l'image pour fermer la popup.
				 */
			
				var contentBlock = myC_addBlock("insContentBlock", "", block);
				var closeBlock = myC_addBlock("closePopupBlock", "", block);
				
					//Creation d'un tableau pour ordonner les résultats...
					var tab = document.createElement('table');
					contentBlock.appendChild(tab);
					
					var tbody = document.createElement('tbody');
					tab.appendChild(tbody);
				
					// Ajout du lien pour google bookmarks
					var tableRow = myC_addTR(tbody);
					var imgCell = myC_addTD(tableRow);
					var linkCell = myC_addTD(tableRow);

					myC_addImg("/images/icone_google.gif", "", "", imgCell);
					myC_addLink("http://www.google.com/bookmarks/mark?op=add&output=popup&labels=Art Contemporain&bkmk=" + share + "&title=" + artist, "linkShare", "Partager cet article sur Google Bookmarks", linkCell);
				
					//Ajout du lien pour facebook
					tableRow = myC_addTR(tbody);
					imgCell = myC_addTD(tableRow);
					linkCell = myC_addTD(tableRow);
					
					myC_addImg("/images/facebook.jpg", "", "", imgCell);
					myC_addLink("http://www.new.facebook.com/share.php?u=" + share, "linkShare", "Partager cet article sur Facebook", linkCell);
					
					//ajout du lien pour digg
					tableRow = myC_addTR(tbody);
					imgCell = myC_addTD(tableRow);
					linkCell = myC_addTD(tableRow);
					
					myC_addImg("/images/digg.png", "", "", imgCell);
					myC_addLink("http://digg.com/submit?phase=2&url=" + share, "linkShare", "Partager cet article sur Digg", linkCell);
					
					//ajout du lien pour del.icio
					tableRow = myC_addTR(tbody);
					imgCell = myC_addTD(tableRow);
					linkCell = myC_addTD(tableRow);
					
					myC_addImg("/images/delicius.png", "", "", imgCell);
					myC_addLink("http://del.icio.us/post?url=" + share, "linkShare", "Partager cet article sur Del.Icio.Us", linkCell);
					
				
				/*
				 * Ajout de l'image pour fermer la popup
				 */
				
				myC_addImg("/images/popup/close.png", "closeImg", myC_closePopup, closeBlock);
			/*
			 * Creation du bottom pour le block
			 */					
			myC_addBlock("footerBlock", "", content);
			
		// positionnement du block ....
		content.style.left = '40%';//(screen.availWidth - 300) / 2 + "px";	
		content.style.bottom = '40%';//(screen.availHeight - content.offsetHeight) / 2 + "px";
}

function myC_openPopup(name, url)
{
	if(isCreate == false)
	{
		artist = name;
		share = url;
		myC_createPopup();
		isCreate = true;
	}
	else
	{
		background.style.display = "block";
	}
}

function myC_closePopup()
{
	background.style.display = "none";
}
