/**
* jQuery Cookie plugin
*
* Copyright (c) 2010 Klaus Hartl (stilbuero.de)
* Dual licensed under the MIT and GPL licenses:
* http://www.opensource.org/licenses/mit-license.php
* http://www.gnu.org/licenses/gpl.html
*
*/
jQuery.cookie = function (key, value, options) {

    // key and at least value given, set cookie...
    if (arguments.length > 1 && String(value) !== "[object Object]") {
        options = jQuery.extend({}, options);

        if (value === null || value === undefined) {
            options.expires = -1;
        }

        if (typeof options.expires === 'number') {
            var days = options.expires, t = options.expires = new Date();
            t.setDate(t.getDate() + days);
        }

        value = String(value);

        return (document.cookie = [
            encodeURIComponent(key), '=',
            options.raw ? value : encodeURIComponent(value),
            options.expires ? '; expires=' + options.expires.toUTCString() : '', // use expires attribute, max-age is not supported by IE
            options.path ? '; path=' + options.path : '',
            options.domain ? '; domain=' + options.domain : '',
            options.secure ? '; secure' : ''
        ].join(''));
    }

    // key and possibly options given, get cookie...
    options = value || {};
    var result, decode = options.raw ? function (s) { return s; } : decodeURIComponent;
    return (result = new RegExp('(?:^|; )' + encodeURIComponent(key) + '=([^;]*)').exec(document.cookie)) ? decode(result[1]) : null;
};

function redirect_now() {
    
	if (navigator.cookieEnabled == true) {
	
		var urlString = document.location.href;	
		var baseLength = sPfadRoot.length;
		var redirectPath = urlString.substr(baseLength);
		var getSave = $.cookie('FLASH');
		
		if(getSave == null) {	
			save = 'FLASH=1';
			$.cookie('FLASH', 1, {path: '/'});
		}
		if(redirectPath == '') {
			self.location.href = sPfadRoot;
		} else {
			if(redirectPath.indexOf('#') > -1) {
				location.reload();
			} else {
				self.location.href = sPfadRoot+'#/'+redirectPath;
			}
		}
	} else {
		if($('#flashContainer')) {
			$('#flashContainer').remove();
		}
		return false;
	}
    
}

function redirect() {
	setTimeout('redirect_now()', 1);
}

function redirectHtml() {
	if (navigator.cookieEnabled == true) {	
		var flash = $.cookie('FLASH');

		$.cookie('FLASH', null, {path: '/'});
		var urlString = document.location.href;
		var reg = '.*?#/(.*)$';
		var url = urlString.match(reg);
 
		if(url) {
			self.location.href = sPfadRoot+url[1];
		} else if(flash == 1) {
			self.location.href = sPfadRoot;
		}
	} else {
		if($('#flashContainer')) {
			$('#flashContainer').remove();
		}
		return false;
	}
}

function initResize(){
	window.onresize = resizeSpacer;
	resizeSpacer();
}

function Fensterhoehe()
{
 if (window.innerHeight) return window.innerHeight;
 else if (document.body && document.body.clientHeight) return document.body.clientHeight;
 else return 0;
}

function goToHtmlPage() {
	$.cookie('FLASH', null, {path: '/'});
    $.cookie('NOFLASH', 1, {path: '/'})
	self.location.href = sPfadRoot;
}
function goToFlashPage() {
	$.cookie('NOFLASH', null, {path: '/'});
    $.cookie('FLASH', 1, {path: '/'})
	self.location.href = sPfadRoot;
}

function resizeSpacer(){
	
	var el = document.getElementById('dynamicSpacer');
	
	if(el) {		
		if(Fensterhoehe() >= 660){
			el.style.height="50px";
		}else{
			el.style.height="25px";
		}
	}
}


function removeDiv() {
     var el = $('#mainDiv');
     if(el) {
        el.remove();
     }
}


