function ttDesk_submit(frm){
	x = eval("document."+frm);
	x.action = ttDeskBlogURL +"/plugin/ttDeskDb/";
	x.submit();
}

function ttDesk2_submit(){
	var values = new Array;
	x = document.ttDesk2;
	srcs = document.getElementsByName('td_itemno[]');
	for(i=0;i< srcs.length;i++){
		if(document.getElementById("td_itemno"+i).checked) {
			values.push(document.getElementById("td_itemno"+i).value);
			document.getElementById("td_itemno"+i).checked = false;
		}
	}

	if (values.length > 0){
		td_no = x.td_no.value;
		var url =ttDeskBlogURL +"/plugin/ttDeskDb/?";
		var data = "mode=item_insert&td_no="+td_no+"&td_itemno="+values.toString();
		var rst = requestPostText(url, data);
		if(rst == 1){
			document.getElementById("ttDesk_updownContainer").innerHTML ="";
			ttDesk_getAjax("item","ttDesk_updownContainer");
			setTimeout("ttDesk_ajaxUpdown()",500);
		}else{
			ttDesk_MSGView('아이템 추가실패', true);
		}
		return true;
	}else{
		ttDesk_MSGView('배치할 아이템을 선택하세요.', true);
		return false;
	}
}

function ttDesk_Msg(rst){
	if(rst == 0){
		parent.ttDesk_MSGView('저장 실패! 다시 시도해주세요',false);
	}
	if (rst == 1)
	{
		parent.ttDesk_MSGView('저장하였습니다',true);
		//parent.location.href  = parent.location.href;
		setTimeout('parent.location.href=parent.location.href',1000);
	}
	if(rst == 2 || rst == 7){
		parent.ttDesk_MSGView('저장하였습니다',true);
		if(rst == 2)
			ttDesk_setCookie('ttDeskReload','0',0);
		else
			ttDesk_setCookie('ttDeskReload','1',0);
	}
	if(rst == 3){
		parent.ttDesk_MSGView('아이템에 배치할 컨텐츠를 선택하세요',true);
	}
	if (rst == 4)
	{
		parent.location.href  = parent.location.href;
		//parent.location.reload();
	}
	if (rst == 5)
	{
		parent.ttDesk_MSGView('저장하였습니다',true);
		//parent.location.href  = parent.location.href;
		setTimeout('location.href=location.href',1000);
	}
	if (rst == 6)
	{
		parent.ttDesk_MSGView('저장하였습니다',true);
		//parent.location.href  = parent.location.href;
		setTimeout("parent.location.href='/plugin/ttDeskAdmin/?mode=item'",1000);
	}
}

function ttDesk_MSGView(txt,tmp){
	var objId = "ttDesk_alert";
	ttDesk_EditLayer(objId,250,200);
	document.getElementById('ttDesk_alert').style.display = "block";
	document.getElementById('ttDesk_MSGText').innerHTML = txt;
	if(tmp == true){
	setTimeout('hideLayer("ttDesk_alert")',1000);
	}
}

function  ttDesk_userhtml(id){
	html = document.getElementById(id).value;
	showLayer('ttDesk_htmlpreview');
	document.getElementById("td_preview").innerHTML =  html;
}

function ttDesk_itemsettings(tmp){
	var url = ttDeskBlogURL +"/plugin/ttDeskAdminArrange/?mode=arrange_update&td_arrno="+tmp;
	location.href=url;
//	win = window.open(url, 'ttDesk2', 'width=700, height=600, scrollbars=1, resizable=1')	;
//	win.focus();
}

function ttDesk_itemdelete(tmp){
	var url = ttDeskBlogURL +"/plugin/ttDeskDb/?mode=item_delete&td_arrno="+tmp;
	if (confirm("배치된 아이템을 삭제하시겠습니까?"))
	{
		ifrm.location.href= url;
		hideLayer("ttDesk_AdminItem"+tmp);
		ttDesk_MSGView('아이템이 삭제되었습니다',true);
	}
}

var ttDesk_GetTagStatus = 0;

