﻿homeScrollCountPx = 0;

var element = 0;
$j(window).load(function() {
    if ($j("div#cercaScroll").length > 0) {
        var el = $j("div#cercaScroll a");
        /*** CHECK SCROLL WIDTH ***/
        var max = $j(el).last();
        element = $j(max).position().left + $j(max).width();

        /*** SET MAX HEIGHT FROM TALLEST ELEMENT ***/
        var maxHeight = 0;
        var currHeight = 0;
        $j("div.cercaScroll a img").each(function() {
            currHeight = $j(this).height();
            if (currHeight > maxHeight) {
                maxHeight = currHeight;
                $j("div#contingutHome1").height(325 + maxHeight - 140);
                $j("div#cercaCanvas").height(325 + maxHeight - 140);
                $j("div.cercaContent").height(250 + maxHeight - 140);
                $j("a.destacats").height(240 + maxHeight - 140);
            }
        });
        //$j("p.cicle").height($j("p.cicle").height() + 5);
    }
});

function homeScrollAt() {
    var currentPosition = $j("div#cercaScroll").position().left;
    if (currentPosition < 0)
        $j("div#cercaScroll").css({ 'left': (currentPosition + 515) + 'px' });
}

function homeScrollAd() {
    var currentPosition = $j("div#cercaScroll").position().left;
    if (Math.abs(currentPosition - 535) < element)
        $j("div#cercaScroll").css({ 'left': (currentPosition - 535) + 'px' });
}
