﻿$(document).ready(function () {
    $(document).pngFix();

    // embed
    $('embed').each(function () {
        if (!$(this).attr('wmode')) {
            $(this).attr({ 'wmode': 'transparent' });
            $(this).attr({ 'WindowlessVideo': '-1' });
            $(this).parents("div").eq(0).css('display', 'block');
            $(this).parents("div").eq(0).css('z-index', '0');
        }
    });
    // object
    $('object').each(function () {
        var e = document.createElement('param');
        e.setAttribute('name', 'wmode');
        e.setAttribute('value', 'transparent');
        $(this).append(e);
        e = document.createElement('param');
        e.setAttribute('name', 'WindowlessVideo');
        e.setAttribute('value', '-1');
        $(this).append(e);
        $(this).parents("div").eq(0).css('display', 'block');
        $(this).parents("div").eq(0).css('z-index', '0');
    });

    $("ul.tabs").tabs("div.panes > div");

    if ($('.slideshow').length) {
        $('.slideshow').cycle({
            fx: 'fade',
            speed: 2000,
            timeout: 6000,
            pager: '#nav'
        });
    }

    SetAutocomplete();

    if ($("#slider_meteo DIV.items").children().size() > 0) {
        $("#slider_meteo").scrollable({ circular: true, mousewheel: true }).navigator().autoscroll({
            interval: 4500
        });
    }
});

// perform JavaScript after the document is scriptable.
$(function() {
    // setup ul.tabs to work as tabs for each div directly under div.panes
    $("ul#search_selection").tabs("div.change_form", {
        current: 'active'
    });

    $(".datepicker").datepicker();
});

function SetAutocomplete() {
    $(".autocomplete_what_field").autocomplete({
        source: "/controlli/autocomplete2.ashx",
        minLength: 2,
        zIndex: 9999,
        focus: function (event, ui) {
            $('.autocomplete_what_field').val(ui.item.label);
            return false;
        }
    });

    $(".autocomplete_where_field").autocomplete({
        source: "/controlli/autocomplete.ashx",
        minLength: 2,
        zIndex: 9999,
        focus: function (event, ui) {
            $('.autocomplete_where_field').val(ui.item.label);
            return false;
        },
        select: function (event, ui) {
            $('.autocomplete_hidden_field').val(ui.item.id);
            return false;
        }
    });

    $('.autocomplete_where_field').live('keydown', function (vnt) {
        var key = (vnt.which) ? vnt.which : vnt.KeyCode;
        if (!((key == 8) || (key == 46) || (key == 110) || (key >= 65 && key <= 90) || (key >= 97 && key <= 122) || (key == 32) || (key >= 48 && key <= 57))) {
        } else {
            $('.autocomplete_hidden_field').val("");
            
        }
    });

    //$('.autocomplete_where_field .ui-autocomplete').bgiframe();
}


