﻿/**
 *	ImageFlow 1.0
 *
 *	This code is based on Michael L. Perrys Cover flow in Javascript.
 *	For he wrote that "You can take this code and use it as your own" [1]
 *	this is my attempt to improve some things. Feel free to use it! If
 *	you have any questions on it leave me a message in my shoutbox [2].
 *
 *	The reflection is generated server-sided by a slightly hacked
 *	version of Richard Daveys easyreflections [3] written in PHP.
 *
 *	The mouse wheel support is an implementation of Adomas Paltanavicius
 *	JavaScript mouse wheel code [4].
 *
 *	Thanks to Stephan Droste ImageFlow is now compatible with Safari 1.x.
 *
 *	Thanks to ceasar feijen from cfconsultancy for the extra options and optimizing the js [5]
 *
 *	[1] http://www.adventuresinsoftware.com/blog/?p=104#comment-1981
 *	[2] http://shoutbox.finnrudolph.de/
 *	[3] http://reflection.corephp.co.uk/v2.php
 *	[4] http://adomas.org/javascript-mouse-wheel/
 *	[5] http://www.cfconsultancy.nl/
 *  Script from http://www.imageflow.nl
*/




/* Configuration variables */
var conf_reflection_p = 0.5;         // Sets the height of the reflection in % of the source image
var conf_focus = 2;                  // Sets the numbers of images on each side of the focussed one
//var conf_slider_width = 14;          // Sets the px width of the slider div
var conf_slider_width = 14;          // Sets the px width of the slider div
var conf_images_cursor = 'pointer';  // Sets the cursor type for all images default is 'default'
var conf_slider_cursor = 'e-resize'; // Sets the slider cursor type: try "e-resize" default is 'default'

/* Id names used in the HTML */
var conf_imageflow = 'imageflow';    // Default is 'imageflow'
var conf_loading = 'loading';        // Default is 'loading'
var conf_images = 'images';          // Default is 'images'
var conf_captions = 'captions';      // Default is 'captions'
var conf_heures = 'heures';



//var conf_scrollbar = 'scrollbar';    // Default is 'scrollbar'
//var conf_slider = 'slider';          // Default is 'slider'
//var conf_slideshow = 'slideshow';    // Default is 'slideshow'
//var conf_youtube = 'youtubepopup';   // Default is 'slideshow'

/* Define global variables */
var caption_id = 0;
var new_caption_id = 0;
var current = 0;
var target = 0;
var mem_target = 0;
var timer_flow = 0;
var array_images = [];


//var new_slider_pos = 0;
var dragging = false;
var dragobject = null;
var dragx = 0;
var posx = 0;
//var new_posx = 0;
var xstep = 150;//150 espace en l'image au premier plan et les image à côté
var slide = null;
var sizeAlgo = 0;	// 0 = default, 1 = small to big
/* Glide to a picture on startup. For example 10 is the 11th picture
Use 0 for the starting picture*/
var glidetopicture = 10;
/* Slideshow setting */
var slideshowtime=300; //à priori la valeur ne change rien
var slideshowbutton = true;
var slideshowauto = true;
/* video settings */
var videowidht  = '425';
var videoheight = '350';
var videotop  = '0px';  //350
var videoleft = '0px';
/* Output video, highslide, empty for normal link */
var output = "video";


 var xhr_object_data = null;
 var xhr_object_achat = null;
 var xhr_object_info = null;

var lesmorceaux;
var lesmorceaux_achat;

var info_player_caption_courant='&nbsp;';
var info_player_video='';
var info_player_id='';
var info_player_heure_courant='&nbsp;';

var info_player_caption_reference='&nbsp;';
var info_player_heure_reference='&nbsp;';


var info_player_caption_old='xxx';
var info_player_heure_old='xxx';


var url = '';
var url0= '';
var url1= '';
var url2= '';
var url3= '';
var url4= '';

var recuperation_dataxml=0;
var recuperation_datalienachat=0;


var fondue_etat=0;
var fondue_fin=2;
var fondue_debut=1;

//c'est deux valeur diffèreent suivant le type de player WMP ou QT
var volumeencours=100;  
var volumemax=100;

var increment_variation_volume=6;
var vitesse_volume=20;

var volumemin=0;

var demarrage=1;

var memovolume;

var timer_arret_lecteur;
var timer_interval_image;

var lien_achat_amazon='';
var lien_achat_itunes='';
var lien_achat_fnac='';
var lien_achat_virgin='';

var xmlhttp_vote = null;
var id_global='';
var units_global='';
//var demarragevote=0;

var url_achat;
var sens_volume=0; 
var volume_courant=3;

var parser;
var parser2;
var parserVote;

var recuperation_info=0;

function step()
{
	switch (target < current-1 || target > current+1)
	{
		case true:
			moveTo(current + (target-current)/3);
			window.setTimeout(step, 50); //vitesse de déplacement des images
			timer_flow = 1;
			break;

		default:
			timer_flow = 0;
			break;
	}
}

function slideshow(i){
	var len = img_div.childNodes.length;
    var max = 0;
    for(i=0; i<len; i++)
		{
			if(img_div.childNodes.item(i).nodeType==1)
				max++;
		}
		if( caption_id == max - 1)
		{
			// target == 0;
			//glideTo( 0 , 0 );
			//slide = window.setTimeout('slideshow(1)', slideshowtime ); 
			//En commentaire cela bloque le défilement auto à la fin	
		}
	else
		{
			if (caption_id<2)	//Permet de bloquer en troisième position
				{
					handle(-1);
					i = i+1;
					slide = window.setTimeout('slideshow('+i+')', slideshowtime);
				}  
				
				
				//permet de débloquer le système de vote pour internet explorer
			
			
			
		}
		//slideshow_div.style.display='none';
}

function stopslideshow(){
    //slideshow_div.style.display='block';
	window.clearTimeout(slide);
}

