
$(function () {

scrollOptions = {
		showArrows:true,
		scrollbarWidth: 18,
		scrollbarOnLeft:true,
		arrowSize: 0,
		scrollbarMargin: 5,
		animateTo: false
	};
	
	
treeviewOptions = {
		collapsed: true,
		speed: "slow",
		unique: true,
		persist: "hash"
	};



	//Blur links
	$('a').livequery("click", function(e) {
		$(this).blur();
	});

	// Flash Objects
	var flashloc = "http://"+window.location.hostname;
	if ( $('#tagline').length > 0 ) {
		var so = new SWFObject("http://www.ayrpak.co.nz/flash/tagline.swf", "taglineswf", "100%", "100%", "7", "#000000");
		so.write("tagline");
	}
	if ( $('#banner').length > 0 ) {
		var so = new SWFObject("http://www.ayrpak.co.nz/flash/banner.swf", "bannerswf", "100%", "100%", "7", "#000000");
		so.write("banner");
	}
	if ( $('#news_widget').length > 0 ) {
		var so = new SWFObject("http://www.ayrpak.co.nz/flash/news.swf", "news", "300", "250", "7", "#000000");
		so.write("news_widget");
	}	
	if ( $('#specials_widget').length > 0 ) {
		var so = new SWFObject("http://www.ayrpak.co.nz/flash/specials2.swf", "specials", "300", "295", "7", "#000000");
		so.write("specials_widget");
	}
	if ( $('#featured_widget').length > 0 ) {
		var so = new SWFObject("http://www.ayrpak.co.nz/flash/featured2.swf", "featured", "300", "295", "7", "#000000");
		so.write("featured_widget");
	}
	if ( $('#kgp_widget').length > 0 ) {
		var so = new SWFObject("http://www.ayrpak.co.nz/flash/kgp.swf", "kgp", "300", "160", "7", "#000000");
		so.write("kgp_widget");
	}





	$("#pane").treeview(treeviewOptions);
	$('#pane').jScrollPane(scrollOptions);
	
	$('.bg:first').css('margin-top', '0'); 
	
	// Append right double arrow to scrollpane expandables
	$('.expandable').each( function() {
		$(this).find('span:first').append('&nbsp;&raquo;');
	});
	
	
	// ScrollPane hover
	$('#pane a').hover(
      function () {
        $(this).toggleClass('scrollHover');
      }, 
      function () {
        $(this).toggleClass('scrollHover');
      }
    );
	
	

	
	
	
	
 	// Bind add-to-cart inputs (dynamic)
 	$('.add-cart').livequery("click", function(e) {
		add_item($(this));
		return false;
	});

 	
 
 	// hide messages box
 	$('#messages').hide();
 	
 
 
 }); // end doc ready	





function reinitialiseScrollPane() {
	$('#pane').jScrollPane(scrollOptions);
}




function image_pop(url) {
	window.open(url,'','width=420,height=620,resizable=1,scrollbars=1');
}

Number.prototype.formatMoney = function(c, d, t){
	var n = this, c = isNaN(c = Math.abs(c)) ? 2 : c, d = d == undefined ? "," : d, t = t == undefined ? "." : t, s = n < 0 ? "-" : "", i = parseInt(n = Math.abs(+n || 0).toFixed(c)) + "", j = (j = i.length) > 3 ? j % 3 : 0;
	return s + (j ? i.substr(0, j) + t : "") + i.substr(j).replace(/(\d{3})(?=\d)/g, "$1" + t) + (c ? d + Math.abs(n - i).toFixed(c).slice(2) : "");
};