//////////////////////
// jquery-ui.config //
//////////////////////

$(function(){
	// Tabs
	$('#tabs').tabs();	
	var $tabs = $('#tabs').tabs();
	$('#buy-now-options').click(function() { // bind click event to link
    $tabs.tabs('select', 0); // switch to third tab
    return false;
	});
});

$.widget("custom.catcomplete", $.ui.autocomplete, {
	_renderMenu: function( ul, items ) {
		var self = this,
			currentCategory = "";
		$.each( items, function( index, item ) {
			if ( item.category != currentCategory ) {
				ul.append( "<li class='ui-autocomplete-category'>" + item.category + "</li>" );
				currentCategory = item.category;
			}
			self._renderItem( ul, item );
		});
	}
});

$(function() {
	var data = [
				{ label: "Backyard Composting by John Roulac", category: "Composting - Accessories"},
				{ label: "Big Drippa Watering Kit", category: "Water Saving - Garden"},
				{ label: "Binifresh Refill", category: "Recycling"},
				{ label: "Binifresh Starter Pack", category: "Recycling"},
				{ label: "Biotal All Purpose Compost Maker Liquid", category: "Composting - Accessories"},
				{ label: "Bokashi Bran Refill", category: "Composting - Accessories"},
				{ label: "Can-O-Worms Basic with Budget Pack", category: "Composting - Garden"},
				{ label: "Can-O-Worms with Extra Value Pack", category: "Composting - Garden"},
				{ label: "Can-O-Worms Extension Tray", category: "Composting - Accessories"},
				{ label: "Cloudburst Water Butt Kit", category: "Water Saving - Garden"},
				{ label: "Compost-A-Bag Compostable Caddy Liners", category: "Composting - Accessories"},
				{ label: "Cloudburst Water Butt", category: "Water Saving - Garden"},
				{ label: "Garland Compost Sieve", category: "Composting - Accessories"},
				{ label: "Composting with Worms", category: "Composting - Accessories"},
				{ label: "Blackwall Compost Converter", category: "Composting - Garden"},
				{ label: "Blackwall Compost Converter Kit", category: "Composting - Garden"},
				{ label: "Blackwall Compost Converter Base Plate", category: "Composting - Accessories"},
				{ label: "Rainsaver Diverter Kit", category: "Water Saving - Accessories"},
				{ label: "WaterGreen", category: "Water Saving - Home"},
				{ label: "Earth Maker Composter", category: "Composting - Garden"},
				{ label: "ecoBETA Siphon", category: "Water Saving - Home"},
				{ label: "Efergy Elite", category: "Energy Saving"},
				{ label: "Efergy E2", category: "Energy Saving"},
				{ label: "Klip Kit Wooden Composter Extension Module", category: "Composting - Accessories"},
				{ label: "Efergy Footswitch", category: "Energy Saving"},
				{ label: "Grow Bag Waterers", category: "Water Saving - Garden"},
				{ label: "Giant Rain Diverter", category: "Water Saving - Accessories"},
				{ label: "Harcostar Universal Rain Trap", category: "Water Saving - Accessories"},
				{ label: "Harcostar Water Butt Linking Kit", category: "Water Saving - Accessories"},
				{ label: "Heatkeeper Radiator Panels", category: "Energy Saving"},
				{ label: "Rolson Tools Hole Saw", category: "Water Saving - Accessories"},
				{ label: "Straight Kerbside Box", category: "Recycling"},
				{ label: "Straight Kitchen Caddy", category: "Composting - Home"},
				{ label: "Straight Kerbside Caddy", category: "Recycling"},
				{ label: "Blackwall Kitchen Composter", category: "Composting - Home"},
				{ label: "Klip Kit Wooden Composter", category: "Composting - Garden"},
				{ label: "Klip Kit Wooden Composter Lid", category: "Composting - Accessories"},
				{ label: "Rain Diverter with Leaf Filter", category: "Water Saving - Accessories"},
				{ label: "Water Butt Linking Kit", category: "Water Saving - Accessories"},
				{ label: "Harcostar Magnum Water Butt Kit", category: "Water Saving - Garden"},
				{ label: "Kerbside Box Net", category: "Recycling"},
				{ label: "Straight Kitchen Caddy", category: "Composting - Accessories"},
				{ label: "Plant Waterer", category: "Water Saving - Garden"},
				{ label: "Power Wash Ball", category: "Water Saving - Home"},
				{ label: "Biotal Refresh Liquid", category: "Water Saving - Accessories"},
				{ label: "Rain-Gel", category: "Water Saving - Garden"},
				{ label: "Polytank Polybutt", category: "Water Saving - Garden"},
				{ label: "Rainsaver Water Butt Kit", category: "Water Saving - Garden"},
				{ label: "Flowpoint Water Saving Shower Head", category: "Water Saving - Home"},
				{ label: "Nordic Eco Galant Showerhead", category: "Water Saving - Home"},
				{ label: "Efergy ShowerTime", category: "Water Saving - Home"},
				{ label: "Mini Rainsaver Water Butt Stand", category: "Water Saving - Accessories"},
				{ label: "Mini Rainsaver Water Butt Kit", category: "Water Saving - Garden"},
				{ label: "Mini Rainsaver Water Butt", category: "Water Saving - Garden"},
				{ label: "Efergy Remote Standby Eliminator", category: "Energy Saving"},
				{ label: "Thermo King", category: "Composting - Garden"},
				{ label: "Thermo King", category: "Composting - Accessories"},
				{ label: "Tapmagic Dual Flow for Round Threadless Taps", category: "Water Saving - Home"},
				{ label: "Tapmagic Dual Flow for Internally Threaded Taps", category: "Water Saving - Home"},
				{ label: "Tapmagic Dual Flow for Externally Threaded Taps", category: "Water Saving - Home"},
				{ label: "Tapmagic Dual Flow", category: "Water Saving - Home"},
				{ label: "Blackwall Compost Tumbler", category: "Composting - Garden"},
				{ label: "Compost Aerator", category: "Composting - Accessories"},
				{ label: "Laser Tools Water Butt Drill Pump", category: "Water Saving - Accessories"},
				{ label: "Water Butt Emptier", category: "Water Saving - Accessories"},
				{ label: "Cloudburst 95 litre Water Butt Stand", category: "Water Saving - Accessories"},
				{ label: "Water Butt Stand", category: "Water Saving - Accessories"},
				{ label: "Water Butt Tap", category: "Components"},
				{ label: "Wall Mounted Water Butt", category: "Water Saving - Garden"},
				{ label: "Rainsaver Water Butt", category: "Water Saving - Garden"},
				{ label: "Kingspan Roman Column Water Butt", category: "Water Saving - Garden"},
				{ label: "Wooden Modular Compost Bin Extension Module", category: "Composting - Accessories"},
				{ label: "Wooden Modular Compost Bin Lid", category: "Composting - Accessories"},
				{ label: "Wooden Modular Compost Bin", category: "Composting - Garden"},
				{ label: "Giant Water Tank", category: "Water Saving - Garden"},
				{ label: "Water Slices", category: "Water Saving - Garden"}
];
	
	$('#searchfield').catcomplete({
		delay: 0,
		minLength: 3,
		source: data
	});
});

