﻿$(document).ready(function () {

    BindOverallEvents();
    BindEvents();

});

function BindOverallEvents() {

    /*Create hover on divtable*/
    $("#divtable [class=col]").hover(
    function () { $(this).addClass("hover"); },
    function () { $(this).removeClass("hover"); }
    );

    /*Create hover on divtable*/
    $("#divtable [class=noClickableCol]").hover(
    function () { $(this).addClass("hover"); },
    function () { $(this).removeClass("hover"); }
    );

    /*Create buttons*/
    $(function () {
        $("button, input:submit").button();
        $("a", ".demo").click(function () { return false; });
    });

    /*Create buttons*/
    $(function () {
        $("button, input:button").button();
        $("a", ".demo").click(function () { return false; });
    });

    /*Create buttons*/
    $(function () {
        $("button, input:reset").button();
        $("a", ".demo").click(function () { return false; });
    });
}

function BindEvents() {

    /*Create SBH 2.2 Search Engine Tabs*/
    $(function () {
        $(".tabs").tabs({ cache: false, show: function (event, ui) { setTimeout('updateJquery();', 100); } });
    });

}


function restoreDialogBox() {
    $dialog.dialog({ height: 250 });
    $dialog.dialog({ width: 350 });
    $dialog.dialog({ title: 'Dialog' });
    $dialog.dialog({ buttons: { 'Cancel': function () { $dialog.dialog('close'); } } });
    $dialog.html('');
    $dialog.dialog('close');
}



/*Creates standard UI dialog box*/
var $dialog = $('<div></div>')
$dialog.dialog({
    title: 'SBH 2.0 - Dialog',
    autoOpen: false,
    modal: true,
    width: 350,
    height: 250,
    minHeight: 250,
    minWidth: 350,
    closeOnEscape: true,
    buttons: { 'Stäng': function () { $(this).dialog('close'); } }
});

/*Create browser recommend field*/
var $buoop = {
    vs: { i: 7, f: 2, o: 10.01, s: 2, n: 9 },
    reminder: 0,
    text: "Du använder en äldre webbläsare som <b>inte stödjer Svensk Busshistoria fullt ut</b>. Vi rekommenderar dig att uppdatera till en nyare version! <a href='/asp/about/#browser'>Klicka här för mer information</a>",
    newwindow: false
}

$buoop.ol = window.onload;
window.onload = function () {
    if ($buoop.ol) $buoop.ol();
    var e = document.createElement("script");
    e.setAttribute("type", "text/javascript");
    e.setAttribute("src", "http://browser-update.org/update.js");
    document.body.appendChild(e);
}

function updateJquery() {

    /*Bind SBH 2.3 Search Engine - misc */
    BindOverallEvents();

    /*Bind SBH 2.3 Search Engine - Autocomplete ONLY BETA*/
    $('#OwnerName').autocomplete('/asp/setting/apps/autocomplete/autocomplete.asp?action=ownername', cacheLength = 1);
    $('#strchassityp').autocomplete('/asp/setting/apps/autocomplete/autocomplete.asp?action=chassityp', cacheLength = 1);
    $('#strchassitillverkare').autocomplete('/asp/setting/apps/autocomplete/autocomplete.asp?action=chassitillverkare', cacheLength = 1);
    $('#strKarosstillverkare').autocomplete('/asp/setting/apps/autocomplete/autocomplete.asp?action=karosstillverkare', cacheLength = 1);
    $('#strKarosstyp').autocomplete('/asp/setting/apps/autocomplete/autocomplete.asp?action=karosstyp', cacheLength = 1);
    $('#strmotor').autocomplete('/asp/setting/apps/autocomplete/autocomplete.asp?action=motor', cacheLength = 1);
    $('#strvaxellada').autocomplete('/asp/setting/apps/autocomplete/autocomplete.asp?action=vaxellada', cacheLength = 1);
    $('#strKarossnummer').autocomplete('/asp/setting/apps/autocomplete/autocomplete.asp?action=karossnummer', cacheLength = 1);
    $('#strChassinummer').autocomplete('/asp/setting/apps/autocomplete/autocomplete.asp?action=chassinummer', cacheLength = 1);
    $('#strRegNummer').autocomplete('/asp/setting/apps/autocomplete/autocomplete.asp?action=registreringsnummer', cacheLength = 1);

    /*Bind SBH 2.3 Search Engine - MakeYear Slider ONLY BETA*/
    $(function () {
        $("#slider-range").slider({
            range: true,
            min: 1900,
            max: 2012,
            values: [1900, 2012],
            slide: function (event, ui) {
                $("#amount").val('Visa årsmodell från ' + ui.values[0] + ' till ' + ui.values[1]);
            }
        });
        $("#amount").val('Visa årsmodell från ' + $("#slider-range").slider("values", 0) + ' till ' + $("#slider-range").slider("values", 1));
    });
}



/*Get Querystrings from URL*/
function getUrlVars() {
    var vars = [], hash;
    var hashes = window.location.href.slice(window.location.href.indexOf('?') + 1).split('&');
    for (var i = 0; i < hashes.length; i++) {
        hash = hashes[i].split('=');
        vars.push(hash[0]);
        vars[hash[0]] = hash[1];
    }
    return vars;
}
