
/*--------------------
 * SUGGEST BOX
 *------------------*/

function emSuggestSetCity(_obj) {
    var objThis = jQuery(_obj);
    var intCity = objThis.attr("id");
    jQuery("input#json_ort_suche").val(intCity);
    jQuery("#em_suche_new").val("1");
    jQuery("#em_suche_reset").val("1");
    
    
}

jQuery(document).ready(function() {
    if (document.getElementById("suggestBox")) {
        if (typeof emSuggests != "undefined"
        && typeof emSuggests.orte != "undefined"
        ) {
            jQuery('input#suggestBox').jsonSuggest(emSuggests.orte, {onSelect:emSuggestSetCity});
        }
    }
});


/*--------------------
 * GLOBAL: GET PROPERTY FUNCTIONS
 *------------------*/

function emInitFacebox()
{
    var arrEmBox = jQuery('a[rel=facebox]');
    arrEmBox.each(function(intIdx)
        {
            jQuery(this).click(emBoxOpen);
        }
    );
}

function microtime(get_as_float)
{

    var now = new Date().getTime() / 1000;
    var s = parseInt(now);

    return (get_as_float) ? now : (Math.round((now - s) * 1000) / 1000) + ' ' + s;
}
function getPageScroll()
{
	var xScroll, yScroll;
	if (self.pageYOffset) {
		yScroll = self.pageYOffset;
		xScroll = self.pageXOffset;
	} else if (document.documentElement && document.documentElement.scrollTop) {	 // Explorer 6 Strict
		yScroll = document.documentElement.scrollTop;
		xScroll = document.documentElement.scrollLeft;
	} else if (document.body) {// all other Explorers
		yScroll = document.body.scrollTop;
		xScroll = document.body.scrollLeft;
	}
	arrayPageScroll = new Array(xScroll, yScroll);
	return arrayPageScroll;
};

