//grab each instance of the gallery
var gallery = {

	write:function(){
	  


	},
	
	thumbnailnav:function(p){
		
		/*controls the posiotion of thumbnail bar and whether to show the back and forward arrows*/
		gallery.parent.find('.base-gallery-thumbs ul').animate({marginLeft:p.ulx},{duration:500,queue:false,complete:function(){
			
			var currentx = parseInt(gallery.parent.find('.base-gallery-thumbs ul').css('margin-left'));
			
			if(currentx < 0 ){gallery.parent.find('.base-gallery-thumbs .back em').show();}
			if(currentx == 0 ){gallery.parent.find('.base-gallery-thumbs .back em').hide();}
			
			if(currentx<((gallery.forlength*-760)+760)){gallery.parent.find('.base-gallery-thumbs .forward em').hide()}
			if(currentx>(gallery.forlength*-760)){gallery.parent.find('.base-gallery-thumbs .forward em').show()}
		
		}});
		
	
	},
	
	timer:{
	
		set:function(p){
		
			if(p.el.hasClass('timer-on')==false){
				
				p.el.addClass('timer-on');
				gallery.timer.interval();
				gallery.parent.find('.base-gallery-timer').tooltip({ 
						track: true, 
						delay: 0, 
						showURL: false, 
						fade: 250,
						bodyHandler: function() { 
							return "Stop slideshow"; 
						} 
						
				});
				
			}
			
			else{
				gallery.timer.stop();
				gallery.parent.find('.base-gallery-timer').tooltip({ 
						track: true, 
						delay: 0, 
						showURL: false, 
						fade: 250,
						bodyHandler: function() { 
							return "Start slideshow"; 
						} 
						
				});
			}
	
		},
	
	
	interval:function(){
	
		var interval = gallery.interval/4;
		gallery.parent.find('.base-gallery-timercount').animate({lineHeight:0},interval,function(){
			
				$(this).attr('id','timer-on1');
				$(this).animate({lineHeight:0},interval,function(){
					
					$(this).attr('id','timer-on2');
					$(this).animate({lineHeight:0},interval,function(){
					
						$(this).attr('id','timer-on3');
						$(this).animate({lineHeight:0},interval,function(){
						
							$(this).attr('id','timer-on4');
							$(this).animate({lineHeight:0},interval,function(){
									
								$(this).attr('id','');
								gallery.parent.find('.base-gallery-mainnav:eq(1) em').trigger('click','x');
								gallery.timer.interval();
							
							})
						
						})
					
					})
				
				})
			
			})
		},
		
		stop:function(){
			gallery.parent.find('.base-gallery-timercount').stop().attr('id','');
			gallery.parent.find('.base-gallery-timer').removeClass('timer-on');
		
		
		
		}

	},
	
	ratings:function(p){
	
		var html =  "<div class='base-rating "+p.enable+"' id='"+p.id+"'><div class='base-rating-disable'></div><h5>"+p.message+"</h5><ul><li class='current-rating' style='width:"+(parseInt(p.value)*20)+"%'></li><li><a href='#' title='1 star out of 5' class='one-star'>1</a></li><li><a href='#' title='2 stars out of 5' class='two-stars'>2</a></li><li><a href='#' title='3 stars out of 5' class='three-stars'>3</a></li><li><a href='#' title='4 stars out of 5' class='four-stars'>4</a></li><li><a href='#' title='5 stars out of 5' class='five-stars'>5</a></li></ul></div>"
		
		return html;
		
	
	}
}
gallery.write();