//////////////////////
// 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: "Aqua Lock Hanging Basket", category: "Water Saving - Garden"},
				{ label: "Backyard Composting by John Roulac", category: "Composting - Accessories"},
				{ label: "BeansTalk Pod", category: "Green Gifts"},
				{ label: "Big Drippa Watering Kit", category: "Water Saving - Garden"},
				{ label: "Big Square Compost Bin Extension Module", category: "Composting - Accessories"},
				{ label: "Big Square Wooden Modular Compost Bin", category: "Composting - Garden"},
				{ label: "Binifresh Refill", category: "Recycling"},
				{ label: "Binifresh Starter Pack", category: "Recycling"},
				{ label: "Blackwall Compost Converter Base Plate", category: "Composting - Accessories"},
				{ label: "Blackwall Compost Converter Kit", category: "Composting - Garden"},
				{ label: "Blackwall Compost Converter", category: "Composting - Garden"},
				{ label: "Blackwall Kitchen Composter", category: "Components"},
				{ label: "Blackwall Kitchen Composter", category: "Composting - Home"},
				{ label: "Bokashi Annual Subscription A", category: "Composting - Accessories"},
				{ label: "Bokashi Annual Subscription B", category: "Composting - Accessories"},
				{ label: "Bokashi Annual Subscription C", 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 Extension Tray", category: "Composting - Accessories"},
				{ label: "Can-O-Worms with Extra Value Pack", category: "Composting - Garden"},
				{ label: "Cloudburst 95 litre Water Butt Stand", category: "Water Saving - Accessories"},
				{ label: "Cloudburst Water Butt Kit", category: "Water Saving - Garden"},
				{ label: "Cloudburst Water Butt", category: "Water Saving - Garden"},
				{ label: "CompoSphere", category: "Composting - Garden"},
				{ label: "Compost Aerator", category: "Composting - Accessories"},
				{ label: "Compost Maker", category: "Composting - Accessories"},
				{ label: "Compost-a-Bag", category: "Composting - Accessories"},
				{ label: "Composting with Worms", category: "Composting - Accessories"},
				{ label: "Earth Maker Composter", category: "Composting - Garden"},
				{ label: "Easy2Grow Kit", category: "Water Saving - Garden"},
				{ label: "ecoBETA Dual Flush Converter", category: "Water Saving - Home"},
				{ label: "Efergy E2", category: "Energy Saving"},
				{ label: "Efergy Elite", category: "Energy Saving"},
				{ label: "Efergy Esocket", category: "Energy Saving"},
				{ label: "Efergy Footswitch", category: "Energy Saving"},
				{ label: "Efergy Remote Standby Eliminator", category: "Energy Saving"},
				{ label: "Efergy ShowerTime", category: "Water Saving - Home"},
				{ label: "Flowpoint Water Saving Shower Head", category: "Water Saving - Home"},
				{ label: "Garland Compost Sieve", category: "Composting - Accessories"},
				{ label: "Garland Timber Grow Bed", category: "Water Saving - Garden"},
				{ label: "Giant Rain Diverter", category: "Water Saving - Accessories"},
				{ label: "Giant Water Tank", category: "Water Saving - Garden"},
				{ label: "Grow Bag Waterers", category: "Water Saving - Garden"},
				{ label: "Gutter Mate", category: "Water Saving - Accessories"},
				{ label: "Harcostar Magnum Water Butt Kit", category: "Water Saving - Garden"},
				{ label: "Harcostar Universal Rain Trap", category: "Water Saving - Accessories"},
				{ label: "Harcostar Water Butt Linking Kit", category: "Water Saving - Accessories"},
				{ label: "Hatch for Blackwall Compost Converter", category: "Components"},
				{ label: "Heatkeeper Radiator Panels", category: "Energy Saving"},
				{ label: "Kerbside Box Net", category: "Recycling"},
				{ label: "Kingspan Roman Column Water Butt", category: "Water Saving - Garden"},
				{ label: "Klip Kit Wooden Composter Extension Module", category: "Composting - Accessories"},
				{ label: "Klip Kit Wooden Composter Lid", category: "Composting - Accessories"},
				{ label: "Klip Kit Wooden Composter", category: "Composting - Garden"},
				{ label: "Lid for Big Square Wooden Modular Compost Bin", category: "Composting - Accessories"},
				{ label: "Lid for Blackwall Compost Converter", category: "Components"},
				{ label: "Lid for Cloudburst Water Butt", category: "Components"},
				{ label: "Lid for Rainsaver Water Butt Kit", category: "Components"},
				{ label: "Make Your Own Recycled Paper Train Set", category: "Green Gifts"},
				{ label: "Mini Rainsaver Water Butt Kit", category: "Water Saving - Garden"},
				{ label: "Mini Rainsaver Water Butt Stand", category: "Water Saving - Accessories"},
				{ label: "Mini Rainsaver Water Butt", category: "Water Saving - Garden"},
				{ label: "Nordic Eco Galant Powershower Shower Head", category: "Water Saving - Home"},
				{ label: "Plant Waterer", category: "Water Saving - Garden"},
				{ label: "Polytank Polybutt", category: "Water Saving - Garden"},
				{ label: "Power Wash Ball", category: "Water Saving - Home"},
				{ label: "Rain Diverter with Leaf Filter", category: "Water Saving - Accessories"},
				{ label: "Rain-Gel", category: "Water Saving - Garden"},
				{ label: "Rainsaver Diverter Kit", category: "Water Saving - Accessories"},
				{ label: "Rainsaver Water Butt Kit", category: "Water Saving - Garden"},
				{ label: "Rainsaver Water Butt", category: "Water Saving - Garden"},
				{ label: "Rainwater Refresh Liquid", category: "Water Saving - Accessories"},
				{ label: "Rolson Tools Hole Saw", category: "Water Saving - Accessories"},
				{ label: "Savasocket Mobile", category: "Energy Saving"},
				{ label: "Savasocket Multi-Socket 6", category: "Energy Saving"},
				{ label: "Scoop for Kitchen Composter", category: "Components"},
				{ label: "Spraymagic M22 (Externally Threaded Taps)", category: "Water Saving - Home"},
				{ label: "Spraymagic M24 (Internally Threaded Taps)", category: "Water Saving - Home"},
				{ label: "Spraymagic Unifit", category: "Water Saving - Home"},
				{ label: "Straight Kerbside Box", category: "Recycling"},
				{ label: "Straight Kerbside Caddy", category: "Recycling"},
				{ label: "Straight Kitchen Caddy", category: "Composting - Accessories"},
				{ label: "Straight Kitchen Caddy", category: "Composting - Home"},
				{ label: "Tap for Kitchen Composter", category: "Components"},
				{ label: "Tapmagic M22 (Externally Threaded Taps)", category: "Water Saving - Home"},
				{ label: "Tapmagic M24 (Internally Threaded Taps)", category: "Water Saving - Home"},
				{ label: "Tapmagic Multifit", category: "Water Saving - Home"},
				{ label: "Tapmagic Unifit (Round Threadless Taps)", category: "Water Saving - Home"},
				{ label: "The Towa", category: "Composting - Accessories"},
				{ label: "Thermo King", category: "Composting - Accessories"},
				{ label: "Thermo King", category: "Composting - Garden"},
				{ label: "Tool for Kitchen Composter.", category: "Components"},
				{ label: "TuffBin", category: "Recycling"},
				{ label: "Wall Mounted Water Butt", category: "Water Saving - Garden"},
				{ label: "Water Butt Emptier", category: "Water Saving - Accessories"},
				{ label: "Water Butt Linking Kit", category: "Water Saving - Accessories"},
				{ label: "Water Butt Stand", category: "Water Saving - Accessories"},
				{ label: "Water Butt Tap", category: "Components"},
				{ label: "Water Slices", category: "Water Saving - Garden"},
				{ label: "Wheelie Bin", category: "Recycling"},
				{ label: "Wiggo Pod", category: "Green Gifts"},
				{ 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: "Worm Cafe with Value Pack", category: "Composting - 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();
});

///////////////////////////
// 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...) //true
		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 //true
		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");
 });
             
///////////////////////////
// jquery.uniform.config //
///////////////////////////

 $(function(){
			$("select, input:checkbox, input:radio, input:file").uniform();
 });
 
////////////////////////////
// jquery.pajinate.config //
////////////////////////////
			
			var showresults = 10;
			
			function initPagination(showresults) {
			
			$('#center_content_cat').pajinate({
					items_per_page : showresults,
					item_container_id : '#cat_box',					
					nav_panel_id : '.pagination',
					num_page_links_to_display : 5,
					//start_page : 5,					
					nav_label_first : '<<',
					nav_label_prev : '<',
					nav_label_next : '>',						
					nav_label_last : '>>'
				});
			}
			
			$(document).ready(function(){
				initPagination(showresults);
			});
			
			$(document).ready(function(){
				$('#showresults').change(function() {
				showresults = $('select#showresults').val();
  				initPagination(showresults);
				});
			});
	
/////////////////////////
// jquery.selso.config //
/////////////////////////

var options;

var selso = function(){
	$('#cat_box').find('li').selso(options);
};

//////////////////////////////
// jquery.ajaxchange.config //
//////////////////////////////

$(function () {
	var valueChanged = function () {
		switch (this.selectedIndex) {
			case 1:
				options = {type:'num',orderBy:'span.num',direction:'asc'};
				selso();
				initPagination(showresults);
				$("#sortby").ajaxChange("abort");
				break;
				
			case 2:
				options = {type:'num',orderBy:'span.num',direction:'desc'};
				selso();
				initPagination(showresults);
				$("#sortby").ajaxChange("abort");
				break;
			
			case 3:
				options = {type:'alpha',orderBy:'span.alpha',direction:'asc'};
				selso();
				initPagination(showresults);
				$("#sortby").ajaxChange("abort");
				break;
				
			case 4:
				options = {type:'alpha',orderBy:'span.alpha',direction:'desc'};
				selso();
				initPagination(showresults);
				$("#sortby").ajaxChange("done");
				break;
				
			default:
				selso();
				initPagination(showresults);
				$("#sortby").ajaxChange("done");
					
		}
		
	};
	
	$("#sortby").ajaxChange(function () {
		if (this.selectedIndex === 0) {
			$("#sortby").ajaxChange("done");
		}
		var scope = this;
		setTimeout(function () {
			valueChanged.apply(scope);
		}, 10);
	});
});
