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

jQuery.noConflict();


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;
};


/*--------------------
 * 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 || '';

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

        var objBoxBg = jQuery('<div>')
            .attr('id', 'emBoxBg')
            .css({
                'display' : 'none',
                'position' : 'absolute',
                'z-index' : '99980',
                'background-color' : '#E9E8E5',
                'left' : '0px',
                'top' : '0px',
                'height' : arrPageSize[1] + 'px',
                'width' : arrPageSize[2] + 'px',
                'opacity' : 0.7
            })
            //.click(emBoxClose) //--> Change amoerke 2009-08-21 Do not close by clicking the background of the lightbox
                                 //--> This could cause a loss of designwork in the adfrend by the customer perhaps
            .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 emBoxClose()
{
    _emOverlayClose();
}



/*--------------------
 * 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
        );
    }
}


function emOpenAdfrend(objElement, strName, strOptions){

    var strBoxContent = "";
    var objOptions = {};

	if (!strHeight) {
	    var strHeight = 0;

	    if (strOptions.match(/(^\s*|,)height=(\d+)(,|\s*$)/)) {
	        strHeight = RegExp.$2;
	    } else {
    	    strHeight = 350;
	    }
	}

	if (!strWidth) {
	    var strWidth = 0;

	    if (strOptions.match(/(^\s*|,)width=(\d+)(,|\s*$)/)) {
	        strWidth = RegExp.$2;

	    } else {
    	    strWidth = 600;
	    }
	}
    objOptions.height = strHeight;
    objOptions.width = strWidth;

    strBoxContent = "<iframe src=\"" + objElement + "\" scrolling=\"no\" style=\"width:" + strWidth + "px; height:" + strHeight + "px; frame-border: 0px; border: 0px; padding: 0px;\" border=\"0\" frameborder=\"0\" marginheight=\"0\" marginwidth=\"0\" scrolling=\"auto\" id=\"emBoxIf\" name=\"" + strName + "\"></iframe>"
                + "<div style=\"line-height: 18px; background-color: #fff; padding: 5px; font-family: Verdana; position: absolute; top: 0px; right: 6px;z-index: 1000;z-index: 1000;\">"
                + "<a href=\"javascript:emBoxClose();em_set('em_aufgabe_step',1);em_submit();\" style=\"font-weight: bold; font-size: 12px; color: #EE121C;\">schlie&szlig;en "
                + "<span style=\"color: #000;\">x</span></a></div>";

    _emOverlayOpen(strBoxContent, objOptions);



    return false;
}

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

jQuery(document).ready(function() {


});
