﻿$.fn.hoverClass = function(c) {
	return $(this).hover(
		function() { $(this).addClass(c); },
		function() { $(this).removeClass(c); }
	);
};

$(document).ready(function() {
	$('#nav > li').		// hoverClass('hover').
	hover(
		function() { $('ul',this).fadeIn(); },
		function() { $('ul',this).hide(); }
	);

	//$('#nav li').each(function() {
	//	var $this = $(this);
	//	$this.find('ul').width($this.width());
	//});
	
	$('#nav li').hoverClass('hover');

	if ($.browser.mozilla) {
		$('#nav li ul li').css({marginBottom:3})
	}
	else if ($.browser.msie) {
		$('#nav li ul li').addClass('navTransBorder').css('marginBottom', '-3px');
	}
});

var $header = $('#hero');

var showCaseStudy = function(e) {
	var $cs = $(this);
	var $hero = $cs.find('img.hero');

	var href = $cs.find('a').attr('href');

	if (!firstClick) {
		pageTracker._trackEvent('ui', 'case_study_change', href);
	} else {
		firstClick = false;
	}

	$cs.unbind('click').siblings().unbind('click').bind('click',showCaseStudy);
	$cs.find('p').slideDown();
	$cs.addClass('open').siblings().filter('.open').find('p').slideUp();
	$cs.siblings().removeClass('open');
	$cs.siblings().find('.open').removeClass('open');

	$header.find('img.live_hero').remove();

	$hero.clone().
		addClass('live_hero').appendTo($header).
		css({ top: '370px', left: '-1000px', cursor: 'pointer' }).
		show().
		click(function() {
			window.location.href = href;
		}).
		animate(
			{ left: 0, top: 0 },
			function() {
				$cs.click(function() { 
					window.location.href = href;
				});
			}
       	       );
}

var rotateHero = function(e) {
  var $active = $('#hero li.open');
  var $next = $active.next().length > 0 ? $active.next() : $('#hero li:first');
  
  $active.hide(1000);
  $active.removeClass("open");
  $next.show(1000);
  $next.addClass("open");
}

//$('#hero li a').click(function(e) { e.preventDefault(); });
//alert($('#hero li').size());
//$('#hero li').click(showCaseStudy);

/*$('#hero ul.case_studies').show();*/
//$('#hero ul.case_studies li').hoverClass('hover');
//var firstClick = true;
//$('#hero ul.case_studies li:first').click();



$(document).ready(function() {
	$('body.case_study div.smallbox a').lightBox();
  
  $('#hero li:first').show(1000).addClass("open");  
  if( $('#hero li').size() > 1) {
    setInterval(rotateHero, 10000);
  }
  
  $('a.contactBruce').click(function() {
    pageTracker._trackPageview("/contact/bruce");
  })
});