Shadowbox.init({ players: ["img", "iframe"], continuous: true, autoplayMovies: true });

$(function() {	
	// CLOCK
	var ClockOptions = { format: "%H:%M%p" }
	$("#clock").jclock(ClockOptions);
	
	// VALIDATE ALL FORMS WITH THIS CLASS
	$(".validate").validate();
	
	// ENABLE CURRENCY CHANGER
	$(".currencies ul li input").click(function() {
		var CurrencyType = $(this).val();
		
		$.get("/assets/p_currency.php", { Currency: CurrencyType }, function(data) {
			window.location.reload();
		});
		
		return false;
	});
	
	// ADD TO BASKET IF NOT WIZARD
	$("#ProductItems td a").click(function() {
		var Link = $(this).attr("href");
		var ItemID = $(this).attr("rel");
	
		if (Link == "#") {
			$.post("/assets/p_products.php", { ItemID: ItemID }, function(data){
				$("#mini_basket").load("/assets/mini_basket.php");
			});
		}
		
		return false;
	});
	
	// DELETE ITEMS FROM BASKET
	$(".basket .item .delete a").click(function() {
		var ItemID = $(this).attr("rel");
		var BasketItem = $(this);
		
		$.post("/assets/p_basket.php", { ItemID: ItemID }, function(BasketItemsCount) {
			BasketItem.parent().parent().parent().hide();
			ReloadBasket();
			
			if (BasketItemsCount == 0) {
				$(".basket .items").html("<p>Your basket is currently empty.</p>");	
			}
		});
		
		return false;
	});
});


// ADD ITEM TO BASKET
function AddItem(ItemID) {
	$.post("/assets/p_products.php", { ItemID: ItemID }, function(data){
		window.parent.Shadowbox.close();
		$("#mini_basket").load("/assets/mini_basket.php");
	});
}


// RELOAD BASKET - USED WHEN WIZARD CLOSES
function ReloadBasket() {
	window.parent.Shadowbox.close();
	$("#mini_basket").load("/assets/mini_basket.php");
}


// FORMS
function validateConfirm() {
	var Terms = $("#Terms").val();
	
	if (Terms != "Y") {
		alert("Please confirm you have read and agree to abide by the Terms and Conditions.");
		
	} else {
		document.Confirm.submit();
	}
}

function toggleWizardTabs(divName) {
	if (divName == "customisation") {
		$("#customisation").show();
		$("#prescription").hide();
		$("#tab_customisation").addClass("selected");
		$("#tab_prescription").removeClass();
		
		$("#button_back").hide();
		$("#button_next").show();
		$("#button_add").hide();
		$("#message_stage1").show();
		$("#message_stage2").hide();
		
		return false;
		
	} else if (divName == "prescription") {
		$("#customisation").hide();
		$("#prescription").show();
		$("#tab_customisation").removeClass();
		$("#tab_prescription").addClass("selected");
		
		$("#button_back").show();
		$("#button_next").hide();
		$("#button_add").show();
		$("#message_stage1").hide();
		$("#message_stage2").show();
	}
}

// GLAZING CHECKBOXES
function dontCombine(box) {
   var combinations = {
       3: [4,5,6],
       4: [3,5,6],
       5: [3,4,6],
       6: [2,3,4,5],
       7: [6,8,9],
       8: [2,3,6,7,9],
       9: [2,3,4,5,6,7,8]
	}
	var id = box.name.replace(/\D/g, '');
	if (combinations[id]) {
		// alert("GLSC_" + id);
		if (id > 2) {
			// alert(id);
			if (id >= 6) {
				// Nothing
			} else {
				if (box.form.elements["GLSC_" + id].disabled == false) {
					box.form.elements["GLSC_" + id].disabled = true;
				} else {
					box.form.elements["GLSC_" + id].disabled = false;
				}
			}
		}
		
		for (var i = 0; i < combinations[id].length; ++i) {
			box.form.elements["GLS_" + combinations[id][i]].disabled = box.checked;
			if (box.form.elements["GLS_" + combinations[id][i]].checked == true) {
				box.form.elements["GLS_" + combinations[id][i]].checked = false;
				// alert(box.form.elements["GLS_" + combinations[id][i]].checked);
			}
		}
	}
}