var BreakingNews = {
    init:function() {
        var elements = [],
            bNewsCloseCookie = getValue('mediaTrack','bnClose'),
            bnMinus = readCookie('bnMinus'),
            bNews = document.getElementById('breakingNews'),
            bNewsClose = document.getElementById('breakingNewsClose'),
            bNewsMinus = document.getElementById('breakingNewsMinus'),
            bNewsPlus = document.getElementById('breakingNewsPlus'),
            bNewsTitle = document.getElementById('breakingNewsTitle'),
            bNewsContent = document.getElementById('breakingNewsContent'),
            pRow = document.getElementById('partnerRow'),
            xPos = bNewsTitle.offsetWidth + 10;
        /* Cookie Checks */
        if (bNewsCloseCookie) {
            bNews.style.display = 'none';
            pRow.style.position = 'relative';
            pRow.style.left = '0';
        } else if (bnMinus) {
            bNewsContent.style.display = 'none';
            bNewsPlus.style.display = 'block';
            bNewsTitle.style.borderRight = '0';
            bNews.style.width = 'auto';
            pRow.style.position = 'absolute';
            pRow.style.left = xPos + 'px';
            pRow.style.top = 0;
            pRow.style.height = '35px';
            pRow.style.lineHeight = '35px';
        }
        
        /* Button Functions */
        bNewsClose.onclick = function () {
            bNews.style.display = 'none';
            Cookies.erase('bnMinus',1);
            mTrack('bnClose',1);
            pRow.style.position = 'relative';
            pRow.style.left = '0';
            return false;
        }
        
        bNewsMinus.onclick = function () {
            Cookies.create('bnMinus',1);
            bNewsContent.style.display = 'none';
            bNewsPlus.style.display = 'block';
            bNewsTitle.style.borderRight = '0';
            bNews.style.width = 'auto';
            this.style.display = 'none';
            pRow.style.position = 'absolute';
            pRow.style.left = xPos + 'px';
            pRow.style.top = 0;
            pRow.style.height = '35px';
            pRow.style.lineHeight = '35px';
            return false;
        }
        
        bNewsPlus.onclick = function () {
            Cookies.erase('bnMinus',1);
            this.style.display = 'none';
            if (IE) {
                bNewsContent.style.display = 'block';
            } else {
                bNewsContent.style.display = 'table';
            }
            bNewsMinus.style.display = 'block';
            bNewsTitle.style.borderRight = '1px solid #f5d423';
            bNews.style.position = 'absolute';
            bNews.style.width = '975px';
            if (IE) {
                bNews.style.width = '977px';
            }
            return false;
        }
    }
}

/* Cookie Object */
var Cookies = {
    init: function () {
        var allCookies = document.cookie.split('; ');
        for (var i=0;i<allCookies.length;i++) {
            var cookiePair = allCookies[i].split('=');
            this[cookiePair[0]] = cookiePair[1];
        }
    },
    create: function (name,value,days) {
        if (days) {
            var date = new Date();
            date.setTime(date.getTime()+(days*24*60*60*1000));
            var expires = "; expires="+date.toGMTString();
        }
        else var expires = "";
        document.cookie = name+"="+value+expires+"; domain=.cbssports.com; path=/";
        this[name] = value;
    },
    erase: function (name) {
        this.create(name,'',-1);
        this[name] = undefined;
    }
};

Cookies.init();
BreakingNews.init();