Kino.Advertising = {

    initWallpaper: function() {

        var tmpBannerVar;
        var destBanner;

        if (document.getElementById) {

            tmpBannerVar = document.getElementById('bannerTmp');
            if (LeaderBoard == 1 && wallpaper == 1) {

                    document.getElementById('contentAdHeader').style.display = 'block';
                    destBanner = document.getElementById('contentAdHeader');
            }  else {

                destBanner = document.getElementById('ad-fullsize');
            }

            if (tmpBannerVar && destBanner) {

                if ((navigator.userAgent.toLowerCase().indexOf("msie") != -1) &&
                    (navigator.userAgent.toLowerCase().indexOf("mac") != -1)) {

                    // do nothing
                } else {

                    while ((tmpBannerChild = tmpBannerVar.firstChild)) {

                        if (tmpBannerChild.tagName && tmpBannerChild.tagName.toLowerCase() == "script") {

                            tmpBannerVar.removeChild(tmpBannerChild);
                        } else {

                            destBanner.appendChild(tmpBannerChild);
                        }
                    }
                }
            }
        }
    },

    // Ligatus and skyscraper
    checkAdvertising: function() {

        Kino.Advertising.MediumRectangle.checkAd();
        //Kino.Advertising.ArticleEnd.checkAd();
    },

    // MR
    checkAdvertisingMediumRectangle: function() {

        Kino.Advertising.MediumRectangle.checkAd();
    },

    // Promo
    checkAdvertisingPromo: function() {

        //Kino.Advertising.PromoTeaser.checkAd();
    },

    // Performance Intterupt
    checkAdvertisingPerformanceInterrupt: function() {

        Kino.Advertising.PerformanceInterrupt.checkAd();
    },

    // Performance End
    checkAdvertisingPerformanceEnd: function() {

        Kino.Advertising.PerformanceEnd.checkAd();
    },

    // Halfpage
    checkAdvertisingHalfPage: function() {

        Kino.Advertising.HalfPage.checkAd();
    },

    // Superbanner
    checkAdvertisingSuperbanner: function() {

        Kino.Advertising.Superbanner.checkAd();
    },

    // Skyscraper
    checkAdvertisingSkyscraper: function() {

        Kino.Advertising.Skyscraper.checkAd();
    }
};

// Additional methods
Kino.Advertising.MediumRectangle = {

    checkAd: function() {

        var cont = document.getElementById('adMedRectContent');

        // Without next line js-execution will stop without a warning or error message!!!
        if (cont === null) {

            return;
        }

        // Check if box may be shown; 'contentad' variable => comes from EMS
        // If halfpage ad is to be shown, hide this ad ('halfpage' variable => comes from EMS)
        if ('undefined' == typeof(contentad) || contentad != 1 ||
           ('undefined' != typeof(halfpage) && halfpage == 1)) {

            document.getElementById('adMedRect').style.display = 'none';
            return;
        }
    }
};

Kino.Advertising.PerformanceInterrupt = {
		
	checkAd: function() {

		var isSet = true;
	
		if ('undefined' == typeof(performance_contentmitte) || performance_contentmitte != 1) {
			
			isSet = false;
		} 
	
		// Validate nodes, because at least one DIV node has to be within content block
		var isValid = Kino.Advertising.Content.validate(document.getElementById('performanceTeaserInterruptContent'));                 
                
        // No element found, hide the whole ad block
        if (false === isValid || false === isSet) {
        	
        	document.getElementById('performanceTeaserInterrupt').style.display = 'none';        	
        }      
    }
};

Kino.Advertising.PerformanceEnd = {

	checkAd: function() {

		var isSet = true;
	
		if ('undefined' == typeof(performance_contentende) || performance_contentende != 1) {
		
			isSet = false;
		}
	
		// Validate nodes, because at least one DIV node has to be within content block
		var isValid = Kino.Advertising.Content.validate(document.getElementById('performanceTeaserEndContent'));                 
                
        // No element found, hide the whole ad block
        if (false === isValid || false === isSet) {
        	
        	document.getElementById('performanceTeaserEnd').style.display = 'none';        	
        }    
    }
};

Kino.Advertising.Content = {
		
	validate: function(elementId) {
	
		var isValid = false;
	
	    if (elementId.hasChildNodes()) {
	    	
	    	elementIdChildren = elementId.childNodes;

	    	if (elementIdChildren.length != 0) {
	    		// Walk through array with children and try to find a DIV element
	    		for (var i = 0, item; item=elementIdChildren[i]; i++) {

	    			if ('1' == elementIdChildren[i].nodeType && 'DIV' == elementIdChildren[i].nodeName) {
	    				// DIV may not be empty (be as sure as possible to avoid wrong hiding)
	    				if (elementIdChildren[i].hasChildNodes) {
	    				
	    					isValid = true;
	    				}	    				
	    			}        			
	    		}
	    	}
	    }

	    return isValid;	
	}
}

Kino.Advertising.HalfPage = {

        checkAd: function(element) {

        //  Check if box may be shown; 'halfpage' variable => comes from EMS
        if (('undefined' == typeof(halfpage) || halfpage != 1)) {

            document.getElementById('halfPageAd').style.display = 'none';
            return;
        }
    }
};

Kino.Advertising.Superbanner = {

        checkAd: function() {

        // Check if box may be shown; 'Leaderboard' variable => comes from EMS
        if ('undefined' == typeof(Leaderboard) || Leaderboard != 1) {

            document.getElementById('suberbanner').style.display = 'none';
            return;
        }
    }
};

Kino.Advertising.Skyscraper = {

        checkAd: function() {


        // Check if box may be shown; 'skyscraper' variable => comes from EMS
        if ('undefined' == typeof(skyscraper) || skyscraper != 1) {

            document.getElementById('skyscraper').style.display = 'none';
            return;
        }
    }
};

Kino.Advertising.ArticleEnd = {

    checkAd: function() {

        // Check ad content and set display options.
        var cont = document.getElementById('adArticleEndContent');
        var elemsDiv = cont.getElementsByTagName('div');
        var elemsIns = cont.getElementsByTagName('ins');

        var checkDiv = true;
        var checkIns = true;

        // Check, if no ad was sent from server - then hide the block
        if (elemsDiv.length <= 1 ||
            ('undefined' != typeof(elemsDiv[1]) && elemsDiv[1].innerHTML.length <= 10)) {

                checkDiv = false;
        }

        // Check, if no ad was sent from server - then hide the block
        if (elemsIns.length <= 1 ||
            ('undefined' != typeof(elemsIns[1]) && elemsIns[1].innerHTML.length <= 10)) {

            checkIns = false;
        }

        // Check if box may be shown;
        if (!checkDiv && !checkIns) {

            document.getElementById('adArticleEnd').style.display = 'none';
            return;
        }
    }
};
