$(document).ready(function() {
		/*
		 * Count the number of slides in the carousel and generate number nav
		 */
		var slide_count = $('#carousel_slides > div').size();
		var nav_width = 0;
		if(slide_count > 1){
			//find width of slide nav and append nav container with width
			nav_width = slide_count*22;
			$('#carousel_container').append('<div id="slide_nav_container"><ul style="width:'+nav_width+'px;" id="slide_nav"></ul></div>');
			
			for(var i=0;i<slide_count;i++){
				if(i == 0){
					id =' id="curr_slide"';	
				}else{
					id ='';
				}
				 $('#slide_nav').append('<li class="slide-link" '+id+' rel="'+(i+1)+'"><div class="slide-thumb"><img src="./images/home_slide_thumb_'+(i+1)+'.png" height="87" width="200" /></div></li>');
		  	}
		}
		
		var curr_slide = 1;//set initial current slide
		$('#slide_nav li').click(function(){
			if($(this).attr('id') != 'curr_slide'){
				curr_slide = $('#curr_slide').attr('rel');
				next_slide = $(this).attr('rel');
				$('#curr_slide').attr('id','');
				$(this).attr('id','curr_slide');
				$(this).children('.slide-thumb').stop(false, true).fadeToggle('slow');
				$('#carousel_slides div:nth-child('+curr_slide+')').stop(false, true).animate({
												top:'+=377'
											}, 
											'5000', 
											function(){
														$('#carousel_slides div:nth-child('+curr_slide+')').attr('style', 'top:-377px');
														$('#carousel_slides div:nth-child('+curr_slide+')').attr('id', '');
											});
				//right side image animations
				if(curr_slide == '4'){
					$('.autodesk-piston').animate({top:'-405'}, function(){$('.autodesk-piston').attr('style', 'top:419px;');});
				}else if(curr_slide == '1'){
					    	$('.bike').animate({top:'-422px'}, function(){$('.bike').attr('style', 'top:419px;');});
					  }else if(curr_slide == '2'){
						    	$('.microsoft-people').animate({top:'-413'},  function() {$('.microsoft-people').attr('style', 'top:392px;');});
			   			    }else if(curr_slide == '3'){
										$('.intel-car').animate({ height: '0', width: '0'}, 600);
										$('.intel-car img').animate({ height: '0', width: '0'}, 500);
							  	   }else if(curr_slide == '5'){
											$('.honeywell-mechanic').animate({top:'-368px'}, function(){$('.honeywell-mechanic').attr('style', 'top:417px;');});
							  	   		 }
				
				if(next_slide == '4'){
					$('.autodesk-piston').animate({top:'0'});
				}else if(next_slide == '1'){
				 		   $('.bike').animate({top:'0'});
					  }else if(next_slide == '2'){
						    	$('.microsoft-people').animate({top:'0'});
			   			    }else if(next_slide == '3'){
									$('.intel-car').animate({ height: '304', width: '642'}, 550);
									$('.intel-car img').animate({ height: '304', width: '642'}, 650);
								  }else if(next_slide == '5'){
											$('.honeywell-mechanic').animate({top:'0'});
							  	   		 }
				
				
				$('#carousel_slides div:nth-child('+next_slide+')').stop(false, true).animate({top:'+=370'}, '5000', 
					function(){
						$('#carousel_slides div:nth-child('+next_slide+')').attr('id', 'slide-focused');
						});
				
			}
		});
		
		$('.slide-link').mouseenter(function() {
			if($(this).attr('id') != 'curr_slide'){
	        	$(this).children('.slide-thumb').stop(false, true).fadeToggle('slow');
			}
    	}).mouseleave(function() {
			if($(this).attr('id') != 'curr_slide'){
        		$(this).children('.slide-thumb').stop(false, true).fadeToggle('slow');
			}
    		});
			
			
		$('.carousel_cta img').mouseenter(function() {
			this.src = this.src.replace("_cta","_hover");
    	}).mouseleave(function() {
			this.src = this.src.replace("_hover","_cta");
    		});
	});
	
