function SmoothScroll() {
	$('.scroll').click(function() {
	  if (location.pathname.replace(/^\//,'') == this.pathname.replace(/^\//,'')
	  && location.hostname == this.hostname) {
		var $target = $(this.hash);
		$target = $target.length && $target
		|| $('[name=' + this.hash.slice(1) +']');
		if ($target.length) {
		  var targetOffset = $target.offset().top;
		  $('html,body')
		  .animate({scrollTop: targetOffset}, 1000);
		 return false;
		}
	  }
	});
}

$(document).ready(function() {

	$(document).pngFix();
	Shadowbox.init();
	SmoothScroll();
	$('input').customInput();

	$("a[rel*='external']").attr({ target: "_blank" });

	var volatile = $(".field input")
	volatile.focus(function(event) {
		if ($(this).val() == $(this).attr("title")) {
			$(this).val("");
		} 
	}, volatile.blur(function(event) {
		if ($(this).val() == "") {
			$(this).val($(this).attr("title"));
		}
	}
    ));


	// CarouFredSel

	var slideCounter = $('#bannerSlider li').size();
	$("#bannerSlider li:not(:first) a").attr("tabIndex", "-1");
	$("#bannerSlider").carouFredSel({
		items: 1,
		scroll: {
			pauseOnHover: true,
			easing: "easeInOutExpo",
			duration: 1000,
			onBefore: function(oldItems, newItems) {
				oldItems.children('a').attr("tabIndex", "-1");
				newItems.children('a').removeAttr("tabIndex");
			}
		},
		auto: 5000,
		prev: ".bannerSlider .carouselWrapper .controls .prev",
		next: ".bannerSlider .carouselWrapper .controls .next",
		pagination: {
			container: ".carouselNav ul",
			anchorBuilder: function(nr) {
				var str = '<li><a href="#">';
				str += nr;
				str += '</a></li>';
				return str;
			}
		}
	});

	$('#collectionsDesc').html($('#collectionsSlider li:first div').html());
	var slideCounter = $('#bannerSlider li').size();
	$("#collectionsSlider li:not(:first) a").attr("tabIndex", "-1");
	$("#collectionsSlider").carouFredSel({
		items: 1,
		scroll: {
			pauseOnHover: true,
			easing: "easeInOutExpo",
			duration: 1000,
			onBefore: function(oldItems, newItems) {
				$('#collectionsDesc').fadeOut();
				oldItems.children('a').attr("tabIndex", "-1");
				newItems.children('a').removeAttr("tabIndex");
			},
			onAfter: function(oldItems, newItems) {
				$('#collectionsDesc').html(newItems.children('div').html());
				$('#collectionsDesc').fadeIn();
			}
		},
		auto: 5000,
		prev: "#collectionsSlider .bannerSlider .carouselWrapper .controls .prev",
		next: "#collectionsSlider .bannerSlider .carouselWrapper .controls .next",
		pagination: {
			container: ".carouselNav ul",
			anchorBuilder: function(nr) {
				var str = '<li><a href="#">';
				str += nr;
				str += '</a></li>';
				return str;
			}
		}
	});


	var slideCounter = $('#swatchSlider li').size();
	$("#swatchSlider li:not(:first) a").attr("tabIndex", "-1");
	$("#swatchSlider").carouFredSel({
		items: 1,
		scroll: {
			pauseOnHover: true,
			easing: "easeInOutExpo",
			duration: 1000,
			onBefore: function(oldItems, newItems) {
				oldItems.children('a').attr("tabIndex", "-1");
				newItems.children('a').removeAttr("tabIndex");
			}
		},
		auto: 5000,
		pagination: {
			container: ".carouselNav ul",
			anchorBuilder: function(nr) {
				var str = '<li><a href="#">';
				str += nr;
				str += '</a></li>';
				return str;
			}
		}
	});

	// search filter accordian
	$('.filterSection > ul').hide();
	$('a.toggle').click(function() {
		$(this).parent().toggleClass("active").next().toggle('slow');
		return false;
	}).next().hide();


	$('#stockistMap').empty();
	$('#stockistMap').flash({
		src: '/_images/flash/map.swf',
		wmode: 'transparent',
		width: 585,
		height: 400
	});

	// Search Filter Loader
	$('.searchFilter input.formButton').click(function() {
		SearchFilterLoader();
		return true;
	});
	$('.filterSection ul li a').click(function() {
		SearchFilterLoader();
		return true;
	});
	$('fieldset.searchKeywords div.wrapper a').click(function() {
		SearchFilterLoader();
		return true;
	});

	// Magic Zoom

	MagicZoomPlus.options = {
		'disable-expand': 'true',
		'disable-zoom': 'false',
		'opacity': '50',
		'zoom-width': '300',
		'zoom-height': '400',
		'zoom-position': 'bottom:0, left:0',
		'smoothing-speed': '30'
	}

	setTimeout(function() { $('.MagicZoomPlus').css("cursor", "url('/_images/general/zoomin.cur'), pointer"); }, 1);

	$('a.zoomOverride').click(function(e) {
		e.preventDefault();
		var image = $("#mainImage");
		image.children().attr('src', $(this).attr('href'));
	});

});

function SearchFilterLoader()
{
	$('div.filterSection').hide();
	$('fieldset.searchKeywords div.wrapper').hide();
	$('div.loading').show();
	return true;
}

