var angle = 0;
var dir = 0.01;
var left, right;
var cubetimeout;
function startrotate(node1,node2,direction) {
	var a = Math.PI / 4, b = Math.PI / 2;
	if(cubetimeout) {
		clearTimeout(cubetimeout);
	}
	cubetimeout=setTimeout(function() {
		if(node1 && node2 && node1.id==node2.id) return;
		if(direction >= 0) {left = node1; right = node2; }
		else { right = node1; left = node2; }
		dir = (direction >= 0) ? 0.005 : -0.005;
		angle = (direction >=0) ? 0 : b;
		rotate(direction);
	},1200);
}


function rotate(direction) {
	var a = Math.PI / 4, b = Math.PI / 2;	
	var start = (new Date()).getTime();
	setTimeout(function() {
		var now = (new Date()).getTime();
		angle += dir * (now - start);
		if (dir > 0 && angle >= b) {
			angle = b;
			dir = -dir;
		} else if (dir < 0 && angle < 0) {
			angle = 0;
			dir = -dir;
		} else
			rotate(direction);
		if(left) {	
			left.style.left = Math.round(24 - 24 * Math.cos(angle - a) )+  "px";	
			left.style.width = Math.round(34 * Math.cos(angle)) + "px";
		}
		if(right) {
			right.style.left = Math.round(24 + 24 * Math.cos(angle + a) )+ "px";
			right.style.width = Math.round(34 * Math.sin(angle)) + "px";
		}
	}, 0);
}

/******************************************************/
/*** Find as you type                              ****/
/******************************************************/
register("Loaded",function () {
	if($("menu_search_global_searchfield")) {
		var d=new PreSearch($("menu_search_global_searchfield"));
		d.addEvents();
	} 
	if($("menu_search_mail_searchfield")) {
		var d2=new PreSearch($("menu_search_mail_searchfield"));
		d2.addEvents();
	}
});
PreSearch = function (searchfield) {
	var Self=this;
	this.keytimeout;
	this.actualposition=-1;
	this.searchfield=searchfield;
	this.mycontent=newnode("div",null,{ className : "presearchcontent" },[]);
	this.mycontent.style.display="none";
	this.mycontent.onselectstart = function () { var tmp=menuselectstart ; menuselectstart = false; return tmp; }  
	this.mycontent.onmousedown = function () { var tmp=menumousedown ; menumousedown = false; return tmp; }
	$("body").appendChild(this.mycontent);
}
PreSearch.prototype.close = function () {
	var Self=this;
	popupHide();
}
PreSearch.prototype.open = function () {
	var Self=this;
	popup(Self.mycontent,null,null,null,"findasyoutype",true);
}
PreSearch.prototype.addEvents = function () {
	var Self=this;
	addDOMEvent(this.searchfield,"keydown",Self.addKeyDown()); 	
}
PreSearch.prototype.nextContent = function(direction) {
	if(direction) {
		this.actualposition++;
		this.actualposition=this.setSelected(this.actualposition);
	} else {
		this.actualposition--;
		this.actualposition=this.setSelected(this.actualposition);
	}
}
PreSearch.prototype.addKeyDown = function () {
	var Self=this;
	return function(evt) {
		if(Self.keytimeout) {
			clearTimeout(Self.keytimeout);
		}
		
		if (!evt) evt = window.event;
		var a = evt.keyCode;
		switch (a) {
			case 27: //ESC
				Self.actualposition=-1;
				Self.close();
				stopEvent(evt); 
				return false;
				break;
			case 13: case 9: // ENTER
				if(Self.actualposition!=-1) {
					if(Self.mycontent.childNodes[Self.actualposition]) {
						var myelem=Self.mycontent.childNodes[Self.actualposition];					
 						Self.searchfield.value=myelem.oxvalue;
					} 
				}
				popupHide();
				break;
			case 38:	// UP
				Self.nextContent(false);
				break;
			case 40:	// DOWN
				Self.nextContent(true);
				break;
		
			default:
				Self.actualposition=-1;
				Self.keytimeout=setTimeout(function() {
					var newpresearch=Self.searchfield.value;
					Self.presearch(newpresearch);
				},500);
				break;
		}
	}
}
PreSearch.prototype.presearch = function (searchstring) {
	var Self=this;
	removeChildNodes(this.mycontent);
	if(searchstring.length > 2)  {
		this.mycontent.appendChild(
			newnode("div", { textAlign: "center", width: "100%", padding: "1px" }, null, [ 
				newnode("img",null,{src: "img/ox_animated_withoutbg.gif"},[])
			])
		);
		this.mycontent.style.left=getAbsolutePositionLeft(this.searchfield.parentNode.parentNode.parentNode.parentNode.parentNode)+"px";
		this.mycontent.style.top=(getAbsolutePositionTop(this.searchfield.parentNode.parentNode.parentNode.parentNode.parentNode)+this.searchfield.parentNode.parentNode.parentNode.parentNode.offsetHeight)+"px";
		switch(currentpath2[0]) {
			case "calendar":
				Self.open();
				var reqobj = new Object();
				reqobj.pattern = searchstring;
				if(!configGetKey("gui.calendar.allfolders")) {
					reqobj.folder = activefolder;
				}
				new JSON().put(AjaxRoot + "/calendar?session=" + session + "&action=search&columns=200",
				reqobj, null, 
				function(cb) {
					Self.refill(cb.data);
				});
				break;
			case "contacts":
				Self.open();
				var reqobj = new Object();
				reqobj.pattern = searchstring;
				new JSON().put(AjaxRoot + "/contacts?session=" + session + "&action=search&columns=500",
				reqobj, null, 
				function(cb) {
					Self.refill(cb.data);
				});
				break;
			case "infostore":
				Self.open();		
				var reqobj = new Object();
				reqobj.pattern = searchstring;
				reqobj.folder = activefolder;
				(new JSON()).put(AjaxRoot + "/infostore?session=" + session + "&action=search&columns=700&folder="+activefolder,
				reqobj, null, 
				function(cb) {
					Self.refill(cb.data);
				});
				break;
			case "tasks":				
				Self.open();
				var reqobj = new Object();
				reqobj.pattern = "*"+searchstring+"*";
				reqobj.folder = activefolder;
				(new JSON()).put(AjaxRoot + "/tasks?session=" + session + "&action=search&columns=200",
				reqobj, null, 
				function(cb) {
					Self.refill(cb.data);
				});
				break;
			case "mail":
				var column="";
				var searchcolumn=menumailsearchcontents[mailsearchcontent];
				if(OXMailObject.stringmapping[searchcolumn]) { 
					searchcolumn = OXMailObject.stringmapping[searchcolumn];
					column=""+searchcolumn;
				} else { 
					break;
				}
				Self.open();
				var req=""+AjaxRoot + '/mail?action=search&session='+session+'&columns='
					+ column + '&folder=' + encodeURIComponent(activefolder);
				
				var reqobj = new Array();
				var oObj = new Object();
				oObj.pattern = searchstring;
				oObj.col=searchcolumn;
				reqobj.push(oObj);
				if(reqobj.length<=0) { return; }
				new JSON().put(req,reqobj, null, 
				function(cb) {
					var newarray = new Array();
					function createEntry(entry) {
						if(entry) {
							for(var i2=0;i2<entry.length;i2++) {
								var mystring=entry[i2].join("");
								if(mystring.indexOf(searchstring)!=-1) { 
									if(entry[i2][0] && entry[i2][0]!="") {
										var tmp3=entry[i2][0];
										if(tmp3.charAt(0)=="\"" && tmp3.charAt(tmp3.length-1) == "\"") {
											tmp3=tmp3.substring(1,tmp3.length-1);
										}
										newarray.push([tmp3]);
									} else {
										newarray.push([entry[i2][1]]);
									}
								}
							}
						}
					} 
					if(activemodule=="mail" && (menumailsearchcontents[mailsearchcontent] == "from" || menumailsearchcontents[mailsearchcontent] == "to" || menumailsearchcontents[mailsearchcontent] == "cc")) {
						for(var i=0;i<cb.data.length;i++) {
							createEntry(cb.data[i][0])
						}
						Self.refill(newarray);	
					} else {
						Self.refill(cb.data);
					}
					
				});
				break;
			default:
				popupHide();
		}	
	} else {
		popupHide();
	}	
}
PreSearch.prototype.refill = function (dataarray) {
	var Self=this;
	var tmpobject=new Object();
	var counter=0;
	if(dataarray.length==0) {
		removeChildNodes(this.mycontent);
		popupHide();
	} else {
		removeChildNodes(this.mycontent);
		for (var  i = 0; i < dataarray.length; i++ ) {
			if(!tmpobject[dataarray[i][0]]) {
				tmpobject[dataarray[i][0]]=true;
				counter++;
				if(counter>5) break;
				var nDiv = newnode("div",{ overflow: "hidden", whiteSpace: "nowrap", padding: "1px" }, []);
				nDiv.appendChild(document.createTextNode(dataarray[i][0]));
				addDOMEvent(nDiv,"mouseover",function(e) { this.className = "AutoCompleteHighlight";});
				addDOMEvent(nDiv,"mouseout",function(e) { if(Self.actualposition!= this.position) {this.className = "AutoCompleteBackground";}});
				nDiv.oxvalue= dataarray[i][0];
				nDiv.position=i;
				Self.actualposition=-1;
				addDOMEvent(nDiv,"mousedown",function(e) {
					var myelem=e.currentTarget || e.srcElement;					
 					Self.searchfield.value=myelem.oxvalue; 
					popupHide(); 
					if(activemodule=="mail") {
						triggerEvent("OX_New_Search",activemodule,Self.searchfield.value,menumailsearchcontents[mailsearchcontent]);
					} else {
						triggerEvent("OX_New_Search",activemodule,Self.searchfield.value);
					}  
				});
			}
			if(counter>5) break;
			this.mycontent.appendChild(nDiv);	
		}
	} 
}
PreSearch.prototype.setSelected = function (int1) {
	var Self=this;
	var childs=this.mycontent.childNodes;
	if(int1<0) { int1=0; }
	if(int1>=childs.length) { int1=childs.length-1; }
	for(var i=0;i<childs.length;i++) {
		if(i==int1) {
			childs[i].className = "AutoCompleteHighlight";
		} else {
			childs[i].className = "AutoCompleteBackground";
		}
	}
	return int1;
}

