// oeffnet Popup wird für popup-Modul benötigt
function openPopup(URL,popname,W,H,scroll,rezisable,X,Y) {
	var properties = getPopupProperties(W,H,scroll,rezisable,X,Y);
	popwin=window.open(URL,popname,properties);
	popwin.focus();
}

// liefert eigenschaften fuer popup fenster
function getPopupProperties(W,H,scroll,rezisable,X,Y) {
	var W,H,scroll,rezisable,X,Y;
	if (!W) { W=520; }
	if (!H) { H=460; }
	if (!scroll) { scroll=0; }
	if (!rezisable) { rezisable=0; }
	if (!X) { X=screen.width/2-(W/2); }
	if (!Y) { Y=screen.height/2-(H/2)-20; }
	var properties = "toolbar=no,location=no,directories=no,status=no,menubar=no,scrollbars="+scroll+",resizable="+rezisable+",";
	properties += "width="+W+",height="+H+",left="+X+",top="+Y;
	return properties;
}


function MM_findObj(n, d) { //v4.01
  var p,i,x;  if(!d) d=document; if((p=n.indexOf("?"))>0&&parent.frames.length) {
    d=parent.frames[n.substring(p+1)].document; n=n.substring(0,p);}
  if(!(x=d[n])&&d.all) x=d.all[n]; for (i=0;!x&&i<d.forms.length;i++) x=d.forms[i][n];
  for(i=0;!x&&d.layers&&i<d.layers.length;i++) x=MM_findObj(n,d.layers[i].document);
  if(!x && d.getElementById) x=d.getElementById(n); return x;
}


function MM_changeProp(objName,x,theProp,theValue) { //v6.0
  var obj = MM_findObj(objName);
  if (obj && (theProp.indexOf("style.")==-1 || obj.style)){
    if (theValue == true || theValue == false)
      eval("obj."+theProp+"="+theValue);
    else eval("obj."+theProp+"='"+theValue+"'");
  }
}


/**
 * Hides an div element while setting display style to none
 * 
 * @param  string  setDiv ID (attribute) of element to hide
 */
function hideLayer (setDiv) {
	MM_changeProp(setDiv,'','style.display','none','DIV');
}


/**
 * Shows an div element while setting display style to block
 * 
 * @param  string  setDiv ID (attribute) of element to show
 */
function showLayer (setDiv) {
	MM_changeProp(setDiv,'','style.display','block','DIV');
}


/**
 * Opens recommend article popup window.
 * 
 * @param  string  url  URL to popup window
 */
function recommendArticle(url) {
	var properties = getPopupProperties(486, 610);
	var win = window.open(url, 'cecRecommmend', properties);
	win.focus();
}

/**
 * Opens popup window for zoom images.
 * 
 * @param  string  url  URL to popup window
 */
function openImagePopup(url) {
	var properties = getPopupProperties(445, 410);
	var win = window.open(url, 'cecImagePopup', properties);
	win.focus();
}

/**
 * Opens popup window for video player.
 * 
 * @param  string  url  URL to popup window
 */
function openVideoPopup(url) {
	var properties = getPopupProperties(360, 420);
	var win = window.open(url, 'cecVideoPopup', properties);
	win.focus();
}


/**
 * Toggles desired comment. Ids of commentitem boxes are composed like:
 * - cdatetime-<articleid>-<commentid>
 * - csubject-<articleid>-<commentid>
 * 
 * @param int  articleid  Article id
 * @param int commentid   Id of comment to toggle
 */
function toggleComment(articleid, commentid) {
	// cdatetime-34-1, csubject-34-1, ctext-34-1
	var idDatetime = "cdatetime-"+articleid+"-"+commentid;
	var idSubject  = "csubject-"+articleid+"-"+commentid;
	var idText     = "ctext-"+articleid+"-"+commentid;
	
	if (Element.hasClassName(idDatetime, 'close')) {
		Element.removeClassName(idDatetime, 'close');
		new Effect.BlindUp(idText);
		$(idDatetime).title = "Kommentar aufklappen";
		$(idSubject).title  = "Kommentar aufklappen";
	} else {
		Element.addClassName(idDatetime, 'close');
		new Effect.BlindDown(idText);
		$(idDatetime).title = "Kommentar zuklappen";
		$(idSubject).title  = "Kommentar zuklappen";
	}
}


