$(document).ready(function(){

	$('.product-thumbnail').opacityrollover({
		mouseOutOpacity:   1.00,
		mouseOverOpacity:  0.90,
		fadeSpeed:         'fast',
		exemptionSelector: '.selected'
	});
	
	$('.gallery .photo').opacityrollover({
		mouseOutOpacity:   1.00,
		mouseOverOpacity:  0.80,
		fadeSpeed:         'fast',
		exemptionSelector: '.selected'
	});
	
	$('#basket .option').opacityrollover({
		mouseOutOpacity:   0.85,
		mouseOverOpacity:  1.00,
		fadeSpeed:         'fast',
		exemptionSelector: '.selected'
	});
	
	$('.gallery').each(function() {
		$('a.photo', this).lightBox();
	});
	
	$('a.toggler').toggler({animate:true, speed: 200});
	$('a.toggler:first').click();
	
	$('a.toggler-single').each(function() {
		var ele = $(this).attr('href');
		$(this).bind('click', {id: ele}, function(event) {
				
			$('a.toggler-single').each(function() {
				var ele = $(this).attr('href');
				$(ele).hide();
			});
			
			$(event.data.id).show();
		});
	});
	
	$('a.toggler-single').each(function() {
		if ($(this).attr('href') == '#01')
			$(this).click();
	});
	
	$('select.product-selector').change(function() {
		$(this).parent().attr('action', '/basket/add/' + $(this).val());
	});
	

	// build the slides
	if ($('#wrapper-slideshow').length) {
		$.each($.bgSlideshow.images, function(index, value) {
			var id = index + 1;
			var slide = $('<div></div>')
					.attr('id', $.bgSlideshow.element + '-' + (id))
					.css('position', 'absolute')
					.css('width', '984px')
					.css('height', '522px')
					.css('-moz-border-radius-topleft', '30px')
					.css('-moz-border-radius-topright', '30px')
					.css('-webkit-border-top-left-radius', '30px')
					.css('-webkit-border-top-right-radius', '30px')
					.css('border-top-left-radius', '30px')
					.css('border-top-right-radius', '30px')
					.css('background-image', 'url(' + $.bgSlideshow.path + value + ')')
					.hide();
			
			
			$('#' + $.bgSlideshow.element).append(slide);
			$.bgSlideshow.slides.push($(slide));
		});
	
		// check if the browser is internet explorer
		// and for the existence of the wonderful jquery.curvycorners plugin
		// (http://code.google.com/p/jquerycurvycorners/)
		// this will give us rounded corners in IE
		if ($.browser.msie && $.fn.corner) {
			$.each($.bgSlideshow.slides, function(index, value) {
				this.corner(
					{
					tl: { radius: 30 }, 
					tr: { radius: 30 }, 
					bl: { radius: 0 }, 
					br: { radius: 0 }, 
					antiAlias: true
					}
				);
			});
		}
		
		// show the first slide
		$.bgSlideshow.slides[$.bgSlideshow.current].show();
	
		if ($.bgSlideshow.images.length != 1) {
			
			// create the timer to loop through each slide
			$.bgSlideshow.timer = setInterval(function() {
		
				var previous = $.bgSlideshow.current;
		
				if ((++$.bgSlideshow.current) >= $.bgSlideshow.slides.length)
					$.bgSlideshow.current = 0;
				
				
				$.bgSlideshow.slides[$.bgSlideshow.current].css('z-index', '2');
				$.bgSlideshow.slides[previous].css('z-index', '1');
				
				
				$.bgSlideshow.slides[$.bgSlideshow.current].fadeIn(1000, function() {
					
					$.bgSlideshow.slides[previous].hide();
				});
		
			}, 4000);
	
		}	
	}
	
	$('.news-slideshow').cycle({
			timeout: 5000,
			speed: 1000,
			fx: 'fade'
	});

	$("#featured > ul").tabs({fx:{opacity: "toggle"}}).tabs("rotate", 7500, true);
	
});


function loadhtml(page, where) {

	$.get(	page, 
			function(data) { 
				$(where).html(data);
				// we need to add the lightbox to any newly loaded stuff
				$('.gallery').each(function() {
					$('a.photo', this).lightBox();
				});
			}
		);

}

