$(document).ready(function() {

    // load toggleVal on input fields.
    $("form#short-login-form :text, form#short-login-form :text, .toggle, form#global-search-form :text, form#short-search-form :text, form#newsletter-form :text").toggleVal({
        populateFrom: "label",
        removeLabels: true,
        focusClass: "hasFocus",
        changedClass: "isChanged"
    });

    // add highlighting css hook for focused yform elements
    $(".yform input, .yform select, .yform textarea").focus(function() {
        $(this).parent().addClass("focused");
    }).blur(function() {
        $(this).parent().removeClass("focused");
    });

    // ajax variant selection box
    $(".variantSelector").click(function(e) {
        e.preventDefault();
        myID = $(this).attr("rel");

        // Create variantSelectorBox if none exist
        if ($("#variantSelectorBox").length == 0) {
            $("body").append("<div id='variantSelectorBox'>&nbsp;</div>");
        }
        
        // Show loading gif        
        $("#variantSelectorBox").html("<img id='loadingVariantsImg' src='/chainbox/layouts/02/images/loading.gif' alt='Loading...' />");
        
        // Get ajax content
        $.ajax({
            url: "/?altTemplate=AjaxProxy&selectvariant=" + myID,
            cache: true,
            success: function(html) {
                $("#variantSelectorBox").html(html);
            }
        });
        // spawn modal
        $("#variantSelectorBox").modal({
            opacity: 80,
            overlayCss: { backgroundColor: "#000" },
            minWidth: 200,
            escClose: true,
            overlayClose: true
        });


    });

});


