﻿$(function() {
    $("#ctl00_ContentPlaceHolder1_txtFechaExpiracion").datepicker($.datepicker.regional['es']);
    $("#ctl00_ContentPlaceHolder1_txtFechaPublicacion").datepicker($.datepicker.regional['es']);
    $("#ctl00_ContentPlaceHolder1_txtInicioPublicacion").datepicker($.datepicker.regional['es']);
});

$(document).ready(function() {

    if ($('#foo2').length) {
        $("#foo2").carouFredSel({
            curcular: false,
            infinite: false,
            next: '.sliderNext',
            prev: '.sliderPrev',
            auto: { play: true, pauseDuration: 8000, duration: 2000 }
        });
    }

    $("#searchBox").corner("10px");
    $("#searchBox2").corner("10px");
    $(".spanBuscador").corner("top 10px");


    function addMega() {
        $(this).addClass("hovering");
    }

    function removeMega() {
        $(this).removeClass("hovering");
    }

    var megaConfig = {
        interval: 150,
        sensitivity: 4,
        over: addMega,
        timeout: 500,
        out: removeMega
    };

    $("li.mega").hoverIntent(megaConfig)

    $('#searchButton a').hover(function() {
        $(this).stop().animate({ 'opacity': '0' }, 500);
    }, function() { $(this).stop().animate({ 'opacity': '1' }, 500); });


    $("#ctl00_txtBuscadorTitulo").keydown(function(e) {
        if (e.which == 13) {
            ClickButtonSearch();
        }
    });

    $("#ctl00_txtBuscadorAutor").keydown(function(e) {
        if (e.which == 13) {
            ClickButtonSearch();
        }
    });


});

function monkeyPatchAutocomplete() {

    // don't really need this, but in case I did, I could store it and chain
    var oldFn = $.ui.autocomplete.prototype._renderItem;

    $.ui.autocomplete.prototype._renderItem = function(ul, item) {
        var re = new RegExp("^" + this.term);
        var t = item.label.replace(re, "<b>" +
                  this.term +
                  "</b>");
        return $("<li></li>")
              .data("item.autocomplete", item)
              .append("<a>" + t + "</a>")
              .appendTo(ul);
    };

}


function ClickButtonSearch() {
    __doPostBack('ctl00$lnkSearch', '');
}
