﻿/// <reference path="jquery-1.3.2-vsdoc2.js" />

$(document).ready(function() {
    $(":text").labelify({ labelledClass: "searchHint" });

    var tafDialogLoad = function(hash) {
        $(":text").labelify();
    };

    // Tell a friend window
    if ($.jqm) {
        $('#tafDialog').jqm({ ajax: 'recommend-a-friend.html', trigger: 'a#tafLink', onLoad: tafDialogLoad });
    }

    //Setup the rotater 
    $('#rotator').cycle({
        speed: 500, // << Fade Speed
        timeout: 8000, // << Time between transistions
        pager: '#rotatorNav',
        pagerEvent: 'mouseover',
        fastOnEvent: true
    });

    var bbns = new ByBoxNearestSite($("#searchLocation"), $("#results blockquote"));

    $(window).load(function() { setTimeout(transitionBannerAndPromoTag, 10000) });
});

function transitionBannerAndPromoTag() {
    $("#banner-overlay").fadeOut(500);
    $("#promo-tag").fadeIn(500);
}

var ByBoxNearestSite = function($input, $results) {
    var timeout = null;
    var delay = 400;
    var minChars = 3;

    $(document).ajaxStart(function() {
        $('#ajaxBusy').show();
    }).ajaxStop(function() {
        $('#ajaxBusy').hide();
    });

    $input.keydown(function(e) {
        if (timeout) {
            clearTimeout(timeout);
        }
        timeout = setTimeout(function() { onChange(); }, delay);
    });

    function onChange() {
        // ignore if the following keys are pressed: [del] [shift] [capslock]
        //if (lastKeyPressCode == 46 || (lastKeyPressCode > 8 && lastKeyPressCode < 32)) return $results.hide();
        var v = $input.val();
        //if (v == prev) return;
        //prev = v;
        if (v.length >= minChars) {
            getResults();
        } else {
            //$input.removeClass(options.loadingClass);
            //$results.hide();
        }
    }

    function requestSites() {

    }

    function getResults() {

    }
}
