// JavaScript Document
var Gallery = function()
{
	return{
		images:null,
		current:0,
		holder:null,
		nav_left:null,
		nav_right:null, 
		
		Init:function()
		{
			this.images = $(".gallery_list img");
			this.nav_left = $("#nav_left");
			this.nav_right = $("#nav_right");
			
			this.nav_left.css("visibility" , "hidden");
			
			if(this.images.length <= 1)
				this.nav_right.css("visibility" , "hidden");
				
			this.holder = $("#img_holder");
		},
		
		MoveLeft:function()
		{
			this.current--;
			this.ShowImg();
			
		},
		
		MoveRight:function()
		{
			this.current++;
			
			
			this.ShowImg();
		},
		
		Thumb_Click:function(img)
		{
			for(var i = 0; i < this.images.length; i++)
			{
				if(this.images[i] == img)
				{
					this.current = i;
					break;
				}
			}

			
			this.ShowImg();
		},
		
		ShowImg:function()
		{
			var img = $(this.images[this.current]);
			var width = img.attr("img_w");
			var height = img.attr("img_h");
			
			if(width > 508)
			{
				var percent = 508 * 100 / width; //mažinam procentaliai
				width = 508;
				
				height = parseInt(percent * height / 100) + 10;
			}
			
			if(parseInt(width) <= 0 || parseInt(height) <= 0)
			{
				width = 508;	
				height = 334;
			}
			
			if(img.attr("type") == "1")
			{
				var ft = new FlashTag("player.swf?film=streamer.php?id=" + img.attr("img_id"), width, height);
				ft.setParentNode("img_holder");
				ft.write();	
			}
			else
			{
				this.holder.html('<span class="single"><a href="streamer.php?id='+img.attr("img_id")+'"><img src="streamer.php?id='+img.attr("img_id")+'" width="'+width+'" height="'+height+'" /></a></span>');
				$('.thumbs').piroBox({
				border: 1, 
				mySpeed: 700,
				borderColor : '#444',  
				bg_alpha: 0.5,
				cap_op_start : 0.4,
				cap_op_end: 0.8,
				pathLoader : '#000 url(css_pirobox/ajax-loader.gif) center center no-repeat;', 
				
				single : '.single  a',
				next_class : '.next',
				previous_class : '.previous'
				});	
			}
			
			
			if(this.images.length <= 1)
			{
				this.nav_left.css("visibility","hidden");
				this.nav_right.css("visibility","hidden");
				return;
			}
			
			this.nav_left.css("visibility","visible");
			this.nav_right.css("visibility","visible");
			
			if(this.current >= this.images.length - 1)
			{
				this.current = this.images.length - 1;
				this.nav_right.css("visibility","hidden");
				this.nav_left.css("visibility", "visible");

			}
			
			if(this.current <= 0)
			{
				this.current = 0;
				this.nav_left.css("visibility", "hidden");
				this.nav_right.css("visibility","visible");
			}
			
			
		}
	}

}();