﻿
function getDocumentObject() {
    var a = null; /*Document Object*/
    if (document.body) {
        a = document.body;
    } else {
        if (document.documentElement) {
            a = document.documentElement;
        } else {
            a = null;
        }
    }
    return a;
}

function setCookie(p1, p2, p3) {
    /*Last Updated on 4/18/2009 by Steven Katch*/
    /*Set a cookie*/
    /*p1:  name*/
    /*p2:  value*/
    /*p3:  days (empty will destroy cookie on browser close*/

    /*ErrorTrapping*/try {
        var a = null; /*Date Object*/
        var b = ''; /*Cookie Expiration*/
        var c = ''; /*Time*/

        p1 = p1 + window.location.host;  /*Prevent access from domains with different aliases and ports*/

        if (p3) {
            a = new Date();
            c = a.getTime() + Math.round(p3 * 24 * 60 * 60 * 1000);
            a.setTime(c);
            b = ';expires=' + a.toGMTString();
        }

        /*ADDING PROPERTY DOMAIN TO COOKIE IS REQUIRED, HOWEVER IN DEVELOPMENT IT DOES NOT WORK*/
        /*     ADDED SWITCH TO ALLOW DEVELOPMENT TO WORK AND PRODUCTION WITH SAME CODE*/
        if (window.location.host.indexOf('localhost') < 0) {
            document.cookie = p1 + "=" + p2 + b + ";path=/;domain=" + window.location.host;
        } else {
            document.cookie = p1 + "=" + p2 + b;
        }
        /*ErrorTrapping*/
    } catch (e_) { LogJSError(e_, arguments.callee.toString()); }
}

function getCookie(p1) {
    /*Last Updated on 4/18/2009 by Steven Katch*/
    /*read a cookie*/
    /*p1:  p1*/

    /*ErrorTrapping*/try {
        p1 = p1 + window.location.host;  /*Prevent access from domains with different aliases and ports*/
        var a = '';
        var b = p1 + "=";
        var c = document.cookie.split(';');
        for (var d = 0; d < c.length; d++) {
            var e = c[d];
            while (e.charAt(0) == ' ') e = e.substring(1, e.length);
            if (e.indexOf(b) == 0) {
                a = e.substring(b.length, e.length);
                a = a.replace('null', '');
                return a;
            }
        }
        a = a.replace('null', '');
        return a;
        /*ErrorTrapping*/
    } catch (e_) { LogJSError(e_, arguments.callee.toString()); }
}


function attachEvent_(p1, p2, p3, p4) {
    var a = document.getElementById(p1)

    if (a) {
        if (typeof p3 == 'function') {
            if (p2 != '') {
                if (!p4) p4 = false;
                if (a.addEventListener) {
                    a.removeEventListener(p2, p3, p4);
                    a.addEventListener(p2, p3, p4);
                    return true;
                } else if (a.attachEvent) {
                    a.detachEvent("on" + p2, p3);
                    a.attachEvent("on" + p2, p3);
                    return true;
                }
            }
        }
    }
}

function createDialog(id) {
    $('#' + id).dialog({
        disabled: false,
        autoOpen: false,
        closeOnEscape: true,
        draggable: true,
        resizable: true,
        stack: true,
        //show: 'fade',
        //hide: 'fade', 
        modal: true,
        position: 'center',
        title: 'Vintage European Posters',
        height: 740,
        width: 840,
        maxHeight: 900,
        maxWidth: 1200,
        minHeight: 600,
        minWidth: 800
    });
}

function dialogOpen(id) {
    splash = document.getElementById('dialogSplash');
    if (splash) {
        splash.style.visibility = 'visible';
    }

    $('#' + id).dialog('open');
    //$("#dialogSplash").data("width.dialog", 840).data("height.dialog", 740); 
}

function setYouTube(id) {
    uTube = document.getElementById('youtubemedia');

    if (uTube) {
        switch (id) {
            case '1':
                uTube.src = 'http://www.youtube.com/embed/BjBHW5mZMwk?autoplay=1&autohide=1&enablejsapi=1&hd=1&origin=europeanposters.com&showsearch=0&rel=0&egm=0&showinfo=0&playlist=';
                break;
            case '2':
                uTube.src = 'http://www.youtube.com/embed/rHAE13-N-l4?autoplay=1&autohide=1&enablejsapi=1&hd=1&origin=europeanposters.com&showsearch=0&rel=0&egm=0&showinfo=0&playlist=';
                break
            case '3':
                uTube.src = 'http://www.youtube.com/embed/9kSVXFrnbOc?autoplay=1&autohide=1&enablejsapi=1&hd=1&origin=europeanposters.com&showsearch=0&rel=0&egm=0&showinfo=0&playlist=';
                break
            case '4':
                uTube.src = 'http://www.youtube.com/embed/5U3D_A6hRpk?autoplay=1&autohide=1&enablejsapi=1&hd=1&origin=europeanposters.com&showsearch=0&rel=0&egm=0&showinfo=0&playlist=';
                break
            case '5':
                uTube.src = 'http://www.youtube.com/embed/uFMc1cMh8RE?autoplay=1&autohide=1&enablejsapi=1&hd=1&origin=europeanposters.com&showsearch=0&rel=0&egm=0&showinfo=0&playlist=';
                break
            case '6':
                uTube.src = 'http://www.youtube.com/embed/1ilSol7edq4?autoplay=1&autohide=1&enablejsapi=1&hd=1&origin=europeanposters.com&showsearch=0&rel=0&egm=0&showinfo=0&playlist=';
                break
            case '7':
                uTube.src = 'http://www.youtube.com/embed/Fmph-9bZxmY?autoplay=1&autohide=1&enablejsapi=1&hd=1&origin=europeanposters.com&showsearch=0&rel=0&egm=0&showinfo=0&playlist=';
                break
        }
    }
}

function pauseYouTube() {
    uTube = document.getElementById('youtubemedia');

    if (uTube) {
        uTube.src = ""
    }
}

function initializescripts() {
    var isShow = getCookie('Splash');

    setCookie('Splash', '1', '');

    createDialog('dialogSplash');

    $("#dialogSplash").dialog({
        close: function () {  }
    });
    $('#dialogSplash').bind('dialogclose', function () {
        pauseYouTube();
    });

    $('#dialogSplash').dialog("option", "buttons", { "Close": function () { $(this).dialog("close"); } });

    $('#dialogSplash').dialog("option", "title", '');

    //attachEvent_('tocAbout', 'click', function () { dialogOpen('dialogSplash'); }, false);

    if (isShow == '') {
        setYouTube('1');
        dialogOpen('dialogSplash');
    }
}

