function CufonReplace(){
	Cufon.replace('.lobster');
	Cufon.replace('.menu-navigation');
	Cufon.replace('.product-list li h2');
	Cufon.replace('.cart-container h1');
	Cufon.replace('.order-summary-list h2');
	Cufon.replace('.checkout-total');
	Cufon.replace('.order-summary-container h1');
	Cufon.replace('.form-container h1');
	Cufon.replace('.postcode-check-heading');
	Cufon.replace('.postcode-check-content h2');
	Cufon.replace('.feedback-message');
	Cufon.replace('.thailicious-hotline');
}

$(document).ready(function() {	
	$(".banner-view").loopedSlider();
	$(".polaroid-movie").colorbox({width:"540px", height:"460px", iframe:true});
	
	$("#showvideo_thankyou").colorbox({width:"630px", height:"420px", iframe:true}).click(); // alleen gebruikt voor succes pagina na bestelling

	/**
	 * Form Validation (checkout)
	 */
	$("#order-from").validationEngine();

	/**
	 * Postcode Check (splashscreen)
	 */
	$(".pc-check-bt").click(function() {	
			// 1. get target zipcode
			var targetZipcode = $('#targetZipcode').val().toUpperCase(); // 1234AB
			
			// 2. validate target zipcode
			var zipcodeRegularExpression = new RegExp(/^[0-9]{4}\s*[a-zA-Z]{2}/);
			var result = targetZipcode.match(zipcodeRegularExpression);
			if(!result)
			{
				$('#zipcodeErrorMessage').html('Dit is een ongeldige postcode.');
				CufonReplace();
				return;
			}
			
			// 3. compare target zipcode with the delivery ranges from thailicious
			var storeZipcodes = new Array(3); // 3
			storeZipcodes[0] = [ "1012","1013","1014","1015","1016","1017",
														"1043",
														"1051","1052","1053","1054","1055","1056","1057","1058","1059","1060","1061","1062","1063","1064","1065",
														"1071","1072","1073","1074","1075","1076","1077","1078","1079","1080","1081","1082" ];	// kinkerstraat (alleen bezorg)
			storeZipcodes[1] = [ "1011","1018","1019","1023","1024","1025","1026","1027","1028", 
														"1086","1087","1088","1089","1090","1091","1092","1093","1094","1095","1096","1097","1098",
														"1111" ];  // czaar peterstraat (living/restaurant)
			storeZipcodes[2] = [ "1081","1082","1083",
														"1101","1105","1108",
														"1115","1117","1118","1119",
														"1171",
														"1181","1182","1183","1184","1185","1186","1187","1188","1191",
														"1390", "1391",
														"1421", "1422", "1423", "1424", "1431", "1432" ];	// amstelveen	(avenue/samplestore)
														
														
			
			var i = 0;
			var found = false;
			for(i = 0; i < 3; i++){ // 0..4
				if($.inArray(targetZipcode.substring(0,4), storeZipcodes[i]) > -1){
					$('#thalicious-stores').children().eq(i).addClass("selected");
					$('#zipcodeErrorMessage').html('Wij bezorgen in uw regio!');
					found = true;
				} // special check for four numbers? i.e. dont cares 1234**
			}
		
			if(!found)
			{
				$('#zipcodeErrorMessage').html('Helaas, wij zijn niet actief in uw regio.');
			}
			CufonReplace();
		
	});
	
	/**
	 * Postcode Check (vestiging)
	 */
	$(".pccheck").click(function() {	
		// 1. get target zipcode
		var targetZipcode = $('#targetZipcode').val().toUpperCase(); // 1234AB
		
		// 2. validate target zipcode
		var zipcodeRegularExpression = new RegExp(/^[0-9]{4}\s*[a-zA-Z]{2}/);
		var result = targetZipcode.match(zipcodeRegularExpression);
		if(!result)
		{
			$('#zipcodeErrorMessage').html('Dit is een ongeldige postcode.');
			CufonReplace();
			return;
		}
	
		// 3. check the number of stores and their zipcodes
		// [note] store these values outside this function
		var numStores = $('#thalicious-stores').children().length; // 3
		var storeZipcodes = new Array(numStores); // 3
		storeZipcodes[0] = [ "1012","1013","1014","1015","1016","1017",
													"1051","1052","1053","1054","1055","1056","1057","1058","1059","1060","1061","1062","1063","1064","1065",
													"1071","1072","1073","1074","1075","1076","1077","1078","1079","1080","1081","1082" ];	// kinkerstraat (alleen bezorg)
		storeZipcodes[1] = [ "1011","1018","1019","1023", 
													"1086","1087","1088","1089","1090","1091","1092","1093","1094","1095","1096","1097","1098",
													"1111" ];  // czaar peterstraat (living/restaurant)
		storeZipcodes[2] = [ "1081","1082","1083",
													"1117","1118","1119",
													"1181","1182","1183","1184","1185","1186",
													"1431" ];	// amstelveen	(avenue/samplestore)
		
		// 4. highlight the appropriate store(s)
		$('#thalicious-stores').children().removeClass("selected");
		var i = 0;
		var found = false;
		for(i = 0; i < numStores; i++){ // 0..4
			if($.inArray(targetZipcode.substring(0,4), storeZipcodes[i]) > -1){
				$('#thalicious-stores').children().eq(i).addClass("selected");
				$('#zipcodeErrorMessage').html('Wij bezorgen in uw regio!');
				found = true;
			} // special check for four numbers? i.e. dont cares 1234**
		}
		
		if(!found)
		{
			$('#zipcodeErrorMessage').html('Helaas, wij zijn niet actief in uw regio.');
		}
		CufonReplace();
	});

	/**
	 * Cart Overview Accordion (order)
	 */
	$('.cart-overview-item-header').click(function() {
		var myParent = $(this).parent(); // single li
		var myGrandlist = myParent.parent(); //ul
		
		var myListitems = myGrandlist.children(); // all li
		var myListitemsWithoutMe = myListitems.not(myParent);
		
		// Hide and close all others
		myListitemsWithoutMe.each(function(index) {
			$(this).removeClass('expanded');
			$(this).children('.cart-overview-item-header').children('a:first-child').removeClass('toggle-expand').addClass('toggle-hide')
			$(this).children('.overview-content-toggle').hide('slow');
		});

		
		if(myParent.hasClass('expanded'))
		{
			// Hide me if I am expanded.
			myParent.removeClass('expanded');
			$(this).children('a:first-child').removeClass('toggle-expand').addClass('toggle-hide');
			myParent.children('.overview-content-toggle').hide('slow');
		}
		
		else
		{
			// Show me if I am hidden.
			myParent.addClass('expanded');
			$(this).children('a:first-child').removeClass('toggle-hide').addClass('toggle-expand');
			myParent.children('.overview-content-toggle').show('slow');
		}
		
		// $(this).next().toggle('slow');

		return false;
	}).next().hide(); // closes all..
	
	CufonReplace();
	
	/**
	 * DeleteItem from ShoppingCart
	 */
	$('.remove-item').click(function() {
			//alert($(this).parent().get(0).tagName);
			$(this).parent().get(0).submit();							 
	});	
});	
