function SDMenu(id) {
	if (!document.getElementById || !document.getElementsByTagName)
		return false;
	this.menu = document.getElementById(id);
	this.submenus = this.menu.getElementsByTagName("div");
	this.remember = true;
	this.speed = 3;
	this.markCurrent = true;
	this.oneSmOnly = false;
}
SDMenu.prototype.init = function() {
	var mainInstance = this;
	for (var i = 0; i < this.submenus.length; i++)
		this.submenus[i].getElementsByTagName("span")[0].onclick = function() {
			mainInstance.toggleMenu(this.parentNode);
		};
	if (this.markCurrent) {
		var links = this.menu.getElementsByTagName("a");
		for (var i = 0; i < links.length; i++)
			if (links[i].href == document.location.href) {
				links[i].className = "current";
				break;
			}
	}
	if (this.remember) {
		var regex = new RegExp("sdmenu_" + encodeURIComponent(this.menu.id) + "=([01]+)");
		var match = regex.exec(document.cookie);
		if (match) {
			var states = match[1].split("");
			for (var i = 0; i < states.length; i++)
				this.submenus[i].className = (states[i] == 0 ? "collapsed" : "");
		}
	}
};
SDMenu.prototype.toggleMenu = function(submenu) {
	if (submenu.className == "collapsed")
		this.expandMenu(submenu);
	else
		this.collapseMenu(submenu);
};
SDMenu.prototype.expandMenu = function(submenu) {
	var fullHeight = submenu.getElementsByTagName("span")[0].offsetHeight;
	var links = submenu.getElementsByTagName("a");
	for (var i = 0; i < links.length; i++)
		fullHeight += links[i].offsetHeight;
	var moveBy = Math.round(this.speed * links.length);
	
	var mainInstance = this;
	var intId = setInterval(function() {
		var curHeight = submenu.offsetHeight;
		var newHeight = curHeight + moveBy;
		if (newHeight < fullHeight)
			submenu.style.height = newHeight + "px";
		else {
			clearInterval(intId);
			submenu.style.height = "";
			submenu.className = "";
			mainInstance.memorize();
		}
	}, 30);
	this.collapseOthers(submenu);
};
SDMenu.prototype.collapseMenu = function(submenu) {
	var minHeight = submenu.getElementsByTagName("span")[0].offsetHeight;
	var moveBy = Math.round(this.speed * submenu.getElementsByTagName("a").length);
	var mainInstance = this;
	var intId = setInterval(function() {
		var curHeight = submenu.offsetHeight;
		var newHeight = curHeight - moveBy;
		if (newHeight > minHeight)
			submenu.style.height = newHeight + "px";
		else {
			clearInterval(intId);
			submenu.style.height = "";
			submenu.className = "collapsed";
			mainInstance.memorize();
		}
	}, 30);
};
SDMenu.prototype.collapseOthers = function(submenu) {
	if (this.oneSmOnly) {
		for (var i = 0; i < this.submenus.length; i++)
			if (this.submenus[i] != submenu && this.submenus[i].className != "collapsed")
				this.collapseMenu(this.submenus[i]);
	}
};
SDMenu.prototype.expandAll = function() {
	var oldOneSmOnly = this.oneSmOnly;
	this.oneSmOnly = false;
	for (var i = 0; i < this.submenus.length; i++)
		if (this.submenus[i].className == "collapsed")
			this.expandMenu(this.submenus[i]);
	this.oneSmOnly = oldOneSmOnly;
};
SDMenu.prototype.collapseAll = function() {
	for (var i = 0; i < this.submenus.length; i++)
		if (this.submenus[i].className != "collapsed")
			this.collapseMenu(this.submenus[i]);
};
SDMenu.prototype.memorize = function() {
	if (this.remember) {
		var states = new Array();
		for (var i = 0; i < this.submenus.length; i++)
			states.push(this.submenus[i].className == "collapsed" ? 0 : 1);
		var d = new Date();
		d.setTime(d.getTime() + (30 * 24 * 60 * 60 * 1000));
		document.cookie = "sdmenu_" + encodeURIComponent(this.menu.id) + "=" + states.join("") + "; expires=" + d.toGMTString() + "; path=/";
	}
};

//Show the list
function CriAideoClips(urlTerms,groupName){
eval("document.all.bobo.src='list.asp?groups_id=" + urlTerms + "'");

document.all.Board.innerHTML="<legend>Clips " + groupName + "</legend>"
}

//search
function Search(){
eval("document.all.bobo.src='search.asp?clips_name=" + document.all.clips_name.value + "'")
document.all.Board.innerHTML="<legend>Clips Search</legend>"
}



function showDetail(clipsName,clipsLinkId,mdbId) {

//锁定控件
  document.all.oneSmOnly.disabled=true;
  document.all.smNr.disabled=true;

//背景
  var bgObj=document.getElementById("bgDiv");
  bgObj.style.width = window.screen.availWidth + "px";
  bgObj.style.height = document.body.scrollHeight + "px";

//定义窗口
  var msgObj=document.getElementById("msgDiv");
  msgObj.style.marginTop = 100  + document.documentElement.scrollTop + "px";

//关闭
  document.getElementById("msgShut").onclick = function(){
  bgObj.style.display = msgObj.style.display = "none";
//锁定控件
  document.all.oneSmOnly.disabled=false;
  document.all.smNr.disabled=false;

  }
  msgObj.style.display = bgObj.style.display = "block";
  msgDetail.innerHTML=
"<div style='padding:10px;' align=center><b style='font-family:黑体;font-size:20pt;color:white;'>" + clipsName + "</b></div>"+
"<div style='padding:10px;background: url(img/clips_back.jpg) no-repeat center top;' align=center><object width='400' height='300'><param name='movie' value='" + clipsLinkId + "'></param><param name='allowScriptAccess' value='always'></param><param name='wmode' value='transparent'></param><embed src='" + clipsLinkId + "' type='application/x-shockwave-flash' width=400 height=300 allowFullScreen=true wmode=transparent allowScriptAccess=always></embed></object></div>"+
"<div style='padding:10px;color:white;' align=center>"+

"剪辑地址：<input value='http://cri.372c.net/cri/index.asp?clips_id=" + mdbId +"' size=45 style='BORDER: #E3E3E3 1px solid;font-family:tahoma;color:#999;background-color:#000000;text-align:center;' id=url onclick=CopyText(this.id);alert('当前地址已复制到剪贴板');>"


//+"&nbsp;&nbsp;&nbsp;<button class=btn1_mouseout onmouseover=this.className='btn1_mouseover' onmouseout=this.className='btn1_mouseout' onclick=javascript:window.open('" + clipsLinkId + "/')>原始页面</button></div>";

eval("document.all.ad1.src='gg.asp?id=" + clipsLinkId + "'")
}

//地址复制
function CopyText(id) { 
    try { 
    var targetText = document.getElementById(id); 
    targetText.focus(); 
    targetText.select(); 
    var clipeText = targetText.createTextRange(); 
    clipeText.execCommand("Copy"); 
    }
    catch(e){ } 
} 

//飘移

var lastScrollY = 0;
	function floatRefresh() {
		diffY = document.body.scrollTop;
		percent =.1*(diffY-lastScrollY);
		if(percent>0){
			percent = Math.ceil(percent);
		}else{
			percent = Math.floor(percent);
		}

		document.all.msgDiv.style.pixelTop += percent;

		lastScrollY = lastScrollY + percent;
	}
window.setInterval("floatRefresh();",1);