function ttDesk_GetTags(td_itemno, td_code){
	if(ttDesk_GetTagStatus == 0){
		var url = ttDeskBlogURL +"/plugin/ttDeskDb/?mode=tag&td_itemno="+td_itemno+"&td_code[]="+td_code;
		var rst = requestHttpText(url);
		if(document.getElementById("td_taglist") && rst !="")
			document.getElementById("td_taglist").innerHTML = rst;
		else
			document.getElementById("td_taglist").innerHTML ="<li>태그 가져오기 실패. 새로고침을 해주세요</li>";
		ttDesk_GetTagStatus =1;
	}
}

function ttDesk_Adminitemdelete(tmp,mode){

	var url = ttDeskBlogURL +"/plugin/ttDeskDb/?mode=item_delete&td_arrno="+tmp;

	if (confirm("배치된 아이템을 삭제하시겠습니까?"))
	{
		var rst = requestHttpText(url);
		if(rst == "1"){
			ttDesk_MSGView('아이템이 삭제되었습니다',true);
			ttDesk_getAjax(mode,"ttDesk_updownContainer");
			setTimeout("ttDesk_ajaxUpdown()",500);
		}else{
			ttDesk_MSGView('아이템 삭제실패',true);
		}
	}
}


function ttDesk_itemorder(mode, tmp){

	var url = ttDeskBlogURL +"/plugin/ttDeskDb/?mode="+mode+"&td_arrno="+tmp;
	ifrm.location.href= url;
}

function ttDesk_EditDiv(id1,id2){
	document.getElementById(id1).style.display = "block";
	document.getElementById(id2).style.display = "none";
}

function ttDesk_DelArrange(tmp){
	if(confirm('삭제하시겠습니까?')){
	x = eval("document.ttDesk_"+tmp);
	x.mode.value = "arrange_delete";
	x.submit();
	}
}

function ttDesk_ArrangeInsert(){
	var values = new Array;
	objs = document.getElementsByName("td_code");
	for(i=0;i<objs.length;i++){
		if(objs[i].checked == true && objs[i].value !="") {
			values.push(objs[i].value);
			//objs[i].disabled = true;
		}
	}

	if(values.length < 1){
		ttDesk_MSGView('배치할 글을 선택하세요',true);
		return false;
	}

	var td_arrno = document.ttDesk2.td_arrno.value;
	var td_itemtype = document.ttDesk2.td_itemtype.value;
	var td_itemno = document.ttDesk2.td_itemno.value;
	var url =ttDeskBlogURL +"/plugin/ttDeskDb/?";
	var data = "mode=arrange_insert&td_arrno="+td_arrno+"&td_itemtype="+td_itemtype+"&td_itemno="+td_itemno+"&td_code="+values.toString();
	var rst = requestPostText(url, data);
	//ifrm_setting.location.href= url;
		if(rst == "1"){
			for(i=0;i<objs.length;i++){
				if(objs[i].checked == true) {
					objs[i].disabled = true;
					objs[i].value ="";
				}
			}
			ttDesk_MSGView('저장하였습니다.',true);
		}else{
			ttDesk_MSGView('저장실패'+rst,true);
		}

	return true;
}

function ttDesk_CacheDelete(){
//	ttDesk_MSG('태터데스크 변경사항을 적용하시겠습니까?');

	if(confirm('블로그 첫페이지에 적용하시겠습니까?')){
	var url =ttDeskBlogURL +"/plugin/ttDeskDb/?mode=cachedelete";
	var rst = requestHttpText(url);
	//ifrm_setting.location.href= url;
		if(rst == "1"){
			ttDesk_MSGView('첫페이지 저장완료',true);
			setTimeout("location.href='"+ttDeskBlogURL+"'",1000);
		}else{
			ttDesk_MSGView('첫페이지 저장실패',true);
		}
	}
}

function ttDesk_Setting(){
	td_id = document.ttDesk1.td_id.value;
	var url = ttDeskBlogURL +"/plugin/ttDeskDb/?mode=setting&td_id="+td_id;
	var rst = requestHttpText(url);
	//ifrm_setting.location.href= url;
		if(rst == "1"){
			ttDesk_MSGView('태터데스크 템플릿 저장 완료',true);
			ttDesk_setCookie('ttDeskReload','1',0);
			gourl = ttDeskBlogURL+"/plugin/ttDeskAdmin/?mode=item&new=1";
			setTimeout("location.href=gourl",1000);
		}else{
			ttDesk_MSGView('태터데스크 템플릿 저장 실패',true);
		}
}


