function $_(id) { return document.getElementById(id); }

function addLoadEvent(func){
	var oldonload = window.onload;
	if (typeof window.onload != 'function') {
		window.onload = func;
	} else {
		window.onload = function(){
			oldonload();
			func();
		}
	}
}

function moveElement(elementID,final_x,final_y,interval) {
  if (!document.getElementById) return false;
  if (!document.getElementById(elementID)) return false;
  var elem = document.getElementById(elementID);
  if (elem.movement) {
    clearTimeout(elem.movement);
  }
  if (!elem.style.left) {
    elem.style.left = "0px";
  }
  if (!elem.style.top) {
    elem.style.top = "0px";
  }
  var xpos = parseInt(elem.style.left);
  var ypos = parseInt(elem.style.top);
  if (interval == 0)
  {
	xpos = final_x
	ypos = final_y
	elem.style.left = xpos + "px";
	elem.style.top = ypos + "px";
  }
  if (xpos == final_x && ypos == final_y) {
		return true;
  }
  if (xpos < final_x) {
    var dist = Math.ceil((final_x - xpos)/10);
    xpos = xpos + dist;
  }
  if (xpos > final_x) {
    var dist = Math.ceil((xpos - final_x)/10);
    xpos = xpos - dist;
  }
  if (ypos < final_y) {
    var dist = Math.ceil((final_y - ypos)/10);
    ypos = ypos + dist;
  }
  if (ypos > final_y) {
    var dist = Math.ceil((ypos - final_y)/10);
    ypos = ypos - dist;
  }
  elem.style.left = xpos + "px";
  elem.style.top = ypos + "px";
  var repeat = "moveElement('"+elementID+"',"+final_x+","+final_y+","+interval+")";
  elem.movement = setTimeout(repeat,interval);
}

function classNormal(iFocusBtnID,iFocusTxID,notitle){
	var iFocusBtns= $_(iFocusBtnID).getElementsByTagName('li');
	if (!notitle)
	{
		var iFocusTxs = $_(iFocusTxID).getElementsByTagName('li');
	}
	for(var i=0; i<iFocusBtns.length; i++) {
		iFocusBtns[i].className='normal';
		if (!notitle)
		{
			iFocusTxs[i].className='normal';
		}
	}
}

function classCurrent(iFocusBtnID,iFocusTxID,n,notitle){
	var iFocusBtns= $_(iFocusBtnID).getElementsByTagName('li');
	if (!notitle)
	{
		var iFocusTxs = $_(iFocusTxID).getElementsByTagName('li');
	}
	iFocusBtns[n].className='current';
	if (!notitle)
	{
		iFocusTxs[n].className='current';
	}
}

function addOverEvent(obj,X,Y,indexs,divName,notitle) {
	obj.onmouseover = function() {
		moveElement(divName + '_piclist',X,Y,10);
		classNormal(divName + '_btn',divName + '_tx',notitle);
		classCurrent(divName + '_btn',divName + '_tx',indexs,notitle);
	}
}

function flashDivChange(divName,moveType,moveWidth,notitle) {
	if(!$_(divName)) return false;
	$_(divName).onmouseover = function(){atuokey = true};
	$_(divName).onmouseout = function(){atuokey = false};
	var iFocusBtns = $_(divName + '_btn').getElementsByTagName('li');
	var listLength = iFocusBtns.length;
	var moveX = 0;
	var moveY = 0;
	var lli = 0;
	for (lli = 0;lli<listLength ;lli++ )
	{
		addOverEvent(iFocusBtns[lli],moveX,moveY,lli,divName,notitle);
		if (moveType == 'X')
		{
			moveX = moveX - moveWidth;
		}
		if (moveType == 'Y')
		{
			moveY = moveY - moveWidth;
		}
	}
}

//setInterval('autoiFocus()',5000);

var atuokey = false;
function autoFlashDiv(divName,moveType,moveWidth,notitle) {
	if(!$_(divName)) return false;
	if(atuokey) return false;
	var focusBtnList = $_(divName + '_btn').getElementsByTagName('li');
	var listLength = focusBtnList.length;
	for(var i=0; i<listLength; i++) {
		if (focusBtnList[i].className == 'current') var currentNum = i;
	}
	var moveX = 0;
	var moveY = 0;
	var indexs = 0;
	if (currentNum + 1 != listLength)
	{
		//非最后一个 如果是最后一个，一切为0
		if (moveType == 'X')
		{
			moveX = 0 - (moveWidth * (currentNum + 1));
		}
		if (moveType == 'Y')
		{
			moveY = 0 - (moveWidth * (currentNum + 1));
		}
		indexs = currentNum + 1;
	}
	moveElement(divName + '_piclist',moveX,moveY,10);
	classNormal(divName + '_btn',divName + '_tx',notitle);
	classCurrent(divName + '_btn',divName + '_tx',indexs,notitle);
}
//addLoadEvent(iFocusChange);
