/* GUI Functions */

$(document).ready(function() {
    $("a.toggle, a.FancyBox, a.onclick, input.button_form_button").click(function(e) {
        e.preventDefault();
    });

    $("div.menuItem").click(function() {
        $(".menuItemSelected").removeClass("menuItemSelected");
        $(this).addClass("menuItemSelected");
        window.location = $(this).find("a").attr("href");
    });

    $("div.button_wrap").click(function() {
        var togglevalue = $(this).find("a.toggle").attr("href");
        var onclickvalue = $(this).find("a.onclick").attr("href");
        var hyperlinkvalue = $(this).find("a").attr("href");

        if ($(this).find("a.FancyBox").length) {
            $(this).find("a").click();
        } else if (togglevalue != null) {
            $("#" + togglevalue).toggle("slow", function() {
                if ($("#" + togglevalue).find("input[type='text']").length) {
                    $("#" + togglevalue).find("input[type='text']").focus();
                }
            });
        } else if (hyperlinkvalue != null) {
            window.location = hyperlinkvalue;
        } else {
            $(this).parents("form:first").submit();
        }
    });
});

/* End GUI Functions */

/* Product Details */
function getProductInformation(source, rootUrl, rootImg)
{
	$("#productDetailInformation").html("<img src=\""+rootImg+"loading.gif\" style=\"display:block;width:220px;margin:20px auto;\" />");
	$("#productDetailInformationMenu .tab_detail_selected").removeClass("tab_detail_selected");
	$("#tab_detail_"+source).addClass("tab_detail_selected");
	url = rootUrl + "/product-information/" + source;
	$.ajax({ url: url, dataType: 'html', cache: true,
	success: function(html){
		$("#productDetailInformation").html(html);
	}
	});
}

/* Basket Functions */

$(document).ready(function() {
	$(".addInscription input").focus(function() {
		if($(this).val() == "Type Inscription Here...")
		{
			$(this).val("");
		}
	});
	$(".addInscription input").bind('keyup change', function() {
		var str = $(this).val();
		var val = 0;
		str = str.replace(/ /g, ""); //Remove Spaces
		if(str.length > 0)
		{
			val = 10;
		}
		var i = 1;
		while(i <= str.length)
		{
			if(i > 15)
			{
				$(this).val($(this).val().substring(0,15));
			}
			i++;
		}
		$(this).parent().find(".inscriptionCost").html("&pound;" + val.toFixed(2));
	});
});

/* End Basket Functions */

/* Checkout */
$(document).ready(function() {
	$("#invoice_address").css("display", "none");
	$("#invoice_same").click(function() {
		if($(this).is(":checked"))
		{
			$("#invoice_address").css("display", "none");
		}
		else
		{
			$("#invoice_address").css("display", "block");
		}
	});
});