//////////////////////////////
// jquery.thumbhover.config //
//////////////////////////////

$(function(){
	$("#buyTable img[src*='_th.jpg']").thumbPopup({imgSmallFlag: "_th", imgLargeFlag: "_th", popupCSS:{'border': '1px solid #cccccc', 'background': '#ffffff'}});
});

///////////////////////////////
// jquery.tablesorter.config //
///////////////////////////////

$(function(){
	// extend the default setting to always include the zebra widget.
	$.tablesorter.defaults.widgets = ['zebra'];
	// call the tablesorter plugin
	$("#specTable").tablesorter({
		// pass the headers argument and assing a object
		headers: {
		// define a custom text extraction function
		textExtraction: function(node) {
				// extract data from markup and return it
				return node.childNodes[0].childNodes[0].innerHTML;
			}
		}
	});
	$("#buyTable").tablesorter({
		// pass the headers argument and assing a object
		headers: {
			// assign the first column (we start counting zero)
			0: {
				// disable it by setting the property sorter to false
				sorter: false
				},
			// assign the third column (we start counting zero)
			3: {
				// disable it by setting the property sorter to false
				sorter: false
				},
		// define a custom text extraction function
		textExtraction: function(node) {
				// extract data from markup and return it
				return node.childNodes[0].childNodes[0].innerHTML;
			}
		}
	});
	$("#relatedTable").tablesorter({
		// pass the headers argument and assing a object
		headers: {
			// assign the first column (we start counting zero)
			0: {
				// disable it by setting the property sorter to false
				sorter: false
				},
			// assign the third column (we start counting zero)
			3: {
				// disable it by setting the property sorter to false
				sorter: false
				},
		// define a custom text extraction function
		textExtraction: function(node) {
				// extract data from markup and return it
				return node.childNodes[0].childNodes[0].innerHTML;
			}
		}
	});
	$("#faqTable").tablesorter({
		// pass the headers argument and assing a object
		headers: {
			// assign the first column (we start counting zero)
			0: {
				// disable it by setting the property sorter to false
				sorter: false
				},
			// assign the second column (we start counting zero)
			1: {
				// disable it by setting the property sorter to false
				sorter: false
				},
			// assign the second column (we start counting zero)
			2: {
				// disable it by setting the property sorter to false
				sorter: false
				},
		// define a custom text extraction function
		textExtraction: function(node) {
				// extract data from markup and return it
				return node.childNodes[0].childNodes[0].innerHTML;
			}
		}
	});
}); 
// $(function(){
// 	$("#specTable").tablesorterPager({
// 		container: $("#pager")
// 	}); 
// 	$("#buyTable").tablesorterPager({
// 		container: $("#pager")
// 	});
// 	$("#relatedTable").tablesorterPager({
// 		container: $("#pager")
// 	});
// }); 

