
        window.addEvent('domready',function(){

			$$('a.popup-link').addEvent("click",function(event){
				event.stop();
				link = event.target;
				while (link.tagName != 'A' && link.tagName != 'HTML') {
						link = $(link).getParent();
				}
				link.blur();
				window.open(link.href,'largeimage','width=500,height=500,left=250,top=100,screenX=250,screenY=150,scrollbars=yes,resizable=no,menubar=no,status=no,directories=no,location=no');
			});


			$$('select.option-choice-selector').addEvent("change",changeOptionTrigger);
			$$('select.option-choice-selector').addEvent("keypress",changeOptionTrigger);

			if ($('item-subitems')) {
				$$('#item-subitems .qty-add').addEvent("click",changeQty);
				$$('#item-subitems .qty-sub').addEvent("click",changeQty);
			}

			$$('.ui-showbox-button').addEvent("click",showBox2);
		
			window.fireEvent('resize');
	
        });
		
		window.addEvent('resize',function()
		{
			var size = findViewportSize2();
			
			if(size[0] < 1450)
			{
				$$('div.mattress').addClass('fullwidth');
				$$('div.mattress').removeClass('halfwidth');
			}
			else
			{
				$$('div.mattress').addClass('halfwidth');
				$$('div.mattress').removeClass('fullwidth');
			}
		});
		
		

	function showBox2(event) {

		event.stop();
		target_id = $(event.target).get('id');
		box_id = target_id+'-box';

		document.title = box_id;
		$$("#"+box_id).setStyle("display","");
	}

        function changeQty(event) {

                event.stop();
                event.target.blur();
                tableCell = event.target;
                while (tableCell.tagName != 'TD') { tableCell = tableCell.getParent(); }

                qtybox = tableCell.getElements('.qty-box')[0];

                if (event.target.hasClass("qty-add")) {
                        qtybox.value = (qtybox.value * 1) + 1;
                } else if (event.target.hasClass("qty-sub")) {
                        if (qtybox.value > 0) {
                                qtybox.value = (qtybox.value * 1) - 1;
                        }
                }

		calcPrices();

        }

	function changeOptionTrigger(event) {

		select_element = $(event.target);
		changeOption(select_element);		

	}


	function changeOption(select) {

		select_id = $(select).get('id');
		option = select_id.replace(/option_/,'');
		choice = $(select).get('value');
		
		if(option_triggers[option] && option_triggers[option][choice])
		{
			pairs = option_triggers[option][choice];
		
			pairs.each(function(pair)
			{
				$(pair['field']).set('value',pair['value']);
			});
		}
		else
		{
			console.log('Option info doesn\'t exist: ' + option + ' choice: ' + choice);
		}

		if (option_images[option])
		{
			if (option_images[option][choice])
			{				
				$('option_image_'+option).setStyle("display","block");
				$('option_image_'+option).set('src',option_images[option][choice]);
				$('option_image_popup_'+option).set('href', option_popup_images[option][choice]);
			}
			else
			{
				//$('option_image_'+option).setStyle("display","none");
			}
		}

		calcPrices();
	}

	function calcPrices() {

		overall_total_price = 0;

		$$('input.row-price-field').each(function(rowPriceField){

			prefix = rowPriceField.id.replace(/_unit_price_inc_options/,'');
			row_item_id = prefix.replace(/item_/,'')

			// GET THE BASIC PRICES //
			base_price = $(prefix+'_base_price').get('value');
			if (!base_price || base_price == '') base_price = '0.00';
			base_price = base_price * 1;

			base_rrp_price = $(prefix+'_base_rrp_price').get('value');
			if (!base_rrp_price || base_rrp_price == '') base_rrp_price = false;
			else base_rrp_price = base_rrp_price * 1;
			
			was_price = $(prefix+'_base_was_price').get('value');
			if (!was_price || was_price == '') was_price = '0.00';
			was_price = was_price * 1;

			// GET THE OPTION PRICES //
			options_price = 0.00; options_rrp_price = 0.00; options_was_price = 0.00;
			
			$$('input.'+prefix+'option').each(function(optionField){

				option_price = $(optionField.id+'_price').get('value');
				if (!option_price || option_price == '') option_price = '0.00';
				option_price = option_price * 1;

				option_rrp_price = $(optionField.id+'_rrp_price').get('value');
				if (!option_rrp_price || option_rrp_price == '') option_rrp_price = option_price; // OTHERWISE TOTAL FOR RRP IS LESS! //
				option_rrp_price = option_rrp_price * 1;
				
				option_was_price = $(optionField.id+'_was_price').get('value');
				if (!option_was_price || option_was_price == '') option_was_price = option_price;
				option_was_price = option_was_price * 1;
				
				options_price = options_price + option_price;
				options_rrp_price = options_rrp_price + option_rrp_price;
				options_was_price = options_was_price + option_was_price;
			});

			// COMBINE THE PRICES //
			total_price = base_price + options_price;
			total_rrp_price = base_rrp_price + options_rrp_price;
			total_was_price = was_price + options_was_price;

			// PUT THE PRICES IN THE APPROPRIATE BOXES //
			$(prefix+'_unit_price_inc_options').set('value',total_price);
			if (!base_rrp_price || base_rrp_price == '') {
				$(prefix+'_unit_rrp_price_inc_options').set('value','');
			} else {
				$(prefix+'_unit_rrp_price_inc_options').set('value',total_rrp_price);
			}

			// PUT PRICES IN THE APPROPRIATE FIELDS //

			total_price = total_price.toFixed(2);
			total_was_price = total_was_price.toFixed(2);
			
			$(prefix+'_display_price').set('html','&pound;'+total_price);
			
			if(parseFloat(total_was_price) > parseFloat(total_price)) {
				$(prefix+'_display_was_price').set('html','Was: &pound;'+total_was_price);
			}
			
			if (!base_rrp_price || base_rrp_price == '') {
				$(prefix+'_display_rrp_price').set('html','');
			} else {
				rrp_saving = total_rrp_price - total_price;
				total_rrp_price = total_rrp_price.toFixed(2);
				rrp_saving = rrp_saving.toFixed(2);
				$(prefix+'_display_rrp_price').set('html','&pound;'+total_rrp_price); //+'<br />Save: &pound;'+rrp_saving);
			}

			// GET THE QTY //

			quantity = $(prefix+'_qty').get('value');
			quantity = quantity * 1;

			row_price = total_price * quantity;
			$(prefix+'_row_price').set('value',row_price);

			if (!base_rrp_price || base_rrp_price == '') {
				$(prefix+'_row_rrp_price').set('value','');
			} else {
				row_rrp_price = total_rrp_price * quantity;
				$(prefix+'_row_rrp_price').set('value',row_rrp_price);
			}

			overall_total_price = overall_total_price + row_price;



		});

		overall_total_price = overall_total_price.toFixed(2);
		$('itemlist_total_price').set('html','&pound;'+overall_total_price);

	}

	function addEvent2(obj,type,func) {
		if (obj.addEventListener) { obj.addEventListener(type,func,false); return true; }
		if (obj.attachEvent) { return obj.attachEvent("on"+type,func); }
		return false;
	}

	function removeEvent2(obj,type,func) {
		if (obj.removeEventListener) { obj.removeEventListener(type,func,false); return true; }
		if (obj.detachEvent) { return obj.detachEvent("on"+type,func); }
		return false;
	}

	function findEvent2(e) {
		if (!e) var e = window.event;
		return e;
	}
			
	function findTarget2(e) {
		if (e.target) t = e.target;
		else if (e.srcElement) t = e.srcElement;
		while (t.nodeType != 1) t = t.parentNode;
		return t;
	}

	function findObjectSize2(obj) {
        	x = obj.offsetWidth; y = obj.offsetHeight;
	        return [x,y];
	}

	function findObjectPosition2(obj) {
		var x = y = 0;
		if (obj.offsetParent) {
			x = obj.offsetLeft;
			y = obj.offsetTop;
			while (obj = obj.offsetParent) {
				x += obj.offsetLeft
				y += obj.offsetTop
			}
		}
		return [x,y];
	}

	function findViewportSize2() {
		var x = y = 0;
		if (self.innerHeight) { // if !ie
			x = self.innerWidth;
			y = self.innerHeight;
		} else if (document.documentElement && document.documentElement.clientHeight) { // if ie6 strict
			x = document.documentElement.clientWidth;
			y = document.documentElement.clientHeight;
		} else if (document.body) { // all other ie
			x = document.body.clientWidth;
			y = document.body.clientHeight;
		}
		return [x,y];
	}

	function findPageSize2() {
		var x = y = 0;
		var test1 = document.body.scrollHeight;
		var test2 = document.body.offsetHeight
		if (test1 > test2) { // if !ie mac
			x = document.body.scrollWidth;
			y = document.body.scrollHeight;
		} else { // if ie mac
			x = document.body.offsetWidth;
			y = document.body.offsetHeight;
		}
		return [x,y];
	}

	function findPageOffset2() {
		var x = y = 0;
		if (self.pageYOffset) { // if !ie 
			x = self.pageXOffset;
			y = self.pageYOffset;
		} else if (document.documentElement && document.documentElement.scrollTop) { // if ie6 strict
			x = document.documentElement.scrollLeft;
			y = document.documentElement.scrollTop;
		} else if (document.body) { // all other ie
			x = document.body.scrollLeft;
			y = document.body.scrollTop;
		}
		return [x,y];
	}

	function findMousePos2(e)
	{
		var x = y = 0;
		if (e.pageX || e.pageY) {
			x = e.pageX;
			y = e.pageY;
		} else if (e.clientX || e.clientY) 	{
			x = e.clientX + document.body.scrollLeft + document.documentElement.scrollLeft;
			y = e.clientY + document.body.scrollTop + document.documentElement.scrollTop;
		}
		return [x,y];
	}

	function vector2() {
		this.x = 0; this.y = 0; this.z = 0;
	}

	function addClass2(object,classname) {
		object.className += " "+classname;
	}

	function checkClass2(object,classname) {
		classes = object.className.split(' ');
		var i;
		for (i=0;i<classes.length;i++) {
			if (classes[i] == classname) return true;
		}
		return false;
	}

	function removeClass2(object,classname)
	{
		classes = object.className.split(' ');
		var i; var newclass = "";
		for (i=0;i<classes.length;i++) {
			if (classes[i] != classname) newclass += " "+classes[i];
		}
		object.className = newclass;
	}


	function newRequestForm() {
		
	}

