function shownav(k,h){
for(var i=0;i<4;i++){document.getElementById("main_"+k+i).className="";}
for(var i=0;i<4;i++){document.getElementById("menu_"+k+i).className="";}
document.getElementById("menu_"+k+h).className="tab_on";
document.getElementById("main_"+k+h).className="show";
}
//¶¯Âþ½ÚÄ¿µ¥


function $(id) { return document.getElementById(id); }

function addLoadEvent(func){
	var oldonload = window.onload;
	if (typeof window.onload != 'happypic') {
		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 (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(happypicBtnID,happypicTxID){
	var happypicBtns= $(happypicBtnID).getElementsByTagName('li');
	var happypicTxs = $(happypicTxID).getElementsByTagName('h1');
	for(var i=0; i<happypicBtns.length; i++) {
		happypicBtns[i].className='';
		happypicTxs[i].className='';
	}
}

function classCurrent(happypicBtnID,happypicTxID,n){
	var happypicBtns= $(happypicBtnID).getElementsByTagName('li');
	var happypicTxs = $(happypicTxID).getElementsByTagName('h1');
	happypicBtns[n].className='current';
	happypicTxs[n].className='current';
}

function happypicChange() {
	if(!$('happypic')) return false;
	$('happypic').onmouseover = function(){atuokey = true};
	$('happypic').onmouseout = function(){atuokey = false};
	var happypicBtns = $('happypic_btn').getElementsByTagName('li');
	var listLength = happypicBtns.length;
	happypicBtns[0].onmouseover = function() {
		moveElement('happypic_piclist',0,0,5);
		classNormal('happypic_btn','happypic_tx');
		classCurrent('happypic_btn','happypic_tx',0);
	}
	if (listLength>=2) {
		happypicBtns[1].onmouseover = function() {
			moveElement('happypic_piclist',0,-257,5);
			classNormal('happypic_btn','happypic_tx');
			classCurrent('happypic_btn','happypic_tx',1);
		}
	}
	if (listLength>=3) {
		happypicBtns[2].onmouseover = function() {
			moveElement('happypic_piclist',0,-514,5);
			classNormal('happypic_btn','happypic_tx');
			classCurrent('happypic_btn','happypic_tx',2);
		}
	}
	if (listLength>=4) {
		happypicBtns[3].onmouseover = function() {
			moveElement('happypic_piclist',0,-771,5);
			classNormal('happypic_btn','happypic_tx');
			classCurrent('happypic_btn','happypic_tx',3);
		}
	}
}

setInterval('autohappypic()',5000);
var atuokey = false;
function autohappypic() {
	if(!$('happypic')) return false;
	if(atuokey) return false;
	var focusBtnList = $('happypic_btn').getElementsByTagName('li');
	var listLength = focusBtnList.length;
	for(var i=0; i<listLength; i++) {
		if (focusBtnList[i].className == 'current') var currentNum = i;
	}
	if (currentNum==0&&listLength!=1 ){
		moveElement('happypic_piclist',0,-257,5);
		classNormal('happypic_btn','happypic_tx');
		classCurrent('happypic_btn','happypic_tx',1);
	}
	if (currentNum==1&&listLength!=2 ){
		moveElement('happypic_piclist',0,-514,5);
		classNormal('happypic_btn','happypic_tx');
		classCurrent('happypic_btn','happypic_tx',2);
	}
	if (currentNum==2&&listLength!=3 ){
		moveElement('happypic_piclist',0,-771,5);
		classNormal('happypic_btn','happypic_tx');
		classCurrent('happypic_btn','happypic_tx',3);
	}
	if (currentNum==3 ){
		moveElement('happypic_piclist',0,0,5);
		classNormal('happypic_btn','happypic_tx');
		classCurrent('happypic_btn','happypic_tx',0);
	}
	if (currentNum==1&&listLength==2 ){
		moveElement('happypic_piclist',0,0,5);
		classNormal('happypic_btn','happypic_tx');
		classCurrent('happypic_btn','happypic_tx',0);
	}
	if (currentNum==2&&listLength==3 ){
		moveElement('happypic_piclist',0,0,5);
		classNormal('happypic_btn','happypic_tx');
		classCurrent('happypic_btn','happypic_tx',0);
	}
}
addLoadEvent(happypicChange);

