﻿$(document).ready(function() {
    site_setup();
    switch ($('body').attr('id')) {
        case "markree_competition_page":
            markree_competition_page();
            break;
        case "product_page":
            product_page();
            break;
        case "review_order_page":
            review_order_page();
            break;
        case "make_payment_page":
            make_payment_page();
            break;
 	case "billing_page":
            billing_page();
            break;

    }
});

function site_setup() {
    $(".confirm_delete").click(function() {
        return confirm("Are you sure you want to delete this?");
    });
    $(".confirm_action").click(function() {
        return confirm("Are you sure you want to:  " + this.innerHTML + "?");
    });

    $("#jewellery_by_price_link").click(function() {
        $("#price_range_list").slideToggle("fast");
        return false;
    });
};

function billing_page() {
    var _address_select = $('#customer_address_country_id');
    if (_address_select.val() == "0") {
        _address_select.val("243");
    }
}

function product_page() {
    $('#images a').lightBox({
        fixedNavigation: false,
        imageLoading: '/Content/img/loading_rose.gif',
        imageBtnClose: '/Content/img/lightbox-btn-close.gif',
        imageBtnNext: '/Content/img/lightbox-btn-next.gif',
        imageBtnPrev: '/Content/img/lightbox-btn-prev.gif'
    });
};

function review_order_page() {
    pic1 = new Image();
    pic1.src = "/Content/img/loading_rose.gif";

    pic2 = new Image();
    pic2.src = "/Content/img/paypal_wide.gif";
}

function make_payment_page() {
    window.setTimeout(function() {
        $('form').submit();
    }, 2000);
}

function markree_competition_page() {
    var current_selection = "none";
    var tip_fading = false;
    $('#bond_select').focus(function() {swap_images("bond");});
    $('#bond_select').blur(function() { hide_effects("bond") });
    $('#ann_select').focus(function() { swap_images("ann"); });
    $('#ann_select').blur(function() { hide_effects("ann") });
    $('#bride_select').focus(function() { swap_images("bride"); });
    $('#bride_select').blur(function() { hide_effects("bride") });
    $('#dancers_select').focus(function() { swap_images("dancers"); });
    $('#dancers_select').blur(function() { hide_effects("dancers") });

    function hide_effects(to_hide) {
        current_selection = 'none';
        $('#' + to_hide).fadeOut("slow");
        $('#competition_tip').hide();
        $('#' + to_hide + '_tip').hide();
    }

    function swap_images(image_to_show) {
        if (current_selection != image_to_show) {
            $('#' + image_to_show).fadeIn();
            $('#' + image_to_show + '_tip').show();
            $('#competition_tip').show();
            current_selection = image_to_show;
        }         
    }
};
