function fixNavInAllBrowsers()
{
	$('#nav li ul').hover(function()
	{
		$(this).parent().addClass('BrowserFix');
	},
	function()
	{
		$(this).parent().removeClass('BrowserFix');
	});
	$('ul').each(function()
	{
		$(this).find('li:first').addClass('first');
		$(this).find('li:last').addClass('last');
	});
}
function fixNavInIE6()
{
	$('#nav ul li').hover(function()
	{
		$(this).find('ul:first').addClass('IE6fix');
	},
	function()
	{
		$(this).find('ul:first').removeClass('IE6fix');
	});
}
function externalInNewWindow()
{
	$('a[rel=external]').click(function()
	{
		window.open($(this).attr('href'));
		return false;
	});
	$('a[rel="popupWindow"]').click( function() {
        window.open( $(this).attr('href'), 'popup', 'width=700,height=500,scrollbars=yes,resizable=no,toolbar=no,directories=no,location=no,menubar=no,status=no,left=0,top=0');
        return false;
    });
}
function warningPopup()
{
	$('.warning').append('<span>You are now exiting this web site.  The Clorox Company is not responsible for the content or data collection of the website you are about to go to.</span>');
	$('.warning').hover(function()
	{
		$(this).find('span').show();
	},
	function()
	{
		$(this).find('span').hide();
	});
	$('.warning span').hide();
}
function insertYoutubeVideo(id, title, duration, description)
{
	$('#video').html('<object width="550" height="445"><param name="movie" value="http://www.youtube.com/v/' + id + '&amp;hl=en&amp;fs=1&amp;"></param><param name="allowFullScreen" value="true"></param><param name="allowscriptaccess" value="always"></param><embed src="http://www.youtube.com/v/' + id + '&amp;hl=en&amp;fs=1&amp;" type="application/x-shockwave-flash" allowscriptaccess="always" allowfullscreen="true" width="550" height="445"></embed></object>');
	$('#video-info').html('<strong>' + title + '</strong><br />' + duration + '<br /><br />' + description);
}
function videoOverlay()
{
	$('#video-picker li:first').find('.video-overlay').addClass('on');
	$('#video-picker li a').hover(function()
	{
		$(this).find('.video-overlay').addClass('over');
	},
	function()
	{
		$(this).find('.video-overlay').removeClass('over');
	});
}
function createRoundedCorners(element)
{
	$(element).append('<div class="tl"></div><div class="tr"></div><div class="bl"></div><div class="br"></div>');	
}
function womenNav()
{
	$('#women-nav li .large').hide();
	$('#women-nav li .name').hide();
	$('#women-nav li a').hover(function()
	{
		$(this).find('.large').show();
		$(this).prev().show();
	},
	function()
	{
		$(this).find('.large').hide();
		$(this).prev().hide();
	});
}
function closePopup()
{
	$('#flash-popup').hide();
	if($('#pinesol_map_winners').length) $('#pinesol_map_winners').get(0).slideBlue();
	return false;
}
function populatePopup(name,location)
{
	$.ajax({
		type:'POST',
		url:'/flash-popup/',
		data: 'name=' + name + '&location=' + location,
		success: function(data)
		{
			$('#flash-popup-content').html(data);
			womenNav();
			externalInNewWindow();
			warningPopup();
			$('#flash-popup').show();
		}
	});
	return false;
}



/* SLIDESHOW */

var delay = 9000;
var imgWidth = 527;
var start = 1;
var next;
var total;
var timeout;

$(function()
{
	total = $('#slideshow .slides li').size();
	startSlideshow(start);
	
	$('#slideshow .nav li a').click(function()
	{
		startSlideshow($(this).html());
		return false;
	});
});

function startSlideshow(current)
{
	clearTimeout(timeout);
	$('#slideshow .slides li').hide().each(function(i)
	{
		if((i + 1) == current)
		{
			$(this).show().find('img').animate({ 'left' : '0' }, 0);
			changeSlideshowNav(current);
			timeout = setTimeout('animateSlideshow(' + current + ')', delay);
		}
	});
}

function animateSlideshow(current)
{
	next = current + 1;
	if(next > total) next = start;
	changeSlideshowNav(next);
	
	$('#slideshow .slides li').each(function(i)
	{
		if((i + 1) == current)
		{
			$(this).find('img:first').animate({ 'left' : '-' + imgWidth + 'px' }, 700);
			$(this).find('img:last').animate({ 'left' : '-' + imgWidth + 'px' }, 500);
		}
	});
	$('#slideshow .slides li').each(function(i)
	{
		if((i + 1) == next)
		{
			$(this).show(0).find('img:first').animate({ 'left' : imgWidth + 'px' }, 0).animate({ 'left' : '0' }, 680, function(){ startSlideshow(next); });
			$(this).show(0).find('img:last').animate({ 'left' : imgWidth + 'px' }, 0).animate({ 'left' : '0' }, 480);
		}
	});
}

function animateSlideshowOLD(current)
{
	next = current + 1;
	if(next > total) next = start;
	changeSlideshowNav(next);
	
	$('#slideshow .slides li').each(function(i)
	{
		if((i + 1) == current)
		{
			$(this).fadeOut(500);
		}
	});
	$('#slideshow .slides li').each(function(i)
	{
		if((i + 1) == next)
		{
			$(this).fadeIn(500, function(){ startSlideshow(next); });
		}
	});
}

function changeSlideshowNav(current)
{
	$('#slideshow .nav li').removeClass('selected').each(function(i)
	{
		if((i + 1) == current)
		{
			$(this).addClass('selected');
		}
	});
}

function changeVideo(swfsrc)
{
	var flashvars = {};
	var params = {wmode:"transparent", allowscriptaccess:'always'};
	var attributes = {};
	swfobject.embedSWF(swfsrc, "video-display", "490", "390", "9.0.0","", flashvars, params, attributes);
}