// JavaScript Document

function ra_Gallery(instance_name,opts)
{
// private
var div_id_container=null;
var div_id_new=null;
var div_id_old=null;
var div_id_nfo=null;
var div_id_thumbs=null;
var instanceTime=new Date();
instanceTime=instanceTime.getTime();

var iname=instance_name;
var prev={img:null,img_class:null,width:1,height:1,pfn_callback:null};
var next={img:null,img_class:null,width:1,height:1,pfn_callback:null};
var info={img:null,img_class:null,width:1,height:1,pfn_callback:null};
var close={img:null,img_class:null,width:1,height:1,pfn_callback:null};
var index={img:null,img_class:null,width:1,height:1,pfn_callback:null};
var callbacks={ready:null,prev_ready:null,next_ready:null,on_first_item:null,on_last_item:null,eof_prev:null,eof_next:null,info_open:null,info_close:null,new_selection:null};
var content={image:null,div_source:null,div_source_info:null};
var activation={prev:prev,next:next,info:info,close:close,index:index};
var A=[];
var T=[]; // transitions
var width=640,height=480;
var current=0,last=-1;
var base_zindex=100;
var current_animation={pfn:null,percentage:0.0,duration:1000,callback_time:0,frame:0,frames:50,pfn_start:null,pfn_end:null,timer_handle:null,end_time:0};
var info_animation={pfn:null,percentage:0.0,duration:250,callback_time:0,frame:0,frames:30,pfn_start:null,pfn_end:null,timer_handle:null,end_time:0};
var previous_frame_obj=null;

var thumbs_cfg={cell_width:0,cell_height:0,width:width,height:0,per_page:8,pfn_click:null,pfn_mouseover:null,pfn_mouseout:null,content_text:null,context_image:null,border_width:2,border_color:'000',image_percentage:85,pfn_normal:null,pfn_selected:null,border_selected:'fff'};

if(opts!=null)
	{
	if(opts['div_id_container'])
		div_id_container=opts['div_id_container'];
	}
	
function thumbnails_set(opts)
	{
	var i,obj,count=0;
	
	for(i in thumbs_cfg)
		{
		obj=opts[i];
		if(obj!=null)
			{
			thumbs_cfg[i]=obj;
			count++;
			}
		}
	return (count!=0);
	}
	
function thumbnail_set(selector,val)
	{
	var asel=selector.split(",");
	var sel="";
	var i,j,l,h,count,n,pos,set_count=0;
	
	var bImage=(val.indexOf(".gif")>0 || val.indexOf(".png")>0 || val.indexOf(".jpg")>0);
	
	for(i=0;i<asel.length;i++)
		{
		sel=asel[i];
		pos=sel.indexOf("-");
		if(pos>0)
			{
			l=parseInt(sel.substring(0,pos));
			h=parseInt(sel.substring(pos+1));
			count=(h-l);
			}
		else
			{
			if(sel=='*')
				{
				l=0;
				count=A.length;
				}
			else
				{
				l=parseInt(sel);
				count=1;
				}
			}
		for(j=l;j<(l+count);j++)
			{
			if(j>=0 && j<(A.length))
				{
				set_count++;
				if(bImage)
					{
					A[j].thumbnail=new Image();
					A[j].thumbnail.src=val;
					}
				else
					A[j].thumbnail=val;
				}
			}
		}
	return (set_count>0);
	}
	
function thumbnails_attach(sDiv_ID)
	{
// var thumbs_cfg={cell_width:0,cell_height:0,width:width,height:0,per_page:0,pfn_click:null,pfn_mouseover:null,pfn_mouseout:null,content_text:null,context_image:null,border_width:2,border_color:'#fff',image_percentage:80};
	var obj=$('#'+sDiv_ID);
	if(obj==null)
		return false;
	var count=A.length;
	thumbs_cfg.cell_width=(thumbs_cfg.cell_width==0) ? Math.round(width/count):thumbs_cfg.cell_width;
	thumbs_cfg.cell_height=(thumbs_cfg.cell_height==0) ? thumbs_cfg.cell_width:thumbs_cfg.cell_width;
	thumbs_cfg.per_page=(thumbs_cfg.per_page==0) ? Math.round(width/(thumbs_cfg.cell_width+(thumbs_cfg.border_width<<1))):thumbs_cfg.per_page;
	
	var S="",cell="",i,cc="";
	var style_container="background:none; position:relative; width:"+thumbs_cfg.width+"px;height:"+(thumbs_cfg.height+thumbs_cfg.border_width<<1)+"px;display:block; overflow:hidden;";
	var style_cell="position:relative; background:none; width:"+thumbs_cfg.cell_width+"px;height:"+thumbs_cfg.cell_height+"px;display:none; float:left; text-align:center; ";

if(thumbs_cfg.border_width>0)
	style_cell+="border:solid "+thumbs_cfg.border_width+"px; #"+thumbs_cfg.border_color;

	S="<div style=\""+style_container+"\">";
	
	for(i=0;i<A.length;i++)
		{
		cell="<div id=\""+div_id_thumbs+i+"\" class=\""+div_id_thumbs+"\" style=\""+style_cell+"\">";
		if(A[i].thumbnail==null)
			{
			cc="<div style=\"position:absolute; top:45%; left:45%;\">&bull;</div>";
			}
		else
		if(typeof(A[i].thumbnail)=="string")
				cc="<div style=\"position:absolute; top:45%; left:45%;\">"+A[i].thumbnail+"</div>";
		else		
				
				cc="<img src=\""+A[i].thumbnail.src+"\" style=\"width:"+thumbs_cfg.image_percentage+"%; height:"+thumbs_cfg.image_percentage+"%; position:relative; top:"+(100-thumbs_cfg.image_percentage>>1)+"%;\" />";
				
				
			
		cell+=cc;
		cell+="</div>";
		S+=cell;
		}
	
	S+="</div>";
	
	obj.html(S);
	
	var obj_thumbs=$('.'+div_id_thumbs);
	
	if(thumbs_cfg.pfn_click)
		obj_thumbs.click(function()
								  {
								  var sid=$(this).attr('id');
								  var pos=0,vid=0;
								  pos=sid.lastIndexOf("_");
								  vid=parseInt(sid.substring(pos+1));					  
								  thumbs_cfg.pfn_click(vid);
								  }
								  );
	if(thumbs_cfg.pfn_mouseover)
		obj_thumbs.mouseenter(function()
								  {
								  var sid=$(this).attr('id');
								  var pos=0,vid=0;
								  pos=sid.lastIndexOf("_");
								  vid=parseInt(sid.substring(pos+1));
								  thumbs_cfg.pfn_mouseover(vid);
								  }
								  );
	if(thumbs_cfg.pfn_mouseout)
		obj_thumbs.mouseleave(function()
								  {
								  var sid=$(this).attr('id');
								  var pos=0,vid=0;
								  pos=sid.lastIndexOf("_");
								  vid=parseInt(sid.substring(pos+1));
								  thumbs_cfg.pfn_mouseout(vid);
								  }
								  );
	return true;
	}
	
function internal_show_selected_thumbnail(S)
	{
	var obj=$('#'+S);
	obj.css('border','solid '+thumbs_cfg.border_width+'px #'+thumbs_cfg.border_selected);
	}
	
function internal_show_normal_thumbnail(S)
	{
	var obj=$('#'+S);
	obj.css('border','solid '+thumbs_cfg.border_width+'px #'+thumbs_cfg.border_color);
	}

	
function update_thumbnails()
	{
	var per_page=(thumbs_cfg.per_page-1);
	var current_page=Math.floor(current/per_page);	
	var page=0,item_count=0;
	
	var i,obj;
	var lo,hi,show_count=0;
	for(i=0;i<A.length;i++)
		{
		obj=$('#'+div_id_thumbs+i);
		if(obj==null)
			{
			// alert("exiting update_thumbnails()");
			return false;
			}
		lo=(per_page*current_page);			
		lo=(lo>0) ? lo:0;
		hi=(lo+per_page);	
		hi=(hi<(A.length-1)) ? hi:(A.length-1);
		show_count=(hi-lo);
		if(show_count<per_page)
			{
			lo-=(per_page-show_count);
			hi=(lo+per_page);
			}
			
		if(i>=lo && i<=hi)
			{			
			obj.css('display','block');
			if(current==i)
				{ // do pfn to alter current item
				if(thumbs_cfg.pfn_selected!=null)
					thumbs_cfg.pfn_selected(div_id_thumbs+i);
				}
			else
				{ // do pfn to alter non-current item
				if(thumbs_cfg.pfn_normal!=null)
					thumbs_cfg.pfn_normal(div_id_thumbs+i);
				}
			}
		else
			{
			obj.css('display','none');
			}
		
		}
		
	return true;
	}	


function setup_gallery_container()
	{
	if(div_id_container==null)
		return false;
	var obj=$('#'+div_id_container);
	if(obj==null)
		return false;
		
	
	div_id_new=div_id_container+"_new";
	div_id_old=div_id_container+"_old";
	div_id_nfo=div_id_container+"_nfo";
	div_id_thumbs=div_id_container+"_tn_";
	
	

	obj.css('overflow','hidden');	
	
	width=parseInt(obj.css('width'));
	height=parseInt(obj.css('height'));
	base_zindex=parseInt(obj.css('z-index'));
	if(isNaN(base_zindex))
		base_zindex=100;
		
	var style_old="position: absolute; overflow:hidden; top:0px; left:0px; width:"+width+"px; height:"+height+"px; display:none; z-index:"+(base_zindex+0);
	var style_new="position: absolute; overflow:hidden; top:0px; left:0px; width:"+width+"px; height:"+height+"px; display:block; z-index:"+(base_zindex+1);
	var style_nfo="position: absolute; overflow:hidden; top:0px; left:0px; width:"+width+"px; height:"+height+"px; display:none; z-index:"+(base_zindex+2);
	
	
	var S="<div id=\""+div_id_old+"\" style=\""+style_old+"\"></div>";
	   S+="<div id=\""+div_id_new+"\" style=\""+style_new+"\"></div>";
	   S+="<div id=\""+div_id_nfo+"\" style=\""+style_nfo+"\"></div>";
	 obj.html(S);
	return true;
	}
	
function getTicks()
	{
	var d=new Date();
	var ticks=d.getTime()-instanceTime;
	return ticks;
	}
	
function attach_mouseover(pfn)
	{
	if(pfn==null)
		return false;
	var obj=$('#'+div_id_container);
	obj.mouseenter(pfn);
	return true;
	}
	
function attach_mouseout(pfn)
	{
	if(pfn==null)
		return false;
	var obj=$('#'+div_id_container);
	obj.mouseleave(pfn);
	return true;
	}
	
function attach_mouseclick(pfn)
	{
	if(pfn==null)
		return false;
	var obj=$('#'+div_id_container);
	obj.click(pfn);
	return true;
	}
	
function set_new_content(n)
	{
	var obj_old=$('#'+div_id_old);
	var obj_new=$('#'+div_id_new);
	var obj_nfo=$('#'+div_id_nfo);
	if(n<0 || n>(A.length-1))
			return false;
	var obj=A[n];
	var obj_last=previous_frame_obj;
	
	if(obj.source_content==null)
		{
		var o=$('#'+obj.source); 
		obj.source_content=o.html();
		o.html('');
		}
		
	if(obj.source_info_content==null)
		{
		var o=$('#'+obj.source_info); 
		obj.source_info_content=o.html();
		o.html('');
		}	
	
	if(obj_last!=null)
		obj_old.html(obj_last.source_content);
	obj_new.html(obj.source_content);
	obj_nfo.html(obj.source_info_content);
	
	// var obj={source:null,source_content:null,source_info:null,source_info_content:null,source_pfn:null,name:the_name,pfn_open:pfn_open,pfn_close:pfn_close};	
	
	if(obj.source_pfn) // callers chance to initialize the forground window before the animation occurs
		obj.source_pfn(obj.source);
				
	current=n;
	
	previous_frame_obj=obj;
	
	update_thumbnails();
	
	if(callbacks.new_selection!=null)
		callbacks.new_selection(n);
	
	return true;
	}

function internal_transition_pushleft(percent)
	{
	var obj_old=$('#'+div_id_old);	
	var obj_new=$('#'+div_id_new);
	
	// change z-index
	obj_old.css('z-index',base_zindex+0);
	obj_new.css('z-index',base_zindex+1);	
		
	// change the size
	obj_old.css({width:width+'px',height:height+'px'});
	obj_new.css({width:width+'px',height:height+'px'});
	
	// move the box
	obj_old.css({top:"0px",left:Math.round(-width*percent)+'px'});
	obj_new.css({top:"0px",left:Math.round(width-(width*percent))+'px'});
	
	return true;
	}
	
function internal_transition_pushright(percent)
	{
	var obj_old=$('#'+div_id_old);	
	var obj_new=$('#'+div_id_new);
	
	// change z-index
	obj_old.css('z-index',base_zindex+1);
	obj_new.css('z-index',base_zindex+0);
			
	// change the size
	obj_old.css({width:width+'px',height:height+'px'});
	obj_new.css({width:width+'px',height:height+'px'});
	
	// move the box
	obj_old.css({top:"0px",left:Math.round(width*percent)+'px'});
	obj_new.css({top:"0px",left:Math.round(-width+width*percent)+'px'});
	
	return true;
	}
	
function internal_transition_pushup(percent)
	{
	var obj_old=$('#'+div_id_old);	
	var obj_new=$('#'+div_id_new);
	// change z-index
	obj_old.css('z-index',base_zindex+0);
	obj_new.css('z-index',base_zindex+1);
	
	// change the size
	obj_old.css({width:width+'px',height:height+'px'});
	obj_new.css({width:width+'px',height:height+'px'});
	
	// move the box
	obj_old.css({left:"0px",top:Math.round(-height*percent)+'px'});
	obj_new.css({left:"0px",top:Math.round(height-height*percent)+'px'});
	
	return true;
	}
	
function internal_transition_pushdown(percent)
	{
	var obj_old=$('#'+div_id_old);	
	var obj_new=$('#'+div_id_new);
	
	// change z-index
	obj_old.css('z-index',base_zindex+1);
	obj_new.css('z-index',base_zindex+0);
			
	// change the size
	obj_old.css({width:width+'px',height:height+'px'});
	obj_new.css({width:width+'px',height:height+'px'});
	
	// move the box
	obj_old.css({left:"0px",top:Math.round(height*percent)+'px'});
	obj_new.css({left:"0px",top:Math.round(-height+height*percent)+'px'});
	
	return true;
	}

function internal_transition_centreout(percent)
	{
	var obj_old=$('#'+div_id_old);	
	var obj_new=$('#'+div_id_new);
	
	// change z-index
	obj_old.css('z-index',base_zindex+0);
	obj_new.css('z-index',base_zindex+1);
	
	var tw=Math.round(width*percent),th=Math.round(height*percent);
	var cx=width>>1,cy=height>>1;
	cx-=(tw>>1); cy-=(th>>1);
			
	// change the size
	obj_old.css({width:width+'px',height:height+'px'});
	obj_new.css({width:tw+'px',height:th+'px'});
	
	// move the box
	obj_old.css({left:"0px",top:+"0px"});
	obj_new.css({left:cx+'px',top:cy+'px'});
	
	return true;
	}
	
function internal_transition_fadein(percent)
	{
	var obj_old=$('#'+div_id_old);	
	var obj_new=$('#'+div_id_new);
	
	// change z-index
	obj_old.css('z-index',base_zindex+0);
	obj_new.css('z-index',base_zindex+1);
				
	// change the size
	obj_old.css({width:width+'px',height:height+'px'});
	obj_new.css({width:width+'px',height:height+'px'});
	
	// move the box
	obj_old.css({left:"0px",top:"0px"});
	obj_new.css({left:'0px',top:'0px'});
	
	obj_new.css('opacity',percent);
	obj_new.css('filter',"alpha(opacity="+Math.round(100.0*percent)+")");	
	
	return true;
	}



function newTransition(the_name,pfn)
	{
	var obj={name:the_name,pfn_animate:pfn};
	// pfn_animate(percentage,entry_box_obj,exit_box_obj)
	T[T.length]=obj;
	return true;
	}
	
function findTransition(the_name)
	{
	var i;
	var pfn=null;
	for(i=0;(pfn==null && i<T.length);i++)
		{
		if(T[i].name==the_name)
			pfn=T[i].pfn_animate;
		}
	return pfn;
	}
	

	
function newItemInfo(the_name)
	{	
	var obj={source:null,source_content:null,source_info:null,source_info_content:null,source_pfn:null,source_info_pfn:null,name:the_name,next_effect:'fadein',prev_effect:'fadein',thumbnail:null};
	return obj;
	}
	
function can_do_next()
	{
	return current<(A.length-1);
	}
	
function can_do_prev()
	{
	return current>0;
	}
	
function can_do_info()
	{
	return (A[current].source_info!=null);
	}

	
function set_content(n,ae)
	{
	if(current_animation.frame!=0)
		return false;		
	if(ae==null)
		{
		if(n>current)
			ae=A[n].next_effect;
		else
			ae=A[n].prev_effect;
		ae=(ae==null) ? 'left':ae;
		}
	if(set_new_content(n))
		{
		if(ae!=null)
			{
			var pfn=null;
			if(typeof(ae)=='string')
				{
				// look up animation effect pointer
				pfn=findTransition(ae);
				}
			else
			if(typeof(ae)=='function')
				{
				pfn=ae;
				}
			if(pfn!=null)
				start_animation(pfn);
			return true;
			}
		}
	return false;
	}

	
function moveNext()
	{
	var n=current;
	n++;
	if(n>(A.length-1))
		return false;
	return set_content(n);
	}
	
function movePrev()
	{
	var n=current;
	n--;
	if(n<0)
		return false;
	return set_content(n);
	}
	
function moveIndex(n)
	{	
	return set_content(n);
	}
	
function set_animation_duration(d)
	{
	current_animation.duration=d;
	}
	
function start_animation(pfn_animation)
	{
	var obj_old=$('#'+div_id_old);
	var obj_new=$('#'+div_id_new);
	var obj_nfo=$('#'+div_id_nfo);
	obj_old.css('display','block');
	obj_new.css('display','block');
	obj_nfo.css('display','none');	
	
	current_animation.pfn=pfn_animation;
	current_animation.percentage=0.0;
	current_animation.frame=0;
	current_animation.callback_time=Math.round(current_animation.duration/current_animation.frames);
	current_animation.end_time=getTicks()+current_animation.duration;
	current_animation.pfn(current_animation.percentage);
	current_animation.pfn_start=A[current].pfn_open;
	setTimeout(iname+".playAnimation()",current_animation.callback_time);
	return true;
	}
	
function si_effect_up(n,obj)
	{	
	obj.css({top:(height-height*n)+"px",display:'block'});
	}
	
function si_effect_down(n,obj)
				{				
				obj.css({top:(-height+height*n)+"px",display:'block'});
				}
				
function si_effect_fade(n,obj)
				{				
				obj.css({top:"0px",display:'block'});
				obj.css('opacity',n);
				obj.css('filter',"alpha(opacity="+Math.round(100.0*n)+")");	
				}
				
function is_info_showing()
	{
	var obj_nfo=$('#'+div_id_nfo);
	return (obj_nfo.css('display')=='block');
	}
	
function show_info(effect)
	{
	if(current<0 || current>(A.length-1))
		return false;
	if(A[current].source_info==null)
		return false;
	if(info_animation.timer_handle!=null)
		{
		clearTimeout(info_animation.timer_handle);
		info_animation.timer_handle=null;
		}
	if(effect!=null)
		{
		var pfn=null;		
		if(effect=="up")
			{
			pfn=function(n)
				{
				si_effect_up(n,$('#'+div_id_nfo));
				}
			}
		else
		if(effect=="down")
			{
			pfn=function(n)
				{
				si_effect_down(n,$('#'+div_id_nfo));
				}
			}
		else
		if(effect=="fade")
			{
			pfn=function(n)
				{
				si_effect_fade(n,$('#'+div_id_nfo));
				}
			}
		else
			{
			pfn=function(n)
				{
				// alert("dafault info effect: "+n);
				};
			}
		info_animation.pfn=pfn;
		info_animation.percentage=0.0;
		info_animation.frame=0;
		info_animation.end_time=getTicks()+info_animation.duration;
		info_animation.callback_time=Math.round(info_animation.duration/info_animation.frames);
		info_animation.pfn(info_animation.percentage);
		info_animation.pfn_start=null;
		return true;
		}
	else
		{
		info_animation.frame++;
		if(getTicks()>=info_animation.end_time)
			{
			info_animation.frames=info_animation.frame;
			}
		info_animation.percentage=info_animation.frame/info_animation.frames;			
		info_animation.pfn(info_animation.percentage);
		if(info_animation.frame<info_animation.frames)
			{
			info_animation.pfn(info_animation.percentage);
			return true;
			}
		else
			{
			info_animation.pfn(1.0);
			if(info_animation.pfn_start!=null)
				info_animation.pfn_start();
			info_animation.frame=0;
			$('#'+div_id_nfo).css('display','block');
			return false;
			}

		}
	return false;
	}
	
function hide_info(effect)
	{
	if(current<0 || current>(A.length-1))
		return false;
	if(A[current].source_info==null)
		return false;
	if(info_animation.timer_handle!=null)
		{
		clearTimeout(info_animation.timer_handle);
		info_animation.timer_handle=null;
		}
	if(effect!=null)
		{
		var pfn=null;
		if(effect=="up")
			{
			pfn=function(n)
				{
				si_effect_up(1.0-n,$('#'+div_id_nfo));
				}
			}
		else
		if(effect=="down")
			{
			pfn=function(n)
				{
				si_effect_down(1.0-n,$('#'+div_id_nfo));
				}
			}
		else
		if(effect=="fade")
			{
			pfn=function(n)
				{
				si_effect_fade(1.0-n,$('#'+div_id_nfo));
				}
			}
		else
			{
			pfn=function(n)
				{
				// alert("dafault info effect: "+n);
				};
			}
		info_animation.pfn=pfn;
		info_animation.percentage=0.0;
		info_animation.frame=0;
		info_animation.end_time=getTicks()+info_animation.duration;
		info_animation.callback_time=Math.round(info_animation.duration/info_animation.frames);
		info_animation.pfn(info_animation.percentage);
		info_animation.pfn_start=null;
		return true;
		}
	else
		{
		info_animation.frame++;
		if(getTicks()>=info_animation.end_time)			
			info_animation.frames=info_animation.frame;
		info_animation.percentage=info_animation.frame/info_animation.frames;			
		info_animation.pfn(info_animation.percentage);
		if(info_animation.frame<info_animation.frames)
			{
			info_animation.pfn(info_animation.percentage);
			return true;
			}
		else
			{
			info_animation.pfn(1.0);
			if(info_animation.pfn_start!=null)
				info_animation.pfn_start();
			info_animation.frame=0;
			$('#'+div_id_nfo).css('display','none');
			return false;
			}

		}
	return false;
	}
	
	
this.next=function()
	{
	return moveNext();
	}
	
this.prev=function()
	{
	return movePrev();
	}
	
this.goto=function(n)
	{
	return moveIndex(n);
	}
	

	
this.showInfo=function(effect)
	{
	var res=show_info(effect);
	if(res==true)
		{
		info_animation.timer_handle=setTimeout(iname+".showInfo()",info_animation.callback_time);
		return true;
		}
	info_animation.timer_handle=null;
	return res;
	}
	
this.hideInfo=function(effect)
	{
	var res=hide_info(effect);
	if(res==true)
		{
		info_animation.timer_handle=setTimeout(iname+".hideInfo()",info_animation.callback_time);
		return true;
		}
	info_animation.timer_handle=null;
	return res;
	}
	
this.toggleInfo=function(effect)
	{
	if(is_info_showing())		
		this.hideInfo(effect);
	else
		this.showInfo(effect);
	return true;
	}

	
this.playAnimation=function()
	{	
		current_animation.frame++;
		if(getTicks()>=current_animation.end_time)
			{
			current_animation.frames=current_animation.frame;
			}
		
		current_animation.percentage=current_animation.frame/current_animation.frames;			
		current_animation.pfn(current_animation.percentage);
		if(current_animation.frame<current_animation.frames)
			current_animation.timer_handle=setTimeout(iname+".playAnimation()",current_animation.callback_time);
		else
			{
			// do initialization for the new frame
			
			var obj_old=$('#'+div_id_old);
			var obj_new=$('#'+div_id_new);
			var obj_nfo=$('#'+div_id_nfo);
			obj_old.css('display','none');			
			
			obj_old.css('z-index',base_zindex+0);
			obj_new.css('z-index',base_zindex+1);			
			
			obj_new.css({left:'0px',top:'0px',width:width+'px',height:height+'px'});	
	
			
			if(current_animation.pfn_start!=null)
				current_animation.pfn_start();
			current_animation.frame=0;
			current_animation.timer_handle=null;
			}	
	}
	
	

	
this.createTransition=function(the_name,pfn)
	{
	return newTransition(the_name,pfn);
	}
	
this.changeTransition=function(the_name,pfn)
	{
	var i;
	var obj=null;
	for(i=0;i<T.length && obj==null;i++)
		{
		if(the_name==T[i].name)
			obj=T[i];
		}
	if(obj==null)
		return false;
	obj.pfn=pfn;
	return true;
	}


	
this.setActivation=function(key,opts)
	{
	var obj=activation[key];
	if(obj==null)
		return false;
	var i;	
	for(i in opts)		
		obj[i]=opts[i];		
		
	return true;
	}
	
this.addItem=function(the_name,properties)
	{
	var obj=newItemInfo(the_name);
	var i=A.length;
	if(properties!=null)
		{
		var ii;
		for(ii in properties)			
			obj[ii]=properties[ii];
		}
	A[i]=obj;
	return i;
	}
	
this.changeActivation=function(n,key,opts)
	{
	var i;
	if(typeof(n)=="number")
		{
		if(n<0 || n>(A.length-1))
			return false;
		i=n;
		}
	else
	if(typeof(n)=="string")
		{
		var found=-1;
		for(i=0;(found<0 && i<A.length);i++)
			{
			if(A.name==n)				
			  found=i;				
			}
		if(found<0)
			return false;
		}
	else
		return false;
	var obj=A[i];
	var ii;
	for(ii in opts)		
		obj[ii]=opts[ii];
	return true;
	}

// interface
this.set_Container=function(div_id,fn_list)
	{
	div_id_Container=div_id;
	var i;
	if(fn_list==null)
		return;
	for(i in opts)		
		callbacks[i]=fn_list[i];	
	}
this.getCallbacks=function()
	{
	var S='';
	var i;
	for(i in callbacks)
		{
		if(S!='')
			S+=',';
		S+=(i+":"+(callbacks[i]!=null ? "1":"0"));	
		}
	return i;
	}
	
this.setContainer=function(s)
	{
	div_id_container=s;
	}
	
this.init=function()
	{
	return setup_gallery_container();
	}

this.setAnimationDuration=function(d)
	{
	set_animation_duration(d);
	}
	
this.attachMouseover=function(pfn)
	{
	return attach_mouseover(pfn);
	}
	
this.attachMouseout=function(pfn)
	{
	return attach_mouseout(pfn);
	}
	
this.attachMouseclick=function(pfn)
	{
	return attach_mouseclick(pfn);
	}

	
this.setThumbnails=function(opts)
	{
	return thumbnails_set(opts);
	}
	
this.attachThumbnails=function(SID)
	{
	return thumbnails_attach(SID);
	}
	
	
this.setThumbnail=function(selector,val)
	{
	return thumbnail_set(selector,val);
	}
	
this.canDoNext=function()
	{
	return can_do_next();
	}
	
this.canDoPrev=function()
	{
	return can_do_prev();
	}
	
this.canDoInfo=function()
	{
	return can_do_info();
	}
	
this.onNewSelection=function(pfn)
	{
	callbacks.new_selection=pfn;
	}
// some defaults	
newTransition("left",internal_transition_pushleft);
newTransition("right",internal_transition_pushright);
newTransition("up",internal_transition_pushup);
newTransition("down",internal_transition_pushdown);
newTransition("centreout",internal_transition_centreout);
newTransition("fadein",internal_transition_fadein);

thumbs_cfg.pfn_click=this.goto;
thumbs_cfg.pfn_normal=internal_show_normal_thumbnail;
thumbs_cfg.pfn_selected=internal_show_selected_thumbnail;
}
	