function glideTo(x, new_caption_id)
{
	
	/* Animate gliding to new x position */
	target = x;
	mem_target = x;
	
	
	//document.getElementById('champ1F').value=x;	
	//document.getElementById('champ2F').value=new_caption_id;
	
	if (timer_flow == 0)
	{
		window.setTimeout(step, 50);
		timer_flow = 1;
	}

    if (max == 0)
    {
		hide(conf_loading);
		//hide(conf_scrollbar);
		//hide(conf_slideshow);
    }
    else
    {
		/* Display new caption */
		caption_id = new_caption_id;
		//caption = img_div.childNodes.item(array_images[caption_id]).getAttribute('alt');
		//if (caption == '') caption = '&nbsp;';
		//caption_div.innerHTML = caption;
	   refresh_info_player();
	}

	/* Set scrollbar slider to new position */
	//if (dragging === false)
	//{
		//new_slider_pos = (scrollbar_width * (-(x*100/((max-1)*xstep))) / 100) - new_posx;
		//slider_div.style.marginLeft = (new_slider_pos - conf_slider_width) + 'px';
	//}
		
		
		
		
}

function moveTo(x)
{
	current = x;
	var zIndex = max;
	/* Main loop */
	for (var index = 0; index < max; index++)
	{
		var image = img_div.childNodes.item(array_images[index]);
		var current_image = index * -xstep;
		/* Don't display images that are not conf_conf_focussed */
		if ((current_image+max_conf_focus) < mem_target || (current_image-max_conf_focus) > mem_target)
		{
			image.style.visibility = 'hidden';
			image.style.display = 'none';
		}
		else
		{
			var xs;
			switch(sizeAlgo)
			{
			default:
			    var z = Math.sqrt(10000 + x * x) + 100;   /* défini la taille de l'image au premier plan */
				
				xs = x / z * size + size;
				break;
			case 1:
				var sgn_x = (x > 0) ? 1 : -1; var z = 150 + Math.pow(Math.abs(x), 0.8);
				xs = sgn_x * Math.pow(Math.abs(x), 0.8) + size;
				break;
			}
			/* Still hide images until they are processed, but set display style to block */
			image.style.display = 'block';
			/* Process new image height and image width */
			var new_img_h = (image.h / image.w * image.pc) / z * size;
			switch ( new_img_h > max_height )
			{
				case false:
					var new_img_w = image.pc / z * size;
					break;

				default:
					new_img_h = max_height;
					var new_img_w = image.w * new_img_h / image.h;
					break;
			}
			var new_img_top = (images_width * 0.34 - new_img_h) + images_top + ((new_img_h / (conf_reflection_p + 1)) * conf_reflection_p);

			/* Set new image properties */
			image.style.left = xs - (image.pc / 2) / z * size + images_left + 'px';
		    //array_image_left[index]=xs - (image.pc / 2) / z * size + images_left + 'px';
			
			if(new_img_w && new_img_h)
			{
				image.style.height = new_img_h + 'px';
				image.style.width = new_img_w + 'px';
				image.style.top = new_img_top + 'px';
				
				//array_image_height[index]=new_img_h + 'px';
                //array_image_width[index] =new_img_w + 'px';
                //array_image_top[index]=new_img_top + 'px';
			
			}
			image.style.visibility = 'visible';
		
			/* Set image layer through zIndex */
			switch ( x < 0 )
			{
				case true:
					zIndex++;
					break;

				default:
					zIndex = zIndex - 1;
					break;
			}

			/* Change zIndex and onclick function of the focussed image and stop slideshow */
			switch ( image.i == caption_id )
			{
				case false:
					image.onclick = function()
					{
                        stopslideshow();

                   // glideTo(this.x_pos, this.i);
						glideTo(this.x_pos,this.i);

					};
					break;

				default:
					zIndex = zIndex + 1;

                    if(max == image.i + 1 && document.getElementById('imfl_next') != null &&  document.getElementById('imfl_next') != 'undefined' && document.getElementById('imfl_next') != undefined){

                    image.onclick = function() { document.location = this.url; };
					break;

					  }else if(image.i == 0 && document.getElementById('imfl_previous') != null &&  document.getElementById('imfl_previous') != 'undefined' && document.getElementById('imfl_previous') != undefined){

                    image.onclick = function() { document.location = this.url; };
					break;

	                  }else{

	                    switch (output)
	                    {
	                      case "highslide" :
	                         image.onclick = function() { return hs.expand(this, { src: this.getAttribute('longdesc') }); };
	                         break;
	                      case "video" :
	                         image.onclick = function() { playVid(this.url);};
	                         break;
	                      default :
	                         image.onclick = function() { document.location = this.url; };
	                         break;
	                    }
                      }
			}
			image.style.zIndex = zIndex;
			//array_image_zindex[index]=zIndex;
		}
		x += xstep;
	
	}
}