/**
 * Toggles further comments container.
 * 
 * @param int  articleid  Article id
 */
function toggleFurtherComments(articleid) {
	// cfurtheranchor-34, further-comments-34
	var idAnchor   = "cfurtheranchor-"+articleid;
	var idComments = "further-comments-"+articleid;
	
	if (Element.hasClassName(idAnchor, 'close')) {
		Element.removeClassName(idAnchor, 'close');
		Element.hide(idComments);
		$(idAnchor).title = "Weitere Kommentare aufklappen";
	} else {
		Element.addClassName(idAnchor, 'close');
		Element.show(idComments);
		$(idAnchor).title = "Weitere Kommentare zuklappen";
	}
}


/**
 * Sets state of processing message box. Commentbox container id is composed like:
 * csendstate-<articleid>
 * 
 * @param  int     articleid  Id of article
 * @param  string  msg        The mesasge to set
 */
function setCommentSendState(articleid, msg){
	//csendstate
	var elemid = "csendstate-"+articleid;
	
	$(elemid).innerHTML = msg;
	Element.setStyle(elemid, { display: 'block' });
}

/**
 * Sets state of processing message box.
 * 
 * @param  int     id   Element id (attribute)
 * @param  string  msg  The mesasge to set
 */
function displayMessage(id, msg){
	try {
		$(id).innerHTML = msg;
		Element.setStyle(id, { display: 'block' });
	} catch (e) { /* donut */ }
}



// #################################################################################################

/**
 * just for namespacing (capital estate compass)
 */
var cec = new Object();


/**
 * Simple Debug class. Uses a element (id="ew72debug") to display debug messages.
 * 
 * Usage:
 * <code>
 * debug = new cec.Debug();
 * debug .add('browser', navigator.userAgent);
 * debug .add('app version', navigator.appVersion);
 * debug.reset(); // reset content of debug container
 * </code>
 */
cec.Debug = function(containerid) {
    this.bDebug = true;
	this.container = "debugcontainer";
    if (typeof(containerid) !== "undefined") {
		this.container = containerid;
	}
	if (!$(this.container)) {
        this.bDebug = false;
    }
    this.lf = "<br />";
}
cec.Debug.prototype.add = function (msg, val) {
    if (!this.bDebug) { return; }
    $(this.container).innerHTML += msg + ": " + this._clearValue(val) + this.lf;
}
cec.Debug.prototype.reset = function () {
    if (!this.bDebug) { return; }
    $(this.container).innerHTML = "";
}
cec.Debug.prototype._clearValue = function (val) {
    if (typeof(val) == "string") {
        val = val.replace(/\</g, "&lt;");
        val = val.replace(/\>/g, "&gt;");
    }
    return val;
}


/**
 * Simple storage container class. 
 * 
 * Usage:
 * <code>
 * register = new cec.Register();
 * register.set('browser', 'msie');
 * var text = register .get('browser');
 * register.remove('browser');
 * </code>
 */
cec.Register = function() {
	this.container = new Array();
}
cec.Register.prototype.set = function(key, value) {
	this.container[key] = value;
}
cec.Register.prototype.get = function(key) {
	if (typeof(this.container[key]) !== "undefined") {
		return this.container[key];
	} else {
		return null;
	}
}
cec.Register.prototype.remove = function(key) {
	this.set(key, null);
}


/**
 * Class to handle tabbed navigation items and activation/deactivation of proper data container.
 * 
 * Usage:
 * <code>
 * // create a instance using id of element ("tabbed-nav-location") including the tabbed 
 * // navigation list and the active list item anchor ("tabbed-nav-location-1").
 * // see source of immobilienkompass for more details
 * oLocNav = new cec.TabbedNav("tabbed-nav-location", "tabbed-nav-location-1");
 * </code>
 */
