﻿
var defaultThumb = 0;
var defaultMainSrc = 0;

// Hover functions for thumbnails

function hoverOn(thumbObject,mainImageID,newImgSrc){
	// nur beim ersten Mal
	if(!defaultThumb)defaultThumb = document.getElementById('tx_immo_0');
	if(!defaultMainSrc)defaultMainSrc = document.getElementById(mainImageID).src;
		//activeThumbOrigSrc = activeThumb.src.replace('_th','_thsw');
	if(thumbObject != defaultThumb){
		removeClassName(defaultThumb,'greyThumb');
		addClassName(thumbObject,'greyThumb');
		mainImg = document.getElementById(mainImageID);
		mainImg.src = newImgSrc;
	}
}

function hoverOff(thumbObject,mainImageID){
	if(!defaultThumb)defaultThumb = document.getElementById('tx_immo_0');
	if(thumbObject != defaultThumb){
		removeClassName(thumbObject,'greyThumb');
		addClassName(defaultThumb,'greyThumb');
		mainImg = document.getElementById(mainImageID);
		mainImg.src = defaultMainSrc;
	}
}

function keepImage(thumbObject,mainImageID,newImgSrc){
	if(!defaultThumb)defaultThumb = document.getElementById('tx_immo_0');
	// nur beim ersten Mal
	removeClassName(defaultThumb,'greyThumb');
	defaultThumb = thumbObject;
	defaultMainSrc = newImgSrc;
		//activeThumbOrigSrc = activeThumb.src.replace('_th','_thsw');
	addClassName(thumbObject,'greyThumb');
	mainImg = document.getElementById(mainImageID);
	mainImg.src = newImgSrc;
}

// hover functions for Brauerei overview

var currentBuilding = 0;

function hoverIn(id){
	$('layerImage').src = 'fileadmin/riegel-lofts/images/building' + id + '.gif';
}

function hoverOut(id){
	if(currentBuilding)$('layerImage').src = 'fileadmin/riegel-lofts/images/building' + currentBuilding + '.gif';
	else $('layerImage').src = 'fileadmin/riegel-lofts/images/default.gif';
}

function showMenu(id){
	currentBuilding = id;
	varstring = 'tx_riegel_pi1[ajaxRequest]=1&no_cache=1&tx_riegel_pi1[pid]=' + id;
	var url = window.location.href;

	var myAjax = new Ajax.Updater(
					'tx-riegel-pi1-updateArea', 
					url, 
					{
						method: 'post', 
						parameters: varstring
					});
}

var currentLoft, currentFloor;

function showLoft(id,pid){
	className = 'activeLink';
	if(currentLoft)removeClassName(currentLoft, className);
	if(currentFloor)removeClassName(currentFloor, className);
	currentLoft = $('loftLink' + id);
	currentFloor = $('floorLink' + pid);
	addClassName(currentLoft, className);
	addClassName(currentFloor, className);
	
	
	varstring = 'tx_riegel_pi1[ajaxRequest]=1&no_cache=1&tx_riegel_pi1[loftId]=' + id;
	var url = window.location.href;

	var myAjax = new Ajax.Updater(
					'tx-riegel-pi1-loftInfoWrapper', 
					url, 
					{
						method: 'post', 
						parameters: varstring
					});
}

function showFloor(id){
	floorObj = $('floorList' + id);
	if(floorObj.style.display != 'block')floorObj.style.display = 'block';
	else floorObj.style.display = 'none';
	
	varstring = 'tx_riegel_pi1[ajaxRequest]=1&no_cache=1&tx_riegel_pi1[floorId]=' + id;
	var url = window.location.href;

	var myAjax = new Ajax.Updater(
	'tx-riegel-pi1-loftInfoWrapper', 
					url, 
					{
						method: 'post', 
						parameters: varstring
					});

}





var f;

function popupImg(index,imgSrc){
	defaultThumb = document.getElementById('tx_immo_' + index);
	th = document.getElementById('tx_immo_' + index);
	if(!f || f.closed){
		f = window.open('','',"width=860,height=650,left=150,top=150");
		f.document.open();
		f.document.write('<?xml version="1.0" encoding="iso-8859-1"?><!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"><html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en"><body style="margin:20px;text-align:center;background-image:url(http://' + window.location.host + '/fileadmin/riegel-lofts/images/body_bg.jpg);" ><div id="content"></div></body></html>');
		f.document.close();
		//onunload="opener.f = false;"
	}
	f.focus();
	c = f.document.getElementById('content');
	c.innerHTML = '<img src="/' + imgSrc + '" alt="Bild" style="margin:0 20px;"/><br /><br /><a href="javascript:window.opener.f = false;window.close()" style="font-family:Arial;color:#666">Fenster schließen</a><br />';
	if(defaultThumb)defaultThumb.blur();
}

function galleryPopup(index,imgSrc){
	if(!f || f.closed){
		f = window.open('','',"width=650,height=650,left=150,top=150");
		f.document.open();
	}
	f.focus();
	if(index==0)prevDisplay = 'display:none';
	else prevDisplay = '';
	
	if(index==(imgArray.length - 1))nextDisplay = 'display:none';
	else nextDisplay = '';
	f.document.write('<?xml version="1.0" encoding="iso-8859-1"?><!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"><html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en"><head><title>Einzelbild-Ansicht</title><script src="http://' + window.location.host + '/fileadmin/riegel-lofts/scripte/gallery.js" type="text/javascript"></script><script type="text/javascript">var currentIndex=' + index + ';</script></head><body style="margin:20px;text-align:center;background-image:url(http://' + window.location.host + '/fileadmin/riegel-lofts/images/body_bg.jpg);" ><div id="content"><div style="width:570px;height:550px;margin:0 20px;"><img src="/' + imgSrc + '" alt="Bild" id="mainImage"/></div><br /><a href="javascript:getPrevious()"  style="font-family:Arial;color:#666;' + prevDisplay + '" id="prevLink" >&lt;&lt; </a>&nbsp;&nbsp;&nbsp;<a href="javascript:window.opener.f = false;window.close()" style="font-family:Arial;color:#666">Fenster schließen</a>&nbsp;&nbsp;&nbsp;<a href="javascript:getNext()" style="font-family:Arial;color:#666;' + nextDisplay + '" id="nextLink"> &gt;&gt;</a><br /></div></body></html>');
	f.document.close();
	
}



function getExpose(){
	form = document.tx_immo_requests;
	el = form.elements;
	str = '';
	for(i=0;i<el.length;i++){
		aktField = el[i];
		if(aktField.type=="checkbox" && aktField.checked){
			str += aktField.value + "\n";
			//aktField.value = '';
			
		}
		else if(aktField.type=="hidden" && str!=''){
			str = aktField.value + "\n" + str;
			aktField.value = str;
		}
			
	}
	if(str!=''){
		return true;
	}
	else alert('Keine Objekte ausgewählt!');
	return false;
}




function hideBacklink(){
	if(history.length < 2 && document.getElementById('backlink'))document.getElementById('backlink').style.display = 'none';
	//alert(history.length);
}
window.onload = hideBacklink;

function addClassName(ele, className){
	if (!ele || !className || (ele.className && ele.className.search(new RegExp("\\b" + className + "\\b")) != -1))
		return;
	ele.className += (ele.className ? " " : "") + className;
}

function removeClassName(ele, className){
	if (!ele || !className || (ele.className && ele.className.search(new RegExp("\\b" + className + "\\b")) == -1))
		return;
	ele.className = ele.className.replace(new RegExp("\\s*\\b" + className + "\\b", "g"), "");
};