/* Main function */
function refresh(onload)
{

if (demarrage==1)
{
	
	if(window.XMLHttpRequest) 
		{
			//Firefox   
			xhr_object_data = new XMLHttpRequest();   
			xhr_object_achat= new XMLHttpRequest();   
			xmlhttp_vote = new XMLHttpRequest();  
			xhr_object_info = new XMLHttpRequest();   
				
		}
	 else 
		{ 
			if(window.ActiveXObject) 
				
			{
				try 
						{
								
							xhr_object_data = new ActiveXObject("Msxml2.XMLHTTP"); //Microsoft.XmlDom
							xhr_object_achat = new ActiveXObject("Msxml2.XMLHTTP"); //Microsoft.XmlDom
							xmlhttp_vote = new ActiveXObject("Msxml2.XMLHTTP"); //Microsoft.XmlDom
							xhr_object_info = new ActiveXObject("Msxml2.XMLHTTP"); //Microsoft.XmlDom

							
						}
						catch (e)
						{
							xhr_object_data = new ActiveXObject("Microsoft.XMLHTTP");
							xhr_object_achat = new ActiveXObject("Microsoft.XMLHTTP");
							xmlhttp_vote = new ActiveXObject("Microsoft.XMLHTTP");
							xhr_object_info = new ActiveXObject("Msxml2.XMLHTTP"); //Microsoft.XmlDom

							
						}
			}
		else 
			// XMLHttpRequest non supporté par le navigateur   
			{ 
				alert("Votre navigateur ne supporte pas les objets XMLHTTPRequest...");   
			}
		}	
	
demarrage=0;
}
	
	/* Cache document objects in global variables */
	imageflow_div = document.getElementById(conf_imageflow);
	img_div = document.getElementById(conf_images);
//scrollbar_div = document.getElementById(conf_scrollbar);
//	slider_div = document.getElementById(conf_slider);
	caption_div = document.getElementById(conf_captions);
	
	heure_div = document.getElementById(conf_heures);
	

	
	//slideshow_div = document.getElementById(conf_slideshow);
	//youtube_div = document.getElementById(conf_youtube);

	/* Cache global variables, that only change on refresh */
	images_width = img_div.offsetWidth;
	images_top = imageflow_div.offsetTop;
	images_left = imageflow_div.offsetLeft;
	max_conf_focus = conf_focus * xstep;
	size = images_width * 0.5;
	scrollbar_width = images_width * 0.6;
	conf_slider_width = conf_slider_width * 0.5;
	max_height = images_width * 0.51;

	/* Change imageflow div properties */
	imageflow_div.style.height = max_height + 'px';

	/* Change images div properties */
	img_div.style.height = images_width * 0.338 + 'px';

	/* Change captions div properties */
	caption_div.style.width = images_width + 'px';
	caption_div.style.marginTop = images_width * 0.03 + 'px';
	
	
	/* Change heures div properties */
	heure_div.style.width = images_width + 'px';
	heure_div.style.marginTop = images_width * 0.03 + 'px';


	/* Change scrollbar div properties */
	//scrollbar_div.style.marginTop = images_width * 0.02 + 'px';
	//scrollbar_div.style.marginLeft = images_width * 0.2 + 'px';
	//scrollbar_div.style.width = scrollbar_width + 'px';

	/* Set slider attributes */
  //  slider_div.onmousedown = function () { dragstart(this); return false; };
//	slider_div.style.cursor = conf_slider_cursor;

	/*array_image_i[0]=0;	
	array_image_i[1]=1;	
	array_image_i[2]=2;	
	array_image_i[3]=3;	
	array_image_i[4]=4;	*/
	
		
		
	/* Cache EVERYTHING! */
	max = img_div.childNodes.length;
	var i = 0;
	for (var index = 0; index < max; index++)
	{
		var image = img_div.childNodes.item(index);
		if (image.nodeType === 1)
		{
			array_images[i] = index;

			/* Set image onclick by adding i and x_pos as attributes! */
			//image.onclick = function() {glideTo(this.x_pos, this.i); };
			image.onclick = function() {glideTo(this.x_pos,this.i); };	
				
			image.x_pos = (-i * xstep);
			image.i = i;

			/* Add width and height as attributes ONLY once onload */
			if(onload == true)
			{
				image.w = image.width;
				image.h = image.height;
			}

			/* Check source image format. Get image height minus reflection height! */
			switch ((image.w + 1) > (image.h / (conf_reflection_p + 1)))
			{
				/* Landscape format */
				case true:
					image.pc = 118;
					break;

				/* Portrait and square format */
				default:
					image.pc = 100;
					break;
			}

			/* Set ondblclick event */
				
		//	image.url = image.getAttribute('longdesc');
		
		
		
			//image.ondblclick = function() { document.location = this.url; }

			/* Set image cursor type */
				
			//image.style.cursor = conf_images_cursor;

			i++;
		}
	}
	max = array_images.length;
	/* Display images in current order */
	moveTo(current);
	glideTo(current, caption_id);
			
	
}

/* Show/hide element functions */
function show(id)
{
	var element = document.getElementById(id);
	element.style.visibility = 'visible';
}
function hide(id)
{
	var element = document.getElementById(id);
	element.style.visibility = 'hidden';
	element.style.display = 'none';
}

/* Hide loading bar, show content and initialize mouse event listening after loading */
function startimageflow()
{
	 
	if(document.getElementById(conf_imageflow))
	{
		hide(conf_loading);
		refresh(true);
		show(conf_images);
		//show(conf_scrollbar);
        if (slideshowbutton)
        {
        	//show(conf_slideshow);
        }
		initMouseWheel();
		initMouseDrag();
        if (glidetopicture == 0)
        {
			moveTo(5000);
        }
        if (max < glidetopicture)
        {
			moveTo(5000);
        }else{
			glideTo(-glidetopicture * 150,glidetopicture);
		}
        if (slideshowauto && max > 1)
        {
			slideshow(1);
		}
	}
}

function addLoadEvent(func) {
  var oldonload = window.onload;
  if (typeof window.onload !== 'function') {
    window.onload = func;
  } else {
    window.onload = function() {
      if (oldonload) {
        oldonload();
      }
      func();
    };
  }
}

addLoadEvent(startimageflow);

/* Refresh ImageFlow on window resize */
window.onresize = function()
{
	if(document.getElementById(conf_imageflow)) { refresh();
}
};

if(navigator.userAgent.search(/msie/i)!== -1) {
	// nothing !!
	} else {
/* Fixes the back button issue */
window.onunload = function()
{
  document = null;
	};
}


/* Handle the wheel angle change (delta) of the mouse wheel */
function handle(delta)
{
	var change = false;
	switch (delta > 0)
	{
		case true:
			if(caption_id >= 1)
			{
				target = target + xstep;
				new_caption_id = caption_id - 1;
				change = true;
			}
			break;

		default:
			if(caption_id < (max-1))
			{
				target = target - xstep;
				new_caption_id = caption_id + 1;
				change = true;
			}
			break;
	}

	/* Glide to next (mouse wheel down) / previous (mouse wheel up) image */
	if (change == true)
	{
		glideTo(target, new_caption_id);
	}
}

/* Event handler for mouse wheel event */
function wheel_imageflow(event)
{
	var delta = 0;
	if (!event) { event = window.event;
	}
	if (event.wheelDelta)
	{
     	    stopslideshow();

        delta = event.wheelDelta / 120;
	}
	else if (event.detail)
	{
     		stopslideshow();

		delta = -event.detail / 3;
	}
	if (delta) { handle(delta);
	}
	if (event.preventDefault) { event.preventDefault();
	}
	event.returnValue = false;
}

/* Initialize mouse wheel event listener */
function initMouseWheel()
{
	if(window.addEventListener) { imageflow_div.addEventListener('DOMMouseScroll', wheel_imageflow, false);
	}
	imageflow_div.onmousewheel = wheel_imageflow;
}

