﻿// main messages
var imgs = $('#mc img');
var msgs = $('#bg div.msg');
var news = $('#news li');
var nn = $(news).length;
var mh = $('#mc');
var nm = imgs.length;
$(news.get(0)).show();
var w = Math.round($('#mc img').css('width').replace('px', ''));
var mint = "";
var c = 0;
var n = 0;
var ival = 7000;
var nval = 7000;
var ctrl = $('#bg li a');

$(mh).css('width', nm * w + 'px');
$(ctrl.eq(0)).parent('li').addClass('sel');
$(msgs).hide();
$(msgs.get(0)).show();

$(ctrl).click(function() {
    var i = $(ctrl).index(this);
    clearInterval(mint);
    if (!$(this).parent('li').hasClass('sel')) {
        $(ctrl).parent('li').removeClass('sel');
        $(this).parent('li').addClass('sel');
        $(msgs).hide();
        $(mh).animate({ left: (-i * w) - 72 + 'px' }, 500, function() {
        $(msgs.get(i)).show();
    });
    }
}, function() { });
function msgFeed() {
    c++;
    if (c == nm) { c = 0 }
    $(ctrl).parent('li').removeClass('sel');
    $(ctrl.get(c)).parent('li').addClass('sel');
    $(msgs).hide();
    $(mh).animate({ left: (-c * w) - 72 + 'px' }, 500, function() {
        $(msgs.get(c)).show();
    });
};
mint = setInterval("msgFeed()", (ival));


function newsFeed() {
    n++;
    if (n == nn) { n = 0 }
    $(news).hide();
    $(news.get(n)).fadeIn();
};
nint = setInterval("newsFeed()", (nval));


