﻿/// <reference path="../js/vswd-ext_2.2.js"/>
/// <reference path="../js/Objects.js"/>
/// <reference path="../script/Stores.js"/>

var productTpl = new Ext.XTemplate(
    '<tpl for=".">',
        '<div class="productItem" id="c{id_producto}">',
            '<img src="content/products/{imagen}" alt="{producto}"/>',
        '</div>',
    '</tpl>'
);

var productDV = new Ext.DataView({
    store: productStore,
    id: "dataVCat",
    tpl: productTpl,
    autoHeight: true,
    multiSelect: false,
    selectedClass: "productItemO",
    singleSelect: true,
    overClass: 'productItemO',
    itemSelector: 'div.productItem',
    emptyText: ''
});

productDV.on('beforeclick',
	function (dv, index, node, e) {
	    window.location=productStore.getAt(index).data.pagina;
	}
);

/* para el carrousel */
var indexPromo=1;
var tout;
var pausa=false;

function manualPromo(i) {
    clearTimeout(tout);
    indexPromo=i;
    pausa=true;
    document.getElementById("imgPromoF").src=document.getElementById("imgPromo").src;
    Ext.get("imgPromoF").show();
    document.getElementById("imgPromo").src="/content/promos/" + promoStore.getAt(indexPromo).data.imagen;
    Ext.get("imgPromo").slideIn('t',{duration:2});
    Ext.get("imgPromoF").fadeOut();
    setIndicadores();
}


function setIndicadores() {
    document.getElementById("btn1").src="content/promos/1g.png";
        document.getElementById("btn2").src="content/promos/2g.png";
        document.getElementById("btn3").src="content/promos/3g.png";
        switch(indexPromo) {
            case 0:
                document.getElementById("btn1").src="content/promos/1s.png";
            break;
            case 1:
                document.getElementById("btn2").src="content/promos/2s.png";
            break;
            case 2:
                document.getElementById("btn3").src="content/promos/3s.png";
            break;
        }
}

function setMain() {
        if(!pausa) {
        document.getElementById("imgPromoF").src=document.getElementById("imgPromo").src;
        Ext.get("imgPromoF").show();
        document.getElementById("imgPromo").src="/content/promos/" + promoStore.getAt(indexPromo).data.imagen;
        Ext.get("imgPromo").slideIn('t',{duration:2});
        Ext.get("imgPromoF").fadeOut();
        setIndicadores();
        indexPromo=indexPromo + 1;
        if(indexPromo==3)
            indexPromo=0;
        clearTimeout(tout);
        tout=setTimeout("setMain()",15000);
    }
}





MainLayout = function() {
    return {
        init: function() {
            Ext.BLANK_IMAGE_URL = raizsitio + 'content/images/blank.png';
            Ext.QuickTips.init();
            this.initLayout();
            
        },
        initLayout: function() {
           productDV.render("dataContainer");
           //tout=setTimeout("setMain()",15000);
        }
    } // fin del evento principal
} ();

Ext.EventManager.onDocumentReady(MainLayout.init, MainLayout, true);