/* This function is called to drag an object (= slider div) */
function dragstart(element)
{
	//dragobject = element;
	//dragx = posx - dragobject.offsetLeft + new_slider_pos;
}

/* This function is called to stop dragging an object */
function dragstop()
{
	//dragobject = null;
	//dragging = false;
}

/* This function is called on mouse movement and moves an object (= slider div) on user action */
function drag(e)
{
	//posx = document.all ? window.event.clientX : e.pageX;
	//if(dragobject != null)
	//{
		//dragging = true;

     //	stopslideshow();

	//	new_posx = (posx - dragx) + conf_slider_width;

		/* Make sure, that the slider is moved in proper relation to previous movements by the glideTo function */
		//if(new_posx < ( - new_slider_pos)) { new_posx = - new_slider_pos; }
		//if(new_posx > (scrollbar_width - new_slider_pos)) { new_posx = scrollbar_width - new_slider_pos; }

	//	var slider_pos = (new_posx + new_slider_pos);
	//	var step_width = slider_pos / ((scrollbar_width) / (max-1));
	//	var image_number = Math.round(step_width);
	//	var new_target = (image_number) * -xstep;
	//	var new_caption_id = image_number;

		//dragobject.style.left = new_posx + 'px';
		//glideTo(new_target, new_caption_id);
	//}
}

/* Initialize mouse event listener */
function initMouseDrag()
{
//	document.onmousemove = drag;
//	document.onmouseup = dragstop;

	/* Avoid text and image selection while dragging  */
//	document.onselectstart = function ()
//	{
//		if (dragging == true)
//		{
//			return false;
//		}
//		else
//		{
//			return true;
//		}
//	};
}

function getKeyCode(event)
{
	event = event || window.event;
	return event.keyCode;
}

document.onkeydown = function(event)
{
	var charCode  = getKeyCode(event);
	var i = 0;
	var j = 0;
	var a= 0;
	var b = 0;
	var c = 0;
	var d= 0;
	var e= 0;
	
	switch (charCode)
	{
		/* Right arrow key */
		case 39:
			handle(-1);
			stopslideshow();
			break;
		/* Left arrow key */
		case 37:
			handle(1);
			stopslideshow();
			break;
	
				
	}
};

function playVid(vidId)
{

	if (parent.flagwindowsplayer==true)
		{
		    volumeencours=parent.document.getElementById('wmp_p').settings.volume;
			increment_variation_volume=6;
		}	
		else	
		{
			volumeencours=parent.document.wmp_p.GetVolume();
			increment_variation_volume=8;
		}		
		
		memovolume=volumeencours;
		fondue_volume_player(2);

		
		//timer_arret_lecteur=setTimeout("ShutMeDown()",1000);
	
		//depart_lecture=setTimeout("openMediaBox(info_player_video+'&autoplay=1',info_player_caption_courant,'295','242',info_player_id,info_player_video)",1300);
		
		var no_video="http://www.lesonunique.com/datasun/titre/no-video.png";
		if(info_player_video=="")
			openMediaBox(no_video,info_player_caption_courant,'295','242',info_player_id,no_video);
		else
			openMediaBox(info_player_video+'&autoplay=1',info_player_caption_courant,'295','242',info_player_id,info_player_video);
		timer_arret_lecteur=setTimeout("ShutMeDown()",2000);
	


}

function openMediaBox(url, title, width, height,id_morceau,url_morceau) 
{ 
	var url_tempo=url;	
	var pyoutube=url_tempo.lastIndexOf('youtube');
    var pmp4=url_tempo.lastIndexOf('.mp4');
	if ((pyoutube!=-1) && (pmp4!=-1))
	{
     url_tempo=url_tempo+'&rel=0&egm=0';//	&rel=0&egm=0	
	}	 
	
	
	Mediabox.open(url_tempo, title,width+' '+height,id_morceau,url_morceau); 

} 

function shareWithFacebook()
{
	/* ---------------------------------------------------------------------------------------------------------------------------------------------
	Cette fonction ouvre une fenêtre de partage facebook, 
	et partage le lien de la page "facebook_video" référéncé de l'id du morceau et url de la vidéo.
	Cette page permet de donner les infos de partage à Facebook, son affichage est nul et renvois vers "titres diffusés"
	------------------------------------------------------------------------------------------------------------------------------------------------
	A.R. - dernière mise à jour : 29/09/2010
	------------------------------------------------------------------------------------------------------------------------------------------------ */
	id_morceau_local = parser.affichageDonneePrecise("id_morceau",(caption_id+1));
	url_morceau_local = parser.affichageDonneePrecise("link_video",caption_id+1);
	window.open('http://www.facebook.com/sharer.php?u=http://www.lesonunique.com/player/facebook_video.php?id=' + id_morceau_local + '&url=' + url_morceau_local ,'_blank', 'toolbar=0, location=0, directories=0, status=0, scrollbars=1, resizable=1, copyhistory=0, menuBar=0, width=800, height=350, left=200, top=150');
}

function shareWithTwitter()
{
	/* ---------------------------------------------------------------------------------------------------------------------------------------------
	Cette fonction ouvre une fenêtre de partage twitter, 
	avec un message prédéfini qui contient le titre et l'artiste du morceau écouté (tronqué à 85 caractères pour ne pas dépassé un total de 140).
	le message contient aussi une référence "@lesonunique" et un lien raccourci vers les titres diffusés.
	------------------------------------------------------------------------------------------------------------------------------------------------
	A.R. - dernière mise à jour : 29/09/2010
	------------------------------------------------------------------------------------------------------------------------------------------------ */
	
	var artistAndTitle = document.getElementById('captions').innerHTML.substring(0,85);
	window.open('http://twitter.com/home?status=RT @lesonunique : Ecoute ' + artistAndTitle  + ' sur SUN (Le Son Unique à Nantes) http://bit.ly/ac6tug','_blank','toolbar=0, location=0, directories=0, status=0, scrollbars=1, resizable=1, copyhistory=0, menuBar=0, width=800, height=350, left=200, top=150');
}