function Accordion(maxheight,width,hover) {
	this.hover=hover;
	this.speed=12;
	this.intervalcounts=0;
	this.interval=10;
	this.actualcontent=0;
	this.components=new Object();
	this.maxheight=maxheight;
	this.width="100%";
	if(width) { this.width = width +"px" }
	this.container=newnode("div",{ width: this.width },{},[]);

}
Accordion.prototype.addComponent = function(title,node) {
	this.components[title]= {"title" : title , "content" : node };	
}
Accordion.prototype.refill=function() {
	this.getDomNode();
	this.showContent(this.actualcontent);
	
}
Accordion.prototype.inTree = function() {
	var node=this.container;
	while(node) {
		if(node==$("body")) { return true; }
		node=node.parentNode;
	}
}
Accordion.prototype.setHover = function(hover) {
	this.hover=hover;
}
Accordion.prototype.checkHeight = function() {
	if(this.intervalcounts==0) {
		if(this.maxheight && this.maxheight<this.container.offsetHeight) {
			this.container.style.height=this.maxheight+"px";
			this.container.style.overflowX="hidden";
			this.container.style.overflowY="auto";
		}
		if(!this.hover) {
			if(AppointmentHover.actualHover) {
				AppointmentHover.actualHover.sizeChanged();
			}
		} else {
			this.hover.sizeChanged();
		}
	}
}
Accordion.prototype.getDomNode = function () {
	removeChildNodes(this.container);
	
	var tmpintree=this.inTree();
	if(!tmpintree) { $("body").appendChild(this.container); }
	
	var tmpvis= this.container.style.visibility;
	this.container.style.visibility="hidden";
	for(var i in this.components) {
		var tmp=this.components[i];
		this.container.appendChild(tmp.content);
		tmp.content.style.height="";
		this.components[i].maxheight=tmp.content.offsetHeight;
	}
	if(!tmpintree) { $("body").removeChild(this.container); }
	this.container.style.visibility=tmpvis;
	return this.container;
}
Accordion.prototype.showExtraContent = function(number) {
	var tmpcontents=(""+this.actualcontent).split(",");
	tmpcontents.push(number);
	this.showContent(tmpcontents.join(","));
}
Accordion.prototype.hideExtraContent = function(number) {
	var tmpcontents=(""+this.actualcontent).split(",");
	for(var i=0;i<tmpcontents.length;i++) {
		if(tmpcontents[i] == number) {
			tmpcontents.splice(i,1);
			break;
		}
	}
	this.showContent(tmpcontents.join(","));
	
}

