﻿

$(document).ready(function () {

    /* css buttons */
    $('.button').each(function () {
        // known colours green and white
        var colour = '';
        if ($(this).hasClass('green-button')) {
            colour = 'green-';
        }
        $(this).mouseover(function () {
            $(this).addClass(colour + 'button-hover')
        }).bind('click mousedown', function () {
            $(this).removeClass(colour + 'button-hover')
            $(this).addClass(colour + 'button-press')
        }).mouseup(function () {
            //console.log($(this).attr('class'));
            $(this).removeClass(colour + 'button-press')
            $(this).addClass(colour + 'button-hover')
            //console.log($(this).attr('class'));
        }).bind('mouseout mouseleave', function () {
            $(this).removeClass(colour + 'button-hover ' + colour + 'button-press')
        });
    });

    $.ajaxSetup({ cache: false });

    // only load the validation scripts if we need to
    /*if ($("a.contact-link").length || $("a.quote-link").length) {
    $.getScript('/Content/Scripts/jquery.validate.min.js');
    $.getScript('/Content/Scripts/jquery.validate.unobtrusive.min.js');
    $.getScript('/Content/Scripts/jquery.unobtrusive-ajax.min.js');
    }*/

    $("a.contact-link").live("click", function (e) {
        e.preventDefault();
        var d = $("<div></div>");
        d.attr("id", 'EnquiryDialog');
        d.appendTo("body");
        d.dialog({
            title: 'Enquiry Form',
            height: '590',
            width: '530',
            resize: 'auto',
            close: function () { $(this).remove() },
            modal: true
        });
        // show a loading image
        $('<div id="loading">Loading<br><img src="/Content/Images/loading.gif" width="35" height="35" /></div>').appendTo("#EnquiryDialog");        
        d.load(this.href, function () {
            $('#EnquiryDialog').dialog('option', 'height', 'auto');            
        });
    });

    $("a.quote-link").live("click", function (e) {
        e.preventDefault();
        var d = $("<div></div>");
        d.attr("id", 'QuoteDialog');
        d.appendTo("body");
        d.dialog({
            title: 'Commerical letterbox quote request',
            height: 570, width: 950,
            resize: 'auto',
            close: function () { $(this).remove() },
            modal: true           
        });
        // show a loading image
        $('<div id="loading">Loading<br><img src="/Content/Images/loading.gif" width="35" height="35" /></div>').appendTo("#QuoteDialog");
        d.load(this.href, function () {
            $('#QuoteDialog').dialog('option', 'height', 'auto');        
        });
    });

    $("a.download-button").click(function (e) {
        e.preventDefault();
        window.alert('The 2011/12 catalogue is coming soon!');
    });

});

function QuoteSuccessCallback() {
    // only do this if we don't have the form
    if ($('#QuoteDialog input[type=text]').length < 1) {
        $('#QuoteDialog').dialog({ title: 'Thankyou for your request', height: 190, width: 570 });
        $('#QuoteDialog').dialog('option', 'position', 'center');
    }    
}

