function SlideShow(objNameParam, slideShowIDParam, slideWidthParams, slideHeightParams) {

	var slideShowID = slideShowIDParam;
	var objSlideShow = $('#'+slideShowID);
	var arrSlide;
	var arrSlidePaging;
	var arrCounter;
	var currItem;
	var slideShowPlay;
	var objName = objNameParam;
	var slideWidth = 0;
	var slideHeight = 0;
	var slideTimer = 9000;
	var mouseBehavior = 'click'; //click, mouseOver
	var showPaging = true;
	var pagingID =  ''; //Uses a <ul> <li> as the paging, instead of having the component generating one
	var displayNavigation = false; // Display next/prev buttons
	var isLazyLoad = false; //Loads the any image inside a slide only when the slide is selected. It gets the attributes from the rel='url' and loads the image
	/* Scrolling paging only variables */
	var thumbsPerPage = 0; //Used when creating image gallery including the thumbnail lists with scrolling
	var thumbWidth = 0; //Used same as thumbsPerPage
	var scrollingRight = false;
	var scrollingLeft = false;
	var pageNumberOfLabel = "of";
	
	if (typeof slideWidthParams != "undefined")
		slideWidth = slideWidthParams.replace('px','');
	if (typeof slideHeightParams != "undefined")
		slideHeight = slideHeightParams.replace('px','');
	
	this.getSlideShow = function(start, play) { /* Sets up the configuration and environment and display SlideShow */
		arrSlide = new Array();
		arrSlidePaging = new Array();
		
		/* Applies width and height to the slide show as css styles */
		objSlideShow.css("width", slideWidth+"px");
		if (slideWidth > 0)
			$('#'+slideShowID+'>div:first-child').css("width", slideWidth+"px");
		if (slideHeight > 0)
			$('#'+slideShowID+'>div:first-child').css("height", slideHeight+"px");
		$('#'+slideShowID+'>div:first-child').css("position", "relative");

		/* Grabs data from the divs and insert in the array */
		arrCounter = 0;
		$('#'+slideShowID+' div#'+slideShowID+'Data>div').each( function() { 
			$(this).css('zIndex',1).css('position','absolute').css('display','none');
			arrSlide[arrCounter++] = $(this);
		});

		/* Sets the start slide (random, first or preselected value. Preselected value is start-1 (since JS array start at 0) */
		if (start == 'random')
			start = Math.floor(Math.random() * $('#'+slideShowID+' div#'+slideShowID+'Data>div').length);
		else {
			start = start - 1;
			if (start >= arrSlide.length)
				start = arrSlide.length-1;
		}
		arrSlide[start].show();

		/* Assigns the current Item based on the size of the slideShow (currItem needs to be start-1 to apply next();)*/
		currItem = start-1;
		if (currItem < 0)
			currItem = arrSlide.length-1;
	
		if (arrSlide.length <= 1)
			showPaging = false;

		/* Paging Logic */
		if (showPaging)
			this.displayPaging();
		
		/* Prev/Next navigation Logic */
		if (displayNavigation)
			this.displayNavigation();

		/* Display Item or Start Slideshow */
		if (arrSlide.length > 1) {
			this.next();
			if (play)
				this.play();
		}
	}
	 
	this.slideSwitch = function(position) { /* Switches the picture to the position passed */
		var oldItem = currItem;
		var img;
		currItem = position;

		if (oldItem != currItem) {
			if (isLazyLoad) { /* If Lazy Load Option is on, get the url from alt='url' and insert into src='' (which should be empty) */
				$("#"+slideShowID+"Data .slide_"+(currItem+1)).each(function() {	 
					objIMG = $(this).children("img");
					if (objIMG.attr("src") == '') { 
						objIMG.hide();
						img = new Image();
						img.onload = $(this).append(img);
						img.src = objIMG.attr("alt");
					}
				});
				objSlideShow.trigger("imageSlideChangeLazyLoad", currItem);
			}
			arrSlide[oldItem].fadeOut('slow');
			if (showPaging)
				arrSlidePaging[oldItem].removeClass('slideSelected');
			arrSlide[currItem].fadeIn('slow');
			if (showPaging)
				arrSlidePaging[currItem].addClass('slideSelected');
		}
		objSlideShow.trigger("imageSlideChange", currItem);
	}
		
	this.next = function() { /* Next picture */
		var nextSlide = currItem+1;
		if (nextSlide > arrSlide.length-1)
			nextSlide = 0;
		this.slideSwitch(nextSlide);
	}

	this.prev = function() { /* Previous Picture*/
		var prevSlide = currItem-1;
		if (prevSlide < 0)
			prevSlide = arrSlide.length-1;
		this.slideSwitch(prevSlide);
	}

	this.play = function() { /* Start SlideShow */
		slideShowPlay = true;
		setTimeout(""+objName+".playSlide();",slideTimer);
	}
	 
	this.playSlide = function() { /* SlideShow loop function until stop function is called */
		if (!slideShowPlay)
			return;
		this.next();
		setTimeout(""+objName+".playSlide();",slideTimer);
	}
	
	this.stop = function() { /* Stop Slideshow */
		slideShowPlay = false;
	}
	
	this.displayPaging = function() { /* Display paging */
		arrCounter = 0;
		if ($("#"+slideShowID+"PagingWrapper").length == 0) {
			objSlideShow.append("<div id='"+slideShowID+"PagingWrapper' class='imageSlidePagingWrapper'><div id='"+slideShowID+"Paging' class='imageSlidePaging'><ul></ul></div></div>");/* Creates the paging */
			for (i=0;i<arrSlide.length;i++) {
				if (mouseBehavior == 'click')
					$('#'+slideShowID+' #'+slideShowID+'Paging ul').append("<li id='"+slideShowID+"Item"+i+"'><a href='javascript:;' onclick='"+objName+".slideSwitch("+i+");return false;'>&nbsp;</a></li>");
				else
					$('#'+slideShowID+' #'+slideShowID+'Paging ul').append("<li id='"+slideShowID+"Item"+i+"'><a href='javascript:;' onMouseOver='"+objName+".slideSwitch("+i+");return false;'>&nbsp;</a></li>");
			}
		}
		$('#'+slideShowID+' #'+slideShowID+'Paging li').each( function() {  
			arrSlidePaging[arrCounter++] = $(this);
		});
		arrSlidePaging[currItem].addClass('slideSelected'); /* Highlights the paging box according to the start */
		$('#'+slideShowID+'Paging a').click(function() { eval(objName+'.stop();'); }); /* Appends 'stop play' when clicking on thumbs */
	}
	
	this.displayNavigation = function() { /* Display next/prev buttons */
		if ($("#"+slideShowID+"Prev").length == 0) {
			objSlideShow.append("<div id='"+slideShowID+"Prev' class='imageSlidePrev'><a href='javascript:;' onclick='"+objName+".prev();'></a></div>");
			objSlideShow.append("<div id='"+slideShowID+"Next' class='imageSlideNext'><a href='javascript:;' onclick='"+objName+".next();'></a></div>");
			$('#'+slideShowID+'Prev a,#'+slideShowID+'Next a').click(function() { eval(objName+'.stop();'); }); /* Appends 'stop play' when clicking next/prev */
		}
	}
	
	this.displayPageNumber = function(pageNumberLabel) {
		if ($("#"+slideShowID+"PageNumber").length == 0) {
			var pageNumberOfLabel = pageNumberLabel;
			objSlideShow.append("<div id='"+slideShowID+"PageNumber' class='imageSlidePageNumber'><span class='currNumber'>"+(this.getCurrentItem()+1)+"</span> "+pageNumberOfLabel+" "+(this.getTotalItems())+"</div>");
			//$("#"+slideShowID+"Paging a,#"+slideShowID+"Prev a,#"+slideShowID+"Next a").click(function() {
			objSlideShow.bind('imageSlideChange', function(e, data) { 
				$('#'+slideShowID+' .imageSlidePageNumber .currNumber').html(eval(objName+'.getCurrentItem()+1;'));
			});	
		}
	}
	
	this.switchPage = function(thumbNumber) { /* Scrolls the paging */
		if (typeof(thumbNumber) == "undefined") {
			thumbNumber = currItem - parseInt(thumbsPerPage/2)+1;
			if (thumbsPerPage % 2 == 0)
				thumbNumber = thumbNumber +1;
		}
		$("#"+slideShowID+"PagingWrapper").animate({ scrollLeft: thumbWidth*(thumbNumber-1) });
	}
	
	this.enablePagingScrolling = function(slideThumbWidth, slideThumbsPerPage) { /* Enables the page scrolling */
		thumbsPerPage = slideThumbsPerPage;
		thumbWidth = slideThumbWidth;
		objSlideShow.bind('imageSlideChange', function(e, data) { 
			eval(objName+'.switchPage();');
		});	
		/* Inserting paging arrows */
		objSlideShow.append("<div id='"+slideShowID+"PagingRight' class='imageSlidePagingRight'><a href='javascript:return false;'></a></div>");
		objSlideShow.append("<div id='"+slideShowID+"PagingLeft' class='imageSlidePagingLeft'><a href='javascript:return false;'></a></div>");
		$('#'+slideShowID+'PagingRight').hover(
			function() { eval(objName+'.scrollPagingRight();') },
			function() { eval(objName+'.stopScrolling();') 	}
		);
		$('#'+slideShowID+'PagingLeft').hover(
			function() { eval(objName+'.scrollPagingLeft();') },
			function() { eval(objName+'.stopScrolling();') }
		);
	}
	
	this.scrollPagingRight = function() { /* Scroll Paging Right */
		scrollingRight = true;
		this.scrollPaging(4);
	}

	this.scrollPagingLeft = function() { /* Scroll Paging Left */
		scrollingLeft = true;
		this.scrollPaging(-4);
	}
	
	this.scrollPaging = function(distance) { /* Scroll Paging based on the distance passed and loops over until stopScrolling is called */
		$("#"+slideShowID+"PagingWrapper").scrollLeft($("#"+slideShowID+"PagingWrapper").scrollLeft()+distance);
		if (scrollingRight || scrollingLeft)
			setTimeout(""+objName+".scrollPaging("+distance+")", 30);
	}

	this.stopScrolling = function() { /* Stops auto scrolling */
		scrollingLeft = false;
		scrollingRight = false;
	}

	this.setTimer = function(timerParam) { slideTimer = timerParam;	}
	this.setPagingID = function(slidePagingID) { pagingID = slidePagingID; }
	this.setMouseBehavior = function(type) { mouseBehavior = type;	}/* mouseOver, click */
	this.setShowPaging = function(boo) { showPaging = boo; }
	this.setLazyLoad = function(boo) { isLazyLoad = boo; }
	this.setDisplayNavigation = function(boo) { displayNavigation = boo; }
	this.setPagingItemContent = function(itemIndex, element) { arrSlidePaging[itemIndex-1].children("a").html('').append(element); } /* Inserts any content inside the paging box */
	this.getCurrentItem = function() { return currItem;	}
	this.getTotalItems = function() { return arrSlide.length; }
	
}