var page_width = 885;

function moveRight(type){
	if (!$("#" + type + "-btn-right").hasClass("btn-right-disabled"))
	{
		var current = parseInt($("#" + type + "-slider").css("left")); 
		var left = current - page_width;
		var rightmost = false;
		if (left - page_width <= -1 * $("#" + type + "-slider ul").width())
		{
			left = "-" + ($("#" + type + "-slider ul").width() - page_width);
			rightmost = true;
		}
		$("#" + type + "-btn-left").addClass("btn-left-disabled");
		$("#" + type + "-btn-right").addClass("btn-right-disabled").removeClass("btn-right-hover");
		$("#" + type + "-slider").animate({ left: left + "px" }, 800 * ((current - left) / page_width), "swing", function() {
			$("#" + type + "-btn-left").removeClass("btn-left-disabled");		
			if (rightmost)
			{
				$("#" + type + "-btn-right").addClass("btn-right-disabled");
			}
			else
			{
				$("#" + type + "-btn-right").removeClass("btn-right-disabled");
			}
		});
	}
}
function moveLeft(type){
	if (!$("#" + type + "-btn-left").hasClass("btn-left-disabled"))
	{
		var current = parseInt($("#" + type + "-slider").css("left")); 
		var left = current + page_width;
		if (left > 0)
		{
			left = 0;
		}
		$("#" + type + "-btn-left").addClass("btn-left-disabled").removeClass("btn-left-hover");
		$("#" + type + "-btn-right").addClass("btn-right-disabled");
		$("#" + type + "-slider").animate({ left: left + "px" }, 800 * ((left - current) / page_width), "swing", function() {
			if (left == 0)
			{
				$("#" + type + "-btn-left").addClass("btn-left-disabled");
			}
			else
			{
				$("#" + type + "-btn-left").removeClass("btn-left-disabled");		
			}
			$("#" + type + "-btn-right").removeClass("btn-right-disabled");		
		});
	}
}

function disablebuttons(xposition,xspeed,end){
	var the_style_left = document.getElementById('latest-' + type + '-btn-left');
	var the_style_right = document.getElementById('latest-' + type + '-btn-right');
	var the_style_left_disabled = document.getElementById('latest-' + type + '-btn-left-disabled');
	var the_style_right_disabled = document.getElementById('latest-' + type + '-btn-right-disabled');
	//	if click on move left and x=0 then disable or enable
	if(xspeed>0){
		if (xposition==-888)
		{		
			//alert( the_style_left);
			the_style_left.id="latest-" + type + "-btn-left-disabled";
			
		}else if(xposition==-1782 ){
			//alert("press2");
			//the_style_left.id="latest-" + type + "-btn-left";			
			the_style_right_disabled.id="latest-" + type + "-btn-right";
		}
	}

//if click on move right and x= 950 then disable otherwise enable
	if(xspeed<0){
		if (xposition==-900  )
		{
		//alert (the_style.left + "sd" + new_left);			
			//alert( the_style_right);
			the_style_right.id="latest-" + type + "-btn-right-disabled";
			
			//the_timeout = setTimeout('moveDiv('+end+','+x+');',10);
		}
		else if (xposition==0 ){
			//enable left button
			the_style_left_disabled.id="latest-" + type + "-btn-left";
		}
	}
}



var the_timeout;
function move(nameofid,xspeed,destination)
{
	
	var the_style = getStyleObject(nameofid);
	if (the_style) {
		var start = parseInt(the_style.left);
		var end = start+destination;
		moveDiv(end, 200,nameofid,xspeed);
	}

}

function moveDiv(end, x,nameofid,xspeed)
{
// get the stylesheet
//

var the_style = getStyleObject('latest-' + type + '-slider');
if (the_style)
{
	// get the current coordinate and add 5
	var current_left = parseInt(the_style.left);
	disablebuttons(current_left,xspeed,end);
	var new_left = current_left + xspeed;

	// set the left property of the DIV, add px at the
	// end unless this is NN4
	//
	if (document.layers)
	{
		the_style.left = new_left;
	}
	else
	{
		the_style.left = new_left + "px";
	}

	// if we haven't gone to far, call moveDiv() again in a bit
	//
	if(xspeed>0){
		if (new_left < end  )
		{
		//alert (the_style.left + "sd" + new_left);
			end2=end;
			x2=x;
			nameofid2=nameofid;
			xspeed2=xspeed;
			the_timeout = setTimeout('moveDiv(end2, x2,nameofid2,xspeed2);',10);
			//the_timeout = setTimeout('moveDiv('+end+','+x+');',10);
		}
	}
	if(xspeed<0){
		if (new_left > end  )
		{
		//alert (the_style.left + "sd" + new_left);
			end2=end;
			x2=x;
			nameofid2=nameofid;
			xspeed2=xspeed;
			the_timeout = setTimeout('moveDiv(end2, x2,nameofid2,xspeed2);',10);
			//the_timeout = setTimeout('moveDiv('+end+','+x+');',10);
		}
	}
}
}


function getStyleObject(objectId) {
// cross-browser function to get an object's style object given its
if(document.getElementById && document.getElementById(objectId)) {
// W3C DOM
return document.getElementById(objectId).style;
} else if (document.all && document.all(objectId)) {
// MSIE 4 DOM
return document.all(objectId).style;
} else if (document.layers && document.layers[objectId]) {
// NN 4 DOM.. note: this won't find nested layers
return document.layers[objectId];
} else {
return false;
}
} // getStyleObject