function Gallery(args){
	var arg=0;
	var fields={
				'start_image':0,
				'transition':'SLIDE', 
				'transition_speed':500, 
				'gallery_div':'div#photo_gallery', 
				'image_div':'div#images', 
				'image_array':[], 
				'widths':[], 
				'heights':[], 
				'use_ratings':false, 
				'gateway_script_location':'/talkPod/gateway.php', 
				'play_speed':3000, 
				'use_overlay_arrows':false, 
				'captions':[], 
				'original_image_array':[], 
				'large_image_array':[], 
				'large_widths_array':[], 
				'large_heights_array':[], 
				'UUID_array':[],
				'action_function':false, 
				'lightbox_opacity':0.5, 
				'transtions':['SLIDE','FADE','RANDOM'], 
				'no_rating_display':'--', 
				'file_series':[], 
				'use_rating_stars':false, 
				'series_play_speed':1000, 
				'series_position':0,
				'counter_div':'div#counter',
				'counter_template':'($$AT of $$TOTAL)',  //$$AT and $$TOTAL are replaced
				'now_playing_div':'div#now_playing',
				'play_pause_button':'a.play_pause',
				'caption_div':'div#caption',
				'rating_div':'div#rating',
				'rating_block_div':'div#rating_block',
				'go_left_overlay_div':'a#go_left_overlay',
				'go_right_overlay_div':'a#go_right_overlay',
				'go_left_button':'#go_left',
				'go_right_button':'#go_right',
				'enlarge_button':'a#enlarge',
				'rate_wait_message':'Please Wait...',
				'now_playing_message':'Now Playing',
				'image_data_selector':'',
				'image_data_caption_selector':'',
				'thumbnail_data_selector':'',
				'use_html_for_images':false,
				'slide_thumbs':false,
				'slide_thumbs_selector':'div#thumb_slide',
				'slide_thumbs_left_selector':'a#thumb_move_left',
				'slide_thumbs_right_selector':'a#thumb_move_right',
				'html_guid_attribute':'item_guid',
				'default_snas_content_type':'IMAGE'
				};
	var action_function;
	for(var f in fields){
		if(fields[f]===null && args[f]===undefined){
			throw "Gallery:Argument "+f+" is missing";
		} 
		if(args[f]!==undefined){
			this[f]=args[f];
		}
		else{
			this[f]=fields[f];
		}
	}
	if(!this.use_html_for_images && (this.image_array.length===0 || this.widths.length===0 || this.heights.length===0)){
		throw "Gallery: No images found";
	}
	else if (this.use_html_for_images){
		if(this.image_data_selector===''){
			throw "Gallery: No image data selector specified";		
		}
		else{
			var self=this;
			
			$(this.image_data_selector+' li').each(function(){
				if($('dt img',this).length){
					self.image_array.push($('dt img',this).attr('src'));
					//FIX, should allow for another DD with the large image in it so we can enlarge
					self.original_image_array.push($('dt img',this).attr('src'));
					self.widths.push($('dt img',this).attr('width'));
					self.heights.push($('dt img',this).attr('height'));
					if(self.image_data_caption_selector !==''){
						if($(self.image_data_caption_selector,this).length){
							self.captions.push($(self.image_data_caption_selector,this).html());
						}
					}
					if(self.html_guid_attribute){
						if($(this).attr(self.html_guid_attribute)){
							self.UUID_array.push($(this).attr(self.html_guid_attribute));
						}
					}
				}
			});
			$(this.image_data_selector).html('');
			if(this.thumbnail_data_selector!==''){
				if($(this.thumbnail_data_selector+' li').length===this.image_array.length){
					var i=0;
					$(this.thumbnail_data_selector+' li').each(function(){
						$(this).bind('click',(function(ii){return function(e){self.go_picture(ii);return false};})(i));
						$(this).attr('id','thumb_'+i);
						i++;
					});
				}
				else{
					$(this.thumbnail_data_selector).html(''); //kill the thumbnails if they don't match
				}
			}
			//if the number UUIDS we got from the html does not match with the number of images, then dump it
			if(this.UUID_array.length && this.UUID_array.length!=this.image_array.length){
				this.UUID_array=[];
			}

		}
	}
	if (this.image_array.length!==this.original_image_array.length){
		this.original_image_array=this.image_array;
	}
	if(this.slide_thumbs){
		if($(this.slide_thumbs_selector).length===0 || $(this.slide_thumbs_right).length===0 || $(this.slide_thumbs_left).length===0){
			this.slide_thumbs=false;
		}
	}
	if(typeof this.action_function == 'function'){
		var af=this.action_function;
		this.action_function=function(){setTimeout(af,this.transition_speed);};
	}
	else{
		this.action_function=function(){};
	}

	this.image_div_width=$(this.image_div).width();
	this.image_div_height=$(this.image_div).height();
	this.personUUID='';
	this.rated=[];
	this.ratings=[];
	this.timeout_ids=[];
	this.interval_ids=[];
	this.running='';
	this.add_overlay_arrows();

	if(this.large_image_array.length>0 && this.large_image_array[0]!==''){
		this.can_enlarge=true;
	}
	else{
		this.can_enlarge=false;
	}
	this.total_images=this.image_array.length;
	if(!(this.start_image>=0 && this.start_image<this.total_images)){
		this.at_image=0;
	}
	else{
		this.at_image=this.start_image;
	}
	if(window.location.toString().match(/#/) && this.UUID_array.length){
		var at_uuid=window.location.toString().replace(/^.*#/,'');
		for(var i=0;i<this.UUID_array.length;i++){
			if(at_uuid===this.UUID_array[i]){
				this.at_image=i;
				break;
			}
		}
	}
	
	//check to see if we have a counter div
	if($(this.counter_div).length > 0){this.has_counter=true;}else{this.has_counter=false;}
	//check to see if there is a now playing div
	if($(this.now_playing_div).length > 0){this.has_now_playing=true;}else{this.has_now_playing=false;}
	//check to see if we have a play button
	if($(this.play_pause_button).length > 0){this.has_play=true;}else{this.has_play=false;}
	
	
	$(this.image_div).append('<div id="G_current_image"></div>');
	$(this.image_div).append('<div id="G_previous_image"></div>');
	$(this.image_div).append('<div id="G_next_image"></div>');
	this.display_image(this.at_image,'div#G_current_image');
	this.display_image(this.get_previous(this.at_image),'div#G_previous_image');
	this.display_image(this.get_next(this.at_image),'div#G_next_image');
	
	if(this.slide_thumbs){
		this.thumb_width=$('#thumb_0').width();
		this.thumb_width+=parseInt($('#thumb_0').css('padding-right'));
		this.thumb_width+=parseInt($('#thumb_0').css('padding-left'));
		this.thumb_width+=parseInt($('#thumb_0').css('margin-right'));
		this.thumb_width+=parseInt($('#thumb_0').css('margin-left'));
		this.thumb_slide_container_width=$(this.slide_thumbs_selector).width();
		this.visible_thumbs=Math.round(this.thumb_slide_container_width/this.thumb_width);
		this.at_thumb=0;
		total_width=this.thumb_width*this.total_images;
		$(this.slide_thumbs_selector+' ul').width(total_width);
	}
	
	
	this.bind_actions();
	this.select_thumbnail(this.start_image);
	if(this.captions.length>0){
		this.has_captions=true;
		$(this.caption_div).css('display','block');
		//using css to get the height, because if it is not set, we set
		//it from the longest string length
		this.caption_div_height=parseInt($(this.caption_div).css('height'));
		this.caption_div_width=$(this.caption_div).width();
		if(this.caption_div_height==0 || isNaN(this.caption_div_height)){
			var longest='';
			this.caption_div_height=0;
			$('body').append('<div id="G_caption_sizer"><div>');
			$('div#G_caption_sizer').css({'position':'absolute','width':this.caption_div_width,'top':-99999}); //font size used to be in here, but, it was broken in ie, now needs to be in CSS
			for(var i=0;i<this.captions.length;i++){
				$('div#G_caption_sizer').html(this.captions[i]+'<br/>');
				var hh=$('div#G_caption_sizer').height();
				if(hh>this.caption_div_height){this.caption_div_height=hh;}	
			}
			if(this.caption_div_height>1000 || this.caption_div_height===0){this.caption_div_height=1000;}
			var caption_margin_bottom=parseInt($(this.caption_div).css('margin-bottom'));
			if(!isNaN(caption_margin_bottom) && caption_margin_bottom!=0){
				this.caption_div_height+=caption_margin_bottom;
			}
			
			$(this.caption_div).css('height',this.caption_div_height);
			$('div#G_caption_sizer').remove();
			
			
		}
		$(this.caption_div).html('<div id="G_current_caption">'+this.captions[this.at_image]+'</div><div id="G_next_caption"></div>');
		$('div#G_next_caption').css('display','none');
	}
	else{
		this.has_captions=false;
	}
	if(this.use_ratings){
		$(this.rating_div).html('<div id="G_current_rating" /><div id="G_next_rating" />');
		$(this.rating_block_div).css('display','block');
		$(this.rating_div).css('display','block');
		this.get_rating(this.at_image,true);
	}

	this.change_counter();
	
}
Gallery.prototype.metrics = function(){
	if(window['s']!==undefined){
		if(this.base_page_name === undefined){
			this.base_page_name=s.pageName;
		}
		s.pageName=this.base_page_name+' : '+this.captions[this.at_image];
		if(s.t!==undefined && typeof(s.t)=='function'){
			s.t();
		}
	}
}
//clears any intervals or timeouts
Gallery.prototype.clear_timers = function(){
	while(this.timeout_ids.length){
		clearTimeout(this.timeout_ids.pop());
	}
	while(this.interval_ids.length){
		clearInterval(this.interval_ids.pop());
	}
};
Gallery.prototype.add_overlay_arrows = function(){
	if(this.use_overlay_arrows){
		$(this.image_div).append('<a id="'+this.go_left_overlay_div+'" /><a id="'+this.go_right_overlay_div+'" />');
		var width=Math.floor(this.image_div_width/2);
		$(this.go_left_overlay_div).css({'display':'block','position':'absolute','top':0,'left':0,'width':width,'height':this.image_div_height});
		$(this.go_right_overlay_div).css({'display':'block','position':'absolute','top':0,'left':width,'width':width,'height':this.image_div_height});
	}
};
Gallery.prototype.remove_overlay_arrows = function(){
	if(this.use_overlay_arrows){
		$(this.go_left_overlay_div).remove();
		$(this.go_right_overlay_div).remove();
	}
};
Gallery.prototype.add_enlarge_link = function(){
	if(this.can_enlarge){
		//check to see if there is a link specifically used to enlarge
		if($(this.enlarge_button).length > 0){
			var self=this;
			$(this.enlarge_button).bind('click',function(){self.enlarge(self.at_image);return false;});
		}
		else if($(this.image_div+' #current_image img').length > 0){
			$(this.image_div+' #current_image img').wrap('<a id="G_enlarge_link" href="#"></a>');
			var self=this;
			$('#G_enlarge_link').bind('click',function(){self.enlarge(self.at_image);return false;});
		}
		
	}
};
Gallery.prototype._get_window_offset = function(){
	return $.browser.msie?document.body.scrollTop:window.pageYOffset;

};
Gallery.prototype.move_enlarge = function(){
	var offset=this._get_window_offset();
	$('div#G_lightbox').css('top',offset);
	var eh=$('div#G_enlarged').height();
	var wh=$(window).height();
	$('div#G_enlarged').css('top',Math.ceil((wh-eh)/2)+offset);
};
Gallery.prototype.enlarge = function(at){
	this.pause();
	$('body').append('<div id="G_lightbox"></div><div id="G_enlarged"><div id="G_enlarged_image" /><div id="G_enlarged_caption" /></div>');
	var ww=$(window).width();
	var wh=$(window).height();
	var w=this.large_widths_array[at];
	var h=this.large_heights_array[at];
	var end_opacity=this.lightbox_opacity;
	if(!(end_opacity>=0 && end_opacity<=1)){
		end_opacity=0.5;
	}
	$('div#G_lightbox').width(ww);
	$('div#G_lightbox').height(wh);
	$('div#G_lightbox').css({'top':-10000});

	if(this.has_captions){
		$('div#G_enlarged_caption').html(this.captions[at]);
	}
	
	$('div#G_enlarged').css({'display':'block','top':-10000});
	this.display_image(at,'div#G_enlarged_image',true);
	$('div#G_enlarged_image').css({'display':'block','width':w});
	if(this.has_captions){
		$('div#G_enlarged_caption').css('display','block');
	}
	var ew=$('div#G_enlarged').width();
	var eh=$('div#G_enlarged').height();
	var offset=this._get_window_offset();
	var lightbox_top=0;
	var enlarged_left=Math.ceil((ww-ew)/2);
	var enlarged_top=Math.ceil((wh-eh)/2);
	if(!($.browser.msie && parseInt($.browser.version)<=6)){
		$('div#G_lightbox').css({'position':'fixed'});
		$('div#G_enlarged').css({'position':'fixed'});
	}
	else{
		lightbox_top+=offset;
		enlarged_top+=offset;
	}
	$('div#G_enlarged').css({'left':enlarged_left});
	var trans=this.get_transition();
	var self=this;
	if(trans=='FADE'){
		$('div#G_lightbox').css({'opacity':0,'display':'block'});
		$('div#G_lightbox').fadeTo(1,0.01,function(){
			$('div#G_lightbox').css({'top':lightbox_top});
			$('div#G_lightbox').fadeTo(self.transition_speed,end_opacity);
			});
		$('div#G_enlarged').fadeTo(1,0.01,function(){
			$('div#G_enlarged').css({'top':enlarged_top});
			$('div#G_enlarged').fadeTo(self.transition_speed,1);
			});

	}
	else if(trans=='SLIDE'){
		
		$('div#G_lightbox').css({'top':-wh,'opacity':end_opacity,'display':'block'});
		$('div#G_enlarged').css({'top':-(wh-enlarged_top)});
		$('div#G_lightbox').animate({'top':offset},this.transition_speed);
		$('div#G_enlarged').animate({'top':enlarged_top},this.transition_speed);

	}
	$('div#G_lightbox').wrap('<a href="#" class="G_delarge"></a>');
	$('div#G_enlarged').wrap('<a href="#" class="G_delarge"></a>');
	if($.browser.msie && parseInt($.browser.version)<=6){
		$(window).scroll(function(){self.move_enlarge(); return false;});
	}
	$('.delarge').bind('click',function(){self.delarge();return false;});
	return false;
};
Gallery.prototype.delarge = function(){
	var trans=this.get_transition();
	$(window).unbind('scroll');
	if(trans=='FADE'){
		$('div#G_lightbox').fadeOut(this.transition_speed);
		if(this.has_captions){
			$('div#G_enlarged_caption').fadeOut(this.transition_speed);
		}
		$('div#G_enlarged_image img').fadeOut(this.transition_speed,function(){
			$('div#G_lightbox').remove();
			$('div#G_enlarged').remove();
		});
	}
	else if(trans=='SLIDE'){
		var wh=$(window).height();
		var enlarged_top=parseInt($('div#G_enlarged').css('top'));
		$('div#G_lightbox').animate({'top':wh},this.transition_speed);
		$('div#G_enlarged').animate({'top':wh+enlarged_top},this.transition_speed,function(){
			$('div#G_lightbox').remove();
			$('div#G_enlarged').remove();
		});		
	}
};
Gallery.prototype.get_transition =function(){
	if(this.transition=='RANDOM'){
		var ret='RANDOM';
		while(ret=='RANDOM'){
			var i=Math.round(Math.random()*(this.transitions.length-1));
			ret=this.transitions[i];
		}
		return ret;
	}
	else{
		return this.transition;
	}
};
Gallery.prototype.get_previous = function(at){
	return at==0?this.image_array.length-1:at-1;
};
Gallery.prototype.get_next = function(at){
	return (at==this.image_array.length-1)?0:at+1;	
};

Gallery.prototype.display_image = function(){
	var image_num=arguments[0];
	var image_div=arguments[1];
	var enlarged=arguments[2]?arguments[2]:false;
	var i=new Image();
	var w=0;
	var h=0;
	var divw=0;
	var divh=0;
	if(!enlarged){
		i.src=this.image_array[image_num];
		w=this.widths[image_num];
		h=this.heights[image_num];
		divh=this.image_div_height;
		divw=this.image_div_width;
	}
	else{
		i.src=this.large_image_array[image_num];
		w=this.large_widths_array[image_num];
		h=this.large_heights_array[image_num];
		divh=$(window).height()*0.9;
		divw=$(window).width()*0.9;
	}
	var ratio=w/h;

	if(w>divw && h>divh){
		if(w-divw > h-divh){
			w=divw;
			h=w*(1/ratio);
		}
		else if(h-divh > w-divw){
			h=divh;
			w=h*(ratio);
		}
		else if(h-divh==w-divw){
			h=divh;
			w=divw;
		}
	}
	else if(w>divw && h<=divh){
		w=divw;
		h=w*(1/ratio);
	}
	else if(w<=divw && h>divh){
		h=divh;
		w=h*(ratio);
	}
	i.width=Math.ceil(w);
	i.height=Math.ceil(h);
	$(image_div).empty();
	$(image_div).append(i);
	if(!enlarged){
		if(w<divw){
			$(image_div+' img').css('left',Math.ceil((divw-w)/2));
		}
		if(h<divh){
			$(image_div+' img').css('top',Math.ceil((divh-h)/2));
		}
	}

};
Gallery.prototype.select_thumbnail =function(){
	var selected=arguments[0];
	var unselected=arguments[1]>=0?arguments[1]:'';
	if(unselected>=0){
		if($('#thumb_'+unselected)){
			$('#thumb_'+unselected).removeClass('selected');
		}
	}
	if($('#thumb_'+selected)){
		$('#thumb_'+selected).addClass('selected');
	}
};
Gallery.prototype.go_left = function(){
	var old_id=this.at_image;
	var new_id=this.get_previous(this.at_image);
	this.select_thumbnail(new_id,old_id);
	this.go_slide_thumbs(new_id);
	this.at_image=new_id;
	this.get_rating(this.at_image);
	switch(this.get_transition()){
		case 'SLIDE':
			this.slide_image('left',this.at_image,this.get_previous(this.at_image),this.get_next(this.at_image),'#G_previous_image','#G_next_image');
			break;
		default:
			this.fade_image(this.at_image,this.get_previous(this.at_image),this.get_next(this.at_image),'#G_previous_image','#G_next_image');
	}
	this.change_counter();
};
Gallery.prototype.go_right = function(){
	var old_id=this.at_image;
	var new_id=this.get_next(this.at_image);
	this.select_thumbnail(new_id,old_id);
	this.go_slide_thumbs(new_id);
	this.at_image=new_id;
	this.get_rating(this.at_image);
	switch(this.get_transition()){
		case 'SLIDE':
			this.slide_image('right',this.at_image,this.get_next(this.at_image),this.get_previous(this.at_image),'#G_next_image','#G_previous_image');
			break;
		default:
			this.fade_image(this.at_image,this.get_next(this.at_image),this.get_previous(this.at_image),'#G_next_image','#G_previous_image');
	}
	this.change_counter();
	
};
Gallery.prototype.play_pause = function(){
	if($('a#G_play').length > 0){
		this.play();
		return;
	}
	else if($('a#G_pause').length > 0){
		this.pause();
		return;
	}
};
//slide thumbs
Gallery.prototype.go_slide_thumbs = function(where){
	if(this.slide_thumbs){
		var go_thumb;
		if(this.visible_thumbs>=this.total_images){
			return;
		}
		if(where==='left' || where==='right'){
			if(where==='left'){
				go_thumb=((this.at_thumb-1)%this.total_images);
				if(go_thumb<0){
					go_thumb=this.total_images-(go_thumb+1);
				}

			}
			else{
				go_thumb=((this.at_thumb+1)%(this.total_images-this.visible_thumbs));
			}
		}
		else{
			go_thumb=where;
			if(go_thumb>(this.total_images-this.visible_thumbs)){
				go_thumb=this.total_images-this.visible_thumbs;
			}
		}
		if(isNaN(go_thumb)){
			return;
		}
		else{
			if(go_thumb>(this.total_images-this.visible_thumbs) && go_thumb<=this.total_images){
				go_thumb=(this.total_images-this.visible_thumbs);
			}
			var to_go=go_thumb*this.thumb_width;
			var self=this;
			$(this.slide_thumbs_selector+' ul').animate({'left':-to_go},this.transition_speed,function(){
				self.at_thumb=go_thumb;
			});
		}		
	}

};



//starts the image play feature
Gallery.prototype.play = function(){
	if($('a#G_play').length > 0){
		var self=this;
		this.interval_ids.push(setInterval(function(){self.go_right();},this.play_speed));
		this.running='image_play';
		this.set_now_playing_message(this.now_playing_message);
		$('a#G_play').attr('id','G_pause');
	}
};
//stops anything that is playing
Gallery.prototype.pause = function(){
	if($('a#G_pause').length > 0){
		this.clear_timers();
		this.running=false;
		this.set_now_playing_message('');
		$('a#G_pause').attr('id','G_play');
	}
};
Gallery.prototype.set_now_playing_message = function(message){
	if(this.has_now_playing){
		$(this.now_playing_div).html(message);
	}
};
Gallery.prototype.go_series = function(series_name){
	this.pause();
	if(this.file_series[series_name]){
		this.go_picture(this.file_series[series_name][0]);
		var self=this;
		this.running='series_play';
		this.set_now_playing_message('Playing: '+series_name.replace(/_/g,' '));
		$('a#G_play').attr('id','G_pause');
			this.timeout_ids.push(setTimeout(function(){self.interval_ids.push(setInterval(function(){self.play_series(series_name);},self.series_play_speed));},this.transition_speed));
	}
};
Gallery.prototype.play_series = function(series_name){
	this.series_position++;
	if(this.series_position>=this.file_series[series_name].length){
		this.series_position=0;
	}
	
	this.at_image=this.file_series[series_name][this.series_position];
	this.change_counter();
	this.display_image(this.at_image,'div#G_current_image');
};
Gallery.prototype.go_picture = function(image_num){
	this.pause();
	if(image_num!=this.at_image){
		this.action_function();
		var old_id=this.at_image;
		var new_id=image_num;
		this.select_thumbnail(new_id,old_id);
		this.at_image=image_num;
		this.get_rating(this.at_image);
		this.go_slide_thumbs(new_id);
		switch(this.get_transition()){
			case 'SLIDE':
				this.slide_go_picture();
				break;
			default:
				this.fade_go_picture();
		}
		this.metrics();
	}
	this.change_counter();
	
};
Gallery.prototype.unbind_actions = function(){
	$(this.go_left_button).unbind('click');
	$(this.go_right_button).unbind('click');
	if(this.can_enlarge){
		$('#G_enlarge_link').unbind('click');
		$(this.enlarge_button).unbind('click');
	}
	if(this.has_play){
		$(this.play_pause_button).unbind('click');
		$(this.play_pause_button).addClass('disabled');
	}
	if(this.use_overlay_arrows){
		$(this.go_left_overlay_div).unbind('click');
		$(this.go_right_overlay_div).unbind('click');
	}
	$(this.go_left_button).addClass('disabled');
	$(this.go_right_button).addClass('disabled');
	if(this.slide_thumbs){
		$(this.slide_thumbs_left_selector).unbind('click');
		$(this.slide_thumbs_right_selector).unbind('click');
	}
	this.unbind_ratings();
};
Gallery.prototype.bind_actions =function(){
	var self=this;
	$(this.go_left_button).bind('click',function(){self.action_function(); self.go_left(); self.metrics();return false;});
	$(this.go_right_button).bind('click',function(){self.action_function();self.go_right();  self.metrics();return false; });
	this.add_enlarge_link();
	if(this.use_ratings){this.bind_ratings();}
	if(this.has_play){
		$(this.play_pause_button).bind('click',function(){self.play_pause(); return false;});
		$(this.play_pause_button).removeClass('disabled');
	}
	if(this.use_overlay_arrows){
		$(this.go_left_overlay_div).bind('click',function(){self.action_function(); self.go_left();  self.metrics();return false;});
		$(this.go_right_overlay_div).bind('click',function(){self.action_function(); self.go_right();  self.metrics();return false;});
	}
	if(this.slide_thumbs){
		$(this.slide_thumbs_left_selector).bind('click',function(){self.go_slide_thumbs('left'); return false;});
		$(this.slide_thumbs_right_selector).bind('click',function(){self.go_slide_thumbs('right'); return false;});
	}
	if($.browser.msie){ //add hrefs to all the links we bind so it properly does the hover
		var ids=[this.go_left_button, this.go_right_button, this.play_pause_button, this.go_left_overlay_div, this.go_right_overlay_div, this.thumb_move_right, this.thumb_move_left];
		for(var i=0;i<ids.length;i++){
			if($(ids[i]).length > 0){
				$(ids[i]).attr('href','javascript:;');
			}
		}
		if(this.use_ratings){
			for(var i=1;i<=5;i++){
				var id='#rate_'+i;
				if($(id).length>0){
					$(id).attr('href','javascript:;');
				}
			}
		}
	}
	$(this.go_left_button).removeClass('G_disabled');
	$(this.go_right_button).removeClass('G_disabled');
};
Gallery.prototype.unbind_ratings = function(){
	if(this.use_ratings){
		for(var i=1;i<=5;i++){
			$('#rate_'+i).unbind('click');
		}
	}	
};
Gallery.prototype.bind_ratings = function(){
	if(this.use_ratings){
		var self=this;
		$('#rate_1').bind('click',function(){self.action_function();self.rate(1); return false;});
		$('#rate_2').bind('click',function(){self.action_function();self.rate(2); return false;});
		$('#rate_3').bind('click',function(){self.action_function();self.rate(3); return false;});
		$('#rate_4').bind('click',function(){self.action_function();self.rate(4); return false;});
		$('#rate_5').bind('click',function(){self.action_function();self.rate(5); return false;});
		if(this.use_rating_stars){
			$('#rate_1').bind('mouseenter',function(){self.rate_hover(1,'enter'); return false;});
			$('#rate_1').bind('mouseleave',function(){self.rate_hover(1,'leave'); return false;});
			$('#rate_2').bind('mouseenter',function(){self.rate_hover(2,'enter'); return false;});
			$('#rate_2').bind('mouseleave',function(){self.rate_hover(2,'leave'); return false;});
			$('#rate_3').bind('mouseenter',function(){self.rate_hover(3,'enter'); return false;});
			$('#rate_3').bind('mouseleave',function(){self.rate_hover(3,'leave'); return false;});
			$('#rate_4').bind('mouseenter',function(){self.rate_hover(4,'enter'); return false;});
			$('#rate_4').bind('mouseleave',function(){self.rate_hover(4,'leave'); return false;});
			$('#rate_5').bind('mouseenter',function(){self.rate_hover(5,'enter'); return false;});
			$('#rate_5').bind('mouseleave',function(){self.rate_hover(5,'leave'); return false;});
		}

	}	
};
Gallery.prototype.slide_go_picture =function(){
	$('#G_next_image').remove();
	$(this.image_div).append('<div id="G_next_image"></div>');
	this.display_image(this.at_image,'#G_next_image');
	this.slide_image('up',this.at_image,this.get_next(this.at_image),this.get_previous(this.at_image),'#G_next_image','#G_previous_image');
};
Gallery.prototype.fade_go_picture =function(){
	$('#G_next_image').remove();
	$(this.image_div).append('<div id="G_next_image"></div>');
	this.display_image(this.at_image,'#G_next_image');
	this.fade_image(this.at_image,this.get_next(this.at_image),this.get_previous(this.at_image),'#G_next_image','#G_previous_image');

};
Gallery.prototype.get_id_name = function(from_id){
	return from_id.replace(/^.*#/,'');
};
Gallery.prototype.fade_captions =function(at_image){
	if(this.has_captions){
		$('div#G_next_caption').html(this.captions[at_image]);
		$('div#G_current_caption').fadeOut(this.transition_speed);
		var self=this;
		$('div#G_next_caption').fadeIn(this.transition_speed,function(){
			$('div#G_current_caption').remove();
			$('div#G_next_caption').attr('id','G_current_caption');
			$('div#G_current_caption').after('<div id="G_next_caption"></div>');
		});
	}
};
Gallery.prototype.slide_captions =function(direction,at_image){
	if(this.has_captions){
		$('div#G_next_caption').html(this.captions[at_image]);
		var ahead_caption_animate;
		var from_caption_animate;
		if(direction=='left'){
			$('#G_next_caption').css('left',this.caption_div_width);
			from_caption_animate={'left':-(this.caption_div_width*1.1)};
			ahead_caption_animate={'left':"0"};
		}
		else if(direction=='right'){
			$('#G_next_caption').css('left',-this.caption_div_width);
			from_caption_animate={'left':this.caption_div_width*1.1};
			ahead_caption_animate={'left':"0"};			
		}
		else if(direction=='up'){
			$('#G_next_caption').css('top',this.caption_div_height);
			from_caption_animate={'top':-this.caption_div_height};
			ahead_caption_animate={'top':0};
		}
		else if(direction=='down'){
			$('#G_next_caption').css('bottom',0);
			from_caption_animate={'bottom':this.caption_div_height};
			ahead_caption_animate={'bottom':-this.caption_div_height};
		}
		$('#G_next_caption').css("display","block");
		$('#G_next_caption').html(this.captions[at_image]);
		$('#G_current_caption').animate(from_caption_animate,this.transition_speed);
		var self=this;
		$('#G_next_caption').animate(ahead_caption_animate,this.transition_speed,'',function(){
			$('#G_current_caption').remove();
			$('#G_next_caption').attr('id','G_current_caption');
			$(self.caption_div).append('<div id="G_next_caption"></div>');
		});

	}
};
Gallery.prototype.fade_image = function(at_image,ahead_image,behind_image,ahead_div,behind_div){

	from_div='#G_current_image';
	var from_div_fade=from_div;
	var ahead_div_fade=ahead_div;
	if($.browser.msie){
		from_div_fade+=' img';
		ahead_div_fade+=' img';
		$(ahead_div).css('display','block');
		$(ahead_div_fade).css('display','none');
	}
	this.unbind_actions();
	this.fade_captions(at_image);

	$(ahead_div_fade).fadeIn(this.transition_speed);
	var self=this;
	$(from_div_fade).fadeOut(this.transition_speed,function(){
		$(from_div).remove();
		$(behind_div).remove();
		$(ahead_div).attr('id','G_current_image');
		$(self.image_div).append('<div id="'+self.get_id_name(ahead_div)+'"></div>');
		self.display_image(ahead_image,ahead_div);
		$(self.image_div).append('<div id="'+self.get_id_name(behind_div)+'"></div>');
		self.display_image(behind_image,behind_div);
		self.bind_actions();
	});
};
Gallery.prototype.slide_image = function(direction,at_image,ahead_image,behind_image,ahead_div,behind_div){
	
	from_div='#G_current_image';
	this.slide_captions(direction,at_image);
	//this.slide_ratings(direction,at_image);
	var from_div_animate;
	var ahead_div_animate;
	if(direction=='left'){
		$(ahead_div).css('left',this.image_div_width);
		from_div_animate={'left':-(this.image_div_width*1.1)};
		ahead_div_animate={'left':"0"};
	}
	else if(direction=='right'){
		$(ahead_div).css('left',-this.image_div_width);
		from_div_animate={'left':this.image_div_width*1.1};
		ahead_div_animate={'left':"0"};			
	}
	else if(direction=='up'){
		$(ahead_div).css('top',this.image_div_height);
		from_div_animate={'top':-this.image_div_height};
		ahead_div_animate={'top':0};
	}
	else if(direction=='down'){
		$(ahead_div).css('bottom',0);
		from_div_animate={'bottom':this.image_div_height};
		ahead_div_animate={'bottom':-this.image_div_height};
	}
	$(ahead_div).css("display","block");
	this.unbind_actions();
	$(from_div).animate(from_div_animate,this.transition_speed);
	var self=this;
	$(ahead_div).animate(ahead_div_animate,this.transition_speed,'',function(){
		$(from_div).remove();
		$(behind_div).remove();
		$(ahead_div).attr('id','G_current_image');
		$(self.image_div).append('<div id="'+self.get_id_name(ahead_div)+'"></div>');
		self.display_image(ahead_image,ahead_div);
		$(self.image_div).append('<div id="'+self.get_id_name(behind_div)+'"></div>');
		self.display_image(behind_image,behind_div);
		self.bind_actions();
	});
};
Gallery.prototype.change_counter = function(){
	if(this.has_counter){
		var t=this.counter_template;
		t=t.replace(/\$\$AT/g,(this.at_image+1));
		t=t.replace(/\$\$TOTAL/,this.total_images);
		$(this.counter_div).html(t);
	}
};
Gallery.prototype.display_rating = function(){
	var value=arguments[0];
	if(value==0){value=this.no_rating_display;}
	var init=arguments[1]?arguments[1]:false;
	if(init){
		$('div#G_current_rating').html(value);
		this.display_rating_stars(value,true);
	}
	else{
		this.display_rating_stars(value,false);
		var trans=this.get_transition();
		if(trans=='SLIDE'){
			var rh=$(this.rating_div).height();
			var self=this;
			$('div#G_next_rating').css({'top':rh,'display':'block'});
			$('div#G_next_rating').html(value);
			$('div#G_current_rating').animate({'top':-rh},this.transition_speed);
			$('div#G_next_rating').animate({'top':0},this.transition_speed,function(){
				$('div#G_current_rating').remove();
				$('div#G_next_rating').attr('id','G_current_rating');
				$(this.rating_div).append('<div id="G_next_rating" />');
			});
			
		}
		if(trans=='FADE'){
			$('div#G_next_rating').html(value);
			$('div#G_next_rating').fadeIn(this.transition_speed);
			$('div#G_current_rating').fadeOut(this.transition_speed,function(){
				$('div#G_current_rating').remove();
				$('div#G_next_rating').attr('id','G_current_rating');
				$(this.rating_div).append('<div id="G_next_rating" />');				
			});
		}
	}
};
Gallery.prototype.display_rating_stars = function(value,is_init){
	if(this.use_rating_stars){	
		var id='';
		for(var i=1;i<=5;i++){
			id='#rate_'+i;
			$(id).removeClass('G_rated_value');
			$(id).removeClass('G_rated_half_value');
		}
		var i=0;
		var last_half=Math.round(value-Math.floor(value));
		var floor=Math.floor(value);
		for(i=0;i<=floor;i++){
			id='#rate_'+i;
			$(id).addClass('G_rated_value');
		}

		id='#rate_'+i;
		if(last_half && i<=5){
			$(id).removeClass('G_rated_value');
			$(id).addClass('G_rated_half_value');
		}
	}
};
Gallery.prototype.rate = function(value){

	if(this.rated[this.at_image]){
		this.display_rating(this.ratings[this.at_image]);
		return;
	}
	this.unbind_actions();
	this.wait_start('div#G_current_rating');
	var self=this;
	var data={};
	if(this.UUID_array[this.at_image]!==undefined){
		data.contentSSUK=this.UUID_array[this.at_image];
		data.contentType=this.default_snas_content_type;
	}
	else{
		data.contentURL=escape(this.original_image_array[this.at_image]);
	}
	data.rateValue=value;
	data.action='rateContent';
	$.ajax({
		type: "GET",
		url: this.gateway_script_location,
		data: data,
		dataType: "json",
		timeout: 5000,
		success: function(val){
			self.wait_complete('div#G_current_rating');
			self.ratings[self.at_image]=val.output.averageRating;
			self.rated[self.at_image]=true;
			var to_display=value;
			if(val.output.numRatings>0){
				to_display=val.output.averageRating;
			}
			self.display_rating(to_display);
			self.bind_actions();
		}
	});	
};
Gallery.prototype.rate_hover = function(value,type){
	for(var i=1;i<=value;i++){
		var id='#rate_'+i;
		if(type=='enter'){
			$(id).addClass('G_rate_hover');
		}
		else{
			$(id).removeClass('G_rate_hover');
		}
	}
};
Gallery.prototype.get_rating = function(){
	var at=arguments[0];
	var init=arguments[1]?arguments[1]:false;
	if(this.use_ratings){
		if(this.ratings[this.at_image]){
			this.display_rating(this.ratings[this.at_image]);
			return;
		}
		var data={};
		if(this.UUID_array[this.at_image]!==undefined){
			data.contentSSUK=this.UUID_array[this.at_image];
			data.contentType=this.default_snas_content_type;
		}
		else{
			data.contentURL=escape(this.original_image_array[this.at_image]);
		}
		
		data.action='getRating';
		var self=this;
		$.ajax({
			type: "GET",
			url: this.gateway_script_location,
			data: data,
			dataType: "json",
			success: function(val){
				self.ratings[self.at_image]=val.output.averageRating;
				self.display_rating(self.ratings[self.at_image],init);
			}
		});
	}
};

Gallery.prototype.wait_start = function(div){
	$(div).addClass('wait');
	$(div).html(this.rate_wait_message);
};
Gallery.prototype.wait_complete = function(div){
	$(div).empty();
	$(div).removeClass('wait');
};
