// Modifié par GC, 2008-08-21
function cVisualPictures(name, id, imgs, rec, index, base_url)
{
	//Valeurs par defaut
	this.current_index = 0;
	this.timer = 0;
	this.current_index = 0;
	this.current_pos = 1;
	this.slide_speed = 3;
	this.records = new Array();
	this.index = new Array();
	this.base_url = base_url;
	this.num_list_lim = 5;

	this.timer_listener = new Boolean(false);

	for(var i=0;i<imgs.length;i++)
	{
		var imgtemp = new Image(0,0);
		imgtemp.src = imgs[i];
	}

	this.name = name;
	this.id=name;
	this.records = rec;
	this.index = index;
}

cVisualPictures.prototype.g = function(id) { return document.getElementById(id);};

cVisualPictures.prototype.Speed = function(speed) {
	this.slide_speed = speed;
};

cVisualPictures.prototype.NumberList = function(lim) {
	this.num_list_lim = lim;
};

cVisualPictures.prototype.Navigation = function(move) {
	var last_index = this.current_index;
	if( move < 0 )
	{
		if( this.current_pos > 1 ) this.current_pos--;
		if( this.current_index == 0 )
		{
			try{
			for(var i=0;i<(this.index.length-this.num_list_lim);i++)
				this.HideObject('p_num_'+this.id+'_'+i);
			for(var i=(this.index.length-this.num_list_lim);i<this.index.length;i++)
				this.ShowObject('p_num_'+this.id+'_'+i);
			}catch(er){}
			this.current_index = this.index.length;
			this.current_pos = this.num_list_lim;
		}
		this.current_index -- ;
		var id = 'p_'+this.index[this.current_index];
		this.ChangePicture(id);
		try{
        this.g('p_num_'+this.id+'_'+last_index).className='number';
		if( this.g('p_num_'+this.id+'_'+this.current_index).style.display == 'none' )
		{
			if( this.last_index != 0 )
				this.HideObject('p_num_'+this.id+'_'+(this.last_index+this.num_list_lim-1));
			this.ShowObject('p_num_'+this.id+'_'+this.current_index);
		}
		this.g('p_num_'+this.id+'_'+this.current_index).className='current';
		if( this.current_pos == 1 && this.current_index != 0 )
		{
			this.NumberScroll('left')
		}
		}catch(er){}
	}
	else
	{
		if( this.current_pos < this.num_list_lim ) this.current_pos++;

		if( this.current_index == this.index.length-1 )
		{
			try{
			for(var i=this.index.length-1;i>(this.num_list_lim-1);i--)
				this.HideObject('p_num_'+this.id+'_'+i);
			for(var i=0;i<this.num_list_lim;i++)
				this.ShowObject('p_num_'+this.id+'_'+i);
			}catch(er){}
			this.current_index = - 1;
			this.current_pos = 1;
		}
		this.current_index ++ ;
		var id = 'p_'+this.index[this.current_index];
		this.ChangePicture(id);
		try{
		this.g('p_num_'+this.id+'_'+last_index).className='number';
		if( this.g('p_num_'+this.id+'_'+this.current_index).style.display == 'none' )
		{
			if( this.last_index < (this.index.length) )
				this.HideObject('p_num_'+this.id+'_'+(this.current_index-this.num_list_lim));
			this.ShowObject('p_num_'+this.id+'_'+this.current_index);
		}
		this.g('p_num_'+this.id+'_'+this.current_index).className='current';

        if( this.current_pos == this.num_list_lim && this.current_index != this.index.length-1 )
		{
			this.NumberScroll('right')
		}
		}catch(er){}
	}
	return false;
};