function moveHandler(e)
{
 // if (e == null)
 // {
 // 	e = window.event
  //}
  //if (e.button<=1&&dragOK)
  //{
   //  selObj.style.left=e.clientX-dragXoffset+'px';
   //  selObj.style.top=e.clientY-dragYoffset+'px';
    // return false;
  //}
}

function cleanup(e)
{
	document.onmousemove=null;
	document.onmouseup=null;
	selObj.style.cursor=orgCursor;
	dragOK=false;
}

function dragHandler(e)
{
  //var htype='-moz-grabbing';
//	  if (e == null)
//	  {
//	  e = window.event; htype='move';
//	  }
//	      var target = e.target != null ? e.target : e.srcElement;
//	      selObj=target;
//	      orgCursor=target.style.cursor;

//	  if (target.className=="vidFrame" || target.className=="youtubemoveable")
//	  {
	     //target.style.cursor=htype;
	     //dragOK=true;
	     //dragXoffset=e.clientX-parseInt(selObj.style.left);
	     //dragYoffset=e.clientY-parseInt(selObj.style.top);
	     //document.onmousemove=moveHandler;
	     //document.onmouseup=cleanup;
	     //return false;
	  //}
}
document.onmousedown=dragHandler;
//##############################################################
//Classe Parseur
//##############################################################
	// Constructeur de la classe
	function Parseur(txtXml){
		this.texteXml=txtXml;
     
        // Déclaration des fonctions  (méthode)
		this.verifXml = VerifierXmlVide;
        this.affichageTouteDonnee = ObtenirDonnee;
		this.affichageDonneePrecise = ObtenirDonneePrecise;
		this.compterMorceaux = ObtenirNbMorceaux;
		}

    // Implémentation du code des fonctions 
	function VerifierXmlVide(){
		var xml=this.texteXml;
		var cherche1="<morceau>";
		var cherche2="</morceau>";

		var res1 = xml.indexOf(cherche1,0)+cherche1.length;
		var res2 = xml.lastIndexOf(cherche2,xml.length);
		var resultat = xml.substring(res1,res2);
		if(resultat=="")
			return 0;
		else
			return 1;
     }
	 
	 function ObtenirDonneePrecise(baliseRecherchee,pos){
		var xml=this.texteXml;
		var cherche1="<"+baliseRecherchee+">";
		var cherche2="</"+baliseRecherchee+">";
		var baliseInfoFermante="</information>";

		var posInformation1=0;
		var resultat="";
		
		for(i=1;i<=5;i++){
			var posInformation2 = xml.indexOf(baliseInfoFermante,posInformation1);
			var res1 = xml.indexOf(cherche1,posInformation1)+cherche1.length;
			var res2 = xml.lastIndexOf(cherche2,posInformation2);
			if(pos==i)
			resultat += xml.substring(res1,res2);
			posInformation1=posInformation2+14;
		}
		return resultat;
     }
	 
    function ObtenirDonnee(baliseRecherchee){
		var xml=this.texteXml;
		var cherche1="<"+baliseRecherchee+">";
		var cherche2="</"+baliseRecherchee+">";
		var baliseInfoFermante="</information>";

		var posInformation1=0;
		var resultat="";
		for(i=1;i<=5;i++){
			var posInformation2 = xml.indexOf(baliseInfoFermante,posInformation1);
			var res1 = xml.indexOf(cherche1,posInformation1)+cherche1.length;
			var res2 = xml.lastIndexOf(cherche2,posInformation2);
			resultat += xml.substring(res1,res2)+" | ";
			posInformation1=posInformation2+14;
		}
		return resultat;
     }
	 
	 	
	   function ObtenirNbMorceaux(){
		var xml=this.texteXml;
		var cherche1="<information>";
		var baliseInfoFermante="</information>";

		var posInformation1=0;
		var resultat=0;
		for(i=1;i<=5;i++){
			var posInformation2 = xml.indexOf(baliseInfoFermante,posInformation1);
			var res1 = xml.indexOf(cherche1,posInformation1)+cherche1.length;
			if(xml.substring(res1,posInformation2)!="")
				resultat++;
			posInformation1=posInformation2+14;
		}
		return resultat;
     }


//##############################################################
//Rafraîchissement  du player automatiquement
//##############################################################

function load() 
	{
		
		url0 = document.getElementById('0').src;
		url1 = document.getElementById('1').src;
		url2 = document.getElementById('2').src;
		url3 = document.getElementById('3').src;
		url4 = document.getElementById('4').src;
		
		document.getElementById('0').style.cursor="pointer";
		document.getElementById('1').style.cursor="pointer";
		document.getElementById('2').style.cursor="pointer";
		document.getElementById('3').style.cursor="pointer";
		document.getElementById('4').style.cursor="pointer";
		
		
		timer_interval_image=setInterval('refresh_img()', 5000); //FP 11/03/2011
		
		affichage_volume();	//met à jour l'image du volume
		
	}
	
 function affichage_volume(){

	volume_courant=parent.volume_courant;

	if (volume_courant==0)	
	{
			document.getElementById('id_volume_player').src="http://www.lesonunique.com/player/images/boutonplayer/btn_mute_off0.png";
	}	 
	if (volume_courant==1)	
	{
			document.getElementById('id_volume_player').src="http://www.lesonunique.com/player/images/boutonplayer/btn_mute_off1.png";
	}	 
	if (volume_courant==2)	
	{
			document.getElementById('id_volume_player').src="http://www.lesonunique.com/player/images/boutonplayer/btn_mute_off2.png";	 
	}	 
	if (volume_courant==3)	
	{
			document.getElementById('id_volume_player').src="http://www.lesonunique.com/player/images/boutonplayer/btn_mute_off3.png";	 
	}	 
	if (volume_courant==4)	
	{
			document.getElementById('id_volume_player').src="http://www.lesonunique.com/player/images/boutonplayer/vol4on.png";	 
	}
}

function refresh_img() 
	{
        refresh_info_player();
	}	
	
	
	
	
	//document.getElementById('monimage4').style.visibility='hidden';
	//document.getElementById('monimage4').style.display = 'none';*/
   	//setInterval('refresh_img()', 5000);
