/**
 * This is a modified version of his slideViewer, which can be found at 
 * http://www.gcmingati.net/wordpress/wp-content/lab/jquery/imagestrip/imageslide-plugin.html 
 */

//preloader
jQuery(function(){
   jQuery("div.svw").prepend("<img src='http://www.gcmingati.net/wordpress/wp-content/uploads/svwloader.gif' class='ldrgif' alt='loading...'/ >"); 
});


//scrolling settings
var settings = jQuery.extend(
{
	easeFunc: "easeInOutExpo",
	easeTime: 750,
	toolTip: false
}, settings);


//actual slider
jQuery.fn.slideIt = function(id)
{
	//highlight current, remove all others
	$(this).find("img").addClass("current").parent().parent().parent().find("img").not($(this).find("img")).removeClass("current");
	//set counter
	var cnt = - (pictWidth*id);
	//scroll parent to counter
	$(this).parent().parent().parent().parent().prev().find("ul").animate({ left: cnt}, settings.easeTime, settings.easeFunc);
	//record current id
	current_id = id;
	return false;
}

jQuery.fn.slideNext = function()
{
	//increment current id
	current_id = (current_id >= total) ? 0 : current_id + 1;
	//animate next
	$(".image-thumbs a:eq("+current_id+")").slideIt(current_id);
}

jQuery.fn.slidePrev = function()
{
	//reduce counter
	current_id = (current_id <= 0 ) ? total : current_id-1;
	//animate back
	$(".image-thumbs a:eq("+current_id+")").slideIt(current_id);
}

//get current id
var current_id = 0;
var cnt = 0;
var pictWidth = 0;
var total = 0;
var container;

jQuery.fn.slideView = function(settings)
{
	return this.each(function()
	{
		//map container
		container = jQuery(this);
		//remove preloader image
		container.find("img.ldrgif").remove();
		//remove holder class, set current
		container.removeClass("svw").addClass("stripViewer");
		//get image dimension
		//pictWidth = container.find("li").find("img").width();
		pictWidth = 300; //fixed as ie reading differently
		var pictHeight = container.find("li").find("img").height();
		//get total elements
		var pictEls = container.find("li").size();
		//calc total width
		var stripViewerWidth = pictWidth*pictEls;
		//get first list of images
		var first_list = container.find(".images-main");
		first_list.find("ul").css("width" , stripViewerWidth); //assign total with to ul
		//set image dimentions
		container.css("width" , pictWidth);
		container.css("height" , pictHeight);
		//show thumbnails
		$thumblist = container.find(".thumb-list");
		$thumblist.show();
		//iterate div
		container.each(function(i)
		{
			//set next/previous buttons
			$(this).find(".btn-previous a").bind("click", function()
			{
				$(this).slidePrev();
				return false;
			});
			$(this).find(".btn-next a").bind("click", function()
			{
				//show next
				$(this).slideNext();
				return false;
			});
			//get thumb container
			$items = $(this).find(".image-thumbs")
			//get total thumbs (sub 1 to synch ids)
			total =  $items.find("li").size() - 1;
			//link thumbnails
		   	$items.find("li").each(function(n)
			{
				$(this).find("img").wrap("<a href='#"+(n+1)+"' class='rbm-slider-link'></a>");
			});
			//set functionality
			$(".image-thumbs a").each(function(z)
			{
				//assign click action
				$(this).bind("click", function()
				{
					$(this).slideIt(z);
					return false;
				});
			});
			//select first element
			$("div.image-thumbs a img:eq(0)").addClass("current");
		});
  });	
};