cVisualPictures.prototype.NumberScroll = function(dir) {
	switch(dir)
	{
		case 'left':
			this.ShowObject('p_num_'+this.id+'_'+(this.current_index-1));
			this.HideObject('p_num_'+this.id+'_'+(this.current_index+this.num_list_lim-1));
			this.current_pos = 2;
			break;
		case 'right':
			this.HideObject('p_num_'+this.id+'_'+(this.current_index-this.num_list_lim+1));
			this.ShowObject('p_num_'+this.id+'_'+(this.current_index+1));
			this.current_pos = (this.num_list_lim-1);
			break;
	}
	return false;
};
cVisualPictures.prototype.ChangePicture = function(id) {
	
	if(this.g('p_title_'+this.id))
		this.g('p_title_'+this.id).innerHTML = this.records[id]['title'];
	if(this.g('p_description_'+this.id))
		this.g('p_description_'+this.id).innerHTML = this.records[id]['description'];

    if(this.g('link_p_'+this.id)) {
        var href = "javascript:#";
        if( this.records[id]['link'] ) {
            href = this.records[id]['link'];
            //this.g('link_p_'+this.id).target = "_blank";
	        if ( this.records[id]['link_name'] == 1 )
	        {
	            this.g('link_p_'+this.id).innerHTML = this.records[id]['link'];
	        }
	        this.g('link_p_'+this.id).style.display = '';
        }
        else 
    	{
    		//this.g('link_p_'+this.id).target = "";
	        if ( this.records[id]['link_name'] == 1 ) this.g('link_p_'+this.id).innerHTML = "";
	        this.g('link_p_'+this.id).style.display = 'none';
    	}

        this.g('link_p_'+this.id).href = href;
    }
	if( this.g('p_'+this.id) )
	{
        this.g('p_'+this.id).alt = this.records[id]['title'];
        this.g('p_'+this.id).title = this.records[id]['title'];
		this.g('p_'+this.id).src = this.records[id]['url'];
		$jQ('.container_pictures').fadeIn("normal");
	}
	// Description ?
	if ( this.g('desc_'+this.id) )
	{
		this.g('desc_'+this.id).innerHTML = this.records[id]['description'];
	}
	

	return false;
};

cVisualPictures.prototype.ShowPicture = function(pos) {
	var last_index = this.current_index;
	this.current_pos = this.current_pos+((pos) - this.current_index);
	this.current_index = pos;
	var id = 'p_'+this.index[this.current_index];
	this.ChangePicture(id);
	this.g('p_num_'+this.id+'_'+last_index).className='number';
	this.g('p_num_'+this.id+'_'+this.current_index).className='current';
	if( this.current_pos == 1 && this.current_index != 0 )
		this.NumberScroll('left');
	else if( this.current_pos == this.num_list_lim && this.current_index != this.index.length-1 )
		this.NumberScroll('right');
	return false;
};

cVisualPictures.prototype.SlideShow = function(action) {
	switch(action)
	{
		case 'start':
			this.Navigation(1);
			this.timer_listener = true;
			clearTimeout(this.timer);
			this.timer = setTimeout(this.name+'.SlideShow("'+action+'");', this.slide_speed);
			break;
		case 'click':
			if( this.timer_listener == true )
			{
                clearTimeout(this.timer);
                this.timer = 0;
                this.timer_listener  = false;
            }
			else
			{
				this.timer = setTimeout(this.name+'.SlideShow("start");', 1);
				this.timer_listener = true;
			}
			break;
		case 'over':
                clearTimeout(this.timer);
                this.timer = 0;
                this.timer_listener  = false;
			break;
		case 'out':
        		this.timer = setTimeout(this.name+'.SlideShow("start");',1);
				this.timer_listener = true;
			break;
	}
	return false;
};

cVisualPictures.prototype.PopPicture = function(obj) {
var i = this.g('p_'+obj);
var h = 50;
var w = 50;
var left=(screen.width-w)/2;
var top=(screen.height-h)/2;
window.open(this.base_url+"m.php?m=pictures_popup&pk="+obj,null,'directories=no,fullscreen=no,height='+h+',left='+left+',location=no,menubar=no,resizable=yes,scrollbars=no,status=no,toolbar=no,top='+top+',width='+w);
};

cVisualPictures.prototype.HideObject = function(obj) {
	if( this.g(obj) )
		this.g(obj).style.display = 'none';
};

cVisualPictures.prototype.ShowObject = function(obj) {
	if( this.g(obj) )
		this.g(obj).style.display = 'inline';
};


// Fin de la classe.
