/**
 * Top Menu Sliding Panels
 *
 * This is the script for the sliding panels at the top of the
 * Cutpastecreate website. It only allows one panel to be open at a
 * time, and uses the links href value as the name of the target div.
 *
 * @author Chris Mytton
 * @copyright 2008 Cutpastecreate
 * @package Cutpastecreate
 * @url http://cutpastecreate.com
 *
 */
Shadowbox.loadSkin('classic', 'http://www.cutpastecreate.com/cpc/static/scripts/shadowbox-2.0/skin');
Shadowbox.loadLanguage('en', 'http://www.cutpastecreate.com/cpc/static/scripts/shadowbox-2.0/lang');
Shadowbox.loadPlayer(['img', 'iframe', 'html'], 'http://www.cutpastecreate.com/cpc/static/scripts/shadowbox-2.0/player');

/* Wait until the DOM is ready to be manipulated */
$(document).ready(function(){

	var options = {
		overlayColor: '#000',
		overlayOpacity: '0.8'
	};

	Shadowbox.init(options);

	$("#graphic").cycle({
		timeout: 6000,
		speed: 3000
	});
	
	$("#testimonials").cycle({
		timeout: 10000,
		speed: 3000,
		sync: 0,
		random: true
	});
	
	
	/* Hide the three top panels */
	$('div#top-extra div.top-panel').hide();
	
	/* For each li in the ul.top menu */
	$('ul.top li').each(function() {
	
		/* Find all children that are links and attach a click event. */
		$(this).children('a').click(function(e)
		{
			e.preventDefault();
			e.stopPropagation();
			/* The div that needs to slide open is referenced in the links href attribute, so we store it first */
			var div = $(this).attr('href');
			
			/* If the corresponding div is already open then we close it and we're done */
			if ($(div).is(':visible')) 
			{
				$(div).slideUp().removeClass('current');
			}
			/* Else the corresponding div is closed */
			else 
			{
				/* Check for other visible div's with the class current. */
				if ($('div.current').is(':visible'))
				{
					/* Close the open div and then open the requested div as a callback. */
					$('div.current').slideUp('fast', function() 
					{
						/* Callback to slide down the original div */
						$(div).slideDown().addClass('current');
						
					}).removeClass('current');
				} 
				/* Else there are no divs open currently, so we just open the requested div and add the class current. */
				else 
				{
					$(div).slideDown().addClass('current');
				}
			}
			/* Return false to prevent the link from working on click */
			return false;
		});
	});
	
	/* Close button */
	$('a.close').click(function(){
		$('div.current').slideUp('fast').removeClass('current');
		return false;
	});
});