(function($){
	$.fn.iss_gallery = function(options){
		var opts = $.extend({}, $.fn.iss_gallery.defaults, options);
		var jThis = $(this);
		var second_img = jThis.find('.photos_gallery_second li');
		/*
		second_img.everyTime(5000, "transition", function(){
				//second_img.click();
				second_img.removeClass('selected_photo');
				next = jThis.find('.photos_gallery_second li');
				next.addClass('selected_photo');
			});
		*/	
		

		second_img.each(function(){
			if($(this).hasClass('selected_photo')){
				$(this).find("img").css({"border":"0px"});
			}
		});		
		
		return this.each(function(){
			
			second_img.each(function(){
				
				$(this).click(function(){
						if(!$(this).hasClass('selected_photo')){
							
							second_img.each(function(){
								if($(this).hasClass('selected_photo')){
									$(this).removeClass('selected_photo');
									$(this).find("a").css({"border":"1px solid #ffffff"});
								}
							});
							$(this).addClass('selected_photo');
							$(this).find("a").css({"border":"3px solid #F5CA00"});
							$(this).find("a img").css({"border":"0px"});
							
							var target = $(this).find("a").attr("href");
							var title = $(this).find("a").attr("title");
							var sapou = $(this).find("a").attr("rel");
							var permalink = $(this).find("p").html();
							
							$('p#description_title a').html(title);
							$('p#description_title a').attr("href",permalink);
							$('p#description_title a').attr("title",title);
							$('p#description_sapou').html(sapou);
							
							$('img#primary_photo').fadeOut("fast", function(){
								$('img#primary_photo').attr({"src": target}).fadeIn("fast");								
							});
						}
						return false;
					}
				);
				
			});
            
            //$(document).stopTime("transition");
            //$(document).everyTime(2000, "transition", function(){});
		});
		
	}; 
	$.fn.iss_gallery.defaults = {
		
	};
})(jQuery);
