var currentLoc = 0;

function leftClick()
{
	slideWidth = parseInt(document.getElementById("gallery").style.width.replace( /px/, "" ));
	totalWidth = parseInt(document.getElementById("totalWidthDiv").style.width.replace( /px/, "" ));

	if(currentLoc <=slideWidth)								// Already at first node, can't go left
	{
		currentLoc = currentLoc - slideWidth;
		jQuery(document.getElementById("gallery")).find("ul").animate({left:-currentLoc},750,"easeInOutExpo");
		currentLoc = totalWidth - (2*slideWidth);
		slightOfHand(currentLoc);	
	}
	else													// Normal case, can move left
	{
		currentLoc = currentLoc - slideWidth;		
		jQuery(document.getElementById("gallery")).find("ul").animate({left:-currentLoc},750,"easeInOutExpo");
	}
}

function rightClick()
{
	slideWidth = parseInt(document.getElementById("gallery").style.width.replace(/px/,""));
	totalWidth = parseInt(document.getElementById("totalWidthDiv").style.width.replace(/px/,""));
	
	if(currentLoc >= totalWidth - (2*slideWidth))			// Already at last node, can't go right
	{
		currentLoc = currentLoc + slideWidth;
		jQuery(document.getElementById("gallery")).find("ul").animate({left:-currentLoc},750,"easeInOutExpo");
		currentLoc = slideWidth;
		slightOfHand(currentLoc);
	}	
	else													// Normal case, can move right
	{
		currentLoc = currentLoc + slideWidth;
		jQuery(document.getElementById("gallery")).find("ul").animate({left:-currentLoc},750,"easeInOutExpo");	
	}
}

function slightOfHand(currentLoc)
{	
	jQuery(document.getElementById("gallery")).find("ul").animate({left:-currentLoc},1);
}

jQuery(function()
{
   jQuery("div.svw").prepend("<img src='http://www.gcmingati.net/wordpress/wp-content/uploads/svwloader.gif' class='ldrgif' alt='loading...'/ >"); 
});

jQuery.fn.slideView = function()
{
	slideList = document.getElementById("slideViewContainer");
	dupFirstNode = document.getElementById("firstSlide").cloneNode(true);
	dupLastNode  = document.getElementById("lastSlide").cloneNode(true);
		
	slideList.appendChild(dupFirstNode);
	slideList.insertBefore(dupLastNode,slideList.firstChild);

	return this.each(function()
	{
		var container = jQuery(this);
		container.find("img.ldrgif").remove();
		container.removeClass("svw").addClass("stripViewer");		
		subcontainer = container.find("li");
		var pictWidth = subcontainer.find("div").width();
		var pictHeight = subcontainer.find("div").height();
		var pictEls = container.find("li").size();
		var stripViewerWidth = pictWidth*pictEls;
		container.find("ul").css("width" , stripViewerWidth); 	
		container.find("ul").attr("id","totalWidthDiv");
		container.css("width" , pictWidth);
		container.css("height" , pictHeight);

		slideWidth = parseInt(document.getElementById("gallery").style.width.replace(/px/,""));
		currentLoc = currentLoc + slideWidth;
		jQuery(document.getElementById("gallery")).find("ul").animate({left:-currentLoc},1);
  	});	
};
