//Format for each new article:
//  Index 0: Title
//  Index 1: Headline
//  Index 2: Source
//  Index 3: Date
//  Index 4: Summary - ALWAYS end with '...'
//  Index 5: Link
var BreachNews = [
        [
            "Hackers for Hire",
            "Hacking for Fun and Profit in China's Underworld",
            "NY Times",
            "Feb 02, 2010",
            "Internet security experts say China has legions of hackers, and that they are behind an escalating number of global attacks to steal credit card numbers, commit corporate espionage and other nefarious activities...",
            "http://www.nytimes.com/2010/01/13/world/asia/13beijing.html" ],

        [
            "Digital River Sues over Breach",
            "Indian company steals customer data",
            "Star Tribune",
            "June 4, 2010",
            "200,000 customers' data stolen and attempted sale to Colorado marketing company stopped...",
            "http://www.startribune.com/local/95584209.html?elr=KArksLckD8EQDUoaEyqyP4O:DW3ckUiD3aPc:_Yyc:aUac8HEaDiaMDCinchO7DU" ],

        [
            "Canada: Breaches Soar in 09",
            "",
            "Globe and Mail",
            "Sept 26 2009",
            "IT security breaches cost the average Canadian organization $834,149 in 2009, almost double that of 2008, pointing to a disturbing trend...",
            "http://www.theglobeandmail.com/news/technology/it-security-breaches-soar-in-2009/article1305011/" ],

        [
            "Rock You Password Theft",
            "",
            "Computerworld.com",
            "Feb 17 2010",
            "Social netoworking password service hacked. Over 30 million passwords exposed...",
            "http://www.computerworld.com/s/article/9142327/RockYou_hack_exposes_names_passwords_of_30M_accountsm" ]
    ];



var SecurityNews = [
        [
            "Global State of Security Report: PWC and CIO Magazine",
            "Cloud Computing a major security concern",
            "PWC Global",
            "Jan 10, 2010",
            "Among many points of agreement, the security of online information is a major concern for business leaders and CIOs alike...",
            "http://www.pwc.com/gx/en/information-security-survey/index.jhtml" ],

        [
            "HP Speaks out on data threat",
            "",
            "HP.com",
            "Nov 27 2009",
            "Lack of national data breach standards places burden on small businesses...",
            "http://www.communities.hp.com/securitysoftware/blogs/spilabs/archive/2010/06/03/lack-of-national-data-breach-standards-places-burden-on-small-businesses.aspx" ],

        [
            "Banks increase security spend",
            "Financial institutions increase security spending, as threats and regulatory penalties rise",
            "SC Magazine UK",
            "June 9, 2010",
            "Financial institutions are investing heavily in information security in light of a growing number of threats and increased regulatory pressure...",
            "http://www.scmagazineuk.com/financial-institutions-increase-security-spending-as-threats-and-regulatory-penalties-rise/article/171986/" ],

        [
            "Survey: IT Managers Blame Insiders",
            "",
            "CNET News",
            "Aug 24, 2009",
            "IT managers in small and midsize businesses blame their fellow workers for online security breaches...",
            "http://news.cnet.com/Discover-security-breach,-blame-the-co-workers/2100-7355_3-6204295.html" ]
    ];



function BuildNewsArticlesForTicker( news_article_array )
{
    var news_html_all = new Array();

    for( i=0 ; i<news_article_array.length ; i++ )
    {
        var news_html_each = "";

        news_html_each=
            '<b><a href="' + news_article_array[i][5] + '" target="_blank" title="">' + news_article_array[i][0] + '</a></b><br />'
            +   (news_article_array[i][1].length==0 ? '' : (news_article_array[i][1] + '<br />'))
            +   news_article_array[i][2] + ' ' + news_article_array[i][3] +'<br />'
            +   news_article_array[i][4] + '<a href="' + news_article_array[i][5] + '" target="_blank" title="">more</a><br /><br />'

        news_html_all[i] = news_html_each;
    }

    return news_html_all;
}


// The time (msec) to freeze the news article when it is fully displayed
var time_to_freeze_article = 10000;

// Size of new ticker DIV height (pixel), need to be the same size as #ticker_container
var ticker_div_height = 100

