$(document).ready(function(){
    // *** Step 1 - Confirm Transfer ***
    $(".domainSubmit").live("click", function(e) {
        var domainInfo = $("input:radio:checked").val();
        var domainType = domainInfo.substring(domainInfo.length -1, domainInfo.length);
        var domainName = domainInfo.substring(0, domainInfo.length -1);

        if(domainType == 1) { // if this is a transfer display confirmation box
            e.preventDefault();
            $("#mask").css({
                "width": $(document).width(),   // set mask to fill the whole screen
                "height": $(document).height()
            });
            $("#mask").fadeIn(50);      // use some effects to bring in the mask
            $("#mask").fadeTo("fast",0.6);
            $("#confirm").css("top", ($(window).height()/2-$("#confirm").height()/2) + $(window).scrollTop());
            $("#confirm").css("left", $(window).width()/2-$("#confirm").width()/2);
            var confirmText = "The domain name <b>" + domainName + "</b> is a transferable domain.<br />" +
            "This means that you <b>must</b> own this domain.<br />" +
            "It also means that it may take awhile to transfer this domain." +
            "Please do not continue if you do not own this domain.";
            $("#confirmText").html(confirmText);
            $("#confirm").fadeIn(500);
            $("#mask, .window2 .close").live("click", function() {
                $("#mask, .window2").fadeOut('slow');
            });
            $(".submitTransfer").live("click", function() {
                $("#mask, .window2").hide();
                $.ajax({
                    type: "POST",
                    url: "/step1s/save/" + domainName,
                    success: function(){
                        window.location.replace("/step2s");
                    }
                });

            })
        }
    });
    // *** End Step 1 - Confirm Transfer ***
    // *** Step 2 - Theme & Color Links ***
    var searchType = window.location.href.split('/')[4];
    var searchTerm = window.location.href.split('/')[5];
    //var searchTheme = "li.templateTheme:contains("
    if(searchType == "searchTheme") {
        $("li.templateTheme:contains('"+searchTerm+"')").addClass('active');
    } else if(searchType == "searchColor") {
        $("li.templateColor:contains('"+searchTerm+"')").addClass('active');
    } else {
        $("li.templateOptionAll").addClass('active');
    }
    // *** End Step 2 - Theme & Color Links ***
    // *** Step 2 - Modal ***
    $(".templateModal").live("click", function(e) {
        e.preventDefault(); // stop the click action
        $("#mask").css({
            "width": $(document).width(),   // set mask to fill the whole screen
            "height": $(document).height()
        });
        $("#mask").fadeIn(50);      // use some effects to bring in the mask
        $("#mask").fadeTo("fast",0.7);
        // Set the popup window to center
        $("#dialog").css("top", ($(window).height()/2-$("#dialog").height()/2) + $(window).scrollTop());
        $("#dialog").css("left", $(window).width()/2-$("#dialog").width()/2);
        // set up the data
        var templatePic = $(this).attr('id');
        var templateName = $(this).text();
        var dialogHeader = templateName;
        var dialogContent = "<img src='/sourceImages/templates/" + templatePic + "' >";
        // insert data into the header and content areas of the dialog
        $("#dialogHeader").html(dialogHeader);
        $("#dialogContent").html(dialogContent);
        $(".submitTemplate").attr({
            id: $(this).attr('rel')
        });
        $(".demoTemplate").attr({
            id: $(this).attr('rel')
        });
        // bring in the modal
        $("#dialog").fadeIn(500);
        // close modal by clicking mask or close button
        $("#mask, .window .close").live("click", function() {
            $("#mask, .window").fadeOut('slow');
        });

    });
    // *** End Step 2 - Modal ***
    // *** Step 2 - Save Template ***
    $(".submitTemplate").live("click", function() {
        $("#mask, .window").hide();
        var templateId = $(this).attr('id');
        $.ajax({
            type: "POST",
            url: "/step2s/addTemplate/" + templateId,
            success: function(){
                window.location.replace("/step3");
            }
        });

    });
    // *** End Step 2 - Save Template ***
    // *** Step 2 - Demo Template ***
    $(".demoTemplate").live("click", function() {
        var templateId = $(this).attr('id');
        window.open("http://demo.marketmymenu.com/index.php?templateId="+templateId);
    });
    // *** End Step 2 - Demo Template ***
    // *** Step 4 - Loading Screen ***
    $(".processOrder").live("click", function() {
        $("#mask").css({
            "width": $(document).width(),   // set mask to fill the whole screen
            "height": $(document).height()
        });
        $("#mask").fadeIn(50);      // use some effects to bring in the mask
        $("#mask").fadeTo("fast",0.6);
        // Set the popup window to center
        $("#loading").css("top", ($(window).height()/2-$("#loading").height()/2) + $(window).scrollTop());
        $("#loading").css("left", $(window).width()/2-$("#loading").width()/2);
        $("#loading").fadeIn(500);
    });

// *** End Step 4 - Loading Screen ***
});