var looping_small = true;

$(document).ready(function(){


	change_image_small($(".items_small a:first"));
	

	$(".items_small a").click(function() {
		looping_small = false;
		change_image_small($(this));
	});


	$('.browse_small').click(function(){
		looping_small = false;
		var item;

		if($(this).hasClass('right')){
			item = $(".items_small a.active").parent().next('span').children('a');
		}else{
			item = $(".items_small a.active").parent().prev('span').children('a');
		}
		change_image_small(item);
	});

	window.setTimeout('loop_small()', 3000);
	

});



function change_image_small(obj){

	if(typeof(obj.attr("href")) != 'string'){
		return;
	}
	
	// see if same thumb is being clicked
	if (obj.hasClass("active")) {return;}

	// calclulate large image's URL based on the thumbnail URL (flickr specific)
	//var url = obj.attr("href").replace("_t", "");
	var url = obj.attr("href");

	// get handle to element that wraps the image and make it semi-transparent
//	var wrap = $("#image_wrap").fadeTo("fast", 0.5);
	var wrap = $("#image_wrap_small").show();

	// the large image from www.flickr.com
	var img = new Image();


	// call this function after it's loaded
	img.onload = function() {

		// make wrapper fully visible
		wrap.fadeTo("fast", 1);

		// change the image
		wrap.find("img").attr("src", url);

	};

	// begin loading the image from www.flickr.com
	img.src = url;

	// activate item
	$(".items_small a").removeClass("active");
	obj.addClass("active");

	var textcont = obj.next('span').children('.text').html();
	$('#slider_text_cont').html(textcont);

	var newlink = obj.next('span').children('.link').html();
	if(!newlink){
		newlink = "#";
	}
	$('#slider_link').attr('href',newlink);
}




function loop_small(){
	if(!looping_small){
		return false;
	}
	
	var item = $(".items_small a.active").parent().next('span').children('a');
	if(item.length == 0){
		item = $(".items_small a:first");
	}

	change_image_small(item);

	window.setTimeout('loop_small()', 3000);
}
