﻿var CreateAPizza = {
    getCookie: function(cookieName) {
        var results = document.cookie.match('(^|;) ?' + cookieName + '=([^;]*)(;|$)');
        if (results)
            return (unescape(results[2]));
        else
            return null;    
    },
    
    hideCreatePizzaPanel : function() {
        document.getElementById('pex-cyp-teaser').style.display = 'none';
        var cookie_date = new Date();
        cookie_date.setTime(cookie_date.getTime() + 86400000);
        document.cookie = "hide-create-a-pizza=yes; path=/; expires=" + cookie_date.toGMTString();
        return false;    
    },
    
    init: function() {
        if (CreateAPizza.getCookie('hide-create-a-pizza') == null) {
            var fileref = document.createElement("link");
            fileref.rel = "stylesheet";
            fileref.type = "text/css";
            fileref.href = 'http://www.pizzaexpress.com/create-your-pizza/external-teaser/styles/teaser.css?' + Math.floor(Math.random() * 11);

            document.getElementsByTagName("head")[0].appendChild(fileref);
            document.write('<div id="pex-cyp-teaser"><a href="http://www.pizzaexpress.com/create-your-pizza/?fromTeaser=true&uri=' + window.location + '" class="redirect" title="Find out more">PizzaExpress - Create your favourite pizza and you could star on our menu and win &pound;5000. Find out more.</a><a href="#" class="hide" title="Hide this" id="create-your-pizza-teaser-close" onClick="return CreateAPizza.hideCreatePizzaPanel();">Hide this</a></div>');
        }    
    }
};
CreateAPizza.init();