﻿$(document).ready(function() {

$('body').supersleight();


    $('#content').externalLink();

    $(".header_box_button").bind('click', function(event) {
        event.preventDefault();
        var id = $(this).attr("id");
        if (id == "header_box_search") {
            $("#header_box_search_content").show();
            $("#header_box_brochure_content").hide();
            $("#header_box_search").parent().addClass("selected");
            $("#header_box_brochure").parent().removeClass();
        }
        else if (id == "header_box_brochure") {
            $("#header_box_search_content").hide();
            $("#header_box_brochure_content").show();
            $("#header_box_brochure").parent().addClass("selected");
            $("#header_box_search").parent().removeClass();
        }
    });

    $('#footer-subscribe-form').bind('submit', function() {

        if(!$('#subscribe-message').length)
            $('#subscribe-submit').after(' &nbsp; <span id="subscribe-message"></span>');

        $.ajax({
            url: '/subscribe/',
            data: $(this).serialize(),
            dataType: 'json',
            type: 'POST',
            success: function(data, status, request) { 
                
                if(data.Success)
                {
                    $('#form_name, #form_email').val('');

                    $('#subscribe-message').html('<span class="success">Thank you, you are now subscribed.</span>');
                }
                else
                {
                    $('#subscribe-message').html('<span class="error">' + data.Message + '</span>');
                }                   
            },
            error: function(request, status, error) { 

                $('#subscribe-message').html('<span class="error">Load Error</span>');

            }
        });

        return false;        

    });

    $("input.button_replace").each(function() {
        $(this).replaceWith("<div class=\"inputButton\"" + (($(this).attr("id")) ? "id=\"" + $(this).attr("id") + "\"" : "") + "><div class=\"button_curve_TL\"><\/div><div class=\"button_curve_TR\"><\/div><div class=\"button_curve_BL\"><\/div><div class=\"button_curve_BR\"><\/div>" + $(this).attr("value") + "</div>");
    });

    $("a.button_replace").each(function() {
        $(this).replaceWith("<div class=\"inputButton\"" + (($(this).attr("id")) ? "id=\"" + $(this).attr("id") + "\"" : "") + "><div class=\"button_curve_TL\"><\/div><div class=\"button_curve_TR\"><\/div><div class=\"button_curve_BL\"><\/div><div class=\"button_curve_BR\"><\/div><a href=\"" + $(this).attr("href") + "\">" + $(this).text() + "</a></div>");
    });


    $("input.button_replace_green").each(function() {
        $(this).replaceWith("<div class=\"inputButtonGreenBg\"" + (($(this).attr("id")) ? "id=\"" + $(this).attr("id") + "\"" : "") + "><div class=\"curve_TL_green\"><\/div><div class=\"curve_TR_green\"><\/div><div class=\"curve_BL_green\"><\/div><div class=\"curve_BR_green\"><\/div>" + $(this).attr("value") + "</div>");
    });

    $(".inputButton, .inputButtonGreenBg").bind('click', function(event) {
        $(this).closest("form").submit();
    });

});
