var hotnewsDiv;
var documentBodyScrollY;
var NEWS_BASE_URL = "http://www.atlasct.com/site/hotnews"

initHotNews();

function initHotNews() {
    eraseCookie("hotnews");
    hotnewsDiv = document.getElementById("hotnews");
    if (!readCookie("hotnews","true")) {
        createCookie("hotnews","true",7)
        displaySideNews(1);
        //openPopup();
    }
}

function displaySideNews(number) {
    hotnewsDiv.style.position = "absolute";
    hotnewsDiv.style.zIndex = "1000";
    hotnewsDiv.style.top = "50px";
    hotnewsDiv.style.right = "0px";
    hotnewsDiv.style.width = "32px";
    hotnewsDiv.style.height = "108px";
    hotnewsDiv.innerHTML = "<img src='" + NEWS_BASE_URL + "/hotnews" + number + ".png' onClick='openPopup();'>";
}

function openPopup() {
    //alert("openPopup()");
    documentBodyStyleY = document.body.style.height;
    documentBodyScroll = document.body.scroll;
    documentBodyStyleOverflow = document.body.style.overflow
    document.body.scroll = "no";
    document.body.style.overflow = "hidden";
    document.body.style.height = "100%";
    //window.scrollTo(0, 0);

    hotnewsDiv.style.position = "absolute";
    hotnewsDiv.style.zIndex = "1000";
    hotnewsDiv.style.top = "0px";
    hotnewsDiv.style.width = "100%";
    hotnewsDiv.style.height = "500%";
    hotnewsDiv.style.textAlign = "center";
    //hotnewsDiv.style.marginRight = "auto";
    //hotnewsDiv.style.overflow = "hidden";
    //hotnewsDiv.style.overflowY = "hidden";
    hotnewsDiv.style.backgroundImage = "url('" + NEWS_BASE_URL + "/bg.png')";
    hotnewsDiv.style.backgroundRepeat = "repeat";
    //hotnewsDiv.onClick = closePopup();
    hotnewsDiv.innerHTML = "<img src='" + NEWS_BASE_URL + "/popup.png' onClick='closePopup();'>";
    hotnewsDiv.style.visibility = "visible";
//alert("done.");
}
function closePopup() {
    //alert("closePopup()");
    document.body.style.height = documentBodyStyleY;
    document.body.style.overflow = documentBodyStyleOverflow;
    document.body.scroll = documentBodyScroll;

    hotnewsDiv.style.textAlign = "right";
    hotnewsDiv.style.backgroundImage = "";
    hotnewsDiv.style.backgroundRepeat = "";

    hotnewsDiv.innerHTML = "";
    //popupDiv.style.visibility = "hidden";
    displaySideNews(0);
    //alert("done.");
}
function createCookie(name,value,days) {
    var expires;
    if (days) {
        var date = new Date();
        date.setTime(date.getTime()+(days*24*60*60*1000));
        expires = "; expires="+date.toGMTString();
    }
    else {
        expires = "";
    }
    document.cookie = name+"="+value+expires+"; path=/";
}

function readCookie(name) {
    var nameEQ = name + "=";
    var ca = document.cookie.split(';');
    for(var i=0;i < ca.length;i++) {
        var c = ca[i];
        while (c.charAt(0)==' ') c = c.substring(1,c.length);
        if (c.indexOf(nameEQ) == 0) return c.substring(nameEQ.length,c.length);
    }
    return null;
}
function eraseCookie(name) {
	createCookie(name,"",-1);
}

