// RG 2012-02-02


$(document).ready(function() {
    $("select").selectBox();
    $(".homeTitleProtect:last").css('padding-right','none').css('border','none');
    $(".atelierMenuRight > .homeTitleProtect:last").css('padding-right','none').css('border','none');
});

// LOAD SCRIPTs  ------------------------------------------------------------------
$(window).load(function() {
    
    // carrega as dimensoes das imagens 
    imgWidth=$("#backGroundImg > img").width();
    imgHeight=$("#backGroundImg > img").height();
  
    // faz resize inicial
    backGroundResize();
    
    // quando resize da win volta a calcular
    $(window).resize(function() {
        backGroundResize();
    });
   
});

// Resize das imagens e cycle ----------------------------------------------------
function backGroundResize() {
    
    // para cycle do anterior 
    $('#backGroundImg').cycle('stop');
    
    
    // remove ultimo cycle
    $("#nav").html(' ');
    
    // get win dim
    attrHeight=$(window).height();
    attrWidth=$(window).width();
    
    // resize player do flash 
    $(".myPlayer").attr('height',attrHeight);
    $(".myPlayer").attr('width',attrWidth);
    
    // resize da mask das imgs
    $("#backGroundImg").attr('style','height:'+attrHeight+'px,width:'+attrWidth+'px');
    // resize do next|prev mask
    $("#backGroundImg_pager").attr('style','height:'+attrHeight+'px,width:'+attrWidth+'px');
    
    
    // calculos para resize das imgs FG :)
    var wD  = imgWidth;
    var hD = imgHeight;

    var wR = attrWidth;
    var hR = attrHeight;

    var sX = wR / wD;
    var sY = hR / hD;

    var rD  = wD / hD;
    var rR  = wR / hR;

    var s  = rD >= rR ? sY : sX;

    var imageWidth  = wD * s;
    var imageHeight = hD * s; 
    
    // set resize das imgs
    $(".backGroundImgs").attr('height',imageHeight);
    $(".backGroundImgs").attr('width', imageWidth);
        
        
    // se tem mais que uma
    if($("#backGroundImg > img").size()>0){
        
        // fix resize 
        $("#backGroundImg > img").attr('style','height:'+attrHeight+'px,width:'+attrWidth+'px');
        
        // inicia slide cycle de imagens 
        $('#backGroundImg').cycle({
            next:   '.pager_next',
            prev:  '.pager_prev',
            fx:'fade', 
            speed:'750', 
            timeout: 0, 
            width: $("#backGroundImg > img").width(), 
            height: $("#backGroundImg > img").height(), 
            pager:  '#nav',
            pagerAnchorBuilder: function(idx, slide) {
                return '<li><a href="#">&bull;</a></li>';
            }
        });
    }

}


