/*
 * author: vhhsw01 (06.2011):
 * Constructor des Sidebox Objektes
 *
 * id ... ist die id mit der as HTML Mutterelement der Box in dei seite eingefügt wird.
 *        Achtung auch die instanzvariable in muss genauso benannt werden.
 * titel ... Titel in der Box der oben im blauen Bereich angezeigt wird
 * zindex ... der Z-Index des divs der aufgeklappt wird
 * contentFixed ... der Inhalt der Box immer fix sichtbar 
 * contentHidden ... der Inhaklt der in dem Aufklappbaren Bereich angezeigt wird
 *
 */
function sidebox(id, title, zindex, contentFixed, contentHidden) {
	//
	// properties die über constructir gesetzt werden können
	//
	this.id = id;
	this.title = title;
	this.zindex = zindex;
	this.contentFixed = contentFixed;
	this.contentHidden = contentHidden;
	
	//
	// sonstige properies
	//
	this.opened = 0;
	this.isDisplayed = 0;  // wird gesetzt wenn erstmalig die methode display aufgerufen wird
	
	//
	// methods
	//
	this.display = displayBox;
	this.switchView = switchTheBoxView;
	
}

function displayBox(doc) {
	
	var displayValue = "";
	if (this.opened == 1) {
		displayValue = "block";
	} else {
		displayValue = "none";
	}
	
	
	// Anzeige HTML code einfügen
	if (this.isDisplayed == 0 ) {
		doc.getElementById('right').innerHTML = doc.getElementById('right').innerHTML + "<div id='" + this.id + " style='width:230px; position:absolute; z-index:" + this.zindex + ";'>" + 
		" <div id='" + this.id + "_boxpart_fixed' style='width:230px; border:1px solid #999999; background-color:#ffffff;'>" +
			"<h4 style='background: none repeat scroll 0 0 #005EA8; color: #FFFFFF;  font-size: 100%;  font-weight: normal;  margin: 1px;  padding: 3px 0;   text-align: center;'>" + this.title + "</h4>" +
			"<div style='padding:10px 10px 5px; width:210px; background-color:#FFF; color:#4A4A4A; font-size:80%;'>" + this.contentFixed + " </div>" +
			"<div id='" + this.id + "_boxpart_hidden' class='boxes' style='width:210px; padding:0px 10px 5px; margin-left:-1px ;border-left:1px solid #999999; border-right:1px solid #999999; background-color:#FFF; color:#4A4A4A; font-size:80%; display:" + displayValue + "; position:absolute; z-index:9999;'>" + this.contentHidden + " " +
			"   <div style='height:23px; width:230px; position:relative; top:7px; left:-11; border-left:1px solid #999999; border-bottom:1px solid #999999; border-right:1px solid #999999;'><img style='" + displayValue + "' src='http://uniqa.gentics.com/Content.Node/images/global/plus_open.gif' id='" + this.id + "_switcherimg' alt='open' width='230' height='23' border='0' class='box_head' onClick='sideboxHandler.switchView(\"" + this.id + "\");'/></div>" +
			"</div>" +
			"<div style='height:23px; width:230px; position:relative; left:-1px; top:1px; border-left:1px solid #999999; border-bottom:1px solid #999999; border-right:1px solid #999999;'><img src='http://uniqa.gentics.com/Content.Node/images/global/plus_close.gif' id='" + this.id + "_switcherimg' alt='open' width='230' height='23' border='0' class='box_head' onClick='sideboxHandler.switchView(\"" + this.id + "\");'/></div>" +
		"</div><br/>";
	
		this.isDisplayed = 1;
	}
	
	
}

function switchTheBoxView() {

	var hiddenBoxPart = document.getElementById(this.id + "_boxpart_hidden");

	if (this.opened == 1) {
		hiddenBoxPart.style.display = "none";
		//switcherImg.src = "http://uniqa.gentics.com/Content.Node/images/global/plus_close.gif";
		this.opened  = 0;
	} else {
		hiddenBoxPart.style.display = "block";
		//switcherImg.src = "http://uniqa.gentics.com/Content.Node/images/global/plus_open.gif";
		this.opened  = 1;
	}
	
}

/*
 * Sidebox handler verwaltet alle Sidebioxebn auf einer seite,
 * kümmert sich um den Z-Index und eindeutige Id's
 *
 */
function sideboxHandler(startZIndex) {

	//
	// Properties die via constructor mitgegeben werden können
	//
	this.startZIndex = startZIndex
	
	//
	// sonstige Properties
	//
	this.currZIndex = startZIndex;
	this.idCounter = 0;
	this.boxesMap = new Object();
	
	//
	// methods
	//
	this.createNewSidebox = createNewSidebox;
	this.displayBox = displaySideBox;
	this.switchView = switchSideBoxView;
}

function createNewSidebox() {

	this.idCounter++;
	var nextId = "box_" + this.idCounter;
	this.currZIndex++;
	var newSidebox = new sidebox(nextId, 'title not set', this.currZIndex, 'fixed content not set', 'hidden content not set');
	this.boxesMap[nextId] = newSidebox;
	
	return newSidebox;
	
}

function displaySideBox(doc, boxId) {

	if (this.boxesMap[boxId] != 'undefined') {
		this.boxesMap[boxId].display(doc);
	}
}

function switchSideBoxView(boxId) {

	if (this.boxesMap[boxId] != 'undefined') {
		this.boxesMap[boxId].switchView();
	}
}
