/*
	[UCenter Home] (C) 2007-2008 Comsenz Inc.
	$Id: script_upload.js 13226 2009-08-24 02:39:06Z zhengqingpeng $
*/

function scrollPic(e, LN, Width, Price, Speed) {
	id = e.id;
	if(LN == 'Last'){ scrollNum = Width; } else if(LN == 'Next'){ scrollNum = 0 - Width; }
	scrollStart = parseInt(e.style.marginLeft, 10);
	scrollEnd = parseInt(e.style.marginLeft, 10) + scrollNum;
	
	MaxIndex = (e.getElementsByTagName('li').length / Price).toFixed(0);
	sPicMaxScroll = 0 - Width * MaxIndex;

	if(scrollStart == 0 && scrollEnd == Width){
		scrollEnd = -1806;
		e.style.marginLeft = parseInt(e.style.marginLeft, 10) - Speed + 'px';
	} else if(scrollStart == sPicMaxScroll + Width && scrollEnd == sPicMaxScroll){
		scrollEnd = 0;
		e.style.marginLeft = parseInt(e.style.marginLeft, 10) + Speed + 'px';
	}
	scrollShowPic = setInterval(scrollShow, 1);
	
	function scrollShow() {
		if(scrollStart > scrollEnd) {
			if(parseInt(e.style.marginLeft, 10) > scrollEnd) {
				$(id + '_last').onclick = function(){ return false; };
				$(id + '_next').onclick = function(){ return false; };
				e.style.marginLeft = parseInt(e.style.marginLeft, 10) - Speed + 'px';
			} else {
				clearInterval(scrollShowPic);
				$(id + '_last').onclick = function(){ scrollPic(e, 'Last', Width, Price, Speed);return false; };
				$(id + '_next').onclick = function(){ scrollPic(e, 'Next', Width, Price, Speed);return false; };
			}
		} else {
			if(parseInt(e.style.marginLeft, 10) < scrollEnd) {
				$(id + '_last').onclick = function(){ return false; };
				$(id + '_next').onclick = function(){ return false; };
				e.style.marginLeft = parseInt(e.style.marginLeft, 10) + Speed + 'px';
			} else {
				clearInterval(scrollShowPic);
				$(id + '_last').onclick = function(){ scrollPic(e, 'Last', Width, Price, Speed);return false; };
				$(id + '_next').onclick = function(){ scrollPic(e, 'Next', Width, Price, Speed);return false; };
			}					
		}
	}
}
function scrollShowNav(e, Width, Price, Speed) {
	id = e.id;
	$(id + '_last').onclick = function(){ scrollPic(e, 'Last', Width, Price, Speed);return false; };
	$(id + '_next').onclick = function(){ scrollPic(e, 'Next', Width, Price, Speed);return false; };
	
}
function getUserTip(obj) {
	var tipBox = $('usertip_box');
	tipBox.childNodes[0].innerHTML = '<strong>' + obj.rel + ':<\/strong> ' + obj.rev + '...';
	
	var showLeft;
	if(obj.parentNode.offsetLeft > 730) {
		showLeft = $('showuser').offsetLeft + obj.parentNode.offsetLeft - 148;
		tipBox.childNodes[0].style.right = 0;
	} else {
		tipBox.childNodes[0].style.right = 'auto';
		showLeft = $('showuser').offsetLeft + obj.parentNode.offsetLeft + 18;
	}
	tipBox.style.left = showLeft + 'px';
	
	var showTop; 
	showTop = $('showuser').offsetTop + obj.parentNode.offsetTop + 100;
	tipBox.style.top = showTop + 'px';
	
	tipBox.style.visibility = 'visible';
}
