/**
 * Carousel noticies
 */

function cycle_auto(){
    var sel_next = sel_story + 1;
    if (sel_next > 4) {
        sel_next = 1;
    }
    switch_story(sel_next, 1);
}

function gecko_fader(speed){

    var x = Math.round(($('img#img_top').css('opacity') - speed) * 10) / 10;
    $('img#img_top').css('opacity', x);
    if (x <= 0) {
        $('img#img_top').attr('src', res_full[sel_temp].src);
        $('img#img_top').css('opacity', 1.0);
        clearInterval(timer_fade);
        dhtml_busy = 0;
    }
}

function click_story(){
    document.location.replace(res_url[sel_story]);
}

function switch_story(id, long_fade){
    dhtml_busy = 1;
    switch (dhtml_engine) {
        case 'IE':
            document.getElementById('thumb_' + sel_story).filters.alpha.opacity = 50;
            document.getElementById('thumb_' + id).filters.alpha.opacity = 100;
            if (long_fade) {
                document.getElementById('img_top').style.filter = "blendTrans(duration=1)";
                document.getElementById('img_top').filters.blendTrans(duration = 1).Apply();
                document.getElementById('img_top').filters.blendTrans.Play();
                document.getElementById('img_top').src = res_full[id].src;
                setTimeout('dhtml_busy = 0;', 1000);
            }
            else {
                document.getElementById('img_top').style.filter = "blendTrans(duration=0.15)";
                document.getElementById('img_top').filters.blendTrans(duration = 0.15).Apply();
                document.getElementById('img_top').filters.blendTrans.Play();
                document.getElementById('img_top').src = res_full[id].src;
                setTimeout('dhtml_busy = 0;', 150);
            }
            break;
        case 'Firefox':
            $('img#thumb_' + sel_story).css('opacity', 0.5);
            $('img#thumb_' + id).css('opacity', 1.0);
            if (dhtml_fades) {
                //$('img#img_bottom').attr('src',res_full[id].src);
                try {
                    clearInterval(timer_fade);
                } 
                catch (e) {
                }
                sel_temp = id;
                if (long_fade) {
                    timer_fade = setInterval('gecko_fader(0.25);', 50);
                }
                else {
                    timer_fade = setInterval('gecko_fader(0.5);', 50);
                }
            }
            else {
                $('img#img_top').attr('src', res_full[id].src);
                dhtml_busy = 0;
            }
            break;
        default:
            $('img#img_top').attr('src', res_full[id].src);
            dhtml_busy = 0;
            break;
    }
    $('img#thumb_' + sel_story).attr('src', res_grey[sel_story].src);
    $('img#thumb_' + id).attr('src', res_thumb[id].src);
    $('div#novetat_' + sel_story).attr('class', 'entry-row-txt');
    $('div#novetat_' + id).attr('class', 'entry-row-txt-active');
    
    sel_story = id;
}

function thumb_mouseover(id){
    clearInterval(timer_auto_cycle);
    switch_story(id, 0);
}

function thumb_mouseout(id){
    timer_auto_cycle = setInterval('cycle_auto();', 6000);
}
