$(function () {
    var $newsplace = $('#newsplace');
    if ($newsplace.length == 1) {
        var $images = $newsplace.find('a.i');
        var $links = $newsplace.find('a.l');
        if ($images.length > 0 && $links.length > 0 && $images.length == $links.length) {
            var curimage = 0;
            $images.eq(curimage).show();
            $links.eq(curimage).addClass('selected');

            var changer = function () {
                $images.eq(curimage).hide();
                $links.eq(curimage).removeClass('selected');
                curimage++;
                if (curimage == $images.length) {
                    curimage = 0;
                }
                $links.eq(curimage).addClass('selected');
                $images.eq(curimage).show();
            };

            var newsplaceInterval;

            var runInterval = function () {
                clearInterval(newsplaceInterval);
                newsplaceInterval = setInterval(changer, 3000);
            };

            runInterval();

            $links.click(function () {
                clearInterval(newsplaceInterval);
                $images.eq(curimage).hide();
                $links.eq(curimage).removeClass('selected');
                curimage = parseInt($(this).text())-1;
                $links.eq(curimage).addClass('selected');
                $images.eq(curimage).show();
                setTimeout(runInterval, 7000)
                return false;
            })
        }
    }

    var flashvars = {};
    var params = {};
    var attributes = {};
    swfobject.embedSWF("/swf/loader.swf", "main_video", "450", "355", "9.0.0", "/swf/swfobject/expressInstall.swf", flashvars, params, attributes);

});