Accordion.prototype.showContent = function(number) {
	var Self=this;
	
	var newnumbers=(""+number).split(",");
	var oldnumbers=(""+Self.actualcontent).split(",");
	var oldobject=new Object();
	var newobject=new Object();
	for(var i=0;i<oldnumbers.length;i++) {
		oldobject[oldnumbers[i]]=true;
	}
	for(var i=0;i<newnumbers.length;i++) {
		newobject[newnumbers[i]]=true;
	}
	this.container.style.height="";
	this.container.style.overflow="";
	for(var i2 in Self.components) {
		
		if(!oldobject[i2]) {
			if(!newobject[i2]) {
				Self.components[i2].content.style.height="0px";
			} else {
				Self.setDisplay(Self.components[i2],true);
			}
		} else {
			if(!newobject[i2]) {
				Self.setDisplay(Self.components[i2],false);			
			} else {
				if(Self.components[i2].content.style.height=="0px") {
					Self.setDisplay(Self.components[i2],true);
				}
				
			} 
		}
	} 
	Self.checkHeight();
	var newnumbers=new Array();
	for(var i in newobject) {
		newnumbers.push(i);
	}
	Self.actualcontent=newnumbers;
}
Accordion.prototype.setDisplay = function(containerobject,direction) {
	var Self=this;
	if(direction) {
		containerobject.content.style.height="0px";
		containerobject.content.style.display="block";
		if(containerobject.interval) {
			clearInterval(containerobject.interval);
			Self.intervalcounts--;
		}
		Self.intervalcounts++;
		containerobject.interval=setInterval(function() {
			var actheight=containerobject.content.offsetHeight;
			if(actheight<containerobject.maxheight) {
				var nextheight=containerobject.content.offsetHeight + Math.round(containerobject.maxheight/Self.speed);
				if(nextheight>containerobject.maxheight) { nextheight=containerobject.maxheight; }
				containerobject.content.style.opacity = (nextheight/containerobject.maxheight);
				containerobject.content.style.filter = "alpha(style=0,opacity:" +((nextheight/containerobject.maxheight)*100)+ ")";	// IE 
				containerobject.content.style.height = nextheight+"px";

			} else {
				containerobject.content.style.opacity = 1;
				containerobject.content.style.filter = "alpha(style=0,opacity:" +(100)+ ")";	// IE 
				containerobject.content.style.height="";
				clearInterval(containerobject.interval);
				containerobject.interval=null;
				Self.intervalcounts--;
				Self.checkHeight();
			}			
		},Self.interval);	 
					
	} else {
		containerobject.content.style.height=containerobject.maxheight+"px";
		if(containerobject.interval) {
			clearInterval(containerobject.interval);
			Self.intervalcounts--;
		}
		Self.intervalcounts++;
		containerobject.interval=setInterval(function() {
			var actheight=containerobject.content.offsetHeight;
			if(actheight>0) {
				var nextheight=containerobject.content.offsetHeight - Math.round(containerobject.maxheight/Self.speed);
				if(nextheight<0) { nextheight=0; }
				containerobject.content.style.opacity = (nextheight/containerobject.maxheight);
				containerobject.content.style.filter = "alpha(style=0,opacity:" +((nextheight/containerobject.maxheight)*100)+ ")";	// IE 
				containerobject.content.style.height = nextheight+"px";
			} else {
				containerobject.content.style.opacity = 0;
				containerobject.content.style.filter = "alpha(style=0,opacity:" +(0)+ ")";	// IE 
				
				containerobject.content.style.height="0px";
				clearInterval(containerobject.interval);
				containerobject.interval=null;
				Self.intervalcounts--;
				Self.checkHeight();
			}			
		},Self.interval);	
	}
}
function Slider(count) {
	this.content;
	this.count=count;
	this.slidercontents=new Array();
	for(var i=0;i<count;i++) {
		this.slidercontents[i]=new Object();
		this.slidercontents[i]["active"]=false;
	}
	this.multiple;
	this.disableall;
}
Slider.prototype.enableButton = function(i) {
	this.slidercontents[i]["active"]=true;
	this.content.getElementsByTagName("tr")[i].getElementsByTagName("img")[0].style.display="";
	this.content.getElementsByTagName("tr")[i].getElementsByTagName("img")[1].style.display="none";
	this.content.getElementsByTagName("tr")[i].getElementsByTagName("img")[2].style.display="none";
	if(this.slidercontents[i].enable) {
		this.slidercontents[i].enable();
	}
}
Slider.prototype.disableButton = function(i) {
	this.slidercontents[i]["active"]=false;
	this.content.getElementsByTagName("tr")[i].getElementsByTagName("img")[0].style.display="none";
	this.content.getElementsByTagName("tr")[i].getElementsByTagName("img")[1].style.display="none";
	this.content.getElementsByTagName("tr")[i].getElementsByTagName("img")[2].style.display="";	
	if(this.slidercontents[i].disable) {
		this.slidercontents[i].disable();
	}
}
Slider.prototype.mouseOver = function(i) {
	if(this.slidercontents[i]["active"]) return;
	this.content.getElementsByTagName("tr")[i].getElementsByTagName("img")[0].style.display="none";
	this.content.getElementsByTagName("tr")[i].getElementsByTagName("img")[1].style.display="";
	this.content.getElementsByTagName("tr")[i].getElementsByTagName("img")[2].style.display="none";
	if(this.slidercontents[i].mouseover) {
		this.slidercontents[i].mouseover();
	}		
}
Slider.prototype.mouseOut = function(i) {
	if(this.slidercontents[i]["active"]) return;
	this.content.getElementsByTagName("tr")[i].getElementsByTagName("img")[0].style.display="none";
	this.content.getElementsByTagName("tr")[i].getElementsByTagName("img")[1].style.display="none";
	this.content.getElementsByTagName("tr")[i].getElementsByTagName("img")[2].style.display="";	
	if(this.slidercontents[i].mouseout) {
		this.slidercontents[i].mouseout();
	}
}

Slider.prototype.nodeClicked = function(i) {
	if(this.slidercontents[i]["active"]) {	
	} else {
		for(var i2=0;i2<this.slidercontents.length;i2++) {
			if(this.slidercontents[i2]["active"]) {
				this.disableButton(i2);
				break;
			}
		}
		this.enableButton(i);
	}
}
Slider.prototype.setNodeFunctions =function(i,enable,disable) {
	if(i>=0 && this.slidercontents.length > i) {
		this.slidercontents[i].enable=enable;
		this.slidercontents[i].disable=disable;
	}
}
Slider.prototype.getDomNode = function() {
	var tmpnodetop=newnode("tr",{},{},[
		newnode("td",{ width: "100%", lineHeight:"0px"},{},[
			newnode("img",{ width:"28px",height:"28px", display:"none"},{ src:"img/slider/Slider_top_active.png"},[]),
			newnode("img",{ width:"28px",height:"28px", display:"none"},{ src:"img/slider/Slider_top_mouseover.png"},[]),
			newnode("img",{ width:"28px",height:"28px"},{ src:"img/slider/Slider_top_none.png"},[])
		])
	]);
	var tmpnodemiddle=newnode("tr",{},{},[
		newnode("td",{ width: "100%", lineHeight:"0px"},{},[
			newnode("img",{ width:"28px",height:"28px", display:"none"},{ src:"img/slider/Slider_middle_active.png"},[]),
			newnode("img",{ width:"28px",height:"28px", display:"none"},{ src:"img/slider/Slider_middle_mouseover.png"},[]),
			newnode("img",{ width:"28px",height:"28px"},{ src:"img/slider/Slider_middle_none.png"},[])
		])
	]);
	var tmpnodebottom=newnode("tr",{},{},[
		newnode("td",{ width: "100%", lineHeight:"0px"},{},[
			newnode("img",{ width:"28px",height:"28px", display:"none"},{ src:"img/slider/Slider_bottom_active.png"},[]),
			newnode("img",{ width:"28px",height:"28px", display:"none"},{ src:"img/slider/Slider_bottom_mouseover.png"},[]),
			newnode("img",{ width:"28px",height:"28px"},{ src:"img/slider/Slider_bottom_none.png"},[])
		])
	]);
				
				
	var Self=this;
	if(this.content) {
		return this.content;
	}
	this.content=newnode("table",{ width : "30px"},{ cellPadding : 0, cellSpacing:0 , border: 0},[
		newnode("tbody",{},{},[
		])
	]);
	var tmptbody=this.content.getElementsByTagName("tbody")[0];
	for(var i=0;i<this.count;i++) {
		var node;
		if(i==0) {
			node=tmpnodetop.cloneNode(true);
		} else if(i==this.count-1) {
			node=tmpnodebottom.cloneNode(true);
		} else {
			node=tmpnodemiddle.cloneNode(true);
		}
		addDOMEvent(node,"click",
			(function(i1) { 
				return function(e) { Self.nodeClicked(i1); } 
			})
		(i));
		addDOMEvent(node,"mouseover",
			(function(i1) { 
				return function(e) { Self.mouseOver(i1); } 
			})
		(i));
		addDOMEvent(node,"mouseout",
			(function(i1) { 
				return function(e) { Self.mouseOut(i1); } 
			})
		(i));
		tmptbody.appendChild(node);
	}
	return this.content;
}

