//jquery

$(document).ready( function () { 
	
	$('.nav-col li').hover( 
		function() {
			$('.desc-col').stop(true,true);
			$(this).addClass('hover');
		},
		function() {
			$(this).removeClass('hover');
		}
	);
	
	// ------- HOME PAGE ------------------------------------------------------------
	
	
	$.fn.wait = function(time, type) {
		time = time || 1000;
		type = type || "fx";
		return this.queue(type, function() {
			var self = this;
			setTimeout(function() {
				$(self).dequeue();
			}, time); 
		});
	};
	
	$.fn.roundRobin = function() {
		$(this).fadeIn(800, function() {
			$(this).addClass('active');
			if(jQuery.browser.msie) {
				$(this).get(0).style.removeAttribute('filter'); 
			}
			$(this).wait(5000);
			$(this).fadeOut(400, function() {
				if(jQuery.browser.msie) {
					$(this).get(0).style.removeAttribute('filter'); 
				}
				$(this).removeClass('active');
				$(this).dequeue();
				if (($('.homepage-results-pane').index(this)+1) == $('.homepage-results-pane').size()) {
					$('.homepage-results-pane').eq(0).roundRobin();
				} else {
					$(this).next('.homepage-results-pane').roundRobin();
				}
			});
		});
	};
	
	for(var i = 0; i<pageImages.length; i++)
	{
		jQuery("<img>").attr("src", pageImages[i]);
	}
	

	$('.homepage-results-pane:first-child').roundRobin(); 
	
	// takes you to the case study if you click
	$('.homepage-results-pane').click( function() {
		var id = $(this).find('img').attr('id').replace('img-','');
		var url = "http://kdc.axiomwebgroup.com/results/id:" + id;    
		$(location).attr('href',url);
	});
	
	// pauses the animation when you hover over the image
	$('.homepage-results-pane')
	.hover( 
		function() {
			$('.homepage-results-pane').stop(true, true);
		}, 
		function() {
			var currentId = $(this).attr('id');
			$('#'+currentId).roundRobin();
		}
	);
	
	
	// displays a case study for the expertise when hovered over
	$('#nav-row li')
	.hover( 
		function() {
			var currentId = $(this).attr('id').replace('nav-','');
			
			$('.homepage-results-pane.active').stop(true, true);
			$('.homepage-results-pane').hide();
			$('.homepage-results-pane.active').removeClass('active');
			$('#pane-'+currentId).fadeIn('fast', function() {
				if(jQuery.browser.msie) {
					$(this).get(0).style.removeAttribute('filter'); 
				}
			});
		}, 
		function() {
			$('.homepage-results-pane').stop(true, true);
			var currentId = $(this).attr('id').replace('nav-','pane-');
			$('#'+currentId).roundRobin();
		}
	);
	
	
	// ------------------------------------------------------------------------------
	 
});