function refresh_info_player()
	{
		//var ndate = new Date();
		//var nocache = ndate.getTime();
		//caption=nocache;
		
		//caption=caption_courant;
		//caption_div.innerHTML = caption;
		if (recuperation_dataxml==0)	
			{
				recuperation_dataxml=1;
				
				recuperation_fichier_xml();
			}
		
		//alert(caption_id);	
		
		
	}		
	
var previousOnload = window.onload;
window.onload = function () 
	{
		if(previousOnload) previousOnload();
		load();
	}

//##############################################################
// AJAX récupération du fichier XML mis à disposition sur le serveur	
//##############################################################
function recuperation_fichier_xml()
{

	var data     = null; 
	var url='http://www.lesonunique.com/datasun/iphone/service/coverflow.php';
	//var url='sun.xml';
		var ndate = new Date();
	var nocache = ndate.getTime();
	
	url=url+ '?' + nocache+'&uuid=ip&navigateur=player_web&decalage=25';
    
		// On défini ce qu'on va faire quand on aura la réponse
	    		
			xhr_object_data.open("GET",url,true);
			xhr_object_data.onreadystatechange = handleHttpResponse;    
			
			xhr_object_data.setRequestHeader("Content-Type","application/xml");
				// ne pas oublier ça pour le post
			xhr_object_data.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");

			xhr_object_data.setRequestHeader("Cache-Control","no-cache");
		
		
			xhr_object_data.setRequestHeader("Content-Type","charset=ISO-8859-1");

			xhr_object_data.send(data);   
			
			
			
}

//##############################################################
function recuperation_xml_info()
{

	var data     = null; 
	var url='http://www.lesonunique.com/player/construireXML_info.php';

		var ndate = new Date();
	var nocache = ndate.getTime();
	
	url=url+ '?' + nocache;
    
		// On défini ce qu'on va faire quand on aura la réponse	        
			
			xhr_object_info.open("GET",url,true);
			xhr_object_info.onreadystatechange = handleHttpResponseInfo;    
			
			xhr_object_info.setRequestHeader("Content-Type","application/xml");
				// ne pas oublier ça pour le post
			xhr_object_info.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");

			xhr_object_info.setRequestHeader("Cache-Control","no-cache");
		
		
			xhr_object_info.setRequestHeader("Content-Type","charset=ISO-8859-1");
			xhr_object_info.send(data);   
			
			
			
}


// ############################## nettoyage fichier XML #####################################
// Node cleaner
function go(c)
	{
		if(!c.data.replace(/\s/g,''))
		c.parentNode.removeChild(c);
	}

function clean(d)
	{
		var bal=d.getElementsByTagName('*');
		for(i=0;i<bal.length;i++)
			{
				a=bal[i].previousSibling;
				if(a && a.nodeType==3)
					go(a);
				b=bal[i].nextSibling;
				if(b && b.nodeType==3)
					go(b);
			}
			return d;
	}
// ############################## fin nettoyage fichier XML #####################################	
	
function handleHttpResponse()
{
	var actualiser=0; 
	var ndate = new Date();
	var nocache = ndate.getTime();
	
    if(xhr_object_data.readyState == 4)   // données complètement  accèssibles 
		{
			if  (xhr_object_data.status == 200) 
					{
						var xml=xhr_object_data.responseText;
						parser=new Parseur(xml);
						var verif=parser.verifXml();
						
						if (verif==0)
						{
							alert('xml vide');
						}	
						else
						{	
							lecture_morceau(caption_id);
							
						}
						
						if (info_player_id!=0)
							{
									chargementnouveauvote(info_player_id,'3');
							}	
							

						
						
						
						caption_div.innerHTML=info_player_caption_courant;
						heure_div.innerHTML=info_player_heure_courant;

						
														
                		if (info_player_caption_old!=info_player_caption_reference)
							{
									actualiser=1;
							}	
						if (info_player_heure_old!=info_player_heure_reference)
							{
								actualiser=1;
							}
							if (actualiser==1)	
									{
										    nocache = ndate.getTime();
											url2=parser.affichageDonneePrecise("link_pochette",3);
											document.getElementById('2').src = "reflect.php?img=" + url2.replace("http://www.lesonunique.com","..")+ '&' + nocache;
										    nocache = nocache+1;

											url1=parser.affichageDonneePrecise("link_pochette",2);
											document.getElementById('1').src = "reflect.php?img=" + url1.replace("http://www.lesonunique.com","..")+ '&' + nocache;
										    nocache = nocache+1;

											url3=parser.affichageDonneePrecise("link_pochette",4);
											document.getElementById('3').src = "reflect.php?img=" + url3.replace("http://www.lesonunique.com","..")+ '&' + nocache;
										    nocache = nocache+1;

											url0=parser.affichageDonneePrecise("link_pochette",1);
											document.getElementById('0').src = "reflect.php?img=" + url0.replace("http://www.lesonunique.com","..")+ '&' + nocache;
										    nocache = nocache+1;

											url4=parser.affichageDonneePrecise("link_pochette",5);
											document.getElementById('4').src = "reflect.php?img=" + url4.replace("http://www.lesonunique.com","..")+ '&' + nocache;
										    nocache = nocache+1;

											info_player_caption_old=info_player_caption_reference;
											info_player_heure_old=info_player_heure_reference;
											
																
									}	
								
					}
					else
					{	
						xhr_object_data.abort();
					}	
					recuperation_dataxml=0;			
		}		
}

//##############################################################
function handleHttpResponseInfo()
{
    if(xhr_object_info.readyState == 4)   // données complètement  accessibles 
		{
			if  (xhr_object_info.status == 200) 
					{
						var xml=xhr_object_info.responseText;
						parser2=new Parseur(xml);
						var verif=parser2.verifXml();
						
						if (verif==0){
							alert('xml vide');
						}
						else{
							var animateur=parser2.affichageDonneePrecise("animateur",1);
							document.getElementById('animateur').innerHTML=animateur;
							var evenement=parser2.affichageDonneePrecise("evenement",1);
							document.getElementById('evenement').innerHTML=evenement;
							var image=parser2.affichageDonneePrecise("image",1);
							document.getElementById('imgInfo').src=image;
							var diffuse_info=parser2.affichageDonneePrecise("diffusion",1);
							if(diffuse_info==0){
								init_timer();
								monter(200,'bandeau_info');
								recuperation_info=1;
							}
							else if(diffuse_info==1 && recuperation_info==1){
								init_timer();
								descendre(450,'bandeau_info');
							}
						}
								
					}
					else{	
						xhr_object_info.abort();
					}	
		}		
}	

