/*
Copyright (c) 2008 Ylab, www.ylab.nl
*/
jQuery(document).ready(function($){
	//channelInteraction
	var channelInteraction = function(){
		var sel = '.col'+this;
		$(sel).hover(function(){
			if(jQuery.browser.msie && parseInt(jQuery.browser.version)<7){
				$('#features div'+sel).css({filter:"progid:DXImageTransform.Microsoft.AlphaImageLoader(src='../graphics/bg-features.png', sizingMethod='scale')"});
			}
			$('#features div'+sel).show();
			hover($('#menu '+sel+' img')[0], true);
		},function(){
			if(jQuery.browser.msie && parseInt(jQuery.browser.version)<7){
				$('#features div'+sel).css({filter:''});
			}
			$('#features div'+sel).hide();
			hover($('#menu '+sel+' img')[0], false);
		}).click(function(){
			location.href = ($('#menu a'+sel)[0].href);
		}).css({cursor:'pointer'});
	}
	jQuery.each(cols, channelInteraction);

	//slide show, clone images so they can fade into the next
  $("#navbar img").each(function(n){
  	if(n<3){
    	$(this).clone(true).insertAfter(this);
			if(!debugging || !hasFirebug){
				window.setTimeout('nextRound();', 4000);
			}
    }
  });
});

//slide show
var curRound = -1;
var useSets = false;
var allLoaded = false;

function nextRound(){
	//toggle between sets and singles
	useSets = !useSets;
	if(useSets){
		curRound++;
	}
	if(curRound==10){
		//reset
		curRound=0;
		allLoaded = true;
	}
	//preload images
	if(!allLoaded){
		new Image().src = getSlideName(1);
		new Image().src = getSlideName(3);
		new Image().src = getSlideName(2);
	}
	window.setTimeout('nextSlide(1);', 1000);
	window.setTimeout('nextSlide(3);', 2000);
	window.setTimeout('nextSlide(2);', 3000);
	window.setTimeout('nextRound();', 5000);
}

function nextSlide(n){
	var sSelTop = '#navbar img.col' + n + ':eq(1)';
	var sSelBot = '#navbar img.col' + n + ':eq(0)';

	var img = $(sSelTop).fadeOut('normal', function(){
		this.src = getSlideName(n);
		$(this).fadeIn('normal', function(){
			$(sSelBot).attr({src:this.src});
		});
	});
}

function getSlideName(n){
	return '/graphics/' + (useSets ? 'sets' : 'singles') + '/' + n + '/' + curRound + '.jpg';
}
