$(function () {
	$('#slideshow .inner').cycle({
		timeout: 5000,
		speed: 1000, 
		next:   'a.next', 
		prev:   'a.prev' 
	}); 
});

$(document).ready(function () {	
	
	/* Navigation Finctionality */
	$('#navigation ul li ul li:first-child').addClass('first');
	$('#navigation ul li ul li:last-child').addClass('last');

	/*
	$('#navigation ul li').hover(function () {
		if ($(this).find('ul').length !== 0)
		{
			$(this).addClass('hover');
			$(this).find('ul').addClass('down');
			$(this).find("ul").css("display", "block");
			//$(this).find('ul').fadeIn(400);
		}
		else
		{
			return false;
		}
	}, function (mouse) {	
		$(this).removeClass('hover');
		$('#main-nav ul li').clearQueue();
		$(this).find('ul').removeClass('down');
		$(this).find("ul").css("display", "none");
		//$(this).find('ul').fadeOut(200);
	});
	*/

	$('#navigation ul li ul').parent().hover(function () {
        	$(this).addClass('hover');
        }, function (mouse) {
                $(this).removeClass('hover');
        });
	
	case_studies();
});


// handles case studies
function case_studies ()
{
	if ($('.winning-case-studies .box-row').length)
	{
		// set up hover states 
		$('.winning-case-studies .box-row h3').hover(function () {
                	$(this).css('cursor', 'pointer');
		}, function () {
                	$(this).css('cursor', '');
	        });

		// set up on clicks
		$('.winning-case-studies .box-row h3').click(function () {
	                var caseClass = $(this).parent('.box-row').attr('class');

        	        if (caseClass.indexOf('box-active') != -1)
                	{
                        	// If case study is active
		                $(this).parent('.box-row').find('row').slideUp(600);
                	        $(this).parent('.box-row').removeClass('box-active');
	                }
        	        else
                	{
                        	// If case study is not active
	                        $(this).parent('.box-row').find('row').slideDown(600);
        	                $(this).parent('.box-row').addClass('box-active');
	                }
		});

		// if year passed show it and remove all others
		if (getQuerystring("year") > 0)
		{
			$('.winning-case-studies .box-row h3').each(function()
			{
				if ($(this).text() == getQuerystring("year"))
				{
					$(this).parent().addClass("box-active");
				}
				else
				{
					$(this).parent().remove();
				}
			});
		}
		// no year passed so just highlight latest
		else
		{
			$('.winning-case-studies .box-row:first').addClass('box-active');
		}
	}
}



// returns value from query string
function getQuerystring(key, default_)
{
	if (default_==null) default_="";
	key = key.replace(/[\[]/,"\\\[").replace(/[\]]/,"\\\]");
	var regex = new RegExp("[\\?&]"+key+"=([^&#]*)");
	var qs = regex.exec(window.location.href);
	if(qs == null)
	return default_;
	else
	return qs[1];
}

