(function($) {
	
	Drupal.behaviors.hfs2011 = {
		attach: function(context, settings) {
			
			$('.region-specials ul li div').css('display', 'block')
			$('.region-specials ul li span').css('display', 'auto')
			$('.specials-infobox-bg').css('display', 'block')
			$('.specials-infobox').css('display', 'block')
			
			/**
			 * Specials jCarousel product information.
			 * We grab the instance of the carousel, and update the infobox contents
			 * by using the "first" method within the jCarousel instance.
			 */
			
			// Returns the carousel index of the first item in view
			function getItem() {
				var i = $('.jcarousel-view--specials--block').data('jcarousel').first
				return i
			}
			
			// Grabs the textual information of our item and copies it to the infobox
			function getInfo(n) {
				var i = getItem() + n
				i = i.toString()
				$('.specials-infobox .wrapper').fadeOut('fast',
					function() {
						$(this).children('span').remove()
						$('.jcarousel-item-' + i + ' span').clone().appendTo(this)
					}
				).fadeIn('fast')
			}
			
			$('.jcarousel-next').click(
				function() {
					getInfo(3)
				}
			)
			
			$('.jcarousel-prev').click(
				function() {
					getInfo(1)
				} 
			)
			
			// Initial state of the carousel after page load
			function initInfoBox() {
				$('.jcarousel-item-3 span').clone().appendTo('.specials-infobox .wrapper')
				$('.specials-infobox .wrapper').fadeIn('slow')
			}

			initInfoBox()
			
			
			/**
			 * Product Finder accordion style filters.
			 * We call the accordion library from the 'product finder' template file
			 * and apply the accordion with some non-default options.
			 *
			 * We capture the active accordion index via a hidden input field,
			 * so it is persistent during postbacks,
			 * and then populate it during the change event of the accordion.
			 */
			// var activeIndex = parseInt($().val())
			
			// $('.accordion-exposed-form').accordion({
			// 	// active: false,
			// 	autoHeight: false,
			// 	// collapsible: true,
			// 	// event: 'mouseover',
			// 	navigation: true,
			// 	// active: activeIndex,
			// 	// change: function (event, ui) {
			// 	// 	var index = $(this).children('h3').index(ui.newHeader)
			// 	// 	$().val(index)
			// 	// }
			// })
			
			
			/**
			 * Diverse photo slideshows
			 */
			$('.slideshow').cycle('fade')
			
			$('.slideshow-random').cycle({
				fx: 'fade',
				random: 1
			})
			
			
			/**
			 * Diverse overlay content
			 */
			$('.overlay-trigger[rel]').overlay({
				mask: {
					color: '#333',
					loadSpeed: 200,
					opacity: 0.9
				},
				closeOnClick: false
			})
			
			
		}
	}
	
})(jQuery);