cec.TabbedNav = function(navid, activeItem) {
	this.bInit = false;
	this.navId = navid;
	this.activeItem = activeItem;
	if ($(this.navId) && $(this.activeItem)) {
		this.bInit = true;
	}
    this.anchors = $(this.navId).getElementsByTagName("a");
	if (!this.anchors) {
		this.bInit = false;
	}
}
cec.TabbedNav.prototype.show = function (item) {
	// some checks
	if (this.bInit == false) {
		return;
	} else if (this.activeItem == item.id) {
		return;
	} else if (!$(item.id)) {
		return;
	}
	
	try	{

		var posCurrent       = this._getPos(item.id);
		var posBeforeCurrent = posCurrent-1;

		// remove classname "current" from actual item
		Element.removeClassName(this.activeItem, "current");
		
		for (var i=0; i < this.anchors.length; i++) {
			var anchorItem = this.anchors[i];
			
			// add classname to selected item
			if (anchorItem.id == item.id) {
				Element.addClassName(anchorItem.id, "current");
			}

			// remove any existing old classname "before-current"
			if (Element.hasClassName(anchorItem.id, "before-current")) {
				Element.removeClassName(anchorItem.id, "before-current");
			}

			// add new classname "before-current" to prior item
			if (posBeforeCurrent == i+1) {
				Element.addClassName(anchorItem.id, "before-current");
			}
		}
		
		$(item.id).blur();

		var dataContainerOld = this._getDataContainerId(
			this._getPos(this.activeItem)
		);
		var dataContainerNew = this._getDataContainerId(posCurrent);
		
		Element.show(dataContainerNew);
		Element.hide(dataContainerOld);

		this.activeItem = item.id;
		
	} catch (e) { }
}
cec.TabbedNav.prototype._getPos = function (itemId) {
	var arr = itemId.split("-");
	return arr[arr.length-1];
}
cec.TabbedNav.prototype._getDataContainerId = function (pos) {
	return this.navId + "-" + pos + "-data";
}


// #################################################################################################


/**
 * Class which provides loading of an flash file depending on installed flash version
 */