function ttDesk_Reset(){
	if(confirm('태터데스크 설정을 초기화하시겠습니까?\n\n초기화를 하시면 모든 설정정보가 삭제됩니다.')){
	var url = ttDeskBlogURL +"/plugin/ttDeskDb/?mode=resetting";
	var rst = requestHttpText(url);
	//ifrm_setting.location.href= url;
		if(rst == "1"){
			ttDesk_MSGView('태터데스크 설정 초기화 완료',true);
			ttDesk_setCookie('ttDeskReload','1',0);
			/*setTimeout('location.href=location.href',1000);*/
		}else{
			ttDesk_MSGView('태터데스크 설정 초기화 실패',true);
		}
	}
}

function ttDesk_ResetItem(){
	if(confirm('현재 배치된 아이템을 모두 삭제하시겠습니까?')){
	var url = ttDeskBlogURL +"/plugin/ttDeskDb/?mode=item_resetting";
	var rst = requestHttpText(url);
	//ifrm_setting.location.href= url;
		if(rst == "1"){
			ttDesk_MSGView('아이템이 삭제되었습니다',true);
			setTimeout('location.href=location.href',1000);
		}else{
			ttDesk_MSGView('아이템 삭제 실패',true);
		}
	}
}


function ttDesk_Admin(){
	var url = ttDeskBlogURL +"/plugin/ttDeskAdmin/";
	txt = "<iframe name='ttDesk_Adminframe' src='"+url+"' frameborder=0 style='width:640px;height:600px;border:0px;'></iframe>";
//	document.getElementById('ttDesk_AdminDiv').style.display = "block";
	document.getElementById('ttDesk_AdminDiv').style.display = "block";
	document.getElementById('ttDesk_AdminDivText').innerHTML = txt;

//	new Draggable('ttDesk_AdminDiv',{scroll:window, handle:'ttDesk_drag', revert:function(element){return ''}});
}


function ttDesk_AdminClose(){
	document.getElementById('ttDesk_AdminDiv').style.display = "none";
}

function ttDesk_reloadClose(type){
			var Reload = ttDesk_getCookie("ttDeskReload");
			document.getElementById('ttDesk_overlay').style.display = "none";
			ttDesk_AdminClose();
			//document.getElementById('ttDeskifrm_setting').src = "about:blank";
			document.getElementById('ttDesk_AdminDivText').innerHTML = "";
			showSelectBoxes();
			if(type == 1){
				if(Reload == 1){
					location.href=ttDeskBlogURL+"/?mode=ttDeskAdmin";
					location.reload();
				}else{
					ttDesk_getAjax("viewitem","ttDesk_updownContainer");
					setTimeout("ttDesk_ajaxUpdown()",500);
				}
			}
}

function ttDesk_parentSetheight(objid){
	objParent = document.getElementById(objid).parentNode;
   	objParent.style.height = document.getElementById(objid).offsetHeight + 'px';
}

function ttDesk_getAjax(mode,objid){
	document.getElementById(objid).style.visibility = "hidden";
	var url = ttDeskBlogURL +"/plugin/ttDeskAjax/?mode="+mode;
	var rst = requestHttpText(url);
	if(document.getElementById(objid)){
		document.getElementById(objid).innerHTML = rst;
	}

}

function ttDesk_ajaxUpdown(){
			var newlayout = new Array;

			obj = document.getElementById('ttDesk_updownContainer');
			var objList = obj.getElementsByTagName("div");
			for (var j=0; j < objList.length; j++) {
				if(objList[j].className == "ttDesk_updownbox") {
					newlayout.push(objList[j].id)
				}
			}
			obj.style.visibility = "visible";
			if(newlayout.length > 0){
				ttDeskUpdown_init(newlayout.toString());
			}else{
				//setTimeout("ttDesk_parentSetheight('ttDesk_updownContainer')",300);
				obj.style.height = "250px";
			}
}