//##############################################################	
function lecture_morceau(numero)
{
	info_player_caption_courant ='&nbsp;';
	info_player_heure_courant ='&nbsp;';
	var nombre = -1;
	try
		{
				nombre=parser.compterMorceaux("titre",numero+1);
		}
		catch (e)
		{
				//alert('défaut lecture XML');	
				nombre=-1;
		}

		if (numero<=nombre)
				{
					info_player_caption_courant=parser.affichageDonneePrecise("caption_text",numero+1);
					
					info_player_video=parser.affichageDonneePrecise("link_video",numero+1);
					if (numero==2)
						{
							info_player_heure_courant='En cours';
						}
					else{
						info_player_heure_courant=parser.affichageDonneePrecise("temps_diffusion",numero+1);
					}
					
					info_player_id=parser.affichageDonneePrecise("id_morceau",numero+1);
				}		
				
				if (2<=nombre)
				{
					info_player_caption_reference=parser.affichageDonneePrecise("caption_text",numero+1);
					
					info_player_heure_reference=parser.affichageDonneePrecise("temps_diffusion",numero+1);
				}		
					
				recuperation_xml_info();				
}		
//##############################################################	

function fondue_volume_player(commande_fondue_local)
{
	var v=0;
	v=volumeencours;
	
	if (commande_fondue_local!=0)
		{
			fondue_etat=commande_fondue_local;
		}
	
	
	switch (fondue_etat )
		{
			case 1:  // fondue début
					
				v=v+increment_variation_volume;     
				if (v>=memovolume)
					{
                      	v=memovolume;
						fondue_etat=0;
					}	
				volumeencours=v;	
				
				EcrireVolume(volumeencours);
				
				break;
			case 2: //fondue fin
				
			
				v=v-increment_variation_volume;
				if (v<=volumemin)
					{
						v=volumemin;
						fondue_etat=0;
					}	
				volumeencours=v;	
				EcrireVolume(volumeencours);

		}

		
	if (fondue_etat!=0)
		{
			window.setTimeout("fondue_volume_player(fondue_etat)", vitesse_volume); 
		}		
			
}
	
//##############################################################	
function StartMeUp ()
{
	if (parent.flagwindowsplayer==true)
		{
		    increment_variation_volume=6;
			parent.document.wmp_p.controls.play()
			
		}
		else
		{	
		    increment_variation_volume=8;
			parent.document.wmp_p.Play()
		}		
}

//##############################################################	
function ShutMeDown ()
{
	if (parent.flagwindowsplayer==true)
		{
			parent.document.wmp_p.controls.stop();
		}	
		else
		{	
			parent.document.wmp_p.Stop()
		}		
}

//##############################################################	
function MuteMe()
{
	if (flagwindowsplayer==true)
		{
			document.getElementById('wmp_p').settings.mute=!document.getElementById('wmp_p').settings.mute;
		}
		else
		{	
			v=document.wmp_p.GetVolume();
			if (v!=0)
				{	
					document.wmp_p.SetVolume(0) ;
				}
			else
				{
					document.wmp_p.SetVolume(255) ;
					
				}	
		}		
}

//##############################################################	
function  VolPlusMe()
{
	if (flagwindowsplayer==true)
		{
			document.getElementById('wmp_p').settings.volume+=35;
			memovolume=document.getElementById('wmp_p').settings.volume;
		}	
		else	
		{
			v=document.wmp_p.GetVolume();
			v=v+90;
			document.wmp_p.SetVolume(v);
			memovolume=v;
			
		}	
}


//##############################################################	
function VolMoinsMe()
{
	if (flagwindowsplayer==true)	
		{
			document.getElementById('wmp_p').settings.volume-=35;
			memovolume=document.getElementById('wmp_p').settings.volume;
		}	
		else
		{	
			v=document.wmp_p.GetVolume();
			v=v-90;
			document.wmp_p.SetVolume(v);
			memovolume=v;
		}	
}	
	

//##############################################################	
function EcrireVolume(valeur_local)
{	
	if (parent.flagwindowsplayer==true)	
		{
			parent.document.getElementById('wmp_p').settings.volume=valeur_local;
		}	
		else
		{	
			parent.document.wmp_p.SetVolume(valeur_local);
		}	
}
//##############################################################	
function demande_fichier_achat_xml(id_dela_musique,nomlien)
{

	var data=null; 
	var url='http://www.lesonunique.com/datasun/ajaxtitresdiffuses.php';
	
			xhr_object_achat.open("POST",url,true);
			xhr_object_achat.onreadystatechange = handleHttpResponse_achat;    
			
			
			xhr_object_achat.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");

            data="id_musique_achat="+id_dela_musique+"&lien="+nomlien;
			
			xhr_object_achat.send(data);   

}


//##############################################################	
function handleHttpResponse_achat()
{
	var actualiser=0; 
	var nombre = -1;
	var numero=0;
	var url_achat_local;
	lien_achat_amazon='';
	lien_achat_itunes='';
	lien_achat_fnac='';
	lien_achat_virgin='';
	
    if(xhr_object_achat.readyState == 4)   // données complètement  accèssibles 
		{
			if  (xhr_object_achat.status == 200) 
				{
					if (xhr_object_achat.responseText!=null)
							{
								var url_achat_local=xhr_object_achat.responseText;
								var debut_lien=url_achat_local.substring(url_achat_local.lastIndexOf(":"));
								url_achat_local='http'+debut_lien;
								OuvrirPopup(url_achat_local);
							}


				}	
			else
				{	
					xhr_object_achat.abort();
				}	
			recuperation_datalienachat=0;
		}		
}	


//##############################################################	
function mafonction_js_lien_video(nomdulien)
{
	if (recuperation_datalienachat==0)
		{
			if (info_player_id!='0')
				{
					recuperation_datalienachat=1;
					demande_fichier_achat_xml(info_player_id,nomdulien);
				}								
		}	
}	