function NewsTickerDivVariables( news_articles_structured, div_id ) {
    // current news article being displayed
    this.current_article_index = 0;

    // Format the structured news articles into array of HTMLs
    this.article_array = BuildNewsArticlesForTicker( news_articles_structured );

    this.div_id = div_id;

    // Function to get the next news article (in html)
    this.get_next_article = function() {
            this.current_article_index += 1;
            if( this.current_article_index>=this.article_array.length )
                this.current_article_index = 0;
            return this.article_array[this.current_article_index];
        };
}

var breach_news_div_var;
var security_news_div_var;

//scroller's speed
var sspeed=3;
var resumesspeed=sspeed


$( function()
{
    breach_news_div_var = new NewsTickerDivVariables( BreachNews, 'breach_news_ticker' );
    security_news_div_var = new NewsTickerDivVariables( SecurityNews, 'security_news_ticker' );

    breach_news_div_var.var_name = 'breach_news_div_var';
    security_news_div_var.var_name = 'security_news_div_var';

    start();

});

function start() {
        if (document.all) {
            iemarquee_prepare(breach_news_div_var);
            iemarquee_prepare(security_news_div_var);

            // Freeze the scrolling for a while
            setTimeout("ieslide()", time_to_freeze_article)

        } else if (document.getElementById) {
            ns6marquee_prepare(breach_news_div_var);
            ns6marquee_prepare(security_news_div_var);

            // Freeze the scrolling for a while
            setTimeout("ns6slide()", time_to_freeze_article)
        }
}

function iemarquee_prepare( news_ticker ){
        news_ticker.iediv=eval(news_ticker.div_id)

        news_ticker.iediv.style.pixelTop=0;
        news_ticker.iediv.innerHTML = news_ticker.article_array[0];
}

function ieslide(){
        if (breach_news_div_var.iediv.style.pixelTop >= ticker_div_height*(-1)){

                // scroll the page up
                if( breach_news_div_var.iediv.style.pixelTop>0 && breach_news_div_var.iediv.style.pixelTop<=sspeed )
                {
                    // The article will be in full view
                    breach_news_div_var.iediv.style.pixelTop=0;
                    security_news_div_var.iediv.style.pixelTop=0;
                }
                else
                {
                    breach_news_div_var.iediv.style.pixelTop-=sspeed;
                    security_news_div_var.iediv.style.pixelTop-=sspeed;
                }

                if( breach_news_div_var.iediv.style.pixelTop==0 ) {
                    setTimeout("ieslide()",time_to_freeze_article)
                } else {
                    setTimeout("ieslide()",100)
                }
        }
        else{
                // Finish sliding to the top

                // Prepare the next breach and security articles to display
                breach_news_div_var.iediv.innerHTML = breach_news_div_var.get_next_article();
                security_news_div_var.iediv.innerHTML = security_news_div_var.get_next_article();

                // Move the ticker below the view
                breach_news_div_var.iediv.style.pixelTop = ticker_div_height;
                security_news_div_var.iediv.style.pixelTop = ticker_div_height;

                // Freeze the scrolling for a while
                ieslide();
        }
}

function ns6marquee_prepare( news_ticker ){
        var test = document.getElementById(news_ticker.div_id);
        news_ticker.ns6div=eval( document.getElementById(news_ticker.div_id) )

        news_ticker.ns6div.style.top="0px";
        news_ticker.ns6div.innerHTML=news_ticker.article_array[0];
}

function ns6slide(){
        if (parseInt(breach_news_div_var.ns6div.style.top) >= ticker_div_height*(-1)){

                var cur_divtop = parseInt(breach_news_div_var.ns6div.style.top);
                var new_divtop = 0;

                // scroll the page up
                if( cur_divtop>0 && cur_divtop<=sspeed )
                {
                    // The article will be in full view
                    new_divtop = 0;
                }
                else
                {
                    new_divtop = cur_divtop - sspeed;
                }

                breach_news_div_var.ns6div.style.top = new_divtop + "px";
                security_news_div_var.ns6div.style.top = new_divtop + "px";

                if (new_divtop==0) {
                    setTimeout("ns6slide()",time_to_freeze_article)
                } else {
                    setTimeout("ns6slide()",100)
                }
        }
        else {
                // Finish sliding to the top

                // Put in the next article to scroll
                breach_news_div_var.ns6div.innerHTML = breach_news_div_var.get_next_article();
                security_news_div_var.ns6div.innerHTML = security_news_div_var.get_next_article();

                // Move the ticker below the view
                breach_news_div_var.ns6div.style.top = ticker_div_height + "px";
                security_news_div_var.ns6div.style.top = ticker_div_height + "px";

                ns6slide();
        }
}




