$(document).ready(function(){
	
	// IE 6 won't do arbitrary :hover, so we need this
	$('header ul li').hover(function() {
		$(this).addClass('menuOn');
	}, function() {
		$(this).removeClass('menuOn');
	});
	
	// maintain background position on hovered menu item
	$('header ul li ul').hover(function() {
		$(this).parents('li').addClass('hovered');
	}, function() {
		$(this).parents('li').removeClass('hovered');
	});
	
	// hover for the sub-menu items
	$('header ul li ul li').hover(function() {
		$(this).addClass('hovered');
	}, function() {
		$(this).removeClass('hovered');
	});
	
	$("nav ul li ul li:has(ul)").hover(function () {
	     $(this).children("a").click(function () {
	        return false;
	     });
	  });

	//ipad and iphone fix
	// if((navigator.userAgent.match(/iPhone/i)) || (navigator.userAgent.match(/iPod/i)) || (navigator.userAgent.match(/iPad/i))) {
	//     $("#nav-work a").click(function(){
	//         //we just need to attach a click event listener to provoke iPhone/iPod/iPad's hover event
	//         //strange
	//     });
	// }
	
	// if((navigator.userAgent.match(/iPhone/i)) || (navigator.userAgent.match(/iPod/i)) || (navigator.userAgent.match(/iPad/i))) {
	//     $("#nav-work li a").bind('touchstart', function(){
	//         $(this).parents('li').addClass('hovered');
	//     });
	// 	 $("#nav-work li a").bind('touchend', function(){
	// 	        $(this).parents('li').removeClass('hovered');
	// 	    });
	// }
		
	// cycle with auto-advance, prev/next buttons
	$('#heroImages.cycleMe, #panels.cycleMe').cycle({ 
	    fx:     'fade', 
	    speed:  '750', 
	    timeout: 8000, 
	    pager: '#cycleNav',
			slideExpr: "div.panel"
	});
	$('#heroImages.cycleMe').cycle({ 
	    fx:     'fade', 
	    speed:  '750', 
	    timeout: 8000, 
	    pager: '#cycleNav',
			slideExpr: "img"
	});
	$('#cycleNav a').click(function(){
		$('#heroImages').cycle('pause'); 
	});
	
	// cycle with auto-advance for case studies - paging
   $('#heroImages.caseCycle').cycle({
       fx:     'fade',
       speed:  '750',
       timeout: 4000,
       pager:  '#casenav',
			 slideExpr: 'img'
   });
	
	// cycle for case studies
   $('#cycle').cycle({
       fx:     'fade',
       speed:  '750',
       timeout: 5500,
			 slideExpr: 'div',
			 prev: '#prev',
			 next: '#next'
   });
	$('#cycle iframe').mouseover(function(){
		$('#cycle').cycle('pause'); 
	});
	
	
	// hover for the previous/next buttons
	$('#prev, #next').hover(function() {
		$(this).addClass('hovered');
	}, function() {
		$(this).removeClass('hovered');
	});
	
	
});

