
jQuery(function($)
{
	$('#navigation-menu a.level-0').click(function()
	{
		_gaq.push(['_trackEvent', 'Home Page Navigation', 'Click', $(this).attr('href')]);
	});

	$('#navigation-menu ul.dropdown').superfish({ delay: 200 });

	var i, events = ['left', 'center', 'right'];

	for(i = 0; i < 3; i++)
	{
		(function(event)
		{
			$('#psf-'+(i+1)+' a').click(function() 
			{
				_gaq.push(['_trackEvent', 'Home Page Banner', 'Click', event]);
			});
		})(events[i]);
	}

	$('#recipe-category select').change(function()
	{
		window.location = $(this).val();
	});

	$('ul.faq-qa-set a.question').toggle(
		function()
		{
			$(this).siblings().filter('ul.answer').css('display', 'block');
		},
		function()
		{
			$(this).siblings().filter('ul.answer').css('display', 'none');
		}
	);


	$('.social-media-btns a.colorbox-iframe').colorbox({
		width: '600px'
	});

	$(document).bind('cbox_complete', function()
	{
		$('#cboxLoadedContent form.contact').submit(function()
		{
			var form = $(this);
			
			$.post(form.attr('action'), form.serialize(), function(data)
			{
				$.fn.colorbox({
					html: data
				});				
			});
			
			return false;
		});

		$('#cboxLoadedContent a.colorbox-close').click(function()
		{
			$.fn.colorbox.close();
			return false;
		});
	});

	$('a.subject-replace').each(function()
	{
		var link = $(this);
		link.attr('href', link.attr('href').replace('subject=subject', 'subject='+encodeURIComponent(document.title)));
	})

	$('a.star-vote').click(function(e)
	{
		e.preventDefault();

		if (window.location.toString().match(/recipes\//))
		{
			alert('Please visit the recipe page to vote.');
			return;
		}

		var link = $(this);

		if (link.hasClass('voted'))
		{
			alert('You already voted.');
			return false;
		}

		$.get(link.attr('href'), function(data, textStatus)
		{
			link.addClass('voted');

			if(data.match(/^\s*1\s*$/))
			{
				alert('Your vote has been counted.');
			}
			else
			{
				alert('Your already voted.');
			}
		});
	});

	$('#blurb-details select[name=product-subcategory]').change(function()
	{
		window.location = $(this).val();
	});

	$('.product ul.image-thumbs li a').click(function()
	{
		var link = $(this),
		 img = link.find('img');
		
		$('.product .big-image img').attr('src', link.attr('href')).attr('alt', img.attr('alt')+' - large');
		//$('.product .big-image p.credit').html(img.attr('alt'));
		return false;
	});

	if (Grannys['alert'])
		alert(Grannys['alert']);

	$('#blurb-details select[name=faq]').change(function() {
		window.location = $(this).val();
	});

	CWS.AudioPlayers = 0;


	$('a.audio-player').each(function()
	{
		if (CWS.AudioPlayers < 1)
			AudioPlayer.setup("/js/player.swf", { width: 290 });

		var file = $(this).attr('href').replace('../..', '');

		AudioPlayer.embed($(this).attr('id'), {
			soundFile: file
		});

		CWS.AudioPlayers++;
	});
});