cec.FlashPlayer = function(){
	this.dom = (document.getElementById) ? true : false;
	if (!this.dom) {
		return;
	}
	
	this.playerPath = "/video/player/";
	
	//required flash version : reqMajorVer, reqMinorVer, reqRevision (7,0,14)
	this.reqMajorVer = 7;
	this.reqMinorVer = 0;
	this.reqRevision = 14;
	
	this.requirementsOk = false;
}
cec.FlashPlayer.prototype.initSwfVersionScript = function () {
	if (!this.dom) {
		return;
	} else if ($("swfversionscript")) {
		return;
	}
	var isIE    = (navigator.appVersion.indexOf("MSIE") != -1) ? true : false;
	var isWin   = (navigator.appVersion.toLowerCase().indexOf("win") != -1) ? true : false;
	var isOpera = (navigator.userAgent.indexOf("Opera") != -1) ? true : false;
	if (isIE && isWin && !isOpera) {
		document.write('<scr'+'ipt id="swfversionscript" type="text/vbscript">\n');
		document.write('Function cecWhichFlash(i)\n');
		document.write('on error resume next\n');
		document.write('Dim swControl, swVersion\n');
		document.write('swVersion = 0\n');
		document.write('set swControl = CreateObject("ShockwaveFlash.ShockwaveFlash." + CStr(i))\n');
		document.write('if (IsObject(swControl)) then\n');
		document.write('swVersion = swControl.GetVariable("$version")\n');
		document.write('end if\n');
		document.write('cecWhichFlash = swVersion\n');
		document.write('End Function\n');
		document.write('<\/scr'+'ipt>\n');
		document.write('\n');
	} else {
		document.write('<scr'+'ipt id="swfversionscript" type="text/javascript">\n');
		document.write('function cecWhichFlash(i)\n');
		document.write('{\n');
		document.write('if (navigator.plugins != null && navigator.plugins.length > 0) {\n');
		document.write('if (navigator.plugins["Shockwave Flash 2.0"] || navigator.plugins["Shockwave Flash"]) {\n');
		document.write('var swVer2 = navigator.plugins["Shockwave Flash 2.0"] ? " 2.0" : "";\n');
		document.write('var flashDescription = navigator.plugins["Shockwave Flash" + swVer2].description;\n');
		document.write('descArray = flashDescription.split(" ");\n');
		document.write('tempArrayMajor = descArray[2].split(".");\n');
		document.write('versionMajor = tempArrayMajor[0];\n');
		document.write('versionMinor = tempArrayMajor[1];\n');
		document.write('if ( descArray[3] != "" ) {tempArrayMinor = descArray[3].split("r");} else {tempArrayMinor = descArray[4].split("r");}\n');
		document.write('versionRevision=tempArrayMinor[1] > 0 ? tempArrayMinor[1] : 0;\n');
		document.write('// variable flashVer zusammensetzen -> analog zu ie\n');
		document.write('flashVer="x " + versionMajor + "," + versionMinor + "," + versionRevision;\n');
		document.write('}else{flashVer=-1;}\n');
		document.write('}\n');
		document.write('// MSN/WebTV 2.6 supports Flash 4\n');
		document.write('else if (navigator.userAgent.toLowerCase().indexOf("webtv/2.6") != -1) flashVer = 4;\n');
		document.write('// WebTV 2.5 supports Flash 3\n');
		document.write('else if (navigator.userAgent.toLowerCase().indexOf("webtv/2.5") != -1) flashVer = 3;\n');
		document.write('// older WebTV supports Flash 2\n');
		document.write('else if (navigator.userAgent.toLowerCase().indexOf("webtv") != -1) flashVer = 2;\n');
		document.write('// Can\'t detect in all other cases\n');
		document.write('else {flashVer = -1;}\n');
		document.write('return flashVer;\n');
		document.write('}\n');
		document.write('<\/scr'+'ipt>\n');
		document.write('\n');
	}
	
	this.requirementsOk = this._detectRequiredVersion(
		this.reqMajorVer, this.reqMinorVer, this.reqRevision
	);
	
}
cec.FlashPlayer.prototype._detectRequiredVersion = function (reqMajorVer, reqMinorVer, reqRevision) {
	if (!this.dom) {
		return;
	}

	var reqVer = parseFloat(reqMajorVer + "." + reqRevision);
	// loop backwards through the versions until we find the newest version
	for (var i=25; i>0; i--) {
		versionStr = cecWhichFlash(i);
		if (versionStr == -1 ) {
			return false;
		} else if (versionStr != 0) {
			var versionArray = new Array();
			var tempArray   = versionStr.split(" ");
			var tempString  = tempArray[1];
			versionArray    = tempString .split(",");
			var versionMajor    = versionArray[0];
			var versionMinor    = versionArray[1];
			var versionRevision = versionArray[2];
			var versionString   = versionMajor + "." + versionRevision;   // 7.0r24 == 7.24
			var versionNum      = parseFloat(versionString);
			// is the major.revision >= requested major.revision AND the minor version >= requested minor
			if ( (versionMajor > reqMajorVer) && (versionNum >= reqVer) ) {
				return true;
			} else {
				return ((versionNum >= reqVer && versionMinor >= reqMinorVer) ? true : false );
			}
		}
	}
}
cec.FlashPlayer.prototype.loadVideo = function (videoid, flashvars, width, height, playertype) {
	if (!this.dom) {
		return;
	}
	if (this.requirementsOk == true) {
		var player = this.playerPath + playertype + ".swf"
		$("video_swf_"+videoid).innerHTML = '<div style="'+width+'"><object classid="clsid:d27cdb6e-ae6d-11cf-96b8-444553540000" codebase="http://fpdownload.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=8,0,0,0" width="' + width + '" height="' + height + '" id="cec-video" align="middle">\n<param name="allowScriptAccess" value="sameDomain" />\n<param name="FlashVars" value="' + flashvars + '" />\n<param name="movie" value="'+player+'" />\n<param name="quality" value="high" />\n<param name="bgcolor" value="#ffffff" />\n<embed src="'+player+'" quality="high" bgcolor="#ffffff" width="' + width + '" height="' + height + '" name="cec-video" align="middle" FlashVars="' + flashvars + '" allowScriptAccess="sameDomain" type="application/x-shockwave-flash" pluginspage="http://www.macromedia.com/go/getflashplayer" />\n</embed>\n</object>\n</div>';
	} else {
		$("video_swf_"+videoid).innerHTML = '<div style="width:100%;height:152px;background-color:#f0f0f0;font-size:9px;font-family:verdana;">\nDer benötigte Flash Player ' + this.reqMajorVer + ' wurde nicht gefunden.<br />\nMögliche Ursachen:<br /><br />\nJavaScript erkennt den Player nicht korrekt.<br />\n<br /><br />\nDer Player ist nicht vorhanden.<br />\n<a href="http://www.macromedia.com/go/getflash/" target="_blank">Jetzt installieren<\/a>\n<\/div>';
		$("video_swf_"+videoid).style.zIndex=3;
	}
}
cec.FlashPlayer.prototype.loadMiniVideo = function (videoid, flvfile) {
	/*
	 * Details about used flash player:
	 * http://www.jeroenwijering.com/?item=JW_Media_Player
	 */
	var width  = 145;
	var height = 129;
	var flashvars = "file="+flvfile+"&width="+width+"&height="+height+"&autostart=true&usefullscreen=false";
	this.loadVideo(videoid, flashvars, width, height, "flvplayer");
}


