﻿/// <reference path="http://ajax.microsoft.com/ajax/jQuery/jquery-1.5.1.min.js" />
/// <reference path="http://ajax.aspnetcdn.com/ajax/jquery.validate/1.9/jquery.validate.min.js" />
jQuery(document).ready(function () {
    $(".quick-contact-show").click(function () { $(".quick-contact").toggleSidebar(); });
    $(".directions-show").click(function () { $(".quick-directions").toggleSidebar(); });
    $("form").validate();
    $("a[rel^='prettyPhoto']").prettyPhoto({ social_tools: "", deeplinking: false });
});
$.fn.toggleSidebar = function () {
    return this.each(function () {
        $(this).stop();
        if ($(this).width() > 0)
            $(this).animate({ width: 0 }, 600);
        else
            $(this).animate({ width: 241 }, 300);
        $(".side-bar").not(this).animate({ width: 0 }, 600);
    });
};
Cufon.replace('.museo500', { fontFamily: 'Museo500' });
Cufon.replace('.museo300', { fontFamily: 'Museo300' });
Cufon.replace('.helv', { fontFamily: 'HelveticaNeue' });
Cufon.replace('h1.number', { fontFamily: 'HelveticaNeue' });
Cufon.replace('.page-pager a', { fontFamily: 'HelveticaNeue' });

//adding a postback request init handler

jQuery(document).ready(function () {

    $('form').data("isvalid", false);
    Sys.WebForms.PageRequestManager.getInstance().add_initializeRequest(CheckValidationStatus);
    function CheckValidationStatus(sender, args) {
        if ($("form").valid())
            return;

        //if the form is not valid,  then cancel the async postback 
        args.set_cancel(true);

    }
//    $.pauseRotateQuote = false;
//    $.startRotateQuote();
//    $(".quotes").hover(function () { $.pauseRotateQuote = true; }, function () { $.pauseRotateQuote = false; });
});
$.pauseRotateQuote = false;
$.startRotateQuote = function () {
    setTimeout(function () { $.rotateQuote($.startRotateQuote); }, 5000);
};
$.rotateQuote = function (complete) {
    var quotes = $(".quote");
    var current = $(".quote:visible");

    var currentIndex = $(quotes).index(current);
    var next = $(quotes).eq(currentIndex + 1);

    if (next.length == 0)
        next = $(quotes).first();
    if ($.pauseRotateQuote && complete)
        complete();
    else
        $(current).fadeOut("slow", function () { $(next).fadeIn("slow", complete); });

};

$.fn.startRotate = function (speed, interval) {
    return this.each(function () {
        setTimeout(function () { $(this).rotate(speed, interval); }, interval);
    });
};

