/*
BASIC USAGE: Place ABC_Script.init(); in JavaScript tags somewhere in your BODY or call ABC_Script.init('id'); on-the-fly passing a non-hidden DOM element's 'id'.
If you have settings.video.show set to true, please note that you will need to also include the swfobject.js file as well as have the JW FLV Media Player swf file provided here: http://www.longtailvideo.com/players/jw-flv-player/
*/
var ABC_Script = { //Alert Before Close Script
    //USER-CHANGEABLE SETTINGS
    shown: (document.cookie.length>0 && document.cookie.indexOf("exitoffer20090630=1")!=-1),
    settings: { 
        alertMessage: {
            preText: "*****************************************************", //Shown above/before the message
            text: "DON'T CLOSE THE PAGE! CLICK CANCEL!", //Message shown to them when trying to close the page
            postText: "*****************************************************" //Shown under/after the message
        },
        video: {
            show: true, //Pop up a video when trying to close page too? true or false
            height: 281, //The height of the video in pixels
            width: 500, //The width of the video in pixels
            location: "http://cdn.cloudfiles.mosso.com/c60902/Exit Offer.flv", //The location to a file usable by JW FLV Media Player to use for the video; can be relative or absolute, as long as it's accessible by this page
            swfFile: "player.swf", //The location to the JW FLV Media Player swf file which'll be used to play your video.location file.
            position: {
                top: 15, //The number of pixels between the top of the video and the top of the browser page
                left: 30 //The number of pixels between the left of the video and the left of the browser page
            },
            closeImg: {
                show: true, //If set to true, will show the vidCloseImg with the vidCloseText as the ALT/title. If false, it will show a regular text link with vidCloseText
                location: "close.png", //The location to the image to use for the close button; can be relative or absolute, as long as it's accessible by this page.
                width: 18, //The width in pixels to resize the close image to; if set to null, the image's width will not be resized. Example: width: null
                height: 18 //The height in pixels to resize the close image to; if set to null, the image's height will not be resized. Example: height: null
            },
            closeText: "Close", //Text to use for close link if you do not wish to use the image; will also be the image's ALT text and will show when hovering over the image if vidCloseImg.show is true
            flashVars: {skin: 'stylish_slim.swf', stretching: 'fill'} //You can put EXTRA flashvars here; not required and not recommended unless you know what you're doing! file/autostart/width/height are pre-set. Format: {varName: 'varValue', varName2: 'varValue2'}
        }
    },
    //THE REST OF THIS FILE CAN BE EDITED AT YOUR OWN RISK!
    init: function(id) {
        /*You can provide an OPTIONAL id parameter when calling this.
        If one is provided, the video HTML is written to the element defined with the id. This is useful if you want to be able to call the function after the page has loaded. Note that the element with the id shouldn't be hidden.
        If one isn't provided, the HTML is written directly into the document where the function is called, which means it must be called before the page is done loading and should be somewhere within the BODY.
        Note that if settings.showVid is set to false, you do not have to worry about passing an ID or calling init within the BODY; calling it will simply initiate the alert box.*/
        if (ABC_Script.shown)
            return;
        if(ABC_Script.settings.video.show) {
            var html  = '<div id="ABC_vidMainContainer" style="display:none; text-align: center;z-index:1000; position: fixed; top: ' + ABC_Script.settings.video.position.top + 'px; left: ' + ABC_Script.settings.video.position.left + 'px; width: ' + ABC_Script.settings.video.width + 'px;">' +
                            '<table width="98%" align="center" border="0" cellpadding="0" cellspacing="0">' +
                                '<tr style="background-color: #cccccc;">' +
                                    '<td >&nbsp;</td>' + 
                                    '<td align="right">' + 
                                        (ABC_Script.settings.video.closeImg.show ? ('<img src="' + ABC_Script.settings.video.closeImg.location + '" alt="' + ABC_Script.settings.video.closeText + '" title="' + ABC_Script.settings.video.closeText + '" onClick="document.getElementById(\'ABC_vidContainerTD\').innerHTML=\'\';document.getElementById(\'ABC_vidMainContainer\').style.display=\'none\';" style="cursor:pointer;' + (ABC_Script.settings.video.closeImg.width != null ? 'width:' + ABC_Script.settings.video.closeImg.width + 'px;':'') + (ABC_Script.settings.video.closeImg.height != null ? 'height:' + ABC_Script.settings.video.closeImg.height + 'px;':'') + '" />')
                                        : ('<span onClick="document.getElementById(\'ABC_vidContainerTD\').innerHTML=\'\';document.getElementById(\'ABC_vidMainContainer\').style.display=\'none\';" style="cursor:pointer">' + ABC_Script.settings.video.closeText + '</span>&nbsp;&nbsp;')) +
                                    '</td>' +
                                '</tr>' +
                                '<tr><td colspan="2" id="ABC_vidContainerTD"><div id="ABC_vidContainer" style="position:relative; top:2px"></div></td></tr>' +
                            '</table>' +
                        '</div>';
            if(typeof id != 'undefined')
                document.getElementById(id).innerHTML = html;
            else
                document.write(html);
            var flashVars = (typeof ABC_Script.settings.video.flashVars == typeof {}) ? ABC_Script.settings.video.flashVars : {};
            flashVars['file'] = ABC_Script.settings.video.location;
            flashVars['autostart'] = true;
            flashVars['width'] = ABC_Script.settings.video.width;
            flashVars['height'] = ABC_Script.settings.video.height;
            swfobject.embedSWF(ABC_Script.settings.video.swfFile, "ABC_vidContainer", ABC_Script.settings.video.width, ABC_Script.settings.video.height, "8", null, flashVars);
        }
        window.onbeforeunload = ABC_Script.show;
        var exdate=new Date();
        exdate.setDate(exdate.getDate()+365);
        //document.cookie="exitoffer20090630=1;expires="+exdate.toGMTString();
    },
    
    show: function() {
        if (ABC_Script.shown)
            return;
        ABC_Script.shown = true;
        if(ABC_Script.settings.video.show)
            document.getElementById("ABC_vidMainContainer").style.display='block';
			document.getElementById('mainvideo').sendEvent('STOP');

        var msg = "";
        
        if(ABC_Script.settings.alertMessage.preText.length)
            msg += ABC_Script.settings.alertMessage.preText + "\n\n";
        
        msg += ABC_Script.settings.alertMessage.text;
        
        if(ABC_Script.settings.alertMessage.postText.length)
            msg += "\n\n" + ABC_Script.settings.alertMessage.postText;
        
        return msg;
    },
    
    cancel: function() {
        ABC_Script.shown = true; //We're lying to it
    }
}