/*
* loadFullScreenIframe
* @param {String} url the url which should open in the iframe
* @param {String} lang the active language
* @param {String} (optional) the background-color as hexcode for the fade-in, default: #E4E3DA
* @param {String} (optional) hash, default: null
* @param {String} (optional) closeBtnRight, default: 18px
* @param {String} (optional) closeBtnTop, default: 18px
* @param {Booelan} (optional) displayCloseBtnImage, default: true
*/
function loadFullScreenIframe(url, lang, initBgColor, hash, closeBtnRight, closeBtnTop,displayCloseBtnImage) {      
 

    window.scrollTo(0, 0);
    if(initBgColor == null) initBgColor = '#E4E3DA';
    if(closeBtnRight == null) closeBtnRight = '18px';
    if(closeBtnTop == null) closeBtnTop = '18px';
    if(displayCloseBtnImage == null) displayCloseBtnImage = true;
    if(lang.length == 2) {
        lang = lang+'-'+lang;
    }
    var openUrl = url+((url.indexOf('?') == -1) ? '?' : '&')+'lang='+lang;
    
    if(hash != null) {
        openUrl += hash;
    }
    
    jQuery('body').css('overflow','hidden').prepend(jQuery('<div id="fullScreenContainer">').css({
        'width':'100%',
        'height':'100%',
        'position':'absolute',
        'background-color':initBgColor,
        'z-index':'200',
        'top':'0',
        'left':'0'
    })
    .append(jQuery('<div id="fullScreenIframeContainer">)').css('height','100%')
        ).fadeIn(500, function() {
        jQuery('#fullScreenIframeContainer').append(jQuery('<iframe id="fullScreenIframe" src="'+openUrl+'" frameboarder="0">').css({
            'width':'100%',
            'height':'100%'
        }));
        jQuery('#fullScreenIframeContainer').append(jQuery('<div id="closeFullScreenContainer">').css({
            'position':'absolute',
            'top':'0',
            'right':'0',
            'right':closeBtnRight,
            'top':closeBtnTop,
            'z-index':'201',
            'cursor':'pointer',
            'color':'#ffffff',
            'background-color':'transparent'
        }));       

        
        if(displayCloseBtnImage) {
            jQuery('#closeFullScreenContainer').append('<img widh="50" height="53" alt="close" border="0" src="http://emagazin.pfisterag.ch/close.png">').click(closeFullScreenIframe);
        } else {
            jQuery('#closeFullScreenContainer')
            .append('<div>').css({
                'background' : 'url(\'http://www.pfister.ch/img/icons/filter_expand.gif\')',
                'background-position' : '2px',
                'background-repeat': 'repeat',
                'width' : '100px',
                'height' : '53px'
            }).click(closeFullScreenIframe);
        }
        
    })
    );
    
}


function closeFullScreenIframe() {
    jQuery('#fullScreenContainer').remove();
    jQuery('body').css('overflow','auto')
}

//check if necessary to load fullScreenIframe
jQuery(function() {

	//config
	var config = {
		    "/de/sofaspiel.html": {link: 'http://meinsofa.pfister-game.ch/home/', lang: 'de', closeBtnRight:'52px', closeBtnTop:'5%', displayCloseBtnImage:false},
		    "/fr/sofaspiel.html": {link: 'http://meinsofa.pfister-game.ch/home/', lang: 'fr', closeBtnRight:'52px', closeBtnTop:'5%', displayCloseBtnImage:false},
		    "/it/sofaspiel.html": {link: 'http://meinsofa.pfister-game.ch/home/', lang: 'it', closeBtnRight:'52px', closeBtnTop:'5%', displayCloseBtnImage:false}
	};

    var loc = window.document.location;
    var configPart = config[loc.pathname];
    
    if(configPart != undefined) {    
        if(loc.hash != '' && loc.hash != '#') {
            loadFullScreenIframe(configPart.link, configPart.lang, null, loc.hash, configPart.closeBtnRight, configPart.closeBtnTop, configPart.displayCloseBtnImage);
        }
    }
    
});


