//roundedcornr - box

//Description: Determinate the highest tab content and setting all the other to that. 
//After that, get the height from carrossel and set the height so we can show always a major number of products.

var major_content_height = 0;
$(window).load(function () {

       //Recomendado();
	//Acessorios();
});

//
function Recomendado() {

    var array_content_div = new Array('visao-geral', 'itens-inclusos', 'especificacoes', 'fabricantes', 'guia-de-compras', 'avaliacao');
    var target = 'roundedcornr-box';
    var min_product_quantity = 1;    
    var carrossel_item = 'div.crossSellProducts';
    var divSlider = 'vertSliderRecomendado';
    var divWrapper = 'wrapperRecomendado';

    NormalizeHeight(target, array_content_div, divSlider, divWrapper, carrossel_item, min_product_quantity);
	

}
//

function Acessorios() {


    var array_content_div = new Array('visao-geral', 'itens-inclusos', 'especificacoes', 'fabricantes', 'guia-de-compras', 'avaliacao');
    var target = 'roundedcornr-box';
    var min_product_quantity = 1;
    var carrossel_item = 'div.crossSellMore';
    var divSlider = 'vertSliderAcessorios';
    var divWrapper = 'wrapperAcessorios';

    NormalizeHeight(target, array_content_div, divSlider, divWrapper, carrossel_item, min_product_quantity);

}

//
function NormalizeHeight(target, array_content_div, divSlider, divWrapper, carrossel_item, min_product_quantity) {

    //var major_content_height = 0;
    var carrossel_item_height = 290;
    var carrossel_holder_height = 0;
    var quantity_show = 3;
    var carrossel_offset_buttom = 0
    var carrossel_new_height = 8;
	var offset_bottom = 8;

    //Discovering the major div height.
    if (major_content_height == 0)
        major_content_height = GetMajorHeight(array_content_div);

    //Setting the major height to target
    $('#' + target).css('height', major_content_height + 'px');
    
    //Recovering the carrossel item height
    if ($(carrossel_item).length > 0)
        carrossel_item_height = $(carrossel_item)[0].clientHeight;

    //alert('$(carrossel_item).length: ' + $(carrossel_item).length);

    //Getting the quantity of itens possible to show using the major_content_height
    //quantity_show = GetQuantityCarrossel(major_content_height, carrossel_item_height);
    
    //Calulate the height of buttons area from carrossel.
    carrossel_offset_buttom = ($('#' + divSlider).height() - $('#' + divWrapper).height());

    //calculate height of carrosel necessary to display all itens.
    carrossel_new_height = ((quantity_show * carrossel_item_height) + carrossel_offset_buttom);

    if ( carrossel_new_height > major_content_height) {

        SetHeightOfArray(array_content_div, carrossel_new_height - 20);
        $('#' + target).height(carrossel_new_height - 20);

        $('#' + divWrapper).css('height', (carrossel_new_height - carrossel_offset_buttom) + 'px');
        $('#' + divSlider).css('height', (carrossel_new_height + offset_bottom) + 'px');

    } else {

        $('#' + divWrapper).css('height', (major_content_height - carrossel_offset_buttom) + 'px');
        $('#' + divSlider).css('height', (carrossel_new_height + offset_bottom) + 'px');
    
    }

}


function GetQuantityCarrossel(major_height, carrossel_item_height) {

    var quantity = major_height / carrossel_item_height;

    //return Math.ceil(quantity);

    if (quantity > (Math.round(quantity) + 0.5))
        return Math.ceil(quantity);
    else
        return Math.round(quantity);

}


function GetMajorHeight(array_obj_id){
     var major_content_height = 0;

     var aux_height = 0;
     if (array_obj_id)
        $('#' + array_obj_id[0]).removeClass('active');
    //Discovering the major div height.
     for (var i = 0; i < array_obj_id.length; i++) {
         if ($('#' + array_obj_id[i]).height() != 0)
             aux_height = $('#' + array_obj_id[i]).height();
         else
             aux_height = $('#' + array_obj_id[i])[0].clientHeight;

         //alert(array_obj_id[i] + ': ' + aux_height + 'px');

         if (major_content_height < aux_height) {
             major_content_height = aux_height;
         }

     }

     $('#' + array_obj_id[0]).addClass('active');
    
    return major_content_height;
}


function SetHeightOfArray(array_obj_id, heightValue) {
    if (array_obj_id) {
        for (var i = 0; i < array_obj_id.length; i++) {

            $('#' + array_obj_id[i]).css('height', heightValue + 'px');            

        }
    }
}