function ttDesk_Adminitemsettings(obj, tmp,mode){
//	var top = getOffsetTop(obj);
//	var left = getOffsetLeft(obj);
	var arrayPageSize = ttDesk_PageSize();
	var url='';
	var pagewidth  = arrayPageSize[0];
	var pageheight  = arrayPageSize[1];
	var windowheight  = arrayPageSize[3];
	var arrayPageScroll = ttDesk_getPageScroll();
	var top = arrayPageScroll[1] + (windowheight / 15);

	var left = (pagewidth -700) /2;
	if(tmp == 0){
	 url = ttDeskBlogURL +"/plugin/ttDeskAdmin/?mode="+mode;
	}else{
	 url = ttDeskBlogURL +"/plugin/ttDeskAdminArrange/?mode=arrange_update&td_arrno="+tmp;
	}

	hideSelectBoxes();
	document.getElementById('ttDesk_overlay').style.display ="block";
	if(isIE) 	document.getElementById('ttDesk_overlay').style.width = pagewidth+'px';
	document.getElementById('ttDesk_overlay').style.height = (pageheight+50)+'px';

	document.getElementById('ttDesk_overlay').onclick = function() {
			document.getElementById('ttDesk_overlay').style.display = "none";
			document.getElementById('ttDesk_AdminDiv').style.display = "none";
			//document.getElementById('ttDeskifrm_setting').src = "about:blank";
			document.getElementById('ttDesk_AdminDivText').innerHTML = "";
			showSelectBoxes();
			return false;
	}

	txt = "<iframe name='ttDeskifrm_setting' src='"+url+"' width=100% height=600 frameborder='0' style='border:0px;z-index:99999;overflow-y:auto;overflow-x:hidden;'></iframe>";
//	document.getElementById('ttDeskifrm_setting').src=url;
	document.getElementById('ttDesk_AdminDivText').innerHTML = txt;
	document.getElementById('ttDesk_AdminDiv').style.display = "block";
	ttDesk_adminLayer('ttDesk_AdminDiv');
	/*new Draggable('ttDesk_AdminDiv',
		{handle:'ttDesk_drag',
		revert:function(element){return false;},
	    onStart:function(){},
	    onDrag:function(){},
		onEnd:function(){}}
	);*/

}

var paragraphScroller;

function ttDeskUpdown_init(objList) {
	if(objList !=""){
		paragraphScroller = new ParagraphScroller(objList.split(','));
		paragraphScroller.init();
	}
}

function ttDesk_updownCheck(){

	if(document.getElementById("ttDesk_updown_checked").checked == true){
		ttDesk_setCookie('ttDeskUpdown','0',365);
		location.reload();
	}else{
		ttDesk_setCookie('ttDeskUpdown','1',365);
		paragraphScroller.SCROLL_ENABLE = false;
	}
}

var TimeIterator = function (obj) {
	this.objTimeout = null;
	this.bStop = false;
	this._waitingTime = 0;
	this.id = TimeIterator.list.length;
	TimeIterator.list[this.id] = obj;
}

TimeIterator.list = new Array();
TimeIterator.prototype.start = function() {
	if (this.objTimeout) clearTimeout(this.objTimeout);
	this.bStop = false;
	this.objTimeout = setTimeout('TimeIterator.list["' + this.id + '"]._iterate();', this.getWaitingTime());
}
TimeIterator.prototype.stop = function() {
	if (this.objTimeout) clearTimeout(this.objTimeout);
	this.bStop = true;
}

TimeIterator.prototype._iterate = function() {
	this.iterate();
	if(this.bStop) return;
	this.objTimeout = setTimeout('TimeIterator.list["' + this.id + '"]._iterate();', this.getWaitingTime());
}
TimeIterator.prototype.setWaitingTime = function(msec) {
	this._waitingTime = msec
}
TimeIterator.prototype.getWaitingTime = function() {
	return this._waitingTime;
}
TimeIterator.prototype.inheritTo = function(obj) {
	for (var p in this) {
		obj[p] = this[p];
	}
}



var ParagraphScroller = function (pIdList) {
	var ti = new TimeIterator(this);
	ti.inheritTo(this);

	this.objParent = null;
	this.pIdList = pIdList;
	this.objParagraphList = null;
	this.objCloneList = null;
	this.clickedId = '';

	this.bWorking = false;
	this.bCloneCreated = false;

	//const
	this.SHOW_CLONE = true;
	this.SHOW_ORIGNAL = true;
	if(ttDesk_getCookie('ttDeskUpdown') == "0")
	    this.SCROLL_ENABLE = true;
	else
	    this.SCROLL_ENABLE = false;

	this.SCROLL_DISABLE = false;

	//이동설정
	this.hSpace = 10;    //행여백
	this.scrollStep = 30; //무빙수치
	this.scrollCount = 0;
	this.scrollInfoList = null;
	this.objTimeIteratorList = new Array();
	this.setWaitingTime(0);

};

