// Resize Menus
function size_menu() {
	// top menu numbers
	top_num = $$("div.hor_menu li").size();
	top_w = Math.floor(764/top_num)-1;
	top_last = 1 + top_w + 764%top_num;

	// botom menu numbers
	bottom_num = $$("div.bottom li").size();
	bottom_w = Math.floor(764/bottom_num)-1;
	bottom_last = bottom_w + 764%bottom_num;

	// top menu
	$$("div.hor_menu li").each(function(n) {
		n.setStyle({
		  width: top_w+'px',
		  textAlign: 'center'
		});

	});

	// bottom menu
	$$("div.bottom li").each(function(n) {
		n.setStyle({
		  width: bottom_w+'px',
		  textAlign: 'center'
		});

	});

	$$("div.hor_menu li a, div.bottom li a").each(function(n) {
		n.setStyle({
		  width: '100%'
		});

	});

	// top
	$$("div.hor_menu li").last().setStyle({	  width: top_last+'px', border: 'none'	});
	// bottom
	$$("div.bottom li").last().setStyle({	  width: bottom_last+'px', border: 'none'	});

}


// Show Info Message ---------------------------------------------------------------------------------
function info_msg(text) {
	top_offset=document.viewport.getScrollOffsets()['top'];
	screen_height=document.viewport.getHeight();

	var x=Builder.node('div', { className:'info_msg', id:'info_msg'}, [
		Builder.node('div', { className:'info_msg_box' }, [
			Builder.node('p'),
		]),
	]);

	// extend this element for Prototype
	x=$(x);

	// set height & top offset
	x.setStyle({height:screen_height+'px', top:top_offset+'px'});

	// insert text
	x.down('p').update(text);
	x.down('p').insert({top:'<img src="images/green_tick.gif" align="left"> &nbsp;&nbsp;&nbsp;&nbsp;'});
	
	// set box offset
	var msg_box=x.down('div.info_msg_box');
	var t=(screen_height-msg_box.getHeight())/2;
	msg_box.setStyle( {top:t+'px'} );

	// Add to document
	var body = document.getElementsByTagName("body").item(0);
	new Insertion.Bottom(body, x);

	var t=setTimeout('$("info_msg").remove();', 4000);
	$('info_msg').fade({ duration: 4.0 });

}
// ---------------------------------------------------------------------------------------------------
// Update Qty in Shopping Cart -----------------------------------------------------------------------
function update_qty(id,qty,ss) {

	new Ajax.Request('add.php', { 
		parameters: {
			action: 'update_qty',
			p: id,
			qty: qty,
			ss: ss
		},
		onSuccess: function(transport) {
			//  refresh shopping cart table
			$('checkout_cart').update(transport.responseText);
		}

	});
	return false;
}
// Update Colour Qty in Shopping Cart -----------------------------------------------------------------------
function update_cqty(id,col,qty,ss) {

	new Ajax.Request('add.php', { 
		parameters: {
			action: 'update_cqty',
			p: id,
			col: col,
			qty: qty,
			ss: ss
		},
		onSuccess: function(transport) {
			//  refresh shopping cart table
			$('checkout_cart').update(transport.responseText);
		}

	});
	return false;
}
// ---------------------------------------------------------------------------------------------------


function addLoadEvent(func) {
  var oldonload = window.onload;
  if (typeof window.onload != 'function') {
    window.onload = func;
  } else {
    window.onload = function() {
      oldonload();
      func();
    }
  }
}



addLoadEvent(size_menu);

