var $ = jQuery;
$(document).ready(function() {
  $('#featured-products').after('<div id="featured-products-label">Products:</div><ul id="featured-products-nav">').cycle({ 
    fx:     'fade', 
    timeout: 2500, 
    pager:  '#featured-products-nav', 
     
    // callback fn that creates a thumbnail to use as pager anchor 
    pagerAnchorBuilder: function(idx, slide) { 
	if(window.console) console.log(slide);
        //return '<li><a href="#"><img src="' + $('img:first',slide).attr('src') + '" width="50" height="50" /></a></li>'; 
	return '<li><a href="' + $('a:first',slide).attr('href') + '">' + $('h4',slide).html() + '</a></li>';
    } 
  });
  
  //find any list items with an image as a child, and cycle the list
  $('ul li > a > img,ul li > img').parents('ul:first').cycle({timeout: 2500});
  
  
	/*
		$('#featured-products li').not(':first').css('display','none');
		$('#homefeature_nav-clearwish').click(function() { change_homefeature('clearwish',true); });
		$('#homefeature_nav-simple').click(function() { change_homefeature('simple',true); });
		$('#homefeature_nav-universal').click(function() { change_homefeature('universal',true); });
		$('#homefeature_nav-addictive').click(function() { change_homefeature('addictive',true); });
	*/
	
	/* Suckerfish Script for IE6 */
	$('#nav li').hover(
		function() { $(this).addClass('sfhover'); }
		,function() { $(this).removeClass('sfhover'); }
	);

});

function advance_homefeature()
{
	var tabs = ['clearwish','universal','simple','addictive'];
	
	for(var i = 0;i<tabs.length;i++)
	{
		if($('#home_feature-'+tabs[i]).is(':visible'))
		{
			change_homefeature(tabs[(i+1) % 4]);
			return;
		}
	}
}

function change_homefeature(el,clear_interval)
{
	$('div.home_feature').not('#home_feature-'+el).fadeOut();
	$('#home_feature-'+el).fadeIn();
	
	if(el == 'clearwish') offset = 0;
	else if(el == 'universal') offset = -36;
	else if(el == 'simple') offset = -72;
	else if(el == 'addictive') offset = -108;
	
	$('#homefeature_nav').css('background-position','0 '+offset+'px');
	
	if(clear_interval) clearInterval(homefeature_interval);
}

var homefeature_interval = setInterval('advance_homefeature()',6000);