function lvp_reset ()
{
        document.cookie = 'lvp0id=delete; expires=Fri, 27 Jul 2001 02:47:11 UTC; path=/';
        document.cookie = 'lvp1id=delete; expires=Fri, 27 Jul 2001 02:47:11 UTC; path=/';
        var lvp = $('lvp');
        var blocks = document.getElementsByClassName('block_lastviewedproducts', lvp);
        blocks.each(function (b) { lvp.removeChild(b); });
        lvp.removeChild(document.getElementsByClassName('remove_product', lvp)[0]);
}

function lp_update()
{
        clearInterval(lp_interval);

        $('grid-3x3').style.left = '0px';
        $('grid-3x3').style.opacity = '0';

        var el = null;

        for (var i = 0; i < 9; i++) {
                                el = $('product-' + i);
                                if ((lp_offset + i) >= lp_nbProducts) {
                                        el.style.visibility = 'hidden';
                                } else {
                                        el.style.visibility = 'visible';

                                        var fin_url = '';

                                        if(lp_products[i + lp_offset].subsubfamily != ''){
                                                fin_url += '/' + lp_products[i + lp_offset].subsubfamily;
                                        }
                                        /*if(lp_products[i + lp_offset].subsubsubfamily != ''){
                                                fin_url += '/' + lp_products[i + lp_offset].subsubsubfamily;
                                        }*/
                                        fin_url += '/' + lp_products[i + lp_offset].urlname;

                                        el.innerHTML = '<a href="/produktow/' + lp_products[i + lp_offset].family + '/' + lp_products[i + lp_offset].subfamily + fin_url + '"><img style="cursor:hand;width:100px;height:100px;padding:5px;border: 1px solid gray;-moz-border-radius:5px;" alt="' + lp_products[i + lp_offset].title + '" title="' + lp_products[i + lp_offset].title + '" src="' + lp_products[i + lp_offset].image + '" /><p style="margin: 0 !important;text-align: center;">' + lp_products[i + lp_offset].title + '<br /> ' + lp_products[i + lp_offset].sap + '</p></a>';

                                }
        }

        lp_interval = setInterval(lp_animate2, 40);
}

function lp_fetch()
{
        alert('TODO: fetch!');
}


function lp_animate2()
{
        var opacity = parseFloat($('grid-3x3').style.opacity);
        opacity += 0.2;
        $('grid-3x3').style.opacity = ''+opacity+'';
        if (opacity >= 1) {
                clearInterval(lp_interval);
                                $('grid-3x3').style.opacity = '1';
                $('go-prev').style.visibility = (lp_offset < 9) ? 'hidden' : 'visible';
                $('go-next').style.visibility = (lp_offset > lp_nbProducts-9) ? 'hidden' : 'visible';
                lp_interval = null;
        }
}


function lp_animate(offsetx)
{
        var curx = $('grid-3x3').style.left;
        curx = parseInt(curx.substr(0,curx.length-2));
        if (curx <= -lp_width || curx >= lp_width) {
                lp_update();
                return;
        }
        $('grid-3x3').style.left = (curx+offsetx)+'px';
        $('grid-3x3').style.opacity = ''+(1-(Math.abs(curx)/450))+'';
}


function lp_go(offset)
{
        if (document.all) return true;//TEMP IE WORKAROUND
        if (lp_interval != null)
                return false;

        document.getElementById('pagination').innerHTML = '<p>page <b>'+(Math.ceil((lp_offset+offset)/9)+1)+'</b> / '+lp_nbPages+'</p>';

        if((lp_offset+offset)!=0 && lp_nbPages!=0){
                if ((Math.ceil((lp_offset+offset)/9)+1)==lp_nbPages){
                        document.getElementById('go-next').style.display = 'none';}
                else { document.getElementById('go-next').style.display = 'block';}
        }

        if (!lp_width)
                lp_width = parseInt($('grid-3x3').style.width.substr(0, $('grid-3x3').style.width.length-2));
        if ((lp_offset+9) > lp_products.length && (lp_offset+9) < lp_nbProducts)
                lp_fetch();

        lp_offset += offset;
        lp_interval = setInterval(lp_animate, 60, (offset > 0) ? -40 : 40);
        return false;
}

/* fonction d'ouverture et de fermeture de l'espace area des drapeaux */

function openArea()
{
    elem = document.getElementById("drapeau");
    //elem.style.display = "list-item";
	elem.style.height = "113px";
	div = document.getElementById("drapeau");
	div.style.border = "1px solid #000000";
}

function closeArea()
{
    elem = document.getElementById("drapeau");
    //elem.style.display = "none";
	elem.style.height = "11px";
	div = document.getElementById("drapeau");
	div.style.border = "1px solid #ffffff";
}


/* fin fonction d'ouverture et de fermeture de l'espace area des drapeaux */
