var carousel_current_id = 1;
var carousel_total = 4;

$(function(){
    $(".click_blur").focus(function(e){
        $(this).val("");
    });
    
    $("#carousel a").click(function(e){
        e.preventDefault(); // do nothing
        click_id = $(this).attr("href").split("#");
        carousel_current_id = click_id[1];
        
        $("#carousel a").removeClass("active");
        $(this).addClass("active");
        
        // immediately show the requested image
        $("#carousel img").attr("src", "/img/banners/" + site_lang + '/' + carousel_current_id + ".jpg").show();
    });
    setInterval(rotate, 8000);
    
    $("#NewsletterForm").submit(function(e){
        e.preventDefault();
        $f = $(this);
        if (!validateForm($f))
        {
            return false;
        }
        if (!$("#ppRead").attr("checked"))
        {
            $("label[for=ppRead]").addClass("error");
            return false;
        }
        
        $.post($f.attr("action"), $f.serialize(), function(msg){
            $("#newsletter_pan").html(msg);
        });
    });
    
    // init colorbox if applicable
    if ($("a.lightbox, a.colorbox").length)
    {
        $("a.lightbox, a.colorbox").colorbox();
    }
});

function rotate()
{
    carousel_current_id ++;
    if (carousel_current_id > carousel_total)
    {
        carousel_current_id = 1;
    }
    
    $("#carousel img").fadeOut(1500, function(){
        $(this).attr("src", "/img/banners/" + site_lang + '/' + carousel_current_id + ".jpg").fadeIn(1500);
        $("#carousel a").removeClass("active");
        $("#carousel a[href='#" + carousel_current_id +"']").addClass("active");
    });
}
