var GATEKEEPERHINWEIS = null;
var COOKIE_GATEKEEPERHINWEIS = null;
var COOKIE_URL  = document.location.pathname.replace('#');
/*
function doIframe(){
	o = document.getElementsByTagName('iframe');
	for(i=0;i<o.length;i++){
		if (/\bautoHeight\b/.test(o[i].className)){
			setHeight(o[i]);
			addEvent(o[i],'load', doIframe);
		}
	}
}

function setHeight(e){
	if(e.contentDocument){
		e.height = e.contentDocument.body.offsetHeight + 35;
	} else {
		e.height = e.contentWindow.document.body.scrollHeight;
	}
}

function addEvent(obj, evType, fn){
	if(obj.addEventListener)
	{
	obj.addEventListener(evType, fn,false);
	return true;
	} else if (obj.attachEvent){
	var r = obj.attachEvent("on"+evType, fn);
	return r;
	} else {
	return false;
	}
}

if (document.getElementById && document.createTextNode){
 addEvent(window,'load', doIframe);	
}
*/

jQuery.preloadImages = function()
{
  for(var i = 0; i<arguments.length; i++)
  {
    jQuery("<img>").attr("src", arguments[i]);
  }
}

jQuery.fn.center = function(params) {

	var options = {
		vertical: false,
		horizontal: true
	}
	
	op = jQuery.extend(options, params);

	return this.each(function(){
	
		//initializing variables
		var $self = jQuery(this);
		//get the dimensions using dimensions plugin
		var width = $self.width();
		var height = $self.height();
		
		//get the paddings
		var paddingTop = parseInt($self.css("padding-top"));
		var paddingBottom = parseInt($self.css("padding-bottom"));
		//get the borders
		var borderTop = parseInt($self.css("border-top-width"));
		var borderBottom = parseInt($self.css("border-bottom-width"));
		if(isNaN(borderBottom)) borderBottom = 0;
		//get the media of padding and borders
		var mediaBorder = (borderTop+borderBottom)/2;
		if(isNaN(mediaBorder)) mediaBorder = 0;
		var mediaPadding = (paddingTop+paddingBottom)/2;
		//get the type of positioning
		var positionType = $self.parent().css("position");
		// get the half minus of width and height
		var halfWidth = (width/2)*(-1);
		var halfHeight = ((height/2)*(-1))-mediaPadding-mediaBorder;
		// initializing the css properties
		var cssProp = {
			position: 'absolute'
		};

		if(op.vertical) {
			$self.css('height', height);
			$self.css('top', ((jQuery(window).height()/2)-50)+'px');
			if(isNaN(halfHeight) == false){
			  $self.css('margin-top',halfHeight+'px');
			}
		}
		if(op.horizontal) {
			$self.css('width', width);
			$self.css('left', '50%');
			if(isNaN(halfWidth) == false){
			  $self.css('margin-left',halfWidth+'px');
			}
			
		}
		//check the current position
		if(positionType == 'static') {
			$self.parent().css("position","relative");
		}
		//aplying the css
		$self.css(cssProp);
	});
};

jQuery.cookie = function(name, value, options) {
	
    if (typeof value != 'undefined') { // name and value given, set cookie
        options = options || {};
        if (value === null) {
            value = '';
            options.expires = -1;
        }
        var expires = '';
        /*
        if (options.expires && (typeof options.expires == 'number' || options.expires.toUTCString)) {
            var date;
            if (typeof options.expires == 'number') {
                date = new Date();
                date.setTime(date.getTime() + (options.expires * 24 * 60 * 60 * 1000));
            } else {
                date = options.expires;
            }
            expires = '; expires=' + date.toUTCString(); // use expires attribute, max-age is not supported by IE
        }
        */
        // CAUTION: Needed to parenthesize options.path and options.domain
        // in the following expressions, otherwise they evaluate to undefined
        // in the packed version for some reason...
        var path = options.path ? '; path=' + (options.path) : '';
        var domain = options.domain ? '; domain=' + (options.domain) : '';
        var secure = options.secure ? '; secure' : '';
        document.cookie = [name, '=', encodeURIComponent(value), expires, path, domain, secure].join('');
    } else { // only name given, get cookie
        var cookieValue = null;
        if (document.cookie && document.cookie != '') {
            var cookies = document.cookie.split(';');
            for (var i = 0; i < cookies.length; i++) {
                var cookie = jQuery.trim(cookies[i]);
                // Does this cookie string begin with the name we want?
                if (cookie.substring(0, name.length + 1) == (name + '=')) {
                    cookieValue = decodeURIComponent(cookie.substring(name.length + 1));
                    break;
                }
            }
        }
        return cookieValue;
    }
};

function setGatekeeper(type, status){
  if(type != ''){
	GATEKEEPERHINWEIS = type;
	COOKIE_GATEKEEPERHINWEIS = 'gatekeeper_'+type;	  
	cookie = COOKIE_GATEKEEPERHINWEIS;
  }
  else{
	  cookie = null; 
  }
  
  if(cookie !== null){
    jQuery.cookie('1', status, { expires: 7 });
  }
  
  jQuery('#gatekeeperblocker').css('display', 'none');
  jQuery('#div_'+type).css('display', 'none');
  
  if(status == 1){
	  jQuery('#blockContentInner').css('visibility', 'visible');
	  jQuery('#blockRightInner').css('visibility', 'visible');
  }
  else{
	history.back();  
  }
  
  return false;	
}

function setHyporechner(type, status){
  jQuery.cookie(type, status, { expires: 7 });
}

function getHyporechner(type){
  return jQuery.cookie(type);
}


jQuery.fn.browserDetection = function() {
	jQuery.os = {name: (/(win|mac|linux|sunos|solaris|iphone)/.exec(navigator.platform.toLowerCase()) || [u])[0].replace('sunos', 'solaris')};
	
	var userAgent = navigator.userAgent.toLowerCase();
	
	jQuery.browser.chrome = /chrome/.test(navigator.userAgent.toLowerCase()); 
	
	if(jQuery.browser.msie){
	    jQuery('body').addClass('browserIE');
	    jQuery('body').addClass('browserIE' + jQuery.browser.version.substring(0,1));
	}
	
	if(jQuery.browser.chrome){
	
	    jQuery('body').addClass('browserChrome');
	    userAgent = userAgent.substring(userAgent.indexOf('chrome/') +7);
	    userAgent = userAgent.substring(0,1);
	    jQuery('body').addClass('browserChrome' + userAgent);
	    
	    jQuery.browser.safari = false;
	}
	
	if(jQuery.browser.safari){
	    jQuery('body').addClass('browserSafari');
	    userAgent = userAgent.substring(userAgent.indexOf('version/') +8);
	    userAgent = userAgent.substring(0,1);
	    jQuery('body').addClass('browserSafari' + userAgent);
	}
	
	
	if(jQuery.browser.mozilla){
	    if(navigator.userAgent.toLowerCase().indexOf('firefox') != -1){
	        jQuery('body').addClass('browserFirefox');
	        userAgent = userAgent.substring(userAgent.indexOf('firefox/') +8);
	        userAgent = userAgent.substring(0,1);
	        jQuery('body').addClass('browserFirefox' + userAgent);
	    }
	    else{
	        jQuery('body').addClass('browserMozilla');
	    }
	}
	
	if(jQuery.browser.opera){
	    jQuery('body').addClass('browserOpera');
	}
	
	jQuery('body').addClass(jQuery.os.name);
};
