player = function (obj_name)
{
	/*
	**
	**ImagePlayer width jquery 1.2.3 
	**by oriolc
	**tempomedialab.com
	**V1.1b
	**
	*/
	this.object_name = obj_name
	
	this.imatges = new Array(); //les fotos
	
	this.bt_control ;
	this.control ;
	this.bt_img_h ;
	this.bt_img_n ;
	
	this.container ; //contenedor de imagen actual
	
	this.actual = 0; //current imatge as viewed!
}

player.prototype.add = function (image)
{
	this.imatges.push(image);
	
//	for(a in this) this.msg(a+" --> "+this[a]);
	
}

player.prototype.define = function (id_control,id_container)
{
	this.container = id_container
	this.container_img = $('#'+this.container).html();
	this.control = id_control
	this.bt_control = $('#'+this.control).html();
	
	this.bt_img_n = $('#'+this.control+" > li > a > img").attr("src");
	temp_nom = this.bt_img_n.split(".")
	this.bt_img_h = temp_nom[0]+"-h."+temp_nom[1]
}

player.prototype.make_control = function ()
{
	for(i=0;i<this.imatges.length;i++)
	{
		var cur_bt = this.control+"_"+i;
		$('#'+this.control).append(this.bt_control);
		$('#'+this.control+" >:last").attr("id",this.control+"_"+i);		
		$("#"+cur_bt+" > a").attr("href","javascript:"+this.object_name+".clickme("+i+")")
	}
	$('#'+this.control+"_"+this.actual+" > a > img").attr("src",this.bt_img_h)
	
}

player.prototype.make_player = function ()
{
	for(i=0;i<this.imatges.length;i++)
	{
		var cur_ct = this.container+"_"+i;
		$('#'+this.container).prepend(this.container_img);
		$('#'+this.container+" >:first").attr("id",this.container+"_"+i);
		$('#'+this.container+" >:first").attr("src",this.imatges[i])
		
		if(i!=0) $('#'+this.container+" >:first").attr("style","display:none;")
	}

}


player.prototype.make = function ()
{
	this.make_player();
	
	if(this.imatges.length>1) {
		this.make_control();
	}
	/*eliminamos los ejemplos*/
	$('#'+this.control+" >:first").remove()
	$('#'+this.container+" >:last").remove()
	/*end eliminamos*/
	
}

player.prototype.clickme = function (quin)
{
	
	if(status_player==false) return;
	
	status_player = false;
	
	var container = this.container
	
 	$("#"+this.container+"_"+this.actual).fadeOut(300, function (){
		 $("#"+container+"_"+quin).fadeIn(300, function (){ status_player=true; return false; });
		return false;
	});
	
	this.change_bt(quin);
	
	this.actual = quin ;
		
}

player.prototype.change_bt = function (soc)
{
//	this.msg(soc+" -> "+ this.actual);
	
	$('#'+this.control+"_"+this.actual+" > a > img").attr("src",this.bt_img_n)
	
	$('#'+this.control+"_"+soc+" > a > img").attr("src",this.bt_img_h)
}

player.prototype.msg = function (string)
{
	alert("msg: "+string);	
}
var status_player = true;

/*for implementation
<div id="name_for_player">
	<img width="259" height="181" />
</div>
	<ul id="name_for_control">
		<li><a href=""><img src="img/04_player-bt.gif" width="8" height="8" /></a></li>
	</ul>
	rollover for image src = add a -h example: 04_player-bt-h.gif
	
	var object_name = new player("object_name");
	object_name.define("name_for_control","name_for_player");
	object_name.add("picture1.jpg");
	object_name.add("picture2.jpg");
	object_name.add("picture3.jpg");
	object_name.add("picture4.jpg");
	object_name.add("picture5.jpg");
	object_name.make();
	
end for*/
