//Splashpage
//Vítězslav Sára

(function(){

    var self = {

        // Splash Page Script Activation (1=enabled, 0=completely disabled!)
        splashenabled: 1,

        //1) URL to file on your server to display as the splashpage
        splashpageurl: "http://images.google.com/",

        //2) Enable frequency control? (1=yes, 0=no)
        enablefrequency: 0,

        //3) display freqency: "sessiononly" or "x days" (string value). Only applicable if 3) above is enabled
        displayfrequency: "2 days",

        //4) HTML for the header bar portion of the Splash Page
        // Make sure to create a link that calls "javascript:splashpage.close()")
        // An IE bug means you should not right align any image within the bar, but instead use "position:absolute" and the "right" attribute

        defineheader: '<div style="padding: 5px; color: white; font: bold 16px Verdana; background: black url(blockdefault.gif) center center repeat-x;"><a style="position:absolute; top: 2px; right: 5px" href="javascript:splashpage.close()" title="Skip to Content"><img src="skip.gif" border="0" width="114px" height="23px" /></a>Bought to you by Google Image...</div>',

        //5) cookie setting: ["cookie_name", "cookie_path"]
        cookiename: ["splashpagecookie", "path=/"],

        //6) Auto hide Splash Page after x seconds (Integer value, 0=no)?
        autohidetimer: 15,

        ////No need to edit beyond here//////////////////////////////////

        launch: false,
        browserdetectstr: (window.opera && window.getSelection) || (!window.opera && window.XMLHttpRequest), //current browser detect string to limit the script to be run in (Opera9 and other "modern" browsers)
        output: function(){
            document.write('<div id="splashpage" style="position: absolute; z-index: 100;background-color:white">') //Main splashpage container
            document.write(self.defineheader) //header portion of splashpage
            document.write('<iframe name="splashpage-iframe" src="about:blank" style="margin:0; padding:0; width:100%; height: 100%"></iframe>') //iframe
            document.write('<br />&nbsp;</div>')
            self.splashpageref = document.getElementById("splashpage")
            self.splashiframeref = window.frames["splashpage-iframe"]
            self.splashiframeref.location.replace(self.splashpageurl) //Load desired URL into splashpage iframe
            self.standardbody = (document.compatMode == "CSS1Compat") ? document.documentElement : document.body
            if (!/safari/i.test(navigator.userAgent)) //if not Safari, disable document scrollbars
                self.standardbody.style.overflow = "hidden"
            self.splashpageref.style.left = 0
            self.splashpageref.style.top = 0
            self.splashpageref.style.width = "100%"
            self.splashpageref.style.height = "100%"
            self.moveuptimer = setInterval("window.scrollTo(0,0)", 50)
        },

        close: function(){
            clearInterval(self.moveuptimer)
            self.splashpageref.style.display = "none"
            self.splashiframeref.location.replace("about:blank")
            self.standardbody.style.overflow = "auto"
        },

        init: function(){
			if (!self.splashenabled) {
				return;
			};
            if (self.enablefrequency == 1) { //if frequency control turned on
                if (/sessiononly/i.test(self.displayfrequency)) { //if session only control
                    if (self.getCookie(self.cookiename[0] + "_s") == null) { //if session cookie is empty
                        self.setCookie(self.cookiename[0] + "_s", "loaded")
                        self.launch = true
                    }
                }
                else
                    if (/day/i.test(self.displayfrequency)) { //if persistence control in days
                        if (self.getCookie(self.cookiename[0]) == null || parseInt(self.getCookie(self.cookiename[0])) != parseInt(self.displayfrequency)) { //if persistent cookie is empty or admin has changed number of days to persist from that of the stored value (meaning, reset it)
                            self.setCookie(self.cookiename[0], parseInt(self.displayfrequency), parseInt(self.displayfrequency))
                            self.launch = true
                        }
                    }
            }
            else //else if enablefrequency is off
                 self.launch = true
            if (self.launch) {
                self.output()
                if (parseInt(self.autohidetimer) > 0)
                    setTimeout("splashpage.close()", parseInt(self.autohidetimer) * 1000)
            }
        },

        getCookie: function(Name){
            var re = new RegExp(Name + "=[^;]+", "i"); //construct RE to search for target name/value pair
            if (document.cookie.match(re)) //if cookie found
                return document.cookie.match(re)[0].split("=")[1] //return its value
            return null
        },

        setCookie: function(name, value, days){
            var expireDate = new Date()
            //set "expstring" to either an explicit date (past or future)
            if (typeof days != "undefined") { //if set persistent cookie
                var expstring = expireDate.setDate(expireDate.getDate() + parseInt(days))
                document.cookie = name + "=" + value + "; expires=" + expireDate.toGMTString() + "; " + splashpage.cookiename[1] //last portion sets cookie path
            }
            else //else if self is a session only cookie setting
                 document.cookie = name + "=" + value + "; " + splashpage.cookiename[1] //last portion sets cookie path
        }
    }
    splashpage = self;
})();

