﻿
var reqObj = null;

/***********************************************
* Memory Scroller script- © Dynamic Drive DHTML code library (www.dynamicdrive.com)
* This notice MUST stay intact for legal use
* Visit Dynamic Drive at http://www.dynamicdrive.com/ for full source code
***********************************************/

var memorywidth="580px"; //scroller width
var memoryheight="18px"; //scroller height

var memoryspeed=1; //Scroller speed (larger is faster 1-10)
var pauseit=1; //Pause scroller onMousever (0=no. 1=yes)?

var persistlastviewedmsg=1; //should scroller's position persist after users navigate away (1=yes, 0=no)?
var persistmsgbehavior="onload"; //set to "onload" or "onclick".

//Specify the scroller's content (don't delete <nobr> tag)
//Keep all content on ONE line, and backslash any single quotations (ie: that\'s great):

var memorycontent="";

memoryspeed=(document.all)? memoryspeed : Math.max(1, memoryspeed-1); //slow speed down by 1 for NS
var copyspeed=memoryspeed;
var pausespeed=(pauseit==0)? copyspeed: 0;
var iedom=document.all||document.getElementById;
    
var actualwidth='';
var memoryscroller;
var newsElement;

if (window.addEventListener)
    window.addEventListener("load", getNewsStream, false);
else if (window.attachEvent)
    window.attachEvent("onload", getNewsStream);
else if (document.all || document.getElementById)
    window.onload=getNewsStream;

function populatescroller()
{
    memoryscroller=document.getElementById? document.getElementById("memoryscroller") : document.all.memoryscroller;
    memoryscroller.style.left=parseInt(memorywidth)+8+"px";
    if (persistlastviewedmsg && get_cookie("lastscrollerpos")!="")
        revivelastmsg();
        
    memoryscroller.innerHTML=memorycontent;

    actualwidth=memoryscroller.offsetWidth;
    lefttime=setInterval("scrollmarquee()",20);
}

function get_cookie(Name) 
{
    var search = Name + "=";
    var returnvalue = "";
    if (document.cookie.length > 0) 
    {
        offset = document.cookie.indexOf(search);
        if (offset != -1) 
        {
            offset += search.length;
            end = document.cookie.indexOf(";", offset);
            if (end == -1)
                end = document.cookie.length;
                
            returnvalue=unescape(document.cookie.substring(offset, end));
        }
    }
    return returnvalue;
}

function savelastmsg()
{
    document.cookie = "lastscrollerpos=" + memoryscroller.style.left;
}

function revivelastmsg()
{
    lastscrollerpos=parseInt(get_cookie("lastscrollerpos"));
    memoryscroller.style.left=parseInt(lastscrollerpos)+"px";
}

function scrollmarquee()
{
    if (parseInt(memoryscroller.style.left)>(actualwidth * (-1) + 8))
        memoryscroller.style.left=parseInt(memoryscroller.style.left)-copyspeed+"px";
    else
        memoryscroller.style.left=parseInt(memorywidth)+8+"px";
}

/***********************************************
* News Stream script - © www.megalopoli-fm.gr
* The code below is independent from the code above
* but associated each other
***********************************************/

function getNewsStream()
{
    var submitURL = 'http://www.megalopoli-fm.gr/NewsStream.aspx';
    try
    {
        reqObj = createXMLHttpRequest();
        reqObj.onreadystatechange = newsStreamCallback;
        reqObj.open('GET', submitURL, true);
        reqObj.send(null);
    }
    catch(e)
    {
        //alert('Η έκδοση του φυλλομετρητή δεν υποστηρίζει την ροή ειδήσεων.');
    }  
}

function newsStreamCallback()
{
    if(reqObj.readyState == 4)
    {
        if(reqObj.status == 200)
        {
            memorycontent = reqObj.responseText;
            if (memorycontent == null){ return; }
            if (memorycontent == ''){ return; }
            if (memorycontent != '0')
            {   
                if (persistlastviewedmsg && persistmsgbehavior=="onload")
                    window.onunload = savelastmsg;
                    
                populatescroller();
            }
        }
        else
        {
        }
    }
}

function createXMLHttpRequest() 
{
    var req = null;
    try 
    {
        req = new XMLHttpRequest();
    }
    catch(e) 
    {
        try
        {
            req = new ActiveXObject('Msxml2.XMLHTTP');
        }
       catch(e)
        {
            req = new ActiveXObject('Microsoft.XMLHTTP');
        }
    }
    return req;
}
