var playArr=[1,2,3,4,5];
var intValue;
function swapImg(){
    var playItem = $("playItem");
    var links = playItem.getElementsByTagName("a");
    for (var i = 0; i < links.length; i++) {
        links[i].onmouseover = function(){
			if(intValue){
				clearInterval(intValue);
			}
			setSelected(links,this);
			this.id.replace(/(\w)*/,function(a,n){playImg(n-1)});
        }
		links[i].onmouseout=function(){
			this.id.replace(/(\w)*/,function(a,n){autoPlayImg(links,(n-1))});
			
		}
    }
	autoPlayImg(links,1);
}
function setSelected(links,link){
	for (var i = 0; i < links.length; i++) {
		links[i].parentNode.className="";
	}
	link.parentNode.className="selected"
	var num;
	link.id.replace(/(\w)*/,function(a,n){num=n});
	$("playItem").style.backgroundImage="url(/images/play_item"+num+".jpg)"
	
}
function playImg(num){
	  moveElement("play_img", 0, -(num*217), 5);
}
function autoPlayImg(links,num){
	intValue=setInterval(function(){
		if(num==links.length){
			num=0;
		}
		playImg(num);
		setSelected(links, links[num++]);
		
	},2000);
}
window.onload = function(){
    swapImg();
}

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 (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);
}
