
function $(id){	return document.getElementById(id);	}

/**
 *	Fonctions permettant de déplacer des DIV
 *		
 *	Utilisation : 	
 *		avoir un div dans sa page ex : <div id="foo" ></div>
 *	
 *	Pour déplacer en diagonal et zoomer la div "foo" : 
 *		var F = new Slider("foo");
 		F.set(10,10,10,10);
 *		F.slide(200,200,200,200);
 *		
 */
  
	
/**
 *	Construit un div glissant
 */
function Slider(id)
{	
	// public :
	//
	
	/**
	 * Constructeur
	 */
	
	if( ! document.getElementById(id) )	return;
	
	div = document.getElementById(id);
	
	this.set = function(fromTop,fromLeft,fromHeight,fromWidth)
	{
		if( div == null ) return;
		
		div.style.top = parseInt(fromTop);
		div.style.left = parseInt(fromLeft);
		div.style.height = parseInt(fromHeight);
		div.style.width = parseInt(fromWidth);		
	};
	/**
	 *	Utiliser pour faire glisser la div
	 */
	this.slide = function(toTop,toLeft,toHeight,toWidth,CallFrequency,slideDuration)
	{
		if( div == null ) return;

		toTop = parseInt(toTop);
		toLeft = parseInt(toLeft);
		toHeight = parseInt(toHeight);
		toWidth = parseInt(toWidth);

		//display
		datas[div.id] = new Array();
		datas[div.id]["start"] = this.getVector( div.style.top, div.style.left, div.style.height, div.style.width );
		this.show( div.style.top, div.style.left, div.style.height, div.style.width );

		//slide
		datas[div.id]["stop"] = this.getVector( toTop, toLeft, toHeight, toWidth );
		datas[div.id]["nbCall"] = Math.round( slideDuration * CallFrequency / 1000 );
		datas[div.id]["period"] = Math.round( 1000 / CallFrequency );
		datas[div.id]["cursor"] = 0;

		this.run( div.id );
				
	};
	
	
	// private :
	//
	//var CallFrequency=50;	//---50 appels par seconde
	//var slideDuration=700; //---durée du mouvement


	/** 
	 * Définition du vector
	 */
	this.getVector = function( top, left, height, width )
	{
		V = new Array();
		V["top"] = parseInt(top);
		V["left"] = parseInt(left);
		V["height"] = parseInt(height);
		V["width"] = parseInt(width);
		return V;
	};

	/** 
	 * Définition des données du menu
	 */
	this.show = function( top, left, height, width ){
		div.style.width = parseInt(width);
		div.style.height = parseInt(height);	
		div.style.top = parseInt(top);
		div.style.left = parseInt(left);
	};

	/**
	 * Mouvement 
	 */
	this.run = function( divId )
	{
		var t = this.linear( datas[divId]["cursor"] / datas[divId]["nbCall"] );

		var top = ( 1 - t ) * datas[divId]["start"]["top"] + t * datas[divId]["stop"]["top"]; 
		var left = ( 1 - t ) * datas[divId]["start"]["left"] + t * datas[divId]["stop"]["left"]; 
		var height = ( 1 - t ) * datas[divId]["start"]["height"] + t * datas[divId]["stop"]["height"]; 
		var width = ( 1 - t ) * datas[divId]["start"]["width"] + t * datas[divId]["stop"]["width"]; 
		
		datas[divId]["cursor"] = datas[divId]["cursor"] + 1;
		this.show( top, left, height, width );
		if( datas[divId]["cursor"] <= datas[divId]["nbCall"] ){ 
			setTimeout( 'runrun("'+divId+'")', datas[divId]["period"] ); 
		}completed = 1;
	};
	
	/** 
	 *	Type de mouvement
	 */
	this.linear = function( t )
	{	
		return Math.sin( Math.PI * t / 2);	
	};
}

var datas = new Array(); 	//---Contient toutes les données relatives aux divs
function runrun(divId){
	var S = new Slider(divId);
	S.run(divId);
}