ParagraphScroller.prototype.iterate = function() {
	this.scroll();
}

ParagraphScroller.prototype.registSubTimeIterator = function (objTimeIterator) {
	this.objTimeIteratorList[this.objTimeIteratorList.length] = objTimeIterator;
}

ParagraphScroller.prototype.stopSubTimeIterator = function () {
	for(var i = 0; i < this.objTimeIteratorList.length; i++) {
		 this.objTimeIteratorList[i].stop();
	}
}
ParagraphScroller.prototype.startSubTimeIterator = function () {
	for(var i = 0; i < this.objTimeIteratorList.length; i++) {
		 this.objTimeIteratorList[i].start();
	}
}


ParagraphScroller.prototype.reArrange = function () {
   // var objBr = document.getElementById('ClearBr');
	//if(objBr) this.objParent.removeChild(objBr);
	var len = this.objParagraphList.length;
	//alert('1')
	for (var i = 0; i < len; i++) {
		this.objParent.removeChild(this.objParagraphList[i]);
	}
	for (var i = 0; i < len; i++) {
		this.objParent.appendChild(this.objParagraphList[i]);
		this.pIdList[i] = this.objParagraphList[i].id;
	}
	document.getElementById('ttDesk_itemOrders').value = this.pIdList.join();
	arrangeinfo = document.getElementById('ttDesk_itemOrders').value;
	if (arrangeinfo.indexOf('ttDesk_AdminItem') != -1 ){
	var url = ttDeskBlogURL+"/plugin/ttDeskDb/?mode=item_order&td_arrno="+document.getElementById('ttDesk_itemOrders').value;
	}
	if (arrangeinfo.indexOf('ttDesk_Itemdiv') != -1 ){
	var url = ttDeskBlogURL+"/plugin/ttDeskDb/?mode=arrange_order&td_arrno="+document.getElementById('ttDesk_itemOrders').value;
	}
	var request = requestHttpXml(url);
	this.bWorking = false;
}

ParagraphScroller.prototype.displayChange = function (bShowClone) {
	for ( var i = 0; i < this.objParagraphList.length; i++ ) {
		var objParagraph = this.objParagraphList[i];
		var objClone = this.objCloneList[objParagraph.id];
		if (bShowClone)
		{
			objClone.style.display = 'block';
			objParagraph.style.display = 'none';
		} else {
			objParagraph.style.display = 'block';
			objClone.childNodes[0].innerHTML = '';
			objClone.style.display = 'none';
		}
	}
}
ParagraphScroller.prototype.scroll = function () {
	var len = this.scrollInfoList.length;
	if(this.scrollCount  >= this.scrollStep) {
		//scroll end

		//alert('1')
		for (var i=0; i < len; i++) {
			var scrollInfo = this.scrollInfoList[i];
			scrollInfo.obj.style.top = scrollInfo.to + "px";
		}
		this.reArrange();
		this.displayChange(this.SHOW_ORIGINAL);
		this.startSubTimeIterator();
		this.stop();
		return;
	} else {
		for (var i=0; i < len; i++) {
			var scrollInfo = this.scrollInfoList[i];
			var displacement = Math.round(Math.sin(this.scrollCount/this.scrollStep * Math.PI / 2)  * scrollInfo.dist);
			var curPos = scrollInfo.from + displacement;
			scrollInfo.obj.style.top = curPos + "px";
		}
	}
	this.scrollCount++;
}
ParagraphScroller.prototype.createClone = function() {
	this.objCloneList = new Array();
	for ( var i = this.objParagraphList.length - 1; i >= 0; i-- ) {
		var objParagraph = this.objParagraphList[i];
		var objClone = objParagraph.cloneNode(true);
		var objCroneWrap = document.createElement('div');
		objCroneWrap.style.display = '';
		this.objParent.appendChild(objCroneWrap);
		this.objCloneList[objParagraph.id] = objCroneWrap;
		objCroneWrap.appendChild(objClone);
		objClone.style.margin = "0px";
		objCroneWrap.id = "clone_"+objParagraph.id;
		objCroneWrap.style.zIndex = '2';
		objCroneWrap.style.width = objParagraph.offsetWidth + "px"; // for firefox (fix width)
		objCroneWrap.style.position = "absolute";
	}
	this.bCloneCreated = true;
}

