$(function(){



	// Innerfade: ad slider
	$('.adslide').innerfade({
		animationtype: 'fade', // fade or slide
		speed: 500, // animation speed in milliseconds
		timeout: 6000, // time between animations in milliseconds
		type: 'sequence', // sequence, random, or random_start
		containerheight: '143px' // height of the containing element
	});



	// Innerfade: image slider
	$('.imgslide').innerfade({
		animationtype: 'fade', // fade or slide
		speed: 500, // animation speed in milliseconds
		timeout: 5000, // time between animations in milliseconds
		type: 'sequence', // sequence, random, or random_start
		containerheight: '220px' // height of the containing element
	});



	// Product detail images
	$('.pimgs .small a').hover(function(){
		var src = $(this).find('img').attr('src');
		$('.pimgs .large img').attr('src', src);
	});



	// Product size select
	$('.size label').click(function(){
		$(this).closest('.size').find('.active').removeClass('active');
		$(this).addClass('active');
	});



	// News slider
	$('#slider ul').each(function(){

		var $ul = $(this),
			speed = 500,
			timeout = 8000,
			timer = setTimeout(function(){ slide(false); }, timeout);

		function slide(goto){

			clearTimeout(timer);

			var $active = $ul.find('.active');
			
			if (goto) {
				var $li = goto;
			} else {
				var $li = $active.next().hasClass('next') ? $ul.find('li:first-child') : $active.next();
			}

			if (!$li.hasClass('active')) {

				$active
					.removeClass('active first')
					.find('.large, .arrow')
					.fadeOut(speed);

				$li
					.addClass('active')
					.find('.large, .arrow')
					.fadeIn(speed);

			}

			timer = setTimeout(function(){ slide(false); }, timeout);

		}

		$ul.find('li:not(.active)').find('.large, .arrow').hide();

		$ul.find('li:not(.next)').hover(function(){
			$this = $(this);
			slide($this);
		});

	});



});

window.onload = function() {
            var links = document.getElementsByTagName("a");
            for (var i = 0; i < links.length; i++) {
                        var rels = links[i].getAttribute("rel");
                        if (rels) {
                                   var testpattern = new RegExp("external");
                                   if (testpattern.test(rels)) {
                                               links[i].onclick = function() {
                                                           return !window.open(this.href);  
                                               }
                                   }
                        }
            }
}


