
function sliderMain(mName, mContainerId, mSubcontainer1Id, mSubcontainer2Id, mSubcontainer3Id, mPageContainer, loadURL, countURL, blogNumber, showhideLoadingCall, enabledisableNextCall, blogChangeCall)
{
	this.checkValidConstructor = function(sVal){
		if($("#" + sVal)[0]==null)
		{
			alert("sliderMain Error in constructor");
			return null;
		}
		else
		{
			return sVal;
		}
	};
	
	this._container = this.checkValidConstructor(mContainerId);

	this._showhideLoadingCall = showhideLoadingCall;
	this._enabledisableNextCall = enabledisableNextCall;
	this._blogChangeCall = blogChangeCall;
	
	this.loadNew = true;
	this._cCurrent = this.checkValidConstructor(mSubcontainer1Id);
	this._cPrev = this.checkValidConstructor(mSubcontainer2Id);
	this._cNext = this.checkValidConstructor(mSubcontainer3Id);
	this._cPage = this.checkValidConstructor(mPageContainer);
	this._currentItem = 1;
	this._itemCount = 1;
	this._prevID = null;
	this._nextID = null;
	this._disablePrev = true;
	this._disableNext = true;
	this._disablePrevAnn = false;
	this._disableNextAnn = false;
	this._disableAny = false;
	
	this._countURL = countURL;
	this._loadURL = loadURL;
	
	this.disablePrev = function()
	{
		this._disablePrev = true;
		enabledisableNextCall("disable", "prev");
	}
	
	this.enablePrev = function()
	{
		this._disablePrev = false;
		enabledisableNextCall("enable", "prev");
	}
	
	this.disableNext = function()
	{
		this._disableNext = true;
		enabledisableNextCall("disable", "next");
	}
	
	this.enableNext = function()
	{
		this._disableNext = false;
		enabledisableNextCall("enable", "next");
	}
	
	this.setCurrentItemAndCount = function(itemNumber, callback){
		this._currentItem = itemNumber;
		this._doEnableDisable();
		$.getJSON( this._countURL, function(json){
			eval("var self = " + mName + ";");
  			self._setCurrentItemAndCount(json.count);
  			if(callback!=null){callback.call();}
		} );
	};
	
	this._setCurrentItemAndCount = function(count){ 
		this._itemCount = count;
		if(this._currentItem>this._itemCount)
		{
			this._currentItem=this._itemCount;
		}
		this._doEnableDisable();
		this.resetPaging(this._itemCount, this._currentItem);
	};
	
	this._doEnableDisable = function(){ 
		if(this._currentItem>=this._itemCount)
		{
			this.disableNext();
		}
		else
		{
			this.enableNext();
		}
		
		if(this._currentItem<=1)
		{
			this.disablePrev();
		}
		else
		{
			this.enablePrev();
		}
	};
	
	this.goPrev = function(){
	
		if(!this._disablePrev && !this._disablePrevAnn && !this._disableAnyAnn)
		{
			this._disablePrevAnn = true;

			$("#"+this._cCurrent).animate({ left: "880px" }, 500, "easeInQuint", function(){
				eval("var self = " + mName + ";");
				
				$("#"+self._cCurrent).css({ left: "880px"});
				$("#"+self._cPrev).css({ left: "-880px"});
				$("#"+self._cPrev).animate({ left: "0px" }, 500, "easeOutQuint", function(){
					eval("var self = " + mName + ";");
					
					$("#"+ self._cPrev).css({ left: "0px"});
					var TempNext = self._cNext;
					self._cNext = self._cCurrent;
					self._cCurrent = self._cPrev;
					self._cPrev = TempNext;
					self.setCurrentItemAndCount(self._currentItem-1, function(){
						eval("var self = " + mName + ";");
						
						if((self._currentItem)>1)
						{
							if(self._showhideLoadingCall){self._showhideLoadingCall("show", "prev");}
							//alert(self._loadURL + "/" + (self._currentItem-1));
							$("#"+self._cPrev).load(self._loadURL + "/" + (self._currentItem-1), {}, function(){ 
								eval("var self = " + mName + ";");
								self._disablePrevAnn = false;
								if(self._showhideLoadingCall){self._showhideLoadingCall("hide", "prev");}
							} );
						}
						else
						{
							self._disablePrevAnn = false;
						}
						
						self._blogChangeCall(self._currentItem);
					});	
				} );
			} );
		}
	};

	this.goNext = function()
	{
		if(!this._disableNext && !this._disableNextAnn && !this._disableAnyAnn)
		{
			this._disableNextAnn = true;
			
			$("#"+this._cCurrent).animate({ left: "-880px" }, 500, "easeInQuint", function(){
				eval("var self = " + mName + ";");
				
				$("#"+self._cCurrent).css({ left: "-880px"});
				$("#"+self._cNext).css({ left: "880px"});
				$("#"+self._cNext).animate({ left: "0px" }, 500, "easeOutQuint", function(){
					eval("var self = " + mName + ";");
					
					$("#"+ self._cNext).css({ left: "0px"});
					var TempPrev = self._cPrev;
					self._cPrev = self._cCurrent;
					self._cCurrent = self._cNext;
					self._cNext = TempPrev;
					self.setCurrentItemAndCount(self._currentItem+1, function(){
						eval("var self = " + mName + ";");
						
						if((self._currentItem)>1)
						{
							if(self._showhideLoadingCall){self._showhideLoadingCall("show", "next");}
							//alert(self._loadURL + "/" + (self._currentItem-1));
							$("#"+self._cNext).load(self._loadURL + "/" + (self._currentItem+1), {}, function(){ 
								eval("var self = " + mName + ";");
								self._disableNextAnn = false;
								if(self._showhideLoadingCall){self._showhideLoadingCall("hide", "next");}
							} );
						}
						else
						{
							self._disableNextAnn = false;
						}
						
						self._blogChangeCall(self._currentItem);
					
					});	
							
				} );
			} );
		}
	};
	
	
	this.goLast = function(){
		this.goNumber(this._itemCount);
	};
	
	this.goFirst = function(){
		this.goNumber(1);
	};
	
	this.goNumber = function(number, skipfirstLoad){
	
		if(!this._disableAny)
		{
			this._disableAny = true;
			
			var iTime = this.loadNew ? 0: 500;
			this.loadNew = true;
			
			if(skipfirstLoad==true)
			{
				this.setCurrentItemAndCount(number, function(){
					eval("var self = " + mName + ";");
					self._disableAny = false
				});
			}
			else
			{
			this.setCurrentItemAndCount(number, function(){
				eval("var self = " + mName + ";");
				
				var currentTop = parseInt( $("#"+self._cCurrent).css("top") );
				$("#"+self._cCurrent).animate({ top: (currentTop+300) + "px" }, 500, "easeInQuint", function(){
					eval("var self = " + mName + ";");
					
					$("#"+self._cCurrent).css({ top: (currentTop+300) + "px"});
					$("#"+self._cCurrent).load(self._loadURL + "/" + self._currentItem, {}, function(){ 
						eval("var self = " + mName + ";");
						//alert($("#"+self._cCurrent).html());
						$("#"+self._cCurrent).animate({ top: currentTop + "px" }, 500, "easeOutQuint", function(){
							eval("var self = " + mName + ";");
							$("#"+self._cCurrent).css({top: currentTop + "px", left: "0px"});
							
							self._disableAny = false;
							self._blogChangeCall(self._currentItem);
						} );
					} );
					
					if(self._currentItem>1)
					{
						self._disablePrevAnn = true;
						$("#"+self._cPrev).load(self._loadURL + "/" + (self._currentItem-1), {}, function(){
							eval("var self = " + mName + ";");
							self._disablePrevAnn = false;
						} );
					}
					
					if(self._currentItem<self._itemCount)
					{
						self._disableNextAnn = true;
						$("#"+self._cNext).load(self._loadURL + "/" + (self._currentItem+1), {}, function(){
							eval("var self = " + mName + ";");
							self._disableNextAnn = false;
						} );	
					}
					
				} );
			} );
			}
		}
	};
	
	this.resetPaging = function(iCount, iCurrent) {
	
		$("#" + this._cPage).empty();
		
		
		var iDisplayCount = 2;
		
		var i = 1;
		if(!((iCurrent-iDisplayCount)<1)){
			i = (iCurrent-iDisplayCount);
		}
		
		var ilimit = iCount;
		if(!((iCurrent+iDisplayCount)>=iCount)){
			ilimit = (iCurrent+iDisplayCount);
		}
		
		if(ilimit<(iDisplayCount*2)+1)
		{
			ilimit = ((iDisplayCount*2)+1 > iCount) ? iCount : (iDisplayCount*2)+1;
		}

		var newI = i - (iDisplayCount - (ilimit-iCurrent));
		i = (newI<i) ? newI: i;
		i = (i<=0) ? 1 : i;
		
		
		if(ilimit>i)
		{
			if(iCount>1){
			//first
			var node = document.createElement("a");
			node.className = "slideDot";
			node.href = "javascript: " + mName + ".goNumber(1)";
			node.innerHTML = "First";
			$("#" + this._cPage).append(node);
			
			var node = document.createElement("a");
			node.className = "slideDot";
			node.href = "javascript: " + mName + ".goPrev()";
			node.innerHTML = "<";
			$("#" + this._cPage).append(node);
			}
		
			while(i<=ilimit)
			{
				if(i!=iCurrent){
					var node = document.createElement("a");
					node.className = "slideDot";
					node.href = "javascript: " + mName + ".goNumber(" + i + ")";
				}else{
					var node = document.createElement("span");
				}
				//var img = document.createElement("img");
				//img.src = base_urlonly + "/images/dot.png";
				//img.border = "0";
				//node.appendChild(img);
				node.innerHTML = i;
				$("#" + this._cPage).append(node);

				i++;
			}
			
			if(iCount>1){
			//last
			var node = document.createElement("a");
			node.className = "slideDot";
			node.href = "javascript: " + mName + ".goNext()";
			node.innerHTML = ">";
			$("#" + this._cPage).append(node);
			
			var node = document.createElement("a");
			node.className = "slideDot";
			node.href = "javascript: " + mName + ".goLast()";
			node.innerHTML = "Last";
			$("#" + this._cPage).append(node);
			}

		}
		var arrayString = new Array();
	
	};
	
	this.setURL = function(urlCount, urlGet){
	
		this._countURL = urlCount;
		this._loadURL = urlGet;
		
		this.goNumber(1);
		
	};
	
	this.goNumber(blogNumber, ($("#" + this._cCurrent).html()!=""));
}