ParagraphScroller.prototype.copyClone = function() {
	for ( var i = this.objParagraphList.length - 1; i >= 0; i-- ) {
		var objParagraph = this.objParagraphList[i];
		var objClone = this.objCloneList[objParagraph.id];
		objClone.childNodes[0].innerHTML = objParagraph.innerHTML;
		objClone.style.zIndex = '2';
	}
}

ParagraphScroller.prototype.initScroll = function () {
	this.stopSubTimeIterator();
	if (!this.bCloneCreated) {
		this.createClone();
	} else {
		this.copyClone();
	}
	var top = this.posTop;
	this.scrollInfoList = new Array(); //--;
	var idx = 0;
	for ( var i = 0; i < this.objParagraphList.length; i++ ) {
		var objParagraph = this.objParagraphList[i];
		var objClone = this.objCloneList[objParagraph.id];
		var to = top;
		var from = objParagraph.offsetTop;
		objClone.style.top = objParagraph.offsetTop + "px";

		if (from != to) {
			//add scrollInfo
			var scrollInfo = new Object();
			scrollInfo.obj = objClone;
			scrollInfo.from = from;
			scrollInfo.to = to;
			scrollInfo.dist = to - from;
			this.scrollCount = 0;
			this.scrollInfoList[idx++] = scrollInfo;
		}
		top = top + objParagraph.offsetHeight + this.hSpace;
	}
	this.objCloneList[this.clickedId].style.zIndex = '3';
	this.displayChange(this.SHOW_CLONE);
}

ParagraphScroller.prototype.move = function( bUseScroll ) {
	if ( bUseScroll ) {
		this.initScroll();
		this.start();
	} else {
		this.reArrange();
	}
}
ParagraphScroller.prototype.clickUp = function( id ) {

	this.clickedId = id;
	var objList = this.objParagraphList;
	var idx;

	for (idx = objList.length - 1; idx >= 0 && objList[idx].id != id; idx--); //search id's index (position);
		if(idx == 0) { // first position.
			//scroll
			var first = objList[0];
			var len = objList.length - 1;
			for (var i = 0; i < len; i++) {
				objList[i] = objList[i+1];
			}
			objList[i] = first;
		} else {
			//swap position
			var tmp = objList[idx];
			objList[idx] = objList[idx - 1];
			objList[idx - 1] = tmp;
		}

		this.move(this.SCROLL_ENABLE);
}

ParagraphScroller.prototype.clickDown = function( id ) {

	this.clickedId = id;
	var objList = this.objParagraphList;
	var idx;

	for (idx = objList.length - 1; idx >= 0 && objList[idx].id != id; idx--); //search id's index (position);
		if(idx == (objList.length - 1)) { // first position.
//		alert('마지막입니다');
			//scroll
			var first = objList[idx];
			var len = objList.length - 1;
			for (var i = len; i > 0; i--) {
	                objList[i] = objList[i-1];
			}
	        objList[0] = first;
		} else {
			//swap position
			var tmp = objList[idx];
			objList[idx] = objList[idx + 1];
			objList[idx + 1] = tmp;
		}
		this.move(this.SCROLL_ENABLE);
}

ParagraphScroller.prototype.handlerClickUp = function() {
	var objScroller = this.pScroller;
	if( objScroller.bWorking ) return;
	objScroller.bWorking = true;
	objScroller.clickUp.call(objScroller, this.paragraphId);
}