/*###################################################################################*/
function chargementnouveauvote(id_local,units_local)
{
	var url='_drawrating.php'
	//avec le get on ajoute le ? pour les variables     variable1=valeur1&variable2=valeur2...
	url=url+'?id='+id_local+'&units='+units_local;
    xmlhttp_vote.open('GET', url+ "&date=" + escape(new Date()),true);
    xmlhttp_vote.onreadystatechange = handleResponsennewvote;
    xmlhttp_vote.send(null);	
}

//##############################################################	
function handleResponsennewvote()
{
  if(xmlhttp_vote.readyState == 4)
	{
		if (xmlhttp_vote.status == 200)
			{
       	        var response = xmlhttp_vote.responseText;
				document.getElementById('vote_legende').innerHTML=response;
		    }
    }
}

//##############################################################	
function envoievote(ncountlocal)
{
	var url='http://www.lesonunique.com/datasun/iphone/service/vote.php';
	var id_morceau=info_player_id;
	var vote=ncountlocal;
	url=url+'?id_morceau='+id_morceau+'&uuid=ip&vote='+vote;
    xmlhttp_vote.open('get', url,true);
    xmlhttp_vote.onreadystatechange = handleResponsevoteok;
    xmlhttp_vote.send(null);	
		

}

//##############################################################	
function handleResponsevoteok()
{
  if(xmlhttp_vote.readyState == 4)
	{
		if (xmlhttp_vote.status == 200)
			{
				var xmlVote=xmlhttp_vote.responseText;
				parserVote=new Parseur(xmlVote);
				id_global=parserVote.affichageDonneePrecise("id_morceau",1);
				units_global=parserVote.affichageDonneePrecise("note",1);
				chargementnouveauvote(id_global,units_global);				
		     }
    }
}
//##############################################################	
function OuvrirPopup(page)
{

	window.open(page);
	

}

//##############################################################	
function demande_action_player_play_pause()
{
	if (document.getElementById('id_lecture_player').src=="http://www.lesonunique.com/player/images/boutonplayer/play.png")
	{
			if (flagwindowsplayer==true)
			{
					document.wmp_p.controls.play()
			}
			else
			{	
					document.wmp_p.Play();
			}		
			document.getElementById('id_lecture_player').src="http://www.lesonunique.com/player/images/boutonplayer/stop.png";	
	}			
	else
	{	
			if (flagwindowsplayer==true)
			{
					document.wmp_p.controls.stop();
			}	
			else
			{	
					document.wmp_p.Stop();
			}				
			document.getElementById('id_lecture_player').src="http://www.lesonunique.com/player/images/boutonplayer/play.png";	
	}					
}
//##############################################################	
function demande_action_mute()
{

			if (flagwindowsplayer==true)
			{
						if (document.getElementById('wmp_p').settings.mute==true)
						{
							document.getElementById('wmp_p').settings.mute=false;
						}
						else
						{
							document.getElementById('wmp_p').settings.mute=true;
						} 
			}
			else
			{	
						v=document.wmp_p.GetVolume();
						if (v!=0)
						{	
								document.wmp_p.SetVolume(0) ;
								document.getElementById('id_mute_player').src="http://www.lesonunique.com/player/images/boutonplayer/muteon.png";	
						}
						else
						{
								document.wmp_p.SetVolume(255) ;
								document.getElementById('id_mute_player').src="http://www.lesonunique.com/player/images/boutonplayer/muteoff.png";	
						}	
			}			
}	
//##############################################################	
function demande_action_volume()
{
	
	if (sens_volume==0)
	{
		if (volume_courant>0)	
		{
			volume_courant=volume_courant-1;
		}	
		else
		{
			sens_volume=1;
			volume_courant=1;
		}	
	}	
	else
	{
		if (volume_courant<3)
		{
			volume_courant=volume_courant+1;
		}
		else
		{	
			sens_volume=0;
			volume_courant=2;
		}
	}	
			
		
	if (volume_courant==0)	
	{
			document.getElementById('id_volume_player').src="http://www.lesonunique.com/player/images/boutonplayer/btn_mute_off0.png";
	}	 
	if (volume_courant==1)	
	{
			document.getElementById('id_volume_player').src="http://www.lesonunique.com/player/images/boutonplayer/btn_mute_off1.png";
	}	 
	if (volume_courant==2)	
	{
			document.getElementById('id_volume_player').src="http://www.lesonunique.com/player/images/boutonplayer/btn_mute_off2.png";	 
	}	 
	if (volume_courant==3)	
	{
			document.getElementById('id_volume_player').src="http://www.lesonunique.com/player/images/boutonplayer/btn_mute_off3.png";	 
	}	 
	if (volume_courant==4)	
	{
			document.getElementById('id_volume_player').src="http://www.lesonunique.com/player/images/boutonplayer/vol4on.png";	 
	}	 
	
	
	if (flagwindowsplayer==true)
		{
			document.getElementById('wmp_p').settings.volume=33*volume_courant;
			memovolume=document.getElementById('wmp_p').settings.volume;
		}	
		else	
		{
			v=document.wmp_p.GetVolume();
			v=85*volume_courant;
			document.wmp_p.SetVolume(v);
			memovolume=v;
		}		
	
}	
//##############################################################	
function demande_image_plus()
{
	handle(-1);
}	
//##############################################################		
function demande_image_moins()
{
	handle(1);
}	
//##############################################################	
function changetextvote(texte_local)
{	
		//document.getElementById('vote_legende').innerHTML=texte_local;
	//vote_legende_div.innerHTML=texte_local;
}	
//##############################################################	
function demande_action_video()
{
	if (flagwindowsplayer==true)
		{
			volumeencours=document.getElementById('wmp_p').settings.volume;
			increment_variation_volume=6;
		}	
		else	
		{
			volumeencours=document.wmp_p.GetVolume();
			increment_variation_volume=8;
			
		}		
	
			memovolume=volumeencours;
			fondue_volume_player(2);
	
	
	openMediaBox(info_player_video+'&autoplay=1',info_player_caption_courant,'295','242',info_player_id,info_player_video);	
	
	timer_arret_lecteur=setTimeout("ShutMeDown()",2000);
	
}	