function createHoverContent(innerwidth,headerheight,borderheight,imgsizes) {
	if(!innerwidth) { innerwidth= 430;}
	if(!imgsizes) { imgsizes= { t: 6 , r : 13 , b :15 , l : 6} }
	if(!headerheight) { headerheight = 20 }
	if(!borderheight) { borderheight = 20 }
	var mywidth=innerwidth+imgsizes.r+imgsizes.l;
	var coreelement=newnode("div",{ position: "absolute", width: mywidth+"px", zIndex: 100000, left : "300px", top : "100px" , display:"none" },{},[
		newnode("div",{ width: mywidth+"px",height : (headerheight+"px")},{ className : "hover-header-tr" },[
			newnode("div",{ position: "absolute", width: (mywidth+"px"), height: (headerheight +"px") },{ className : "hover-header-tl" },[]),
			newnode("div",{ position: "absolute", marginTop: imgsizes.t+ "px", width: "100%", height: (headerheight-imgsizes.t)+"px" },{ className : "hover-header-l" },[]),
			newnode("div",{ position: "absolute", marginTop: imgsizes.t+ "px", width: "100%", height: (headerheight-imgsizes.t)+"px" },{ className : "hover-header-r" },[]),
			newnode("div",{ position: "absolute", marginLeft: imgsizes.l+ "px", width:(innerwidth)+"px" , height: (headerheight)+"px"},{ className : "hover-header-t" },[]),
			newnode("div",{ position: "absolute", marginLeft: imgsizes.l+ "px", marginTop: imgsizes.t+ "px" , width:(innerwidth)+"px" , height: (headerheight-imgsizes.t)+"px"},{ className : "hover-header-color" },[])
		]),
		newnode("div",{ overflow: "hidden", width: mywidth+"px" },{className : "hover-body-r "},[
			newnode("div",{ width: mywidth+"px" },{className : "hover-body-l"},[
		 		newnode("div", { marginLeft: imgsizes.l+ "px" , width: innerwidth+"px" ,overflow:"hidden"},{className : "hover-body-color"},[
			 	])
			])
		]),
		newnode("div",{ width: mywidth+"px",height : (borderheight+"px")},{ className : "hover-bottom-br" },[
			newnode("div",{ position: "absolute", width: (mywidth+"px"), height: (borderheight +"px") },{ className : "hover-bottom-bl" },[]),
			newnode("div",{ position: "absolute", marginBottom: imgsizes.b+ "px", width: "100%", height: (borderheight-imgsizes.b)+"px" },{ className : "hover-bottom-l" },[]),
			newnode("div",{ position: "absolute", marginBottom: imgsizes.b+ "px", width: "100%", height: (borderheight-imgsizes.b)+"px" },{ className : "hover-bottom-r" },[]),
			newnode("div",{ position: "absolute", marginLeft: imgsizes.l+ "px", width:(innerwidth)+"px" , height: (borderheight)+"px"},{ className : "hover-bottom-b" },[]),
			newnode("div",{ position: "absolute", marginLeft: imgsizes.l+ "px", marginBottom: imgsizes.b+ "px" , width:(innerwidth)+"px" , height: (borderheight-imgsizes.b)+"px"},{ className : "hover-bottom-color" },[])
		])
	]);
	return coreelement;
}
function AppointmentHover() {}
AppointmentHover.content;
AppointmentHover.confirmdialogshown=false;
AppointmentHover.references=new Object();
AppointmentHover.references.allGroups=new Array();
AppointmentHover.references.allGroupsParticipants=new Object();
AppointmentHover.openAttachedFile = function(folderid,objectid,filename,rtfflag,attachmentid) {
	return function() {
		if(rtfflag) { return; }
		var sURL = AjaxRoot + "/attachment/" + filename + "?action=document&session=" + session + "&attached=" + objectid  +
			 "&module=1&folder=" + folderid + "&id=" + attachmentid;
		newWindow(sURL,"width=780px,height=640px,left=50,top=50,resizable=yes,menubar=no,toolbar=no,status=no,scrollbars=yes");
	}
}
AppointmentHover.saveAttachedFile = function(folderid,objectid,filename,rtfflag,attachmentid) {
	return function() {	
		if(rtfflag) return;
		var sContentType = 'application%2Foctet-stream';	
		var sURL = 	AjaxRoot + "/attachment/" + filename + "?action=document&session="+ session + "&attached=" + objectid  + 
		"&module=1&folder="+ folderid + "&id=" + attachmentid + "&content_type=" +sContentType;
		if(IE6) { newWindow(sURL,"width=780px,height=640px,left=50,top=50,resizable=yes,menubar=no,toolbar=no,status=no,scrollbars=yes"); }
		else { parent.frames['dlIframe'].location.href = sURL; }
	}
};
AppointmentHover.saveAttachInInfoStore = function(folderid,objectid,filename,rtfflag,attachmentid) {
	/*if(rtfflag) return;
	if (activemodule == "mail") return;
	var nNumModule = -1;
	switch(activemodule)
		{
			case "calendar": 	nNumModule = 1;
								break;
			case "tasks": 	nNumModule = 4;
								break;
			case "contacts": 	nNumModule = 7;
								break;																
		}
		propertiesPopUp = window.open("newInfoItemMain.html#attachmodule=" + nNumModule+ "&edit_id=" + -1
				+ "&filename=" + Self.selectedFilename
				+ "&attid=" + Self.selectedId
				+ "&attobjid=" + Self.nItemId								
				+ "&attobjfolder=" + Self.folder				
				+ "&folder=" + configGetKey("folder.infostore")
				, "", "width=800px,height=700px,left=50,top=50,resizable=yes");	
		propertiesPopUp.focus();			
	}*/
}
AppointmentHover.followLink = function (module,folder,id) {
	return function() {
		triggerEvent("OX_Direct_Linking",module,{ folder : folder , id : id });
	}
}
AppointmentHover.fillLinks = function() {
	var linksmain=AppointmentHover.references["core_links_template"].cloneNode(true);
	var linksbody=linksmain.getElementsByTagName("tbody")[0];
	var linksfirst=newnode("tr",{},{},[
		newnode("td",{ width: "25px", paddingTop:"12px", lineHeight : "0px"},{},[
			newnode("img",{},{ src: "img/dummy.gif" },[]) 
		]),
		newnode("td",{ paddingTop:"12px"},{ className : "contenttext"},[]),
		newnode("td",{ width: "25px", paddingTop:"12px" , lineHeight : "0px"},{},[
			newnode("img",{},{ src: "img/menu/link_follow.gif" },[])
		])
	]);
	json.get(AjaxRoot + "/link?action=all&session=" + session + "&folder=" +
		AppointmentHover.actualcalendarobject.folder_id + "&id=" + AppointmentHover.actualcalendarobject.id + "&module=1", null,
		function(links) {
			links=links.data;
			if(links.length==0) {
				var tmp=newnode("tr",{},{},[
					newnode("td",{ width: "25px"},{},[
						newnode("img",{},{ src: "img/dummy.gif" },[])
					]),
					newnode("td",{},{ colspan : 4 , className : "contenttext" },[
						document.createTextNode(_("No links available"))
					])		
				]);
				linksbody.appendChild(tmp);
				
			} else {
				var linkobjects=new Object()
				for(var i=0;i<links.length;i++) {		
					var module;
					var folder_id;
					var id;
					if(links[i].id1==AppointmentHover.actualcalendarobject.id &&
					   links[i].folder1==AppointmentHover.actualcalendarobject.folder_id && links[i].module1==1) {
					   	module=links[i].module2;
						folder_id=links[i].folder2;
						id=links[i].id2;
					} else {	
						module=links[i].module1;
						folder_id=links[i].folder1;
						id=links[i].id1;	
					}
					switch (module) {
						case 1: 
							if(!linkobjects["calendar"]) { linkobjects["calendar"]=new Array(); }
							linkobjects["calendar"].push({id : id, folder : folder_id });
							break;
						case 4: 
							if(!linkobjects["tasks"]) { linkObjects["tasks"]=new Array(); }
							linkobjects["tasks"].push({id : id, folder : folder_id });
							break;
						case 7: 
							if(!linkobjects["contacts"]) { linkObjects["contacts"]=new Array(); }
							linkobjects["contacts"].push({id : id, folder : folder_id });
							break;	
						case 137: 
							if(!linkobjects["infostore"]) { linkObjects["infostore"]=new Array(); }
							linkobjects["infostore"].push({id : id, folder : folder_id });
							break;												
					}
				}
				var requests=new Array();
				var requestmodule=new Array();
				
				for(var i in linkobjects) {
					switch (i) {
						case "calendar":
						case "tasks":
							requests.push({
								action: "list",
								module : i,
								columns : "1,20,200",
								data : linkobjects[i]
							});
							break;
						case "contacts":
							requests.push({
								action: "list",
								module : i,
								columns : "1,20,500,602",
								data : linkobjects[i]
							});
							break;
						case "infostore":
							requests.push({
								action: "list",
								module : i,
								columns : "1,20,700",
								data : linkobjects[i]
							});
							break;
					}
					requestmodule.push(i);
				}
				
				json.put(AjaxRoot + "/multiple?session="+session +"&continue=true", 
					requests, 
					null, 
					function(multiplerequests){					
						if(multiplerequests){
							if(multiplerequests.length > 0) {
								for (single=0;single<multiplerequests.length;single++) {
									if(multiplerequests[single].error_id != undefined) {
										newServerError(multiplerequests[single]);
									} else {
										for(var count=0;count<multiplerequests[single].data.length;count++) {
											function getModuleString(mod,dist) {
												if(mod == "tasks") { return "img/tasks/tasks.gif"; }
												if(mod == "contacts" && !dist) { return "img/contacts/contacts.gif"; }
												if(mod == "contacts" && dist) { return "img/menu/distributionlist.gif"; }
												if(mod == "infostore") { return "img/infostore/infostore.gif"; }
												if(mod == "calendar") { return "img/calendar/calendar.gif"; } 
											}
											var tmp_module = requestmodule[single];
											var tmp_folder_id =multiplerequests[single].data[count][1];
											var tmp_id =multiplerequests[single].data[count][0];
											var tmp_title =multiplerequests[single].data[count][2];
											var tmp_distri = multiplerequests[single].data[count][3] || false; 
											var node=linksfirst.cloneNode(true);
											node.getElementsByTagName("img")[0].src=getModuleString(tmp_module,tmp_distri);
											node.getElementsByTagName("td")[1].appendChild(document.createTextNode(tmp_title));
											node.getElementsByTagName("img")[1].title=_("Follow link"); /*stringfuckel*/
											addDOMEvent(node.getElementsByTagName("img")[1],"click",AppointmentHover.followLink(tmp_module,tmp_folder_id,tmp_id));
											linksbody.appendChild(node);
											AppointmentHover.accordion.refill();
										}
									}
								}
							}
						}
						AppointmentHover.accordion.refill();
					} 	
				);
			}
		}
	);
	AppointmentHover.accordion.addComponent("AppointmentLinks",linksmain,false);
}
AppointmentHover.fillAttachments = function() {
	var attachmentfirst=
	newnode("tr",{},{},[
		newnode("td",{ width: "25px", paddingTop:"12px", lineHeight : "0px"},{},[
			newnode("img",{},{ src: "img/dummy.gif" },[]) 
		]),
		newnode("td",{ paddingTop:"12px"},{ className : "contenttext"},[]),
		newnode("td",{ width: "25px", paddingTop:"12px" , lineHeight : "0px"},{},[
			newnode("img",{},{ src: "img/dummy.gif" },[]),
			newnode("img",{ display:"none" },{ src: "img/menu/attachment_open.gif" },[])
		]),
		newnode("td",{ width: "25px", paddingTop:"12px" , lineHeight : "0px"},{},[
			newnode("img",{},{ src: "img/dummy.gif" },[]),
			newnode("img",{ display:"none" },{ src: "img/menu/attachment_save.gif" },[])
		])
	]);
	var attachmentsecond=
	newnode("tr",{},{},[
		newnode("td",{ width: "25px"},{},[
			newnode("img",{},{ src: "img/dummy.gif" },[])
		]),
		newnode("td",{},{ className : "contenttext"},[]),
		newnode("td",{ width: "25px"},{},[]),
		newnode("td",{ width: "25px"},{},[])
	]);
	var attachmentmain=AppointmentHover.references["core_attachments_template"].cloneNode(true);
	var attachbody=attachmentmain.getElementsByTagName("tbody")[0];
	if(!(AppointmentHover.actualcalendarobject.number_of_attachments>0)) {
		var tmp=newnode("tr",{},{},[
			newnode("td",{ width: "25px"},{},[
				newnode("img",{},{ src: "img/dummy.gif" },[])
			]),
			newnode("td",{},{ colspan : 4 , className : "contenttext" },[
				document.createTextNode(_("No attachments available"))
			])		
		]);
		attachbody.appendChild(tmp);
	} else {
		(new JSON()).get(AjaxRoot + "/attachment?action=all&session=" + session + "&folder=" + AppointmentHover.actualcalendarobject.folder_id +
			"&attached=" + AppointmentHover.actualcalendarobject.id + "&module=1&columns=1,801,802,803,804,805,806&sort=803&order=asc",null,
			function(attachments) {
				function getShortByteString(int1,onlybytes) {
					int1=parseInt(int1);
					if((parseInt(int1/(1024))<1) || onlybytes) { return int1+" bytes"; } 
					else if(parseInt(int1/(1024*1024))<1) {
						var comma= Math.round((int1 % (1024)) / 102.4) ;
						if(comma) { return parseInt(int1/(1024))+","+comma+ "Kb" }
						else { return parseInt(int1/(1024)) }
					} else if(parseInt(int1/(1024*1024*1024))<1) {
						var comma= Math.round((int1 % (1024*1024)) / 102.4) ;
						if(comma) { return parseInt(int1/(1024*1024))+","+comma+ "Mb" }
						else { return parseInt(int1/(1024*1024)) }
					}
					else if(parseInt(int1/(1024*1024*1024*1024))<1) {
						var comma= Math.round((int1 % (1024*1024*1024)) / 102.4) ;
						if(comma) { return parseInt(int1/(1024*1024*1024))+","+comma+ "Gb" }
						else { return parseInt(int1/(1024*1024*1024)) }
					} else {
						return parseInt(int1/(1024*1024*1024)) + "Gb";
					}	
				}
				attachments=attachments.data;
				for(var i=0;i<attachments.length;i++) {
					var node=attachmentfirst.cloneNode(true);
					var node2=attachmentsecond.cloneNode(true);
					var attachmentid=attachments[i][0];
					var image=getMimeImage(attachments[i][5]);
					var imagetitle=attachments[i][5];
					var bytesize=attachments[i][4];
					var attachmentname=attachments[i][3];
					var imagertf=attachments[i][6]
					node.getElementsByTagName("img")[0].src=image; 
					node.getElementsByTagName("img")[0].title=imagetitle;
					if(!imagertf) {
						node.getElementsByTagName("td")[1].appendChild(document.createTextNode(attachmentname));
						node.getElementsByTagName("img")[1].style.display="none";
						node.getElementsByTagName("img")[2].style.display="";
						node.getElementsByTagName("img")[2].title=_("Open attachment"); /*stringfuckel*/
						addDOMEvent(node.getElementsByTagName("img")[2],"click",AppointmentHover.openAttachedFile(AppointmentHover.actualcalendarobject.folder_id,AppointmentHover.actualcalendarobject.id,attachmentname,imagertf,attachmentid));
						node.getElementsByTagName("img")[3].style.display="none";
						addDOMEvent(node.getElementsByTagName("img")[4],"click",AppointmentHover.saveAttachedFile(AppointmentHover.actualcalendarobject.folder_id,AppointmentHover.actualcalendarobject.id,attachmentname,imagertf,attachmentid));
						node.getElementsByTagName("img")[4].style.display="";
						node.getElementsByTagName("img")[4].title=_("Save attachment"); /*stringfuckel*/
					} else {	
						node.getElementsByTagName("td")[1].appendChild(document.createTextNode(attachmentname));
					}
					node2.getElementsByTagName("td")[1].appendChild(document.createTextNode(getShortByteString(bytesize)));
					node2.getElementsByTagName("td")[1].title=getShortByteString(bytesize,true);
					attachbody.appendChild(node);
					attachbody.appendChild(node2);
				}
				AppointmentHover.accordion.refill();
			}
		);
	}	
	AppointmentHover.accordion.addComponent("AppointmentAttachments",attachmentmain,false);
}
AppointmentHover.getParticipantsObject = function(participants,users) {
	var tmp_participants=new Array();
	var checked_confirm=new Object();
	for(var i=0;i<participants.length;i++) {
		if(participants[i].type!=5) {
			tmp_participants.push(participants[i]);
		}
	}
	for(var i=0;i<users.length;i++) {
		if(users[i].id) {
			checked_confirm[users[i].id]={ confirm : users[i].confirmation , message : users[i].confirmmessage };
		}
	}
	internalCache.getObjects(tmp_participants,function(data) {
		var tmp_node=newnode("tr",null,null,[
			newnode("td",{ width: "30px" },null,[
			]),
			newnode("td",{},{ className : "contenttextnocolor"},[])
		]);
				
		var tmp_users=new Array();
		var tmp_groups=new Array();
		var tmp_ressources=new Array();
		var tmp_external=new Array();
		for(var i=0;i<participants.length;i++) {
			switch(participants[i].type) {
				case 1:
					var tmpvalue=data[participants[i].id];
					tmpvalue.confirm=checked_confirm[tmpvalue.id].confirm || 0;
					tmpvalue.message=checked_confirm[tmpvalue.id].message || "";
					tmp_users.push(tmpvalue);
					break;	
				case 2:
					var tmpvalue=data[participants[i].id];
					tmp_groups.push(tmpvalue);
					break;
				case 3:
					var tmpvalue=data[participants[i].id];
					tmp_ressources.push(tmpvalue);
					break;
				case 5:
					tmp_external.push(participants[i]);
					break;
				
			}
		}
		var node=AppointmentHover.references["core_participants_users"].getElementsByTagName("tbody")[0];
		
	
		
		removeChildNodes(node);
		node.appendChild(
			newnode("tr",{ fontWeight: "bold"}, { className: "contenttext" },[
				newnode("td",{ paddingTop:"7px" },{colSpan : 2 }, [
					addTranslated('Participants') /*i18n*/
				]),
				newnode("td",{ width : "20px", paddingTop:"7px" },{ title : _("Change confirmation")}, [
					newnode("img",{},{ src : "img/menu/global_confirmation_change.gif"})
				])
			])		
		);
		AppointmentHover.confirmdialogshown=false;
		addDOMEvent(node.getElementsByTagName("td")[1],"click",function() {
			if(AppointmentHover.confirmdialogshown) {
				AppointmentHover.accordion.hideExtraContent("AppointmentConfirmDialog");
				AppointmentHover.confirmdialogshown=false;
			} else {
				AppointmentHover.accordion.showExtraContent("AppointmentConfirmDialog");
				AppointmentHover.confirmdialogshown=true;
			}
		});
		if(checked_confirm[configGetKey("identifier")]) {
			node.getElementsByTagName("td")[1].style.display="";
			var personalnode=$("template_calendar_participants_confirmdialog").cloneNode(true);
			AppointmentHover.references["AppointmentConfirmDialogInput"]=personalnode.getElementsByTagName("input")[0];
			personalnode.id="";
			AppointmentHover.references["AppointmentConfirmDialogInput"].value=checked_confirm[configGetKey("identifier")].message || "";
			AppointmentHover.accordion.addComponent("AppointmentConfirmDialog",personalnode,false);
		} else {
			node.getElementsByTagName("td")[1].style.display="none";
		}
		
		//USERS
		for(var i=0;i<tmp_users.length;i++) {
			var tmpn1=tmp_node.cloneNode(true);
			if(i==0) {
				tmpn1.getElementsByTagName("td")[0].style.paddingTop="10px";
				tmpn1.getElementsByTagName("td")[1].style.paddingTop="10px";
			}
			tmpn1.getElementsByTagName("td")[0].appendChild(newnode("img",null,{src: "img/calendar/user.gif"},[]))
			tmpn1.getElementsByTagName("td")[1].appendChild(document.createTextNode(tmp_users[i].display_name));
			switch(tmp_users[i].confirm) {
				case 1: 
					tmpn1.className="appointmentStatusAccepted";
					break;
				case 2: 
					tmpn1.className="appointmentStatusDeclined";
					break;
				case 3: 
					tmpn1.className="appointmentStatusTentative";
					break;
			}
			if(tmp_users[i].message) {
				tmpn1.title=tmp_users[i].message;
			}
			node.appendChild(tmpn1);
		}
		AppointmentHover.accordion.addComponent("AppointmentParticipantsUsers",AppointmentHover.references["core_participants_users"],false);
		AppointmentHover.references.allGroups=new Array();
		AppointmentHover.references.allGroupsParticipants=new Object();
		//GROUPS
		for(var i=0;i<tmp_groups.length;i++) {
			var accordionnode=AppointmentHover.references["core_participants_group_template"].cloneNode(true);
			var tmpn1=tmp_node.cloneNode(true);
			if(i==0) {
				tmpn1.getElementsByTagName("td")[0].style.paddingTop="10px";
				tmpn1.getElementsByTagName("td")[1].style.paddingTop="10px";
			}
			tmpn1.getElementsByTagName("td")[0].appendChild(newnode("img",null,{src: "img/calendar/group.gif"},[]))
			tmpn1.getElementsByTagName("td")[1].appendChild(document.createTextNode(tmp_groups[i].display_name));
			accordionnode.getElementsByTagName("tbody")[0].appendChild(tmpn1);
			AppointmentHover.accordion.addComponent("AppointmentParticipantsGroups"+i,accordionnode,false);
			AppointmentHover.references.allGroups.push("AppointmentParticipantsGroups"+i);
			
			if(tmp_groups[i].members && tmp_groups[i].members.length) {
				//MEMBERS IN GROUPS
				var accordionnode2=AppointmentHover.references["core_participants_groupparticipants_template"].cloneNode(true);
				AppointmentHover.accordion.addComponent("AppointmentParticipantsGroupUsers"+i+"members",accordionnode2,false);
				AppointmentHover.references.allGroupsParticipants["AppointmentParticipantsGroupUsers"+i+"members"]=new Object();
				AppointmentHover.references.allGroupsParticipants["AppointmentParticipantsGroupUsers"+i+"members"].active=false;
				internalCache.getUsers(tmp_groups[i].members,(function(mynode,mynode2,mynode2name) { return function(cb) { 
					addDOMEvent(mynode,"click",function() {
						if(AppointmentHover.references.allGroupsParticipants[mynode2name]) {
							if(AppointmentHover.references.allGroupsParticipants[mynode2name].active) {
								AppointmentHover.accordion.hideExtraContent(mynode2name);
								AppointmentHover.references.allGroupsParticipants[mynode2name].active=false;
							} else {
								AppointmentHover.accordion.showExtraContent(mynode2name);
								AppointmentHover.references.allGroupsParticipants[mynode2name].active=true;
							}
						}
					});
					var count=0;
					var tmpstring="";
					for(var i in cb) {
						if(count==0) {
							tmpstring+= cb[i].display_name;
							count++;
						} else {
							tmpstring+= " ; " +cb[i].display_name;
							count++;
						}
					}
					var node1=mynode2.getElementsByTagName("td")[1];
					removeChildNodes(node1);
					node1.appendChild(document.createTextNode(tmpstring));
				} })(accordionnode,accordionnode2,"AppointmentParticipantsGroupUsers"+i+"members"));
			}
		}
		if(tmp_ressources.length) {
			for(var i=0;i<tmp_ressources.length;i++) {
				var accordionnode=AppointmentHover.references["core_participants_group_template"].cloneNode(true);
				var tmpn1=tmp_node.cloneNode(true);
				if(i==0) {
					tmpn1.getElementsByTagName("td")[0].style.paddingTop="10px";
					tmpn1.getElementsByTagName("td")[1].style.paddingTop="10px";
				}
				tmpn1.getElementsByTagName("td")[0].appendChild(newnode("img",null,{src: "img/calendar/ressourcen.gif"},[]))
				tmpn1.getElementsByTagName("td")[1].appendChild(document.createTextNode(tmp_ressources[i].display_name));
				accordionnode.getElementsByTagName("tbody")[0].appendChild(tmpn1);
				AppointmentHover.accordion.addComponent("AppointmentParticipantsRessources"+i,accordionnode,false);
				AppointmentHover.references.allGroups.push("AppointmentParticipantsRessources"+i);		
			}
		}	
		if(tmp_external.length) {
			for(var i=0;i<tmp_external.length;i++) {
				var accordionnode=AppointmentHover.references["core_participants_group_template"].cloneNode(true);
				var tmpn1=tmp_node.cloneNode(true);
				if(i==0) {
					tmpn1.getElementsByTagName("td")[0].style.paddingTop="10px";
					tmpn1.getElementsByTagName("td")[1].style.paddingTop="10px";
				}
				tmpn1.getElementsByTagName("td")[0].appendChild(newnode("img",null,{src: "img/calendar/user_extern.gif"},[]))
				tmpn1.getElementsByTagName("td")[1].appendChild(document.createTextNode(tmp_external[i].display_name));
				accordionnode.getElementsByTagName("tbody")[0].appendChild(tmpn1);
				AppointmentHover.accordion.addComponent("AppointmentParticipantsExternal"+i,accordionnode,false);
				AppointmentHover.references.allGroups.push("AppointmentParticipantsExternal"+i);		
			}
		}	
		AppointmentHover.accordion.refill();
	});
}
AppointmentHover.accordion=null;
AppointmentHover.actualHover=null;
AppointmentHover.actualcalendarobject=null;
AppointmentHover.decline= function() {
	AppointmentHover.dialogRequest(2);
	AppointmentHover.hideDialog();
}
AppointmentHover.tentiative= function() {
	AppointmentHover.dialogRequest(3);
	AppointmentHover.hideDialog();
}
AppointmentHover.accept= function() {
	AppointmentHover.dialogRequest(1);
	AppointmentHover.hideDialog();
}	
AppointmentHover.dialogRequest = function(confirmstatus) {
	(new JSON).put(AjaxRoot + "/calendar?session="+session+"&action=confirm", 
		{ "confirmation": confirmstatus, "folder_id" : AppointmentHover.actualcalendarobject.folder_id, "id": AppointmentHover.actualcalendarobject.id, "confirmmessage": AppointmentHover.references["AppointmentConfirmDialogInput"].value  },
		null,
		function(reply) 
		{
			AppointmentHover.refillContent(AppointmentHover.actualcalendarobject.id,AppointmentHover.actualcalendarobject.folder_id,AppointmentHover.actualcalendarobject.recurrence_position); 
		});
}
AppointmentHover.hideDialog= function() {
	AppointmentHover.accordion.hideExtraContent("AppointmentConfirmDialog");
	AppointmentHover.confirmdialogshown=false;
}
AppointmentHover.getCalendarHover = function() {
	if(AppointmentHover.content) { 
		return AppointmentHover.content;
	}
	
	var element=createHoverContent();
	AppointmentHover.accordion=new Accordion(400,400);
	
	refillImages("template_calendar_hover_page1");
	refillImages("template_calendar_hover_page_content");
	refillImages("template_calendar_hover_page_content_full");
	refillImages("template_calendar_hover_attachments");
	refillImages("template_calendar_hover_links");
	var contentnode=$("template_calendar_hover_page1").cloneNode(true);
	$("template_calendar_hover_page1").parentNode.removeChild($("template_calendar_hover_page1"));
	contentnode.id="";
	AppointmentHover.references["core"]=contentnode;
	AppointmentHover.accordion.addComponent("AppointmentCore",contentnode,false);
	
	var contentnode=$("template_calendar_hover_page_content_full").cloneNode(true);
	$("template_calendar_hover_page_content_full").parentNode.removeChild($("template_calendar_hover_page_content_full"));
	contentnode.id="";
	AppointmentHover.references["core_content_full"]=contentnode;
	AppointmentHover.accordion.addComponent("AppointmentNoteFull",contentnode,false);
	
	var contentnode=$("template_calendar_hover_page_content").cloneNode(true);
	$("template_calendar_hover_page_content").parentNode.removeChild($("template_calendar_hover_page_content"));
	contentnode.id="";
	AppointmentHover.references["core_content"]=contentnode;
	AppointmentHover.accordion.addComponent("AppointmentNoteSmall",contentnode,false);
	
	var contentnode=$("template_calendar_hover_participants").cloneNode(true);
	$("template_calendar_hover_participants").parentNode.removeChild($("template_calendar_hover_participants"));
	
	contentnode.id="";
	AppointmentHover.references["core_participants_users"]=contentnode;
	AppointmentHover.references["core_participants_group_template"]=AppointmentHover.references["core_participants_users"].cloneNode(true);
	
	var contentnode=$("template_calendar_hover_groupparticipants").cloneNode(true);
	$("template_calendar_hover_groupparticipants").parentNode.removeChild($("template_calendar_hover_groupparticipants"));
	contentnode.id="";
	AppointmentHover.references["core_participants_groupparticipants_template"]=contentnode;
			
	var tmptds=AppointmentHover.references["core"].getElementsByTagName("td");
	AppointmentHover.references["title"]=tmptds[1];
	AppointmentHover.references["coreimg1"]=tmptds[2];
	AppointmentHover.references["coreimg2"]=tmptds[3];
	AppointmentHover.references["coreimg3"]=tmptds[4];
	AppointmentHover.references["location"]=tmptds[5];
	AppointmentHover.references["start_time"]=tmptds[7];
	AppointmentHover.references["end_time"]=tmptds[9];
	
	var tmptds=AppointmentHover.references["core_content"].getElementsByTagName("td");
	AppointmentHover.references["notesmall"]=tmptds[0];
	
	var tmptds=AppointmentHover.references["core_content_full"].getElementsByTagName("td");
	AppointmentHover.references["notefull"]=tmptds[0];
	
	var contentnode=$("template_calendar_hover_attachments").cloneNode(true);
	$("template_calendar_hover_attachments").parentNode.removeChild($("template_calendar_hover_attachments"));
	AppointmentHover.references["core_attachments_template"]=contentnode;
	
	var contentnode=$("template_calendar_hover_links").cloneNode(true);
	$("template_calendar_hover_links").parentNode.removeChild($("template_calendar_hover_links"));
	AppointmentHover.references["core_links_template"]=contentnode;
	
	
	
		
	var node=AppointmentHover.accordion.getDomNode();
	var d=newnode("div",{width:"30px" , flt : "right" , overflow:"hidden"},{},[]);
	AppointmentHover.slider=new Slider(4);
	var d1=AppointmentHover.slider.getDomNode();
	AppointmentHover.slider.setNodeFunctions(0,function() { AppointmentHover.accordion.showContent("AppointmentCore,AppointmentNoteSmall")});
	AppointmentHover.slider.setNodeFunctions(1,function() { 
		var tmpstring="AppointmentParticipantsUsers";
		for(var i=0;i<AppointmentHover.references.allGroups.length;i++) {
			tmpstring+=","+AppointmentHover.references.allGroups[i];
		}
		AppointmentHover.accordion.showContent(tmpstring);
	});
	AppointmentHover.slider.setNodeFunctions(2,function() { AppointmentHover.accordion.showContent("AppointmentAttachments,AppointmentLinks")});
	AppointmentHover.slider.setNodeFunctions(3,function() { AppointmentHover.accordion.showContent("8")});
	d.appendChild(d1);
	element.childNodes[1].childNodes[0].childNodes[0].appendChild(d);
	element.childNodes[1].childNodes[0].childNodes[0].appendChild(node);
	element.style.display="none";
	body.appendChild(element);
	AppointmentHover.content=element;
	AppointmentHover.slider.nodeClicked(0);
	return element;
}
AppointmentHover.refillContent = function(id,folder,recurrence_position) {
	function fillContent(type,value,titletext,clear,show) {
		if(clear) { removeChildNodes(AppointmentHover.references[type]); }
		if(value) { AppointmentHover.references[type].appendChild(value); }
		if(titletext) { AppointmentHover.references[type].title=titletext; }
		if(show) { AppointmentHover.references[type].style.display=""; }
	}
	function fillText(type,text,titletext,clear) {
		if(clear) { removeChildNodes(AppointmentHover.references[type]); }
		if(text) { AppointmentHover.references[type].appendChild(document.createTextNode(text)); }
		if(titletext) { AppointmentHover.references[type].title=titletext; }
	}
	var reqstr=AjaxRoot + "/calendar?action=get&session=" + session +"&id="+ id + "&folder="+folder;
	if(recurrence_position) { reqstr+="&recurrence_position="+recurrence_position; }
	(new JSON()).get(reqstr,null,function(object) {
		
		object=object.data;
		AppointmentHover.actualcalendarobject=object;
		//TITLE
		fillText("title",object.title ? object.title : "",object.title ? object.title : "",true);
		var count=0;
		//PRIVATE FLAG OR GROUP APPOINTMENT
		if(object.private_flag) {
			fillContent("coreimg"+(count+1),newnode("img",{},{ src: "img/private_flag.gif"},[]),_("Private appointment"),true,true);
			count++;
		} else if(object.participants.length>1) {
			fillContent("coreimg"+(count+1),newnode("img",{},{ src: "img/calendar/group.gif"},[]),_("Group appointment"),true,true);
			count++;
		}
		//RECURRENCE APPOINTMENT
		if(object.recurrence_type && object.recurrence_type != 0) {
			fillContent("coreimg"+(count+1),newnode("img",{},{ src: "img/serientermin.gif"},[]),_("Series appointment"),true,true);
			count++;
		}
		//FLAGS
		if(object.color_label && object.color_label!=0) {
			fillContent("coreimg"+(count+1),newnode("img",{},{ src: "img/menu/tag_"+object["color_label"]+".gif"},[]),null,true,true);
			count++;
		}
		for(;count<3;count++) {
			AppointmentHover.references["coreimg"+(count+1)].style.display="none";
		}
		//LOCATION
		fillText("location",object.location ? object.location : "",object.location ? object.location : "",true);
		var startdate=new Date(object.start_date);
		var enddate=new Date(object.end_date);
		//DATE AND TIME
		if(object.full_time) {
			enddate.setUTCDate(enddate.getUTCDate()-1);
			fillText("start_time", formatDate(startdate,"date"),formatDate(startdate,"date"),true);
			fillText("end_time", formatDate(enddate,"date"),formatDate(enddate,"date"),true);
		} else {
			fillText("start_time", formatDate(startdate,"datetime"),formatDate(startdate,"datetime"),true);
			fillText("end_time", formatDate(enddate,"datetime"),formatDate(enddate,"datetime"),true);
		}
		//NOTE
		if(!object.note) { object.note="" }
		var maxcount=140;
		if(object.note.length>maxcount) {
			fillText("notesmall", object.note.substring(0,maxcount)+"...",null,true);
			fillText("notefull", object.note,null,true);
		} else {
			fillText("notesmall", object.note,null,true);
			fillText("notefull", object.note,null,true);
		}
		//PARTICIPANTS
		if(object.participants) {
			AppointmentHover.getParticipantsObject(object.participants,object.users);
		}
		AppointmentHover.fillAttachments();
		AppointmentHover.fillLinks();
		AppointmentHover.slider.nodeClicked(0);
		AppointmentHover.accordion.refill();
	}); 
}