ParagraphScroller.prototype.handlerClickDown = function() {
	var objScroller = this.pScroller;
//    if( objScroller.bWorking ) return;
	objScroller.bWorking = true;
	objScroller.clickDown.call(objScroller, this.paragraphId);
}
//scroll init
ParagraphScroller.prototype.init = function () {
	this.objParagraphList = new Array();
	objheight =0;
	for ( var i = this.pIdList.length - 1; i >= 0; i-- ) {
		//regist event handler
		var objParagraph = document.getElementById(this.pIdList[i]);
		this.objParagraphList[i] = objParagraph;
		var objList = objParagraph.getElementsByTagName("span");

		for (var j=0; j < objList.length; j++) {
			//clickup
			if(objList[j].className == "ttDesk_iconup") {
				objList[j].onclick = this.handlerClickUp;
				objList[j].pScroller = this;
				objList[j].paragraphId = this.pIdList[i];
				try
				{
					objList[j].style.cursor = 'pointer';
				} catch (e) {
					objList[j].style.cursor = 'hand';
				}
			}

		//clickdown
		 if(objList[j].className == "ttDesk_icondown") {
				objList[j].onclick = this.handlerClickDown;
				objList[j].pScroller = this;
				objList[j].paragraphId = this.pIdList[i];
				try
				{
					objList[j].style.cursor = 'pointer';
				} catch (e) {
					objList[j].style.cursor = 'hand';
				}
			}
		}
		 objheight += objParagraph.offsetHeight +10;
	}

	this.objParent = this.objParagraphList[0].parentNode;
	if(objheight > 200)
	   this.objParent.style.height = objheight + 'px';
//	   this.objParent.style.height = this.objParent.offsetHeight + 'px';

	this.posTop = document.getElementById(this.pIdList[0]).offsetTop;
}


function ttDesk_PageSize(){

	var xScroll, yScroll;

	if (window.innerHeight && window.scrollMaxY) {
		xScroll = document.body.scrollWidth;
		yScroll = window.innerHeight + window.scrollMaxY;
	} else if (document.body.scrollHeight > document.body.offsetHeight){ // all but Explorer Mac
		xScroll = document.body.scrollWidth;
		yScroll = document.body.scrollHeight;

	} else { // Explorer Mac...would also work in Explorer 6 Strict, Mozilla and Safari
		xScroll = document.body.offsetWidth;
		yScroll = document.body.offsetHeight;
	}
	var windowWidth, windowHeight;
	if (self.innerHeight) {	// all except Explorer
		windowWidth = self.innerWidth;
		windowHeight = self.innerHeight;
	} else if (document.documentElement && document.documentElement.clientHeight) { // Explorer 6 Strict Mode
		windowWidth = document.documentElement.clientWidth;
		windowHeight = document.documentElement.clientHeight;
	} else if (document.body) { // other Explorers
		windowWidth = document.body.clientWidth;
		windowHeight = document.body.clientHeight;
	}

	// for small pages with total height less then height of the viewport
	if(yScroll < windowHeight){
		pageHeight = windowHeight;
	} else {
		pageHeight = yScroll;
	}

	// for small pages with total width less then width of the viewport
	if(xScroll < windowWidth){
		pageWidth = windowWidth;
	} else {
		pageWidth = xScroll;
	}

	arrayPageSize = new Array(pageWidth,pageHeight,windowWidth,windowHeight)
	return arrayPageSize;
}

function ttDesk_getPageScroll(){

	var yScroll;

	if (self.pageYOffset) {
		yScroll = self.pageYOffset;
	} else if (document.documentElement && document.documentElement.scrollTop){	 // Explorer 6 Strict
		yScroll = document.documentElement.scrollTop;
	} else if (document.body) {// all other Explorers
		yScroll = document.body.scrollTop;
	}

	arrayPageScroll = new Array('',yScroll)
	return arrayPageScroll;
}

function ttDesk_adminLayer(id){

	var remocon  = document.getElementById("ttDesk_adminmenu");
	var obj = document.getElementById(id);
	objwidth = 653;
	if(document.getElementById("ttDesk_scroll_checked").checked == false){
		ttDesk_menuLayer("ttDesk_adminmenu");
	}
	remocontop = remocon.style.top;
	remoconleft = remocon.style.left;
	if(remocontop.indexOf("px") > -1){
		remocontop =remocontop.replace("px","");
		remoconleft =remoconleft.replace("px","");
	}
	obj.style.top = remocontop+"px";
	obj.style.left = (remoconleft - objwidth)+"px";
}