function getPageSize()
{
	var xScroll, yScroll;
	if (window.innerHeight && window.scrollMaxY) {
		xScroll = window.innerWidth + window.scrollMaxX;
		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
		if(document.documentElement.clientWidth){
			windowWidth = document.documentElement.clientWidth;
		} else {
			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 = xScroll;
	} else {
		pageWidth = windowWidth;
	}
	arrayPageSize = new Array(pageWidth,pageHeight,windowWidth,windowHeight);
	return arrayPageSize;
};

function emTextKuerzen(_strText, _intMax, _intMin, _strEndRepl)
{
    if (!_strText.length) {
        return '';
    }

    _strText = html_entity_decode(_strText);
    var strTemp = _strText;
    _strText = strip_tags(_strText);
    _strText = _strText.replace(/[\s]+/, ' ');
    _strText = _strText.replace(/^[\s]+|[\s]+$/, ' ');
    if (!_strText.length) {
        _strText = strTemp;
    }
    _strText = _strText.replace(/ +/, ' ');
    if (!_intMin) {
        _intMin = _intMax - 50;
    }
    if (_intMax
    &&  _strText.length > parseInt(_intMax + _strEndRepl.length)
    ) {
        var bolOk = 0;
        for (var intIdx = 0; intIdx <= _intMax - _intMin; intIdx++) {
            if (substr(_strText, _intMax - intIdx, 1).match(/\.\?\!/)) {
                _strText = substr(_strText, 0, _intMax - intIdx + (_strEndRepl ? 0 : 1)) + _strEndRepl;
                bolOk = 1;
                break;
            }
        }
        if (!bolOk) {
            for (var intIdx = 0; intIdx <= _intMax - _intMin; intIdx++) {
                if (substr(_strText, _intMax - intIdx, 1).match(/[,]/)) {
                    _strText = substr(_strText, 0, _intMax - intIdx) + _strEndRepl;
                    bolOk = 1;
                    break;
                }
            }
        }
        if (!bolOk) {
            for (var intIdx = 0; intIdx <= _intMax - _intMin; intIdx++) {
                if (!substr(_strText, _intMax - intIdx, 1).match(/[\w\d]/, 'i')) {
                    _strText = substr(_strText, 0, _intMax - intIdx) + _strEndRepl;
                    bolOk = 1;
                    break;
                }
            }
        }
        if (strrpos(_strText, '<') > strrpos(_strText, '>')) {
            _strText = substr(_strText, 0, strrpos(_strText, '<'));
            if (!bolOk) {
                _strText+= _strEndRepl;
            }
        } else if (!bolOk) {
            _strText = substr(_strText, 0, _intMin) + _strEndRepl;
        }
        if (_strEndRepl == '...') {
            _strText = _strText.replace(/\.{3,}/, '...');
        }
    }
    return htmlentities(_strText);
}

function emAddCommas(nStr)
{
	nStr += '';
	x = nStr.split('.');
	x1 = x[0];
	x2 = x.length > 1 ? '.' + x[1] : '';
	var rgx = /(\d+)(\d{3})/;
	while (rgx.test(x1)) {
		x1 = x1.replace(rgx, '$1' + '.' + '$2');
	}
	return x1 + x2;
}


/*--------------------
 * GOOGLE MAPS FUNCTIONS
 *------------------*/

var em_objMap;
function emMarkerOpen(_objMapSmall, _objPoint, _objIcon, _strHtml, _bolInit)
{
    if (_bolInit) {
        var strId = 'emGm_' + microtime(true);
            strId = strId.replace('.', '_');

        var intMapWidth = 640;
        var intMapHeight = 480;

        if (document.getElementById('emBox')) {
            emBoxClose();
        }

        var objContent = jQuery('<div>');

        var objGMapContainer = jQuery('<div>')
            .attr('id', strId)
            .css({
                'height' : intMapHeight + 'px',
                'width' : intMapWidth + 'px',
                'background' : 'url(/_em_daten/mh/_layout/top_news_loading.gif) no-repeat center center'
            })
            .appendTo(objContent);

        var objEndLine = jQuery('<div>')
            .css({
                'margin-left' : (intMapWidth - 90) + 'px',
                'margin-top' : '10px',
                'margin-bottom' : '3px'
            })
            .appendTo(objContent);

        var objLink = jQuery('<a>')
            .attr('href', 'javascript:void(0);')
            .click(emBoxCloseVideo)
            .appendTo(objEndLine);

        var objLinkImg = jQuery('<img>')
            .attr('src', '/_em_daten/mh/_layout/lightbox-btn-close.gif')
            .attr('border', '0')
            .appendTo(objLink);

        _emOverlayOpen(
            objContent,
            {
                'width' : intMapWidth,
                'height' : intMapHeight
            },
            function ()
            {
                _emMarkerOpen(_objMapSmall, _objPoint, _objIcon, _strHtml, strId, _bolInit);
            }
        );
    }

    _emMarkerOpen(_objMapSmall, _objPoint, _objIcon, _strHtml, strId);
}

function _emMarkerOpen(_objMapSmall, _objPoint, _objIcon, _strHtml, _strId, _bolInit)
{
    if (GBrowserIsCompatible()
    &&  _bolInit
    ) {
        em_objMap = new GMap2(document.getElementById(_strId));

        em_objMap.addControl(new GMapTypeControl());

        function ImageZoomControl() {
        }

        ImageZoomControl.prototype = new GControl();

        ImageZoomControl.prototype.initialize = function(map) {
          var container = document.createElement('div');

          var zoomInDiv = document.createElement('div');
          this.setButtonStyle_(zoomInDiv);
          container.appendChild(zoomInDiv);
          var zoomInImg=document.createElement('IMG');
            zoomInImg.setAttribute('src', '/_em_daten/mh/_media/fct_font_plus.gif');
            zoomInImg.setAttribute('alt', 'alternate text');
            zoomInImg.setAttribute('height', '15px');
            zoomInImg.setAttribute('width', '16px');
          zoomInDiv.appendChild(zoomInImg);
          GEvent.addDomListener(zoomInDiv, 'click', function() {
            map.zoomIn();
          });

          var zoomOutDiv = document.createElement('div');
          this.setButtonStyle_(zoomOutDiv);
          container.appendChild(zoomOutDiv);
          var zoomOutImg=document.createElement('IMG');
            zoomOutImg.setAttribute('src', '/_em_daten/mh/_media/fct_font_minus.gif');
            zoomOutImg.setAttribute('alt', 'alternate text');
            zoomOutImg.setAttribute('height', '15px');
            zoomOutImg.setAttribute('width', '16px');
          zoomOutDiv.appendChild(zoomOutImg);
          GEvent.addDomListener(zoomOutDiv, 'click', function() {
            map.zoomOut();
          });

          map.getContainer().appendChild(container);
          return container;
        }

        ImageZoomControl.prototype.getDefaultPosition = function() {
          return new GControlPosition(G_ANCHOR_TOP_LEFT, new GSize(7, 7));
        }

        ImageZoomControl.prototype.setButtonStyle_ = function(button) {
          button.style.float = 'left';
          button.style.cursor = 'pointer';
          button.style.marginBottom = '5px';
        }

        em_objMap.addControl(new ImageZoomControl());
        // em_objMap.addControl(new GLargeMapControl());

        em_objMap.enableScrollWheelZoom();
        em_objMap.setCenter(_objMapSmall.getCenter(), _objMapSmall.getZoom(), _objMapSmall.getCurrentMapType());
    }

    if (em_objMap) {
        var objMarker = new GMarker(_objPoint, _objIcon);
        GEvent.addListener(objMarker, 'click', function() {
           var html = _strHtml;
           objMarker.openInfoWindowHtml(html);
        });
        em_objMap.addOverlay(objMarker);
        //GEvent.trigger(objMarker, 'click');
    }
}

function emMapZoom(_strMapIdx)
{
    if (typeof(arrMaps) != 'undefined'
    &&  typeof(arrMaps[_strMapIdx]) != 'undefined'
    ) {
        for (var i=0; i<arrMaps[_strMapIdx].length;i++) {
            emMarkerOpen(
                arrMaps[_strMapIdx][i]['map'],
                arrMaps[_strMapIdx][i]['point'],
                arrMaps[_strMapIdx][i]['icon'],
                arrMaps[_strMapIdx][i]['html'],
                !i
            );
        }
    }
}

/*--------------------
 * OVERLAY OPEN
 *------------------*/

function _emOverlayOpen(_objContent, _objOptions, _fnCallback)
{
    var arrPageScroll = getPageScroll();
    var arrPageSize = getPageSize();

    if (document.getElementById('emBox')) {
         //_emOverlayClose();
    } else {
        var intHeight = _objOptions.height || _objContent.height();
        var intWidth = _objOptions.width || _objContent.width();
        var intTop = _objOptions.top || (arrPageSize[3] / 2) - (intHeight / 2) + arrPageScroll[1];
        var intLeft = _objOptions.left || (arrPageSize[2] / 2) - (intWidth / 2);
        var intSpeed = _objOptions.speed || 200;
        var intSpeedBg = _objOptions.speedBg || intSpeed;
        var intSpeedCnt = _objOptions.speedCnt || intSpeed;
        var strType = _objOptions.content || '';


        var intAdHeight =  jQuery("#em_ad_superbanner").height();
        if(intTop < (120 + intAdHeight) && strType != 'alert') {
            intTop = 120 + intAdHeight;
        }

        jQuery("embed, object").css({ "visibility" : "hidden" });

        var objBoxBg = jQuery('<div>')
            .attr('id', 'emBoxBg')
            .css({
                'display' : 'none',
                'position' : 'absolute',
                'z-index' : '99980',
                'background-color' : '#000',
                'left' : '0px',
                'top' : '0px',
                'height' : arrPageSize[1] + 'px',
                'width' : arrPageSize[2] + 'px',
                'opacity' : 0
            })
            .click(emBoxClose)
            .append(jQuery('<br>'));

        jQuery('body:first').append(objBoxBg);

        if(strType == 'alert'){
            jQuery('#emBoxBg').css({
               'opacity' : 0.5
            });
        }

        var objBox = jQuery('<div>')
            .attr('id', 'emBox')
            .css({
                'display' : 'none',
                'position' : 'absolute',
                'z-index' : '99990',
                'left' : intLeft + 'px',
                'top' : intTop + 'px'
            });


        if (_objOptions.setWidth) {
            objBox.css('width', intWidth + 'px');
        }
        if (_objOptions.setHeight) {
            objBox.css('height', intHeight + 'px');
        }
        jQuery('body:first').append(objBox);

        objBox.append(_objContent);

        objBoxBg.fadeIn(intSpeed, function() { objBox.fadeIn(intSpeed, _fnCallback); });

        jQuery("#emBox").draggable({
           drag: function(event, ui) {
           }
        });
    }
}
/*--------------------
 * OVERLAY OPEN SEARCH
 *------------------*/

function _emOverlayOpenSearch(_objContent, _objOptions, _fnCallback)
{
    var arrPageScroll = getPageScroll();
    var arrPageSize = getPageSize();

    if (document.getElementById('emBox')) {
         //_emOverlayClose();
    } else {
        var intHeight = _objOptions.height || _objContent.height();
        var intWidth = _objOptions.width || _objContent.width();
        var intTop = _objOptions.top || (arrPageSize[3] / 2) - (intHeight / 2) + arrPageScroll[1];
        var intLeft = _objOptions.left || (arrPageSize[2] / 2) - (intWidth / 2);
        var intSpeed = _objOptions.speed || 200;
        var intSpeedBg = _objOptions.speedBg || intSpeed;
        var intSpeedCnt = _objOptions.speedCnt || intSpeed;
        var strType = _objOptions.content || '';

        jQuery("embed, object, select").css({ "visibility" : "hidden" });

        var objBoxBg = jQuery('<div>')
            .attr('id', 'emBoxBg')
            .css({
                'display' : 'none',
                'position' : 'absolute',
                'z-index' : '99980',
                'background-color' : '#000000',
                'left' : '0px',
                'top' : '0px',
                'height' : arrPageSize[1] + 'px',
                'width' : arrPageSize[2] + 'px',
                'opacity' : 0.7
            })
            .append(jQuery('<br>'));
        jQuery('body:first').append(objBoxBg);

        var objBox = jQuery('<div>')
            .attr('id', 'emBox')
            .css({
                'display' : 'none',
                'position' : 'absolute',
                'z-index' : '99990',
                'left' : intLeft + 'px',
                'top' : intTop + 'px'
            });


        if (_objOptions.setWidth) {
            objBox.css('width', intWidth + 'px');
        }
        if (_objOptions.setHeight) {
            objBox.css('height', intHeight + 'px');
        }
        jQuery('body:first').append(objBox);

        objBox.append(_objContent);

        objBoxBg.fadeIn(intSpeed, function() { objBox.fadeIn(intSpeed, _fnCallback); });
    }
}

function _emOverlayClose(_intWait)
{
    jQuery('#emBox')
        .animate({'opacity' : 1}, _intWait)
        .fadeOut(
            200,
            function() {
                jQuery('#emBox').remove();
                if (document.getElementById('emBoxBg')) {
                    jQuery('#emBoxBg').fadeOut(
                        200,
                        function() {
                            jQuery('#emBoxBg').remove();
                            jQuery("embed, object, select").css({ "visibility" : "visible" });
                        }
                    );
                }
            }
        );

}

function emBoxCloseSearch()
{
	_emOverlayClose();
}

function emBoxOpen(objElement)
{
    var strType = jQuery(this).attr('class');
    var intFrameWidth = 0;
    var intFrameHeight = 0;
    var bolCreateIframe = false;
    var objOptions = {};

    if (document.getElementById('emBox')) {
         emBoxClose();
    } else {
        if (strType.match(/(^| )imagesend( |$)/)) {
            objOptions.top = objElement.pageY - 20 - 280;
            objOptions.left = objElement.pageX - 20 - 380;
        }

        if (strType.match(/(^| )em_box_iframe( |$)/)) {
            bolCreateIframe = true;
            intFrameWidth = 420;
            intFrameHeight = 280;
        } else if (strType.match(/(^| )em_box_map( |$)/)) {
            bolCreateIframe = true;
            intFrameWidth = 957;
            intFrameHeight = 660;
        } else if (strType.match(/(^| )em_box_image( |$)/)) {
            bolCreateIframe = false;
            var thisImage = jQuery(this).attr('href');
            intFrameWidth = 800;
            intFrameHeight = 800;
        } else if (strType.match(/(^| )em_box_innercontent_(.*)( |$)/)) {
            bolCreateIframe = false;
            jQuery('#' + RegExp.$2).show();
        }

        if (bolCreateIframe) {
            objOptions.height = intFrameHeight;
            objOptions.width = intFrameWidth;

            var objFrame = jQuery('<iframe class="emBoxIframe" scrolling="no" frameborder="0" src="' + jQuery(this).attr('href')
                + '" style="border: 0px none; margin: 0px; padding: 0px; width: ' + intFrameWidth + 'px; height: '
                + intFrameHeight + 'px;" border="0" marginheight="0" marginwidth="0"></iframe>');

            _emOverlayOpen(objFrame, objOptions);
        } else if (strType.match(/(^| )em_box_image( |$)/)) {

            strImgWidth = 800;
            objOptions.height = 600;
            objOptions.width = 800;

            var objFrame = jQuery('<div id="em_image_big_container" style="overflow:visible;width: ' + strImgWidth + 'px !important;"><img src="' + jQuery(this).attr('href')
                + '" style="border: 0px none; margin: 0px; padding: 0px; width: ' + strImgWidth + 'px !important;" border="0" id="em_image_big" /></div>'
                + '<div style="line-height: 18px; background-color: #fff; padding: 8px; font-family: Verdana; position: absolute; top: 0px; right: 3px;z-index: 1000;z-index: 1000;">'
                + '<a href="javascript:emBoxClose();" style="font-weight: bold; font-size: 12px;" class="em_hausfarbe">schlie&szlig;en '
                + 'x</a></div>');

            _emOverlayOpen(objFrame, objOptions);
        }
    }
    return false;
}

/**
 * VIDEO IN GALLERY
 */

function em_load_video_gallery(zoom, video, mediaid, width, height, strType)
{
    var em_newvideo = new SWFObject("/_em_oas/_locals/vestimmo/images/video/em_player.swf", "em_video_gallery", "100%", "100%", "8");
    em_newvideo.addVariable("id", mediaid);
    em_newvideo.addVariable("playerskin", "/_em_oas/_locals/vestimmo/images/video/skin_max.swf");
    em_newvideo.addVariable("playerskin2", "/_em_oas/_locals/vestimmo/images/video/skin_max.swf");
    em_newvideo.addVariable("autoplay", "0");
    em_newvideo.addVariable("zoommax", zoom ? "1" : "0");
    em_newvideo.addVariable("playervolume", "50");
    em_newvideo.addVariable("playerwidth", width);
    em_newvideo.addVariable("playerwidthmax", width);
    em_newvideo.addVariable("buffertime", "2");
    if(strType == "wp") {
        em_newvideo.addVariable("contentvideo", "" + video + "?nocache=1245224432");
    } else {
        em_newvideo.addVariable("contentvideo", "/" + video + "?nocache=1245224432");
    }
    em_newvideo.addVariable("btn_farbwert", "0xffffff");
    em_newvideo.addVariable("hg_farbwert", "");
    em_newvideo.addVariable("overlay", "0");
    em_newvideo.addParam("wmode", "transparent");
    em_newvideo.addParam("allowScriptAccess", "always");
    em_newvideo.addVariable("icon_farbwert", "0x000000");
    em_newvideo.addVariable("Fullscreen","1");
    em_newvideo.addVariable("autohide", "0");
    em_newvideo.addVariable("hg_farbwert_fullscreen", "0x000000");
    em_newvideo.addVariable("hg_alpha", "100");
    em_newvideo.addParam("allowFullScreen", "true");
    em_newvideo.addParam("scale", "noscale");
    em_newvideo.addParam("salign", "LT");
    em_newvideo.write(mediaid);
}

function em_resize_video_media_1(_intID) {}

/*--------------------
 * SEARCH VALIDATION
 *------------------*/

function search(_form)
{
    var objSearchBox = jQuery('#' + _form + ' .em_form_user_login');
    var strSearchText = objSearchBox.val();
	if (strSearchText == ''
	||  strSearchText == 'Suche'
	) {
		objSearchBox.focus();
		return false;
	}
}

/*--------------------
 * ANIMATIONS
 *------------------*/

function emSlideDown(strObject, fnCallback)
{
    jQuery(strObject).slideDown(500, fnCallback);
}

function emSlideUp(strObject, fnCallback)
{
    jQuery(strObject).slideUp(500, fnCallback);
}

function emSlideToggle(strObject, fnCallback)
{
    jQuery(strObject).slideToggle(500, fnCallback);
}

function emFadeIn(strObject, fnCallback)
{
    jQuery(strObject).fadeIn(500, fnCallback);
}

function emToggle(strObjectId)
{
    var strOpenId = '';
    jQuery('.em_toggle_box').each(function () {
        var objThis = jQuery(this);
        if (objThis.css('display') != 'none') {
            objThis.animate(
                {
                    'opacity' : 'toggle',
                    'height' : 'toggle'
                },
                500
            );
            strOpenId = '#' + objThis.attr('id');
        }
    });

    if (strOpenId != strObjectId) {
        jQuery(strObjectId).animate(
            {
                'opacity' : 'toggle',
                'height' : 'toggle'
            },
            500
        );
    }
}


var emSucheDetailsShowed = 0;
function emToggleSucheDetails()
{
    emToggle('#em_no_detail_search');
    emToggle('#em_detail_search');

    if (!emSucheDetailsShowed) {
        var srcIfr = jQuery('#em_suche_erweitert_src').attr('src');
        jQuery('#em_suche_erweitert_src').attr('src', srcIfr);
        emSucheDetailsShowed = 1;
    }
}

function emShowMessageLayer(_strInfoMsg)
{
    if (_strInfoMsg) {
        jQuery('div.info').each(function ()
            {
                _strInfoMsg+= jQuery(this).text() + '<br />';
            }
        );

        if (_strInfoMsg.length) {
            var objContent = jQuery('<div style="float: left; padding: 10px; font-weight: bold; width: 200px;">' + _strInfoMsg + '<\/div><div style="float: right; padding: 5px;"><img src="/_em_oas/_locals/vestimmo/images/_icons/48x48/apps/alert.png" border="0"><br/><br/><br/><\/div><div class="em_clear"><br\/><\/div><div style="position: absolute; right: 10px; bottom: 10px;"><a href="javascript:_emOverlayClose();" class="em_btn"><span>schlie&szlig;en<\/span><\/a><\/div>');
            _emOverlayOpen(
                objContent,
                {
                    'height' : 200,
                    'width' : 300,
                    'setWidth' : true,
                    'content' : 'alert'
                },
                function()
                {

                }
            );
        }
    }
}

/*--------------------
 * NEW TO MERKBOX ANIMATION EFFECT
 *------------------*/

function emTransferAnimation(_intID) {
    var strId = "#em_ergebnis_nr_" + _intID;
    jQuery(strId).effect("transfer", { to: "#em_merkbox_transfer" }, 1000);
}


/*--------------------
 * CHANGE GOOGLE MARKER COLOR
 *------------------*/

function emHighlightMarker(_strId) {
    var strId = "#mtgt_" + _strId;
    jQuery(strId).attr("src", "/_em_oas/_locals/vestimmo/images/_layout/em_gmap_pin_active.png");
}

function emHighlightMarkerDis(_strId) {
    var strId = "#mtgt_" + _strId;
    jQuery(strId).attr("src", "/_em_oas/_locals/vestimmo/images/_layout/em_gmap_pin.png");
}

/*--------------------
 * CHANGE ANZEIGEN BG COLOR
 *------------------*/

function emHighlightObject(_strId) {
    var strId = "#em_ergebnis_nr_" + _strId;
    jQuery(strId).children("div:first").addClass("em_active");
}

function emHighlightObjectDis(_strId) {
    var strId = "#em_ergebnis_nr_" + _strId;
    jQuery(strId)
        .animate({'opacity' : 1}, 500, '',
            function() {
                    jQuery(strId).children("div:first").removeClass("em_active");
                }
        );
}

/*--------------------
 * RESIZE OVERLAY
 *------------------*/


function emPlaceObjects(intWidth,intHeight) {
    var arrPageScroll = getPageScroll();
    var arrPageSize = getPageSize();
    var intMapHeight = intHeight;
    var frameTop = (arrPageSize[3] / 2) - (intMapHeight / 2) + arrPageScroll[1];
    var frameLeft = (arrPageSize[2] / 2) - (intWidth / 2);

    if(frameTop < 50) {
        frameTop = 50;
    }

    jQuery("#emBox").animate({"top":frameTop + "px"}, { duration: 200 });
    jQuery("#emBox").animate({"left":frameLeft + "px"}, { duration: 200 });
    jQuery("#emBoxIf").animate({"height":intHeight + 10 + "px" }, { duration: 200 });
    jQuery("#emBoxIf").animate({"width":intWidth + "px" }, { duration: 200 });
}


/*--------------------
 * WARTEFUNKTION
 *------------------*/

function emWaitOpen(_fnCallback)
{
    var arrPageScroll = getPageScroll();
    var arrPageSize = getPageSize();

    if (document.getElementById('emBoxWait')) {
        objBoxBg.remove();
        objBox.remove();
    } else {

        var intHeight = 50;
        var intWidth = 250;
        var intTop = (arrPageSize[3] / 2) - (intHeight / 2) + arrPageScroll[1];
        var intLeft = (arrPageSize[2] / 2) - (intWidth / 2);
        var intSpeed = 200;
        var intSpeedBg = intSpeed;
        var intSpeedCnt = intSpeed;

        if(intTop < 220) {
            intTop = 220;
        }

        jQuery("embed, object").css({ "visibility" : "hidden" });

        var objBoxBg = jQuery('<div>')
            .attr('id', 'emBgWait')
            .css({
                'display' : 'none',
                'position' : 'absolute',
                'z-index' : '99980',
                'background-color' : '#000',
                'left' : '0px',
                'top' : '0px',
                'height' : arrPageSize[1] + 'px',
                'width' : arrPageSize[2] + 'px',
                'opacity' : 0.5
            })
            .append(jQuery('<br>'));
        jQuery('body:first').append(objBoxBg);

        var objBox = jQuery('<div>')
            .attr('id', 'emBoxWait')
            .css({
                'display' : 'none',
                'position' : 'absolute',
                'z-index' : '99990',
                'text-align' : 'center',
                'width' : '260px',
                'font-weight' : 'bold',
                'left' : intLeft + 'px',
                'top' : intTop + 'px'
            });

        jQuery('body:first').append(objBox);

        objBox.append("<span style=\"color: #fff;\"><img src=\"/_em_oas/_locals/vestimmo/images/_layout/em_wait.gif\" border=\"0\" alt=\"Bitte Warten\"><br/><br/>Bitte haben Sie einen kleinen Moment Geduld.</span>");

        objBoxBg.show();
        objBox.show();

    }
}

function emSlider(_strId, _intMin, _intMax, _intMinVal, _intMaxVal, _emLimitMin, _emLimitMax, _intSteps, _strMinField, _strMaxField) {


    jQuery(_strId).slider({
		range: true,
		min: _intMin,
		max: _intMax,
		animate: true,
		values: [_intMinVal, _intMaxVal],

		slide: function(event, ui) {
		    //Tauser Trennzeichen entfernen
		    if(jQuery(ui.handle).hasClass("em_first_handle")) {
       		    if(ui.values[0] < _emLimitMin) {

       		        emSlider(_strId, _intMin, _intMax, ui.values[0], ui.values[1], _emLimitMin, _emLimitMax, _intSteps, _strMinField, _strMaxField);
                    emSetSliderValues(_strId, ui.values[0], ui.values[1], _strMinField, _strMaxField,0);
                    emSliderTooltips();
    		    } else {

    		        emSetSliderValues(_strId, ui.values[0], ui.values[1], _strMinField, _strMaxField,1);
    		        emSliderTooltips();
    		        emSliderTooltips();
    		    }
            }

            if(jQuery(ui.handle).hasClass("em_last_handle")) {
       		    if(ui.values[1] > _emLimitMax) {

                    emSlider(_strId, _intMin, _intMax, ui.values[0], ui.values[1], _emLimitMin, _emLimitMax, _intSteps, _strMinField, _strMaxField);
                    emSetSliderValues(_strId, ui.values[0], ui.values[1], _strMinField, _strMaxField,0);
    		    } else {
    		      emSetSliderValues(_strId, ui.values[0], ui.values[1], _strMinField, _strMaxField,1);

    		    }
            }

		}
	});

	jQuery(_strId).find(".ui-slider-handle:first").addClass("em_first_handle");
	jQuery(_strId).find(".ui-slider-handle:last").addClass("em_last_handle");

	jQuery(_strId).bind("slidestop", function(event, ui) {
        em_submit_verfeinert();
    });

}

function emSetSliderValues(_strSliderId, _intMinValue, _intMaxValue, _strMinField, _strMaxField,_boolLimit) {
            jQuery(_strSliderId).children(".ui-slider-handle:eq(0)").attr("title", _intMinValue);
	        jQuery(_strSliderId).children(".ui-slider-handle:eq(1)").attr("title", _intMaxValue);
            if (_intMinValue > 0 ) {
	           jQuery(_strSliderId+"-text-min").html(emAddCommas(_intMinValue));
            }
	        jQuery(_strSliderId+"-text-max").html(emAddCommas(_intMaxValue));
	        if (_boolLimit == 0) {
	            jQuery(_strSliderId+"-text-min").css("color", "#000000");
    	        jQuery(_strSliderId+"-text-max").css("color", "#000000");

    	        jQuery("#" + _strMinField).val(_intMinValue);

    	       	jQuery("#" + _strMinField + "_show").val(_intMinValue);
    		    jQuery("#" + _strMaxField).val(_intMaxValue);
    		    jQuery("#" + _strMaxField + "_show").val(_intMaxValue);
	        } else {
	            jQuery(_strSliderId+"-text-min").css("color", "#C00000");
    	        jQuery(_strSliderId+"-text-max").css("color", "#C00000");
	        }
}

/*--------------------
 * IMAGE GALLERY
 *------------------*/


function emChangeImgSrc(_obj) {
    var objThis = jQuery(_obj);
    var strType = objThis.children("a").attr("class");
    var strId = objThis.children("a").attr("id");
    var strCaption = objThis.children("a").children(".emthumbimage").attr("var");
    var strSrc = objThis.children("a").children(".emthumbimage").attr("rel");

    if(strType == "image"){
        jQuery("#em_gallery_container").css("height", "198px");
        jQuery("#em_gallery_container").html("<a href=\'javascript:void(0);\' title=\'" + strCaption + "\' onclick=\'emOpenLightbox(this,\"" + strId + "\");\' id=\"strId\" rel=\'" + strSrc + "\'><img src=\'" + strImagePath + "/_layout/no.gif\' alt=\'" + strCaption + "\' width=\'285\' height=\'198\' border=\'0\' style=\'background: url(\"" + strSrc + "\") center center no-repeat;\' rel=\'" + strId + "\' id=\'em_gallery_middle_image\' /></a>");
        jQuery("#em_gallery_caption").show();
        jQuery("#em_gallery_caption").html("<span>" + strCaption + "</span>");
        jQuery(".em_img_thumbnails").removeClass("em_border_active").addClass("em_border");
        objThis.removeClass("em_border").addClass("em_border_active");
        emSetGalleryNav(strId);
       }

    if(strType == "video"){
        jQuery("#em_gallery_container").css("height", "240px");
        jQuery("#em_gallery_container").html("<div style=\'width: 285px; height: 240px;\' id=\'" + strId + "\'><br/></div>");
        jQuery("#em_gallery_caption").hide();
        jQuery(".em_img_thumbnails").removeClass("em_border_active").addClass("em_border");
        objThis.removeClass("em_border").addClass("em_border_active");
        em_load_video_gallery(1, strSrc, strId, 285, 160);
        jQuery("#em_gallery_next").css("display", "none");
        jQuery("#em_gallery_prev").css("display", "none");
    }
}


function em_gallery_initCallback(carousel) {
    window.carousel = carousel;

    jQuery("#em_gallery_next").bind("click", function() {
        //carousel.next();
    });

    jQuery("#em_gallery_prev").bind("click", function() {
        //carousel.prev();
    });

};

function emSetGalleryNav(_strId) {
   _strId.match(/^media_(\d+)$/);
   intCurrId = RegExp.$1;
   intCurrId = parseInt(intCurrId)

   jQuery("#currobjectid").attr("value", intCurrId);

    if(intCurrId > intCountVideos) {
        jQuery("#em_gallery_prev").html("<a href=\"javascript:emGalleryNav(0);\" style=\"display: block; position: absolute; left: 8px; top: 183px; font-weight: bold; width: 25px; z-index: 3;\" class=\"em_hausfarbe\"><img src=\"" + strImagePath + "/_layout/em_btn_prev.png\" alt=\"vorhergehendes Bild\" border=\"0\" /></a>");
        jQuery("#em_gallery_prev").css("display", "block");
    }

    if(intCurrId < intCountImages) {
        jQuery("#em_gallery_next").html("<a href=\"javascript:emGalleryNav(1);\" style=\"display: block; position: absolute; left: 269px; top: 183px; font-weight: bold; width: 25px; z-index: 3;\" class=\"em_hausfarbe\"><img src=\"" + strImagePath + "/_layout/em_btn_next.png\" alt=\"n&auml;chstes Bild\" border=\"0\" /></a>");
        jQuery("#em_gallery_next").css("display", "block");
    }


    if(intCurrId == (1 + intCountVideos)) {
        jQuery("#em_gallery_prev").css("display", "none");
    }

    if(intCurrId == intCountImages) {
        jQuery("#em_gallery_next").css("display", "none");
    }
}

function emGalleryNav(_intDirection) {

    var strId = jQuery("#em_gallery_middle_image").attr("rel");
    strId.match(/^media_(\d+)$/);
    intCurrId = RegExp.$1;

    var intId = parseInt(intCurrId);

    if(_intDirection == 0){
        intId--;
    } else {
        intId++;
    }

   jQuery("#currobjectid").attr("value", intId);

    if (intId == (1 + intCountVideos)) {
        jQuery("#em_gallery_prev").css("display", "none");
        jQuery("#em_gallery_next").css("display", "block");
    } else if (intId == intCountImages) {
        jQuery("#em_gallery_prev").css("display", "block");
        jQuery("#em_gallery_next").css("display", "none");
    } else {
        jQuery("#em_gallery_prev").css("display", "block");
        jQuery("#em_gallery_next").css("display", "block");
    }

    var objThis = jQuery("#media_" + intId);
    var objThisThumb = jQuery("#media_" + intId).parent("div");
    var strType = objThis.attr("class");
    var strId = objThis.attr("id");
    var strCaption = objThis.children(".emthumbimage").attr("var");
    var strSrc = objThis.children(".emthumbimage").attr("rel");

    jQuery("#em_gallery_container").html("<a href=\'javascript:void(0);\' title=\'" + strCaption + "\' onclick=\'emOpenLightbox(this,\"" + strId + "\");\' id=\"strId\" rel=\'" + strSrc + "\'><img src=\'" + strImagePath + "/_layout/no.gif\' alt=\'" + strCaption + "\' width=\'285\' height=\'198\' border=\'0\' style=\'background: url(\"" + strSrc + "\") center center no-repeat;\' rel=\'" + strId + "\' id=\'em_gallery_middle_image\' /></a>");
    jQuery("#em_gallery_caption").html(strCaption);

    jQuery(".em_img_thumbnails").removeClass("em_border_active").addClass("em_border");
    objThis.parents(".em_img_thumbnails").removeClass("em_border").addClass("em_border_active");
}

function emOpenLightbox(_emObject, _strCurrId)
{
   strImgSrc = jQuery("#" + _strCurrId).children(".emthumbimage").attr("alt");
   strImgCaption = jQuery(_emObject).attr("title");

   _strCurrId.match(/^media_(\d+)$/);
   intCurrId = RegExp.$1;

    var intWidth = "800";
    var intHeight = "600";

    var objIMGbox = jQuery("<div>")
        .addClass("em_vollbild")
        .attr("id", "em_vollbild_image")
        .css({
            "background" : "#FFFFFF",
            "overflow" : "hidden",
            "width" : intWidth + "px",
            "display" : "block"
        });

    var objIMGContainer = jQuery("<div>")
        .attr("id", "em_image")
        .css({
            "width" : intWidth + "px",
            "textAlign": "center"
        })
        .appendTo(objIMGbox);

    var objIMG = jQuery("<img>")
        .attr("id", "em_full_image")
        .attr("src", strImgSrc)
        .attr("alt", strImgCaption)
        .attr("border", "0")
        .attr("rel", intCurrId)
        .css("cursor", "pointer")
        .appendTo(objIMGContainer)
        .bind("click", function() {
            emBoxClose();
        });

    var objClear = jQuery("<div>")
        .attr("id", "em_image_clear")
        .css({
            "display" : "block",
            "height" : "15px"
        })
        .addClass("em_clear")
        .append(jQuery("<br/>"))
        .appendTo(objIMGbox);

    var objIMGText = jQuery("<div>")
        .attr("id", "em_image_text")
        .css({
            "display" : "block",
            "textAlign" : "center"
        })
        .append(strImgCaption)
        .appendTo(objIMGbox);

    var objIMGNavigation = jQuery("<div>")
        .attr("id", "em_image_navigation")
        .css({
            "display" : "block"
        })
        .appendTo(objIMGbox);

    if(intCurrId > intCountVideos) {
        var objIMGNavigationPrev = jQuery("<div>")
            .attr("id", "em_image_navigation_prev")
            .css({
                "display" : "block"
            })
            .append("<a href=\"javascript:emGalleryNavigation(0);\" style=\"display: block; margin-top: -15px;  float: left; font-weight: bold; width: 150px;\" class=\"em_hausfarbe\"><img src=\"" + strImagePath + "/_layout/em_btn_prev.png\" alt=\"vorhergehendes Bild\" border=\"0\" /></a>")
            .appendTo(objIMGNavigation);
    }

    if(intCurrId <= intCountImages) {
        var objIMGNavigationNext = jQuery("<div>")
            .attr("id", "em_image_navigation_next")
            .css({
                "display" : "block"
            })
            .append("<a href=\"javascript:emGalleryNavigation(1);\" style=\"display: block; margin-top: -15px; float: right; text-align: right; font-weight: bold; width: 150px;\" class=\"em_hausfarbe\"><img src=\"" + strImagePath + "/_layout/em_btn_next.png\" alt=\"n&auml;chstes Bild\" border=\"0\" /></a>")
            .appendTo(objIMGNavigation);
    }

        var objIMGNavigationClose = jQuery("<div>")
            .attr("id", "em_image_navigation_close")
            .css({
                "display" : "block"
            })
            .append("<a href=\"javascript:emBoxClose();\" style=\"display: block;position: absolute; right: 4px; top: 4px; padding: 10px; background: #fff; text-align: right; font-weight: bold;\" class=\"em_hausfarbe\">schlie&szlig;en x</a>")
            .appendTo(objIMGNavigation);

    _emOverlayOpen(
        objIMGbox,
        {
            "speedCnt" : 1,
            "width" : intWidth,
            "height" : intHeight

        }
    );

    if(intCurrId == (1 + intCountVideos)) {
        jQuery("#em_image_navigation_prev").css("display", "none");
    }

    if(intCurrId == intCountImages) {
        jQuery("#em_image_navigation_next").css("display", "none");
    }

}

function emGalleryNavigation(_intDirection) {

    var intId = parseInt(jQuery("#em_full_image").attr("rel"));

    if(_intDirection == 0){
        intId--;
        //carousel.prev();
    } else {
        intId++;
        //carousel.next();
    }

    if (intId == (1 + intCountVideos)) {
        jQuery("#em_image_navigation_prev").css("display", "none");
        jQuery("#em_image_navigation_next").css("display", "block");
    } else if (intId == intCountImages) {
        jQuery("#em_image_navigation_prev").css("display", "block");
        jQuery("#em_image_navigation_next").css("display", "none");
    } else {
        jQuery("#em_image_navigation_prev").css("display", "block");
        jQuery("#em_image_navigation_next").css("display", "block");
    }

    var objThis = jQuery("#media_" + intId);
    var strType = objThis.attr("class");
    var strId = objThis.attr("id");
    var strCaption = objThis.children(".emthumbimage").attr("var");
    var strSrc = objThis.children(".emthumbimage").attr("alt");

    jQuery("#em_full_image").attr("src", strSrc).attr("rel", intId);
    jQuery("#em_image_text").html(strCaption);

    var objThisObject = jQuery("#" + strId).parent("div");
    emChangeImgSrc(objThisObject);
}


/**
 * Enable a support to keyboard navigation (SMALL GALLERY)
 *
 */
function _enable_keyboard_gallery_navigation() {
	jQuery(document).keydown(function(objEvent) {
        if (document.getElementById("em_vollbild_image")) {
            _keyboard_gallery_big_action(objEvent);
        } else {
    		_keyboard_gallery_action(objEvent);
        }
	});
}


/**
 * Perform the keyboard actions
 *
 */
function _keyboard_gallery_action(objEvent) {

    var inkeyobjid =  jQuery("#currobjectid").val();
	if ( objEvent == null ) {
		keycode = event.keyCode;
		escapeKey = 27;
	} else {
		keycode = objEvent.keyCode;
		escapeKey = objEvent.DOM_VK_ESCAPE;
	}

	key = String.fromCharCode(keycode).toLowerCase();

	if (( keycode == 37 ) ) {
		if (inkeyobjid > (1 + intCountVideos)) {
            emGalleryNav(0);
            //carousel.prev();
		}
	}

	if (( keycode == 39 ) ) {
		if (inkeyobjid < intCountImages) {
            emGalleryNav(1);
            //carousel.next();
		}
	}
}


/**
 * Perform the keyboard actions
 *
 */
function _keyboard_gallery_big_action(objEvent) {

    var inkeyobjid =  jQuery("#currobjectid").val();

	if ( objEvent == null ) {
		keycode = event.keyCode;
		escapeKey = 27;
	} else {
		keycode = objEvent.keyCode;
		escapeKey = objEvent.DOM_VK_ESCAPE;
	}

	key = String.fromCharCode(keycode).toLowerCase();

	if (( keycode == 37 ) ) {
		if (inkeyobjid > (1 + intCountVideos)) {
            emGalleryNavigation(0);
            //carousel.prev();
		}
	}

	if (( keycode == 39 ) ) {
		if (inkeyobjid < intCountImages) {
            emGalleryNavigation(1);
            //carousel.next();
		}
	}
}


/*--------------------
 * UMGEBUNGSKARTE DETAILANSICHT
 *------------------*/

function emShowMap(_intLang, _intLat, _intZoom)
{
    map = new VEMap('em_google_maps_detail');
    map.LoadMap(new VELatLong(_intLat, _intLang), _intZoom);
    map.Hide3DNavigationControl();
    map.HideMiniMap();
    map.SetDashboardSize(VEDashboardSize.Tiny);
    map.HideDashboard();

    map.AttachEvent("onmousewheel", emShapeHandler);
    map.AttachEvent("onmousedown", emShapeHandler);
    map.AttachEvent("ondoubleclick", emShapeHandler);
    map.AttachEvent("onclick", emShapeHandler);

    var icon = "<div class='em_standort'><br/></div>";

    var shape = new VEShape(VEShapeType.Pushpin, map.GetCenter());

    shape.SetCustomIcon(icon);
    map.AddShape(shape);

}

function emFindNeighbour(_emObjThis)
{
    if(_emObjThis.attr("checked") == true) {
        try
        {
            emPoiClass = "";
            emPoiClass = _emObjThis.attr("id");

            layer = "layer" + i;
            layer = new VEShapeLayer();
            layer.SetTitle(_emObjThis.attr("id"));
            layer.Show();

            var strFind =  _emObjThis.val();
            var arrFind = strFind.split(',');

            jQuery("#em_tabdetail_map").find("input[type=checkbox]").attr("disabled", "true")

            for ( i = 0; i < arrFind.length; i++) {
                map.Find(arrFind[i], null, null, layer, null, 20, null, false, false, null, emPoiCallback);
            }
        }
        catch(e)
        {
        }
    } else {}

    jQuery("#" + _emObjThis.attr("id")).bind("click", function () {
       jQuery("#em_google_maps_detail").find("." + _emObjThis.attr("id")).parents(".VEAPI_Pushpin").remove();
    });
    i++;
}

function emPoiCallback(a,b,c,d,e)
{
    if(b != null) {
        for (x=0; x<b.length; x++)
        {
            var icon = "<div class='em_tooltip em_poi " + emPoiClass + "' title='<b>"+b[x].Name+"<\/b><br>"+b[x].Description+"<br>"+b[x].Phone+"'><br></div>";
            var shape = new VEShape(VEShapeType.Pushpin, b[x].LatLong);
            shape.SetCustomIcon(icon);
            map.AddShape(shape);
            emTooltips();
        }
    }
    jQuery("#em_tabdetail_map").find("input[type=checkbox]").removeAttr("disabled")
}

function emDeleteAllLayer()
  {
     map.DeleteAllShapeLayers();
     layer = null;
     jQuery(".em_poi_checkbox").attr("checked", "");

     var icon = "<div class='em_standort'><br/></div>";

     var shape = new VEShape(VEShapeType.Pushpin, map.GetCenter());

     shape.SetCustomIcon(icon);
     map.AddShape(shape);
  }

function emShapeHandler(e)
{
  return true;
}


/*--------------------
 * COOKIE FUNCTIONS
 *------------------*/

function emSetCookie(_strCookieName, _strCookieValue) {
    var arrOptions = { path: '/', expires: 999 };
    jQuery.cookie(_strCookieName, null, arrOptions);
	jQuery.cookie(_strCookieName, _strCookieValue, arrOptions);
}

function emGetCookie(_strCookieName) {
    jQuery.cookie(_strCookieName);
}

function emDeleteCookie(_strCookieName) {
    jQuery.cookie(_strCookieName, null);
}


/*--------------------
 * MERKBOX FUNCTIONS
 *------------------*/

function emMerkboxSlideDown()
{
    jQuery("#em_empty_merkbox").hide();
    if (!merkbox_showed) {
        jQuery("#em_merkbox_container").show();
        merkbox_showed = 1;
        jQuery("#em_merkbox_update").css("display", "none");
    }
    emSetCookie("merkboxeintrage", "yes");
}

function emMerkboxSlideUp()
{
    if (merkbox_showed) {
        jQuery("#em_merkbox_container").hide();
        merkbox_showed = 0;
        jQuery("#em_merkbox_container").removeClass("em_waiting");
    }
    _emCloseMerkbox();
    emSetCookie("merkboxeintrage", "no");
}

function emInitMerkbox()
{
    var strId = "#merkbox";

    jQuery(strId).coverflow({
    				select: function(event, sky) {
    					jQuery(strId + "_slider").slider("value", sky.value+1);
    				}
    			});

    jQuery(strId + "_slider").slider("destroy");
	jQuery(strId + "_slider").slider({
		min: 1,
		max: jQuery(strId + "> *").length,
		animate: true,
		slide: function(event, ui) {
			jQuery(strId).coverflow("select", ui.value-1, true);
		}
	});

	jQuery(strId + "_meta").find(".headline").html("<a href=\"\" class=\"ansehen\">" + jQuery(strId).children("img:eq(0)").attr("titel") + "<\/a>");
	jQuery(strId + "_meta").find(".description").html(jQuery(strId).children("img:eq(0)").attr("alt"));
	jQuery(strId + "_meta").find(".zimmer").html(jQuery(strId).children("img:eq(0)").attr("rel"));
	jQuery(strId + "_meta").find(".flaeche").html(jQuery(strId).children("img:eq(0)").attr("flaeche"));
	jQuery(strId + "_meta").find(".ansehen").attr("href", jQuery(strId).children("img:eq(0)").attr("link"));
	jQuery(strId + "_meta").find(".merken").attr("href", jQuery(strId).children("img:eq(0)").attr("id"));

    jQuery(strId).children("img").unbind("mousedown");
    jQuery(strId).children("img:eq(0)").bind("mousedown", function() {
        window.location.href = jQuery(this).attr("link");
    });

}

function _emOpenMerkbox() {
    jQuery("#em_toggle_merkbox").html("&#09660;");
    jQuery("#em_toggle_merkbox").attr("class", "open");
    jQuery("#em_merkbox_update").animate({"opacity" : "toggle"},200);
    jQuery(".em_toggle_merkbox").show();
    jQuery("#merkbox_container").show();
    jQuery("#em_last_searches").hide();
    jQuery("#em_suchtext_header").hide();
    jQuery("#em_last_searches_ergebnis").hide();

    jQuery("#em_toggle_searches").attr("class", "close");
    jQuery("#em_last_searches").css({"width" : "176px"}).hide();
    emInitMerkbox();
    emTooltips();
    emSetCookie("merkbox", "open");
}

function _emCloseMerkbox() {
    jQuery("#em_toggle_merkbox").html("&#09650;");
    jQuery("#em_toggle_merkbox").attr("class", "close");

    jQuery(".em_toggle_merkbox").hide();
    jQuery("#em_last_searches").show();
    jQuery(document).ready(function() {
        jQuery("#em_suchtext_header").show();
    });
    emSetCookie("merkbox", "close");
}


function _emOpenSearchQuerys() {

    jQuery("#em_toggle_searches").html("&#09660;");

    jQuery("#em_toggle_searches").attr("class", "open");
    jQuery("#em_last_searches").animate({"width" : "842px"},500);
    jQuery("#em_last_searches_ergebnis").show();
    jQuery("#merkbox_container").hide();
    jQuery("#em_suchtext_header").hide();

    jQuery("#em_toggle_merkbox").hide;
    jQuery("#em_suchtext_header").hide;
    jQuery("#em_empty_merkbox").hide();

    emSetCookie("searchquery", "open");
}

function _emCloseSearchQuerys() {
    jQuery("#em_toggle_searches").html("&#09650;");
    jQuery("#em_toggle_searches").attr("class", "close");
    jQuery("#em_last_searches").animate({"width" : "176px"},500);
    jQuery("#merkbox_container").show();
    jQuery("#em_last_searches_ergebnis").hide();
    jQuery("#em_suchtext_header").show();

    jQuery("#em_last_searches").show();
    jQuery("#em_suchtext_header").show();
    var strMBoxContent = jQuery("#merkbox > *").length;
    if(strMBoxContent == 0 ) {
        jQuery("#em_empty_merkbox").show();
    }
    emSetCookie("searchquery", "close");
}


/*--------------------
 * SESSION REFRESH
 *------------------*/

var em_hdlAutoRefresh = null;
function _emAutoRefreshSession(_intAction)
{
    if (_intAction == 1) {
        _emAutoRefreshSession(0);
        em_hdlAutoRefresh = window.setInterval('_emAutoRefreshSession()',  60 * 1000);
    } else if (_intAction == 0) {
        if (em_hdlAutoRefresh) {
            clearInterval(em_hdlAutoRefresh);
            em_hdlAutoRefresh = null;
        }
    } else {
        jQuery.ajax({ url: "/_em_oas/ajax/do_session_refresh.php"});
    }
}


/*--------------------
 * REDIRECT TO ANOTHER PAGE
 *------------------*/

function emRedirect(_strDestination, _strText, _intDuration)
{
    var intWidth = "400";
    var intHeight = "300";

    var objRedirectbox = jQuery("<div>")
        .addClass("em_redirect")
        .css({
            "width" : intWidth + "px",
            "display" : "block",
            "text-align" : "center"
        }).html("<span style=\"font-weight: bold;\">" + _strText + "<\/span><br\/><br\/>Sie werden in " + (_intDuration / 1000) + " Sekunden nach " + _strDestination + " weitergeleitet.");


    _emOverlayOpen(
        objRedirectbox,
        {
            "speedCnt" : 1,
            "width" : intWidth,
            "height" : intHeight,
            "content" : "alert"
        }
    );

    setTimeout("_emRedirectAction(\"" + _strDestination + "\")", _intDuration);
}

function _emRedirectAction(_strDestination){
    window.location = _strDestination;
}


/*--------------------
 * ANIMATE FUNCTION BUTTONS
 *------------------*/



function initAnimateFunctionButton() {

    jQuery(".em_content_box_top").bind("mouseover", function() {
       jQuery(this).find(".em_function_button").stop().animate({
           "opacity" : 1
       }, 250);
    });

    jQuery(".em_content_box_top").bind("mouseout", function() {
       jQuery(this).find(".em_function_button").stop().animate({
           "opacity" : 0.5
       }, 250);
    });
}

/*--------------------
 * WAIT PLUGIN
 *------------------*/
 (function($) {
    $.fn.wait = function(option, options) {
        milli = 1000;
        if (option && (typeof option == 'function' || isNaN(option)) ) {
            options = option;
        } else if (option) {
            milli = option;
        }
        // set defaults
        var defaults = {
            msec: milli,
            onEnd: options
        },
        settings = $.extend({},defaults, options);

        if(typeof settings.onEnd == 'function') {
            this.each(function() {
                setTimeout(settings.onEnd, settings.msec);
            });
            return this;
        } else {
            return this.queue('fx',
            function() {
                var self = this;
                setTimeout(function() { $.dequeue(self); },settings.msec);
            });
        }

    }
})(jQuery);


/*--------------------
 * JAVASCRIPT DYNAMISCH LADEN
 *------------------*/

function emLoadScript(scriptname) {
  var snode = document.createElement('script');
  snode.setAttribute('type','text/javascript');
  snode.setAttribute('src',scriptname);
  document.getElementsByTagName('head')[0].appendChild(snode);
}

/*--------------------
 * REMOVE EMPTY ADS
 *------------------*/

jQuery(document).ready(function() {
    jQuery("div.em_ads_box_dynamic_remove").each(function()
    {
        if (jQuery(this).height() < 50) {
            jQuery(this).remove();
        }
    });
});

/*--------------------
 * process global function when document is ready
 *------------------*/


this.emTooltips = function() {
    this.xOffset = -10; // x distance from mouse
    this.yOffset = 30; // y distance from mouse

   jQuery.each(jQuery(".em_tooltip"),
        function() {
            jQuery(this).bind('mouseover',
                function(e) {
                     if(jQuery(this).attr('title') != '' && jQuery(this).attr('title') != 'undefined') {
                        this.t = this.title;
                        this.title = '';

                        this.top = (e.pageY + yOffset);
                        this.left = (e.pageX + xOffset);

                        $('body').append( '<p id="em_tooltip"><img id="em_tooltipArrow" />' + this.t + '</p>' );

                        $('p#em_tooltip #em_tooltipArrow').attr("src", '/_em_oas/_locals/spl/images/_layout/em_tooltip_arrow.png');
                        $('p#em_tooltip').css("top", this.top +"px").css("left", this.left+"px").fadeIn(250);
                     }
                });


            jQuery(this).bind('mouseout',
                function() {
                    this.title = this.t;
                    $("p#em_tooltip").fadeOut("slow").remove();
                }
            );

            jQuery(this).bind('mousemove',
                function(e) {
                    this.top = (e.pageY + yOffset);
                    this.left = (e.pageX + xOffset);

                    $("p#em_tooltip").css("top", this.top +"px").css("left", this.left+"px");
                }
            );
    });

};

jQuery(document).ready(function($){emTooltips();})