// #################################################################################################


/**
 * Class for handling loading of galleries and display of gallery images
 */
cec.Gallery = function(instanceName) {
	this.ajaxurl       = "./ajax.php";
	this.visibleImages = 4;
	this.thumbwidth    = 95; // 73 image width + 6 border + 16 margin
	this.sliderstep    = 0;
	this.gallerynr     = null;
	this.actimagepos   = null;
	this.countimages   = null;
	this.imageslist    = null;
	oCecRegister.set("galleryinstance", instanceName);
	
	// see http://www.dithered.com/javascript/browser_detect/index.html
	var ua = navigator.userAgent.toLowerCase();
	this.isOpera = (ua.indexOf('opera') != -1);
	this.isIE    = (ua.indexOf('msie') != -1 && !this.isOpera && (ua.indexOf('webtv') == -1));
	this.isIE6up = (this.isIE && ua.indexOf("msie 4")==-1 && ua.indexOf("msie 5")==-1 && ua.indexOf("msie 6")==-1);
}
cec.Gallery.prototype.load = function (gallerynr, imagepos) {
	
	if (gallerynr == this.gallerynr) {
		this.loadImage(imagepos);
		return;
	}
	
	this.gallerynr   = gallerynr;
	this.actimagepos = imagepos;

	new Ajax.Request(this.ajaxurl, {
		method:'get',
		parameters: {action: 'estategallery', gallerynr: gallerynr, imagepos: imagepos },
		onSuccess: function(transport){
			var response  = transport.responseText;
			if (response.substr(0,1) !== "{") {
				// no valid json response
				oCecDebug.add('gallery.response', response);
			}
			
			try {

				var json = eval('(' + response + ')');

				// access to self using window object and stored instance name
				var selfName = oCecRegister.get("galleryinstance");
				var gallerynr = window[selfName].gallerynr;
				var imagepos  = window[selfName].actimagepos;

				//## oCecDebug.add('galleryimg.src', json.image_src);
				//## oCecDebug.add('galleryimg.title', json.image_title);
				window[selfName].countimages = json.count_images;
				$("galleryimg").src = json.image_src;
				$("galleryimg").title = json.image_title;
				$("boxgalleryimgslider").innerHTML = json.gallery_list;
				$("boxgalleryimgsdescr").innerHTML = json.gallery_descr;
				
				// reread new list
				window[selfName].readList();
				
			} catch(e) {
				// error handling
			}
		},
		onFailure: function(){
			alert('Something went wrong...')
		}
	}); 
}
cec.Gallery.prototype._setSliderState = function () {
	try {
		for (var i=0; i < this.imageslist.length; i++) {
			var imageItem = this.imageslist[i];
			var pos = i+1;
			
			if (pos == this.actimagepos) {
				// add classname to selected item
				Element.addClassName(imageItem.id, "active");
			} else if (Element.hasClassName(imageItem.id, "active")) {
				// remove classname from previous selected item
				Element.removeClassName(imageItem.id, "active");
			}
		}
	} catch (e) { }
}