function ttDesk_EditLayer(id,w,h){
	var top, left, w, h;
	var obj = document.getElementById(id);
	var arrayPageSize = ttDesk_PageSize();
	var arrayPageScroll = ttDesk_getPageScroll();
	var pagewidth  = arrayPageSize[0];
	var pageheight  = arrayPageSize[1];
	var windowwidth  = arrayPageSize[2];
	var windowheight  = arrayPageSize[3];
	var curscroll = arrayPageScroll[1];

	toppx = curscroll + ((windowheight -h)/ 2);
	leftpx = (pagewidth -w) /2;
	obj.style.top = toppx+"px";
	obj.style.left = leftpx+"px";
}

function ttDesk_menuLayerInit(){
	if(document.getElementById("ttDesk_scroll_checked").checked == true){
		ttDesk_menuLayer("ttDesk_adminmenu");
		//ttDesk_adminLayer('ttDesk_AdminDiv');
	}
}

function ttDesk_menuLayer(id){
	var w =120;
	var h  = 300;
	var obj = document.getElementById(id);
	var arrayPageSize = ttDesk_PageSize();
	var arrayPageScroll = ttDesk_getPageScroll();
	var pagewidth  = arrayPageSize[0];
	var pageheight  = arrayPageSize[1];
	var windowwidth  = arrayPageSize[2];
	var windowheight  = arrayPageSize[3];
	var curscroll = arrayPageScroll[1];
//	w = obj.style.width;
//	h = obj.style.height;
	toppx = curscroll + 30;
	leftpx = (windowwidth -w);
	obj.style.top = toppx+"px";
	obj.style.left = leftpx+"px";
}

function ttDesk_getCookie(name) {
	var label = name + "=" ;
	var labelLen = label.length ;
	var cLen = document.cookie.length;
	var i = 0;
	while (i < cLen){
		var j = i + labelLen;
		if (document.cookie.substring(i,j) == label) {
			var cEnd = document.cookie.indexOf(";",j);
			if (cEnd == -1){
				cEnd = document.cookie.length;
	        		}
			return unescape(document.cookie.substring(j,cEnd));
	    	}
		i++;
	}
	return "";
}

function ttDesk_setCookie(name, value, days, domain) {
		var expires = "";
		var _domain = '';
		if(days) {
			var date = new Date();
			date.setTime(date.getTime() + (days * 86400000));
			expires = "; expires=" + date.toGMTString();
		}
		if(domain) {
			_domain = 'domain='+domain
		}
		document.cookie = name + "=" + value + expires + "; path=/;"+_domain;
}

function ttDesk_scrollCookie(){
	if(document.getElementById("ttDesk_scroll_checked").checked == true){
		ttDesk_setCookie('ttDeskScroll','0',365);
	}else{
		ttDesk_setCookie('ttDeskScroll','1',365);
	}
}


function ttDesk_shortkey(event){
	if (isIE)
		{
			event = window.event;
			event.target = event.srcElement;
		}

		switch (event.target.nodeName) {
			case "INPUT":
			case "SELECT":
			case "TEXTAREA":
				return;
		}
		switch (event.keyCode) {
			case 68: //D
				if(location.href.indexOf("?mode=ttDeskAdmin") > 0)
					window.location = ttDeskBlogURL + "/";
				else
					window.location = ttDeskBlogURL + "/?mode=ttDeskAdmin";
				break;
			case 73://I
				if(location.href.indexOf("?mode=ttDeskAdmin") > 0)
				ttDesk_Adminitemsettings(document.getElementById("ttDesk_item_tab"),0,'item');
				break;
			case 82://R
				ttDesk_CacheDelete();
				break;
			case 70://F
				if(location.href.indexOf("?mode=ttDeskAdmin") > 0)
					ttDesk_reloadClose(1);
				break;
		}
}

function ttDesk_shortkey2(event){
	if (isIE)
		{
			event = window.event;
			event.target = event.srcElement;
		}

		switch (event.target.nodeName) {
			case "INPUT":
			case "SELECT":
			case "TEXTAREA":
				return;
		}

		switch (event.keyCode) {
			case 82://R
				parent.ttDesk_CacheDelete();
				break;
			case 70://F
					parent.ttDesk_reloadClose(1);
				break;
		}
}

function ttDesk_SampleHtml(objid){
	samplehtml = 	document.getElementById(objid).value;
	document.getElementById("td_summary").value =samplehtml;
}

function ttDesk_CssmakeView(objid){
	toggleLayer(objid);
	ttDesk_EditLayer(objid,500,500);
	hideLayer('ttDesk_htmlpreview');
}
