﻿
$(function() {
    $('.cicle').cycle({
        fx: 'fade',
        speed: 1000,
        timeout: 8000
    });
    $('.cicle2').cycle({
        fx: 'fade',
        speed: 1000,
        timeout: 8000,
        pager: '#nav',
        pagerAnchorBuilder: function(idx, slide) {
            // return selector string for existing anchor 
            return '#nav li:eq(' + idx + ') a';
        }
    });
	    $('.cicle3').cycle({
        fx: 'fade',
        speed: 250,
        timeout: 500,
        pager: '#nav',
        pagerAnchorBuilder: function(idx, slide) {
            // return selector string for existing anchor 
            return '#nav li:eq(' + idx + ') a';
        }
    });
    $("ul.sf-menu").superfish({
        pathClass: 'despliega',
        pathLevels: 1,
        animation: { height: 'show' },   // slide-down effect without fade-in 
        delay: 1200,               // 1.2 second delay on mouseout 
        autoArrows: false,               // if true, arrow mark-up generated automatically = cleaner source code at expense of initialisation performance     
        dropShadows: false,
        onBeforeShow: function() {
        var posicion = $(this).offset();
        //alert(posicion.left);
        //alert(posicion.top);
        }
    });

    $('.hm').click(function() {
        if (hmVisible == 0) {
            $('.hms').css('display', 'block');
            hmVisible = 1;
        } else {
            $('.hms').css('display', 'none');
            hmVisible = 0;
        }
    });
    var ordenVisible = 0;
    $('.orden').click(function() {
        if (ordenVisible == 0) {
            $('.ordenes').css('display', 'block');
            ordenVisible = 1;
        } else {
            $('.ordenes').css('display', 'none');
            ordenVisible = 0;
        }
    });
    var colecVisible = 0;
    $('.colec').click(function() {
        if (colecVisible == 0) {
            $('.colecs').css('display', 'block');
            colecVisible = 1;
        } else {
            $('.colecs').css('display', 'none');
            ordenVisible = 0;
        }
    });

	window.alert = $.prompt;
});

// Limpia el combo 
function clearSelect(oComboElem) {
    if (!oComboElem.options) return;
    for (var aux = oComboElem.options.length - 1; aux >= 0; aux--) oComboElem.options[aux] = null;
}
// Rellena combo
function DataIntoSelect(destinity, data, SelectedValue, emptyValue, firstValue, firstText) {
    var oComboElem = $(destinity)[0];
    clearSelect(oComboElem);
    var opt;
    if (emptyValue) {
        opt = new Option(emptyValue, "");
        oComboElem.options[oComboElem.length] = opt;
    }
    if (firstValue) {
        opt = new Option(firstText, firstValue);
        oComboElem.options[oComboElem.length] = opt;
    }
    if (data == null) return;
    for (var i = 0; i < data.length; i++) {
        var sValue = data[i].value;
        var sDescription = data[i].description;
        opt = new Option(sDescription, sValue);
        if (SelectedValue != null && (SelectedValue == sValue || sDescription.toUpperCase() == SelectedValue.toUpperCase())) {
            opt.selected = true;
        }
        oComboElem.options[oComboElem.length] = opt;
    }
    if (data.length < 1) {
        clearSelect(oComboElem);
        opt = new Option("No hay valores", "-1");
        oComboElem.options[oComboElem.length] = opt;

    }
}

function ShowItems(_idpattern, _imaxitems){
    var i;
    for (i=1;i<=_imaxitems;i++){
        $("#" + _idpattern + "_" + i).fadeIn("slow")
    }
}
/*
if(typeof( $('body#body_inicio')[0] ) != 'undefined') {
	setTimeout('oculta()',2000);
}*/
function oculta(){
$('#portada').fadeOut(1000);
}

function changeCountry(id) {
    if ($("#pais_sel_" + id).val() == '50') { // España
        $("#provincia_sel_" + id).show();
        $("#otra_provincia_" + id).hide();
    } else {
        $("#provincia_sel_" + id).hide();
        $("#otra_provincia_" + id).show();
    }
}
function mostrarDireccion(id) {
    $("#direccion_layer_" + id).fadeIn();
}