cec.Gallery.prototype.readList = function () {
	var list = $("galleryslider").getElementsByTagName("img");
	if (!list) {
		return;
	}
	this.imageslist = list;
}
cec.Gallery.prototype.loadImage = function (imagepos) {
	if (imagepos > this.countimages || imagepos == 0) {
		return;
	} else if (oCecRegister.get("lock_slider_action") == true) {
		return;
	}

	var visiblePos = this.visibleImages + this.sliderstep;

//##	oCecDebug.add('imagepos', imagepos);
//##	oCecDebug.add('visiblePos', visiblePos);
	
	if (imagepos > visiblePos) {

		this.sliderstep++;

		oCecRegister.set("lock_slider_action", true);
		
		// move effect won't work on ie < 7...
		if (this.isIE && this.isIE6up == false) {
			var newAbsPos = this.sliderstep * this.thumbwidth;

			Element.setStyle("galleryslider", { position:"absolute", top:"0px", left: -newAbsPos+"px"} );
			oCecRegister.remove("lock_slider_action");
		} else {
			new Effect.Move ("galleryslider", { 
				x:           -this.thumbwidth, 
				y:           0, 
				mode:        'relative', 
				afterFinish: function(){ oCecRegister.remove("lock_slider_action"); }}
			);
		}

		
	} else if (imagepos <= this.sliderstep) {

		this.sliderstep--;
		oCecRegister.set("lock_slider_action", true);

		// move effect won't work on ie < 7...
		if (this.isIE && this.isIE6up == false) {
			var newAbsPos = (this.sliderstep) * this.thumbwidth;
			Element.setStyle("galleryslider", { position:"absolute", top:"0px", left: -newAbsPos+"px"} );
			oCecRegister.remove("lock_slider_action");
		} else {
			new Effect.Move ("galleryslider", { 
				x:           this.thumbwidth, 
				y:           0, 
				mode:        'relative', 
				afterFinish: function(){ oCecRegister.remove("lock_slider_action"); }}
			);
		}
	}
	
	// path = /images/immokompass/bauen_galerie/bauen_galerie_1_1_thumb.jpg
	// var imgSrc = $("gallerysliderthumb-"+this.gallerynr+"-"+imagepos).src.replace("_thumb.", ".");
	// var imgSrc = $("gallerysliderthumb-"+this.gallerynr+"-"+imagepos).src.replace("_g.", "_m.");
	var imgSrc = $("gallerysliderthumb-"+this.gallerynr+"-"+imagepos).src;
	$("galleryimg").src = imgSrc;

	var descr = $("gallerysliderdescr-"+this.gallerynr+"-"+imagepos).innerHTML
	$("galleryimgdescr").innerHTML = descr;
	
	this.actimagepos = imagepos;
	this._setSliderState();
}
cec.Gallery.prototype.nextImage = function () {
	var actPos = this.actimagepos;
	this.loadImage(++actPos);
}
cec.Gallery.prototype.previousImage = function () {
	var actPos = this.actimagepos;
	this.loadImage(--actPos);
}

// #################################################################################################


/**
 * Class to display or hide estate gallery layer
 */
