var currentFrame=0;
var oldFrame=-1;
var frameCount=0;
var songid;
var fid = "esongs";
var fto;
var esongStatus;
var playMode = "goPlay";

function getObject(movieName) {
  if (document.all) {
    return window.document[movieName];
  } else {
    return document.getElementById(movieName);
  }
}

function countStop(zone) {
	if (fto) clearTimeout(fto);
	if (getObject(fid)) {		
		var f = (zone=="ajaxarea")? document.forms['tv'] : document.forms['fulltv'];
		songid = (playMode == "goPlay")? f.goPlay.value : f.randomPlay.value;
		try {currentFrame = getObject(fid).TGetProperty("/", 4)}
		catch(err){fto = setTimeout("countStop('"+zone+"')",1000);return false}		
		if (oldFrame>=currentFrame){
			fto = setTimeout("countStop('"+zone+"')",3600);
		} else if (oldFrame==currentFrame-1){
			frameCount++;
			if(frameCount>9){
				var pagename = (zone == "ajaxarea")? "e-songs" : "songpop";
		 		getContent("/wonderland/"+pagename+".php?channel="+songid+"&status=play&playMode="+playMode,zone);
		 		oldFrame=-1;
		 		currentFrame=0;
		 		fto = setTimeout("countStop('"+zone+"')",1000);
			} else {
		 		fto = setTimeout("countStop('"+zone+"')",500);
			}
		} else {
		  fto = setTimeout("countStop('"+zone+"')",500);
		}
		oldFrame = currentFrame-1;
	} else {
		fto = setTimeout("countStop('"+zone+"')",1000);
	}
}

function continuePlay(zone) {
		if (getObject(fid)) getObject(fid).Play();
		oldFrame=-1;
		currentFrame=0;
		if (fto) clearTimeout(fto);
		fto = setTimeout("countStop('"+zone+"')",3000);
		esongStatus = "play";
}

function stopPlay() {
	if (fto) clearTimeout(fto);
	getObject(fid).StopPlay();
	esongStatus = "stop";
}

function goRandom(formname,bid) {
	var f = document.forms[formname];
	if (playMode=="goPlay") {
		songid = f.randomPlay.value;
		bid.className="switchscreen onbutton";
		playMode = "randomPlay";
	} else {
		songid = f.goPlay.value;
		bid.className="switchscreen button";
		playMode = "goPlay";
	}
}

function songPop(sid) {
	if (sid!="off") {
		maxheight("on");
		getContent('/wonderland/songpop.php?channel='+sid+'&status='+esongStatus+'&playMode='+playMode,'maxpop');
		document.getElementById("flashlayer").innerHTML="";
		if (esongStatus == "play") continuePlay('maxpop');
	} else {
		maxheight("off");
		if (esongStatus == "play") continuePlay('ajaxarea');
	}
}

function colorPop(id){
	if (id != "off") {
		maxheight("on");
		getContent('/wonderland/colorpop.php?swf='+id,'maxpop');
	} else {
		maxheight("off");
	}
}

function gamePop(id) {
	if (id!="off") {
		maxheight("on");
		getContent('/wonderland/gamePop.php?id='+id,'maxpop');
	} else {
		maxheight("off");
	}
}

function drawPop(turn) {
	if (turn!="off") {
		maxheight("on");
		getContent('/wonderland/drawpop.php','maxpop');
	} else {
		maxheight("off");
	}
}

function reportPop(id,objwin) {
	document.getElementById("maxpop").style.display="block";
	document.getElementById("maxpop").style.width="500px";
	clickMenu("maxpop",objwin)
	getContent('/wonderland/report.php?info_id='+id,'maxpop');
}

function maxheight(turn) {
	if (turn=="on") {
		document.getElementById("maxpop").style.display="block";
		document.getElementById("container").style.display="none";
		document.getElementById("maxpop").style.height=iecompattest().clientHeight-31+"px";
	} else {
		document.getElementById("maxpop").innerHTML="";
		document.getElementById("maxpop").style.display="none";
		document.getElementById("container").style.display="";
		checkheight();
	}
}

function postform(targeturl,formname,targetarea) {
	var inputform = document.forms[formname].getElementsByTagName('input');
	var textform = document.forms[formname].getElementsByTagName('textarea');
	var selectform = document.forms[formname].getElementsByTagName('select');
	var querystring = "";
	if (inputform) {
		for (var i=0; i<inputform.length; i++) {
			if (inputform[i].value)	querystring+=inputform[i].name+"="+inputform[i].value+"&";
		}
	}
	if (textform) {
		for (var i=0; i<textform.length; i++) {
			if (textform[i].value) querystring+=textform[i].name+"="+textform[i].value+"&";
		}
	}
	if (selectform) {
		for (var i=0; i<selectform.length; i++) {
			if (selectform[i].options[selectform[i].selectedIndex].value)	querystring+=selectform[i].name+"="+selectform[i].options[selectform[i].selectedIndex].value+"&";
		}
	}
	querystring = querystring.substring(0,querystring.lastIndexOf("&"));
	postContent(targeturl,querystring,targetarea);
}

function listds(style) {
	$(".displaystyle a:not('."+style+"')").removeClass("on");
	$(".displaystyle a."+style+":not('.on')").addClass("on");
	getContent('/wonderland/displaystyle.php?listds='+style,'maxpop');
	switch(style){
	case "thumbnail":
	  $("#bookmarklist>div:not('.aitem')").removeClass().addClass("aitem");
	  break;
	case "detail":
	  $("#bookmarklist>div:not('.bitem')").removeClass().addClass("bitem");
	  break;
	case "text":
	  $("#bookmarklist>div:not('.citem')").removeClass().addClass("citem");
	  break;
	}
}

function swap(on,off) {
	$("#"+off).slideUp("fast");
	$("#"+on).show("slow");
}

function swapinline(on,off){
	document.getElementById(on).style.display="inline";
	document.getElementById(off).style.display="none";
}

$(document).ready(function(){
	$("div.item").mouseover( function() {
		$("img",this).addClass("hover");
	})
	$("div.item").mouseout( function() {
		$("img",this).removeClass("hover");
	})
});