//////////////////////
// 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: "Binifresh Refill", category: "Two Wheeled Bins"},
				{ label: "Binifresh Starter Pack", category: "Two Wheeled Bins"},
				{ label: "Blackwall Kitchen Composter", category: "Food Waste"},
				{ label: "Brown Glass Lid for Straight EcoSort", category: "EcoSort Lids and Bodies"},
				{ label: "Cans Lid for Straight EcoSort", category: "EcoSort Lids and Bodies"},
				{ label: "Clear Glass Lid for Straight EcoSort", category: "EcoSort Lids and Bodies"},
				{ label: "Colour Coded Bin", category: "Colour Coded Bins"},
				{ label: "Compost-A-Bag Compostable Caddy Liners", category: "Food Waste"},
				{ label: "Engels Battery Box", category: "Battery Boxes"},
				{ label: "Four Wheeled Bin", category: "Four Wheeled Bins"},
				{ label: "Frame Lid for Straight EcoSort", category: "EcoSort Lids and Bodies"},
				{ label: "General Waste Lid for Straight EcoSort", category: "EcoSort Lids and Bodies"},
				{ label: "Green Glass Lid for Straight EcoSort", category: "EcoSort Lids and Bodies"},
				{ label: "Lid for 60 litre Colour Coded Bin", category: "Colour Coded Bins"},
				{ label: "Lid for 90 litre Colour Coded Bin", category: "Colour Coded Bins"},
				{ label: "Minimax Kitchen Caddy", category: "Food Waste"},
				{ label: "Mixed Glass Lid for Straight EcoSort", category: "EcoSort Lids and Bodies"},
				{ label: "Paper Lid for Straight EcoSort", category: "EcoSort Lids and Bodies"},
				{ label: "Personal Document Container", category: "Deskside Bins"},
				{ label: "Plastic Bottles Lid for Straight EcoSort", category: "EcoSort Lids and Bodies"},
				{ label: "Secure Lid for Straight EcoSort", category: "EcoSort Lids and Bodies"},
				{ label: "Straight EcoSort Maxi Brown Glass Kit", category: "EcoSort Maxi"},
				{ label: "Straight EcoSort Maxi Cans Kit", category: "EcoSort Maxi"},
				{ label: "Straight EcoSort Maxi Clear Glass Kit", category: "EcoSort Maxi"},
				{ label: "Straight EcoSort Maxi Frame Kit", category: "EcoSort Maxi"},
				{ label: "Straight EcoSort Maxi General Waste Kit", category: "EcoSort Maxi"},
				{ label: "Straight EcoSort Maxi Green Glass Kit", category: "EcoSort Maxi"},
				{ label: "Straight EcoSort Maxi Mixed Glass Kit", category: "EcoSort Maxi"},
				{ label: "Straight EcoSort Maxi Paper Kit", category: "EcoSort Maxi"},
				{ label: "Straight EcoSort Maxi Plastic Bottles Kit", category: "EcoSort Maxi"},
				{ label: "Straight EcoSort Maxi Secure Kit", category: "EcoSort Maxi"},
				{ label: "Straight EcoSort Maxi Swing Kit", category: "EcoSort Maxi"},
				{ label: "Straight EcoSort Maxi", category: "EcoSort Lids and Bodies"},
				{ label: "Straight EcoSort Midi Brown Glass Kit", category: "EcoSort Midi"},
				{ label: "Straight EcoSort Midi Cans Kit", category: "EcoSort Midi"},
				{ label: "Straight EcoSort Midi Clear Glass Kit", category: "EcoSort Midi"},
				{ label: "Straight EcoSort Midi Frame Kit", category: "EcoSort Midi"},
				{ label: "Straight EcoSort Midi General Waste Kit", category: "EcoSort Midi"},
				{ label: "Straight EcoSort Midi Green Glass Kit", category: "EcoSort Midi"},
				{ label: "Straight EcoSort Midi Mixed Glass Kit", category: "EcoSort Midi"},
				{ label: "Straight EcoSort Midi Paper Kit", category: "EcoSort Midi"},
				{ label: "Straight EcoSort Midi Plastic Bottles Kit", category: "EcoSort Midi"},
				{ label: "Straight EcoSort Midi Secure Kit", category: "EcoSort Midi"},
				{ label: "Straight EcoSort Midi Swing Kit", category: "EcoSort Midi"},
				{ label: "Straight EcoSort Midi", category: "EcoSort Lids and Bodies"},
				{ label: "Straight Kerbside Box", category: "Kerbside"},
				{ label: "Straight Kerbside Caddy", category: "Kerbside"},
				{ label: "Straight Kitchen Caddy", category: "Food Waste"},
				{ label: "Swing Lid for Straight EcoSort", category: "EcoSort Lids and Bodies"},
				{ label: "Trolley for 60 litre Colour Coded Bin", category: "Colour Coded Bins"},
				{ label: "Trolley for 90 litre Colour Coded Bin", category: "Colour Coded Bins"},
				{ label: "Two Wheeled Bin", category: "Two Wheeled Bins"}
				];
	
	$('#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)
			2: {
				// disable it by setting the property sorter to false
				sorter: false
				},
			// assign the sixth column (we start counting zero)
			5: {
				// disable it by setting the property sorter to false
				sorter: false
				},
			// assign the seventh column (we start counting zero)
		// 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 //
///////////////////////////////

$(document).ready(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.lddm.config //
////////////////////////

            $(function() {
				/**
				 * the menu
				 */
				var $menu = $('#ldd_menu');
				
				/**
				 * for each list element,
				 * we show the submenu when hovering and
				 * expand the span element (title) to 510px
				 */
				$menu.children('li').each(function(){
					var $this = $(this);
					var $span = $this.find('span');
					$span.data('width',$span.width());

					$this.bind('mouseenter',function(){												 						 
						$menu.find('.ldd_submenu').stop(true,true).hide();
						//$span.stop().animate({'width':'510px'},300,function(){
							$this.find('.ldd_submenu').slideDown(300);
						//});
					}).bind('mouseleave',function(){
						$this.find('.ldd_submenu').stop(true,true).hide();
						//$span.stop().animate({'width':$span.data('width')+'px'},300);
					});
				});
            });
             
///////////////////////////
// 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);
	});
});

///////////////////////////
// jquery.reorder.config //
///////////////////////////

		$(document).ready(function() {
								   
			var $li = $('#hp_banners').children().hide();
			var len = $li.length;
			var counter = 6; // how many items to display
			var randomnumber;
			
			if ($('#hp_banners').length) {   // do something 
			while (counter > 0) {
				randomnumber = Math.floor(Math.random() * (len + 1));
				if ($li.eq(randomnumber).is(":hidden")) {
					$li.eq(randomnumber).show();
					counter -= 1;
				}
			}	
		}
	});
