﻿/// <reference path="jquery-1.6-vsdoc.js" />

var carChangeInterval = 750;

$(document).ready(function () {
    // Cars subnavigation
    $('#navigation > div > ul > li.AspNet-Menu-WithChildren').hover(function () { showMenu($('ul', $(this)), this.className); }, function () { hideMenu($('ul', $(this)), this.className); });


    // New Cars & Staff filter
    $('#filter a').click(function (event) {
        var className = $(this).attr('rel');
        event.preventDefault();
        $('#filter a').removeClass('selected');
        $(this).addClass('selected');

        var theFilter = '*';

        if (className != 'all') {
            theFilter = '.' + className;
        }

        $('#vehiclelist').isotope({
            // options
            itemSelector: '.vehicle',
            layoutMode: 'masonry',
            filter: theFilter,
            animationEngine: 'best-available'
        });

        $('#stafflist').isotope({
            // options
            itemSelector: '.staffmember',
            layoutMode: 'masonry',
            filter: theFilter,
            animationEngine: 'best-available'
        });
    });


    // Vehicle Tabs
    $('#tabs .tabcontent').hide();
    $('#tabs .header a').click(function (event) {
        event.preventDefault();
        var tabid = $(this).attr('href');
        tabid = tabid.substring(tabid.indexOf('#'));
        $('#tabs .tabcontent').not(tabid).hide();
        $(tabid).show();
        $('#tabs .header li a.selected').removeClass('selected');
        $(this).addClass('selected');
    });

    $('#tabs .header a:first').click();
});

var Timers = [];

function showMenu(selector, timerKey) {
    //console.log(timerKey);
    if (Timers[timerKey] && Timers[timerKey] != 0) {
        window.clearTimeout(Timers[timerKey]);
        Timers[timerKey] = 0;
    }
    $(selector).slideDown('fast', 'swing');
}

function hideMenu(selector, timerKey) {
    //console.log(timerKey);
    Timers[timerKey] = window.setTimeout(function () { $(selector).slideUp('fast', 'swing', function () { Timers[timerKey] = 0; }); }, 300);
}