cec.EstateGalleryLayer = function(instanceName) {
	this.name          = instanceName;
	this.imageBoxWidth = 84;
	this.timer         = null;
	this.isFF          = (navigator.userAgent.search(/Firefox/) >= 0) ? true : false;
}
cec.EstateGalleryLayer.prototype.display = function(obj, numImages, url) {
	var id          = obj.id;
	var arr         = id.split('-');
	var iGalleryPos = arr[1];
	var iImagePos   = arr[2];
	var detailid    = "gallerydetail-"+iGalleryPos+"-"+iImagePos;

	if (typeof(numImages) == "undefined") {
		numImages = 4;
	}

	try {
		// left position depending on image position
		if (iImagePos > numImages - 2) {

			// get/set alignment of last 2 images
			
			if (iImagePos == numImages) {
				var pos = numImages - 2;
			} else if (iImagePos == numImages - 1) {
				var pos = numImages - 3;
			}
			
			// get position of 3. image aPos[0] = left, aPos[1] = top
			var aPos        = Position.cumulativeOffset($("gallerythumb-"+iGalleryPos+"-"+pos));

			var cssImageDiv = 'float:left;';
			var cssImage    = 'margin-left:1px;';
			var csstextDiv  = 'float:left;';

			aPos[0] += 19;
			
		} else {

			// get/set alignment of other images
			
			// get position of 1. image aPos[0] = left, aPos[1] = top
			var aPos        = Position.cumulativeOffset($("gallerythumb-"+iGalleryPos+"-"+iImagePos));
			var cssImageDiv = 'float:left;';
			var cssImage    = '';
			var csstextDiv  = 'float:left;';

			aPos[0] -= 9;
			
		}

		// move top position to top
		aPos[1] -= 10;

		// adjustment 4 ff
		if (this.isFF) {
			aPos[0] -= 1;
			aPos[1] -= 1;
		}

		var onclick = 'oCecGallery.load('+iGalleryPos+', '+iImagePos+'); return false;';
		var href = "#";
		if (typeof(url) !== "undefined") {
			onclick = 'return true;';
			href = url;
		}
		
		// left position depending on image position
		if (iImagePos > numImages - 2) {
		var box = '<div class="box-popuplayer">' +
						'<div class="box-popuplayer-top"></div>' +
						'<div class="box-popuplayer-content">' +
							'<div class="text-r" onmouseover="'+this.name+'.onOut();" style="'+csstextDiv+'">'+$(detailid).innerHTML+'</div>' +
							'<div class="image-r" style="'+cssImageDiv+'">' +
								'<a href="'+href+'" onclick="'+onclick+'">' +
									'<img src="'+obj.src+'" style="'+cssImage+'" width="73" height="73" alt="'+obj.alt+'" onmouseover="'+this.name+'.onOver();" onmouseout="'+this.name+'.onOut();" /></a></div>' +
							'<br class="clear" />' +
						'</div>' +
						'<div class="box-popuplayer-bottom"></div>' +
					'</div>';
			
		} else {
		var box = '<div class="box-popuplayer">' +
						'<div class="box-popuplayer-top"></div>' +
						'<div class="box-popuplayer-content">' +
							'<div class="image" style="'+cssImageDiv+'">' +
								'<a href="'+href+'" onclick="'+onclick+'">' +
									'<img src="'+obj.src+'" style="'+cssImage+'" width="73" height="73" alt="'+obj.alt+'" onmouseover="'+this.name+'.onOver();" onmouseout="'+this.name+'.onOut();" /></a></div>' +
							'<div class="text" onmouseover="'+this.name+'.onOut();" style="'+csstextDiv+'">'+$(detailid).innerHTML+'</div>' +
							'<br class="clear" />' +
						'</div>' +
						'<div class="box-popuplayer-bottom"></div>' +
					'</div>';
			
		}
		
//##		oCecDebug.add('gallerypopuplayer', box);
		$("gallerypopuplayer").innerHTML = box;
		
		Element.setStyle("gallerypopuplayer", { position: 'absolute', left: aPos[0]+'px', top: aPos[1]+'px' });
		Element.show("gallerypopuplayer");
		
	} catch (e) {}
}
cec.EstateGalleryLayer.prototype.onOver = function() {
	if (this.timer) {
		clearTimeout(this.timer);
		this.timer = null;
	}
}
cec.EstateGalleryLayer.prototype.onOut = function() {
	try {
		if (this.timer == null) {
			this.timer = window.setTimeout(this.name+'.onOut()', 250);
		} else {
			Element.hide("gallerypopuplayer");
		}
	} catch (e) {}
}

// #################################################################################################



/**
 * Some global variables
 */
// debug object
var oCecDebug;

// data storage object
var oCecRegister = new cec.Register();

// real estate layer popup instance
var oCecEGLayer  = new cec.EstateGalleryLayer("oCecEGLayer");

var oCecFlashPlayer;


function onPageLoaded(){
	oCecDebug = new cec.Debug("ew72debugJS");
}

Event.observe(window, 'load', onPageLoaded, false);


// #################################################################################################


function ew72debugToggle(id){
	$(id).style.display = ($(id).style.display == 'none') ? 'block' : 'none';
}