function rolloverMyItem(topic,item){
	
	var divId = "topic_content_"+topic.id;
	var F = new Slider(divId);
	var divHeight = 250; //$(divId).style.height;
	var divWidth = 228;//$(divId).style.width;
 	 //	alert (divHeight+divWidth)
		// Dépliage
 		F.set(0,0,divHeight,divWidth);		// définition de la position de départ
 	 	F.slide(0,0,10,divWidth,50,700);	// définition de la position d'arriveealert ($(divId).style.width )
		$(divId).appendChild(getItemCommentsHTML(item,topic));
		//getComments(item.id);
		F.set(0,0,10,divWidth);		// définition de la position de départ
 		F.slide(0,0,divHeight,divWidth,50,700);	// définition de la position d'arrivee
 		
		
 	 	
}
function rolloverMyItem2(topic,item){
	//recupera los todos los items
	var divId = "topic_content_"+topic.id;
	var F = new Slider(divId);
	var divHeight = 250; //$(divId).style.height;
	var divWidth = 228;//$(divId).style.width;
 	 //alert (divHeight+divWidth)
		// Dépliage
		processRemoveAllTopicItems(topic.id);
 		F.set(0,0,divHeight,divWidth);		// définition de la position de départ
 	 	F.slide(0,0,10,divWidth,50,700);	// définition de la position d'arriveealert ($(divId).style.width )
		loadItems(topic);
		//getComments(item.id);
		F.set(0,0,10,divWidth);		// définition de la position de départ
 		F.slide(0,0,divHeight,divWidth,50,700);	// définition de la position d'arrivee
 		
		
 	 	
}

function rolloverRelated(topic){
	
	var divId = "topic_content_"+topic.id;
	var F = new Slider(divId);
	var divHeight = 250; //$(divId).style.height;
	var divWidth = 228;//$(divId).style.width;
 	 //	alert (divHeight+divWidth)
		// Dépliage
 		F.set(0,0,divHeight,divWidth);		// définition de la position de départ
 	 	F.slide(0,0,10,divWidth,50,700);	// définition de la position d'arriveealert ($(divId).style.width )
		$(divId).appendChild(getRelatedHTML(topic));
		//getComments(item.id);
		F.set(0,0,10,divWidth);		// définition de la position de départ
 		F.slide(0,0,divHeight,divWidth,50,700);	// définition de la position d'arrivee
 		
 	 	
}

rollover = false;
width = screen.availWidth*0.5;
widthOpen = screen.availWidth*0.5;

//cerrar.onclick=function(){ fold("top"); }



function unfold(divId){
	
	
	var F = new Slider(divId);
 	 	
 	if( ! rollover ){
 		// Dépliage
 		F.set(0,0,0,width);		// définition de la position de départ
 		completed = F.slide(0,0,100,widthOpen,50,200);	// définition de la position d'arriveealert ($(divId).style.width )
 		rollover = true;
		
		var cerrar = document.createElement ("IMG");
		cerrar.className="link";		
		cerrar.setAttribute('src','./images/fold.png');
		cerrar.onclick=function(){ fold("top"); }
		var folty = $("fold").childNodes;
	    if (folty.length == 1) {$("fold").removeChild(folty.item(0));}
		$("fold").appendChild(cerrar);
		
	}
 	
}
function fold (divId) {
	
	var F = new Slider(divId);
 	 	
 	if( rollover ){
 		// Dépliage
 		F.set(0,0,100,widthOpen);		// définition de la position de départ
 		completed = F.slide(0,0,0,width,50,200);	// définition de la position d'arriveealert ($(divId).style.width )
 		rollover = false;

		var abrir = document.createElement ("IMG");
		abrir.className="link";		
		abrir.setAttribute('src','./images/unfold.png');
		abrir.onclick=function(){ unfold("top"); }
		var folty = $("fold").childNodes;	
	    if (folty.length == 1) {$("fold").removeChild(folty.item(0));}
		$("fold").appendChild(abrir);
		
		
	}
}