///////////////////////////
// jquery.shuffle.config //
///////////////////////////

$(function() {
		$('#banner_offer').shuffle();
		$('#banner_delivery').shuffle();
		$('#product_header').shuffle();
});

////////////////////////////
// jquery.lightbox.config //
////////////////////////////

$(function() {
        $('#gallery a').lightBox();
		$('.lightbox a').lightBox();
});

///////////////////////////
// jquery.fortune.config //
///////////////////////////

$(function() {
		$(".waterwise").fortune({file: "/sites/assets/json/tips.json", cookieNode: "waterwise", metaNodes: {theTitle: "title", theContent: "content"}, animate: false});
});

/////////////////////////////
// jquery.formclear.config //
/////////////////////////////

$(function() { 
   $('.cleardefault').formclear({
   inactivecolor:'', // Defaults to #777 (dark grey)
   activecolor:'',  // defaults to #000 (black)
   emptyval:'' // defaults to '' (nothing, as in cleared)
	}); 
});

///////////////////////////////
// jquery.fancyButton.config //
///////////////////////////////

$(function() {
 $(document).fancyButton();
});

/////////////////////////////
// jquery.linkIcons.config //
/////////////////////////////

$(document).ready(function() {

	// Add pdf icons to pdf links
	$("a[href$='.pdf']").addClass("pdf");
	 
	// Add txt icons to document links (doc, rtf, txt)
	$("a[href$='.doc'], a[href$='.txt'], a[href$='.rft']").addClass("txt");

	// Add zip icons to Zip file links (zip, rar)
	$("a[href$='.zip'], a[href$='.rar']").addClass("zip"); 
	
	// Add email icons to email links
	$("a[href^='mailto:']").addClass("email");

	//Add external link icon to external links - 
	//$('a').filter(function() {
		//Compare the anchor tag's host name with location's host name
	//    return this.hostname && this.hostname !== location.hostname;
	//  }).addClass("external");

});


//////////////////////////////
// jquery.activeLink.config //
//////////////////////////////

 $(function(){
   var path = location.pathname.substring(1);
   if ( path )
     $('#navigation ul li a[href$="' + path + '"]').attr('class', 'selected');
 });
 
 
/////////////////////////
// jquery.pngie.config //
/////////////////////////

$(document).pngie();

////////////////////////////////
// jquery.bxSlider.config //
////////////////////////////////

$(document).ready(function(){
	$('#slides1').bxSlider({
		alignment: 'horizontal',        // 'horizontal', 'vertical' - direction in which slides will move
		controls: false,                // determines if default 'next'/'prev' controls are displayed
		speed: 500,                     // amount of time slide transition lasts (in milliseconds)
		pager: true,                   // determines if a numeric pager is displayed (1 2 3 4...)
		pager_short: false,             // determines if a 'short' numeric pager is displayed (1/4)
		pager_short_separator: ' / ',   // text to be used to separate the short pager
		margin: 0,                      // if 'horizontal', applies a right margin to each slide, if 'vertical' a
		                                // bottom margin is applied. example: margin: 50
		next_text: '',           	    // text to be displayed for the 'next' control
		next_image: '',                 // image to be used for the 'next' control
		prev_text: '',                  // text to be displayed for the 'prev' control
		prev_image: '',                 // image to be used for the 'prev' control
		auto: true,                     // determines if slides will move automatically
		pause: 4000,                    // time between each slide transition (auto mode only) 
		auto_direction: 'next',         // order in which slides will transition (auto mode only)
		auto_hover: true,               // determines if slideshow will pause while mouse is hovering over slideshow
		auto_controls: false,           // determines if 'start'/'stop' controls are displayed (auto mode only)
		ticker: false,                  // determines if slideshow will behave as a constant ticker
		ticker_controls: false,         // determines if 'start'/'stop' ticker controls are displayed (ticker mode only)
		ticker_direction: 'next',       // order in which slides will transition (ticker mode only)
		ticker_hover: true,             // determines if slideshow will pause while mouse is hovering over ticker
		stop_text: 'stop',              // text to be displayed for the 'stop' control
		start_text: 'start',            // text to be displayed for the 'start' control
		wrapper_class: 'bxslider_wrap'  // class name to be used for the outer wrapper of the slideshow
	});
});

////////////////////////////////
// jquery.droplinemenu.config //
////////////////////////////////

 $(function(){
			droplinemenu.buildmenu("navigation");
 });
