/**
 * @requires jquery-1.3.2
 *
 * this function will first call background-slides
 * after this it will call the language-selection
 *
 */
function siteOverlay()
{
    this.init = function(overlayHTML)
    {

    	var showOverlay = true;
    	
    	if (this.readCookie('hideoverlay') == 1) {
    		showOverlay = false;
    	} else if (this.readParam('hideoverlay') == 1) {
            this.createCookie('hideoverlay' ,1, 0);
    		showOverlay = false;
    	}
    	
    	
    	if (showOverlay) {

            $('#body').css( 'display' , 'none' );
            $('#footer-container').css( 'display' , 'none' );
            $('body').append(overlayHTML);

            $('#overlay').fadeIn( 2000 , function () { });

            $(this).oneTime(2000, function() {
                $('#overlay-slides').fadeIn( 500 , function () {
                    $('#overlay').css( 'background', 'none' );
                    $('#overlay-slides').cycle({ fx: 'fade', speed: 2000, timeout: 3000 });
                    $('#language-selection').show( 'slide', { direction: "right" }, 400);
                })
            });
        }

        var that = this;

        $('#language-selection a').bind('click', function(event) { event.preventDefault(); that.fadeOut(event, $(this).context.href) });

    }

    this.fadeOut = function(event, href) {

        this.createCookie('hideoverlay' ,1, 0);
        $('#overlay').fadeOut( 500, function () { $(location).attr('href',href); } );

    }

    this.createCookie = function(name,value,days) {
        if (days) {
            var date = new Date();
            date.setTime(date.getTime()+(days*24*60*60*1000));
            var expires = "; expires="+date.toGMTString();
        }
        else var expires = "";
        document.cookie = name+"="+value+expires+"; path=/";
    }

    this.readCookie = function(name) {
        var nameEQ = name + "=";
        var ca = document.cookie.split(';');
        for(var i=0;i < ca.length;i++) {
            var c = ca[i];
            while (c.charAt(0)==' ') c = c.substring(1,c.length);
            if (c.indexOf(nameEQ) == 0) return c.substring(nameEQ.length,c.length);
        }
        return null;
    }
    
    this.readParam = function(name) {

		  var strReturn = "";
		  var strHref = document.location.href;
		  if ( strHref.indexOf("?") > -1 ){
		    var strQueryString = strHref.substr(strHref.indexOf("?")).toLowerCase();
		    var aQueryString = strQueryString.split("&");
		    for ( var iParam = 0; iParam < aQueryString.length; iParam++ ){
		      if (aQueryString[iParam].indexOf(name + "=") > -1 ){
		        var aParam = aQueryString[iParam].split("=");
		        strReturn = aParam[1];
		        break;
		      }
		    }
		  }
		  return unescape(strReturn);
    }    	
    	
    this.eraseCookie = function(name) {
        createCookie(name,"",-1);
    }

}

