/***** BEGIN SLIDE SHOW *****/
function sliderObject(xmyId, xmyNextBtn, xmyPrevBtn, xmyMaxWidth, xmySlideWidth, xmyMaxHeight) {
	this.myId = xmyId;
	this.myNextBtn = xmyNextBtn;
	this.myPrevBtn = xmyPrevBtn;
	$("#" + this.myId).width(xmyMaxWidth);
	$("#" + this.myId).height(xmyMaxHeight);
	$("#" + this.myId + " .strip").height(xmyMaxHeight);
	$("#" + this.myId + " .singleSlide").width(xmySlideWidth);
	this.mySlideWidth = xmySlideWidth;
	this.defineSlider = initSlider;
	this.sliderMargins = checkMargins;
	this.inaction = false;
	this.enableClicks = readyClicks;
	this.previousSlide = slideToPrevious;
	this.nextSlide = slideToNext;
	this.confirmSlidePlacement = readyPlaced;
	this.resetSlider = slideReset;
	this.defineSlider();
}
function initSlider()
{
	this.sliderMargins();
	newSliderWidth = this.slideCount*this.slideWidth+"px";
	this.slider.width(newSliderWidth);
	$("#" + this.myId).width(parseInt($("#" + this.myId).width())-this.slideMarginLeft-this.slideMarginRight);
	$("#" + this.myId).css("margin-right",parseInt($("#" + this.myId).css("margin-right"))+this.slideMarginRight);
	$("#" + this.myId).css("margin-left",parseInt($("#" + this.myId).css("margin-left"))+this.slideMarginLeft);
	this.slider.css("left",-this.slideMarginLeft);
	this.originalSlider = $("#" + this.myId).html();
	this.enableClicks();
}

function slideReset()
{
	this.inaction = false;
	$("#" + this.myId).html(this.originalSlider);
	this.sliderMargins();
	this.slider.css("left",-this.slideMarginLeft);	
	this.enableClicks();
}

/***************************************************************************************************/
/*This function assigns the widths and set display count as well as slide count.                   */
/***************************************************************************************************/
function checkMargins()
{
	this.slideMarginLeft = 0;
	this.slideMarginRight = 0;
	this.slideWidth = this.mySlideWidth;
	this.slideCount = $("#" + this.myId + " .singleSlide").length;
	/*$("#floatImg")[0].style.styleFloat = "left";
	$("#floatImg")[0].style.cssFloat = "left";*/
	for (var i = 0; i<this.slideCount; i++) {
		$("#" + this.myId + " .singleSlide")[i].style.cssFloat = "left";
		$("#" + this.myId + " .singleSlide")[i].style.styleFloat = "left";
	}
	this.slider = $("#" + this.myId + " .strip");
	$("#" + this.myId + " .strip")[0].myParent =  this;
	 $("#" + this.myId)[0].style.marginLeft = "0px";
	 $("#" + this.myId)[0].style.marginRight = "0px";
	 $("#" + this.myId)[0].style.overflow = "hidden";
	$("#" + this.myId)[0].style.position = "relative";
	$("#" + this.myId)[0].style.left = "0px";
	this.slider[0].style.position = "relative";
	this.slider[0].style.left = "0px";
	this.sliderWidth = this.slider.width();
	this.displayCount = parseInt(this.sliderWidth/this.slideWidth);
	this.currSlide = 1;
}

function slideToNext()
{
	if (!this.myParent.inaction) {
		this.myParent.inaction = true;
		this.myParent.currSlide = ++this.myParent.currSlide;
		if (this.myParent.currSlide > this.myParent.slideCount) 
			this.myParent.currSlide = this.myParent.currSlide - this.myParent.slideCount;
		currLeft = parseInt(this.myParent.slider.css("left"));
		newLeft = (currLeft - this.myParent.slideWidth) + "px";
		movingSlide = $(".singleSlide:first", $("#" + this.myParent.myId + " .strip")).clone();
		movingSlide.appendTo("#" + this.myParent.myId + " .strip");
		this.myParent.slider.animate({
			left: newLeft
		}, function(){
			this.myParent.inaction = false;
			$(".singleSlide:first", ("#" + this.myParent.myId + " .strip")).remove();
			$("#" + this.myParent.myId + " .strip").css("left", parseInt($("#" + this.myParent.myId + " .strip").css("left")) + this.myParent.slideWidth);
		});
		this.myParent.confirmSlidePlacement();
	} else {
		return;
	}
}

function slideToPrevious()
{
	if (!this.myParent.inaction) {
		this.myParent.inaction = true;
		this.myParent.currSlide = --this.myParent.currSlide;
		if(this.myParent.currSlide<1) 
			this.myParent.currSlide=this.myParent.slideCount;
		movingSlide = $(".singleSlide:last",$("#" + this.myParent.myId + " .strip")).clone();
		movingSlide.prependTo("#" + this.myParent.myId + " .strip");
		$("#" + this.myParent.myId + " .strip").css("left",parseInt($("#" + this.myParent.myId + " .strip").css("left"))-this.myParent.slideWidth);
		currLeft = parseInt(this.myParent.slider.css("left"));
		newLeft = (currLeft+this.myParent.slideWidth)+"px";
		this.myParent.slider.animate({left:newLeft},
			function(){
				this.myParent.inaction = false;
				$(".singleSlide:last",("#" + this.myParent.myId + " .strip")).remove();
			}
		);
		this.myParent.confirmSlidePlacement();
	} else {
		return;
	}
}

function readyPlaced()
{
	if((parseInt($("#" + this.myId + " .strip").css("left"))+this.slideMarginLeft)%this.slideWidth!=0)
	{
		zero = -this.slideMarginLeft;
		this.slider.animate({left:zero},function(){setTimeout(this.myParent.resetSlider,500);});
	}
}

function readyClicks()
{
	$("#" + this.myPrevBtn)[0].style.cursor = "pointer";
	$("#" + this.myNextBtn)[0].style.cursor = "pointer";
	$("#" + this.myPrevBtn)[0].myParent = this;
	$("#" + this.myNextBtn)[0].myParent = this;
	$("#" + this.myPrevBtn)[0].myParent.inaction = false;
	$("#" + this.myPrevBtn).click(this.previousSlide);
	$("#" + this.myNextBtn).click(this.nextSlide);
}
/***** END SLIDESHOW *****/