	jQuery.easing.def = "easeInOutSine";

	function mycarousel_itemVisibleInCallback(carousel, item, i, state, evt)
	{
		i > 0 
		? carousel.add(i + 2, divs[(i + 1) % divs.length]) 
		: carousel.add(i, divs[(Math.abs(i) + 2) % divs.length]);
			
		$('.practicebox').hover(
			function () {
				$(this).addClass('practicebox-active',0);
			}, 
			function () {
				$(this).removeClass('practicebox-active',0);
			}
		);	
	};

	function mycarousel_itemVisibleOutCallback(carousel, item, i, state, evt){ };

	var divs = new Array();

    jQuery(document).ready(function()
	{
		divs[0] = $('.practiceboxwrapper')[0].innerHTML;
        divs[1] = $('.practiceboxwrapper')[1].innerHTML;
        divs[2] = $('.practiceboxwrapper')[2].innerHTML;
        divs[3] = $('.practiceboxwrapper')[3].innerHTML;
        divs[4] = $('.practiceboxwrapper')[4].innerHTML;
        divs[5] = $('.practiceboxwrapper')[5].innerHTML;
		
		/* Rotate header background image */
		$('.slideshow').cycle({
			 fx: 'fade', // choose your transition type, ex: fade, scrollUp, shuffle, etc...
			 speed: 10000				  
		});
		
		/* Cycle trough highlight of practiceboxes and serviceboxes */
		setTimeout('next(1,1)',4000);

		$('.practicebox').hover(
			function ()	{
				$(this).addClass('practicebox-active',0);
			}, 
			function () {
				$(this).removeClass('practicebox-active',0);
			}
		);								   
        
		/* Initalize the practicebox carrosel */
		jQuery('#mycarousel').jcarousel({
			easing: 'easeInOutSine',
            wrap: 'circular',
            numVisible: 2,
            size: 2,
            itemVisibleInCallback: { onBeforeAnimation: mycarousel_itemVisibleInCallback },
            itemVisibleOutCallback: { onAfterAnimation: mycarousel_itemVisibleOutCallback }
		});
			
		/* Search box  */
		$("#edit-search-theme-form-1").val(' search');
		$("#edit-search-theme-form-1").focus(function() {
		    	if (this.value == ' search') {
					this.style.color = 'black';
		      		this.value = '';
		    	}
		    	$(this).blur(function() {
		      		if (this.value == '') {
						this.style.color = 'grey';
		        		this.value = ' search';
		      		}
		  	});
		});
	});


var n = 0;

/* Highlight rotator */ 
function next(step,n)
{
	o = n+1;
	
	switch(step)
	{
		case 1:
			/* Compensate for manual moves by the user */
			n = n - Math.floor(($('.jcarousel-item-'+n+' .practicebox').offset().left-145)/310);
			
			$('.jcarousel-item-'+n+' .practicebox').mouseenter(); 		
			break;
		case 2:
			$('.jcarousel-item-'+n+' .practicebox').mouseleave(); 
			$('.jcarousel-item-'+o+' .practicebox').mouseenter(); 
			break;
		case 3:
			$('.jcarousel-item-'+o+' .practicebox').mouseleave(); 
			$('#servicesbox a[href="/services/structure_and_understand"]').toggleClass('hover',0); 
			break;
		case 4:
			$('#servicesbox a[href="/services/structure_and_understand"]').toggleClass('hover',0); 
			$('#servicesbox a[href="/services/develop_and_manage"]').toggleClass('hover',0); 
			break;
		case 5:
			$('#servicesbox a[href="/services/develop_and_manage"]').toggleClass('hover',0); 
			$('#servicesbox a[href="/services/choose_and_use"]').toggleClass('hover',0); 
			break;			
		case 6:
			$('#servicesbox a[href="/services/choose_and_use"]').toggleClass('hover',0); 
			$('.jcarousel-next-horizontal').click();
			step = 0; 
			n++;
			break;
	}
	
	step++;
	setTimeout("next("+step+","+n+")",4000);
}
								
