$(document).ready(
	function() {

	//Follow us section on homepage rollovers
	jQuery('.follow-sec').hover(
								function(){
									jQuery("a", this).css('color', '#0269B8');
									jQuery("img", this).attr("src", templateDirectory +"/images/home-arrow-on.gif");
									$(this).css('cursor','pointer');
								},
								function(){
									jQuery("a", this).css('color', '#000000');
									jQuery("img", this).attr("src", templateDirectory +"/images/home-arrow.gif");
									$(this).css('cursor','auto');
								});
	
	//
	var doit = true; 
	var onLoad = true;
	//not sure why I added  this class with jquery 
	//jQuery('.background-container').addClass('index-background');
	
	
		//scrolls through different images before click
		function slideshow()
		{		
			if(doit == false) {			
				return;
			}
	
			if(onLoad == true){
				jQuery('#intro-copy').fadeOut('slow');
				onLoad = false;
			}
				
			//images
			var divs = jQuery('.index-entry');
			var current_pos = divs.index(jQuery('.displaytrue'));  
			var next_pos = current_pos + 1;
			
			//thumbs
			var thumbs = jQuery('.thumb-entry');
			var current_thumb = thumbs.index(jQuery('.selected'));  
			var next_thumb = current_thumb + 1;
			
			//thumbs
			if(next_thumb == thumbs.length) {
				next_thumb = 0;
			}
		
			//images
			if(next_pos == divs.length) {
				next_pos = 0;
			}
			
			//thumbs
			jQuery(thumbs.get(current_thumb)).removeClass('selected');
			jQuery(thumbs.get(next_thumb)).addClass('selected');
			
			//images
			var the_current = jQuery(divs.get(current_pos));
			the_current.fadeOut('slow', function() { the_current.removeClass('displaytrue');
												});
			
			/*jQuery(divs.get(current_pos)).fadeOut('slow').removeClass('displaytrue');*/
			
			jQuery(divs.get(next_pos)).fadeIn('slow', function() {
				if(doit == true) {
					window.setTimeout(slideshow, 5000);
				}
			   
			}).addClass('displaytrue');
		
		}


window.setTimeout(slideshow, 5000);


		
		function onThumbClicked(){
			doit = false;
				if(jQuery(this).hasClass('selected')) {
					return;
				}
			var current = jQuery('.displaytrue');
			current.css({'z-index' : '0'});
			/*current.fadeOut('slow', function(){ current.removeClass('displaytrue'); });*/
			jQuery('.thumb-entry').removeClass('selected'); 
			jQuery(this).addClass('selected'); 
			var largeEntry = '#large' + jQuery(this).attr('id');
			jQuery(largeEntry).css({'z-index' : '1'});
			jQuery(largeEntry).fadeIn('slow', function(){
													  current.removeClass('displaytrue'); 
													  current.hide();
													  enableButtons(true);
													  });
			jQuery(largeEntry).addClass('displaytrue');
			
			enableButtons(false);
			
		}
		
		
		function enableButtons(_isEnabled) {
				//get all the buttons in thumb_group and disable/enable them
				jQuery(".thumb-entry", "#thumb_group").each(
														function(){
																	if(_isEnabled) {
																		jQuery(this).click(onThumbClicked);		
																		jQuery(".thumb-entry", "#thumb_group").removeClass('arrow')
																		
																	} else {
																		jQuery(this).unbind('click');
																		jQuery(".thumb-entry", "#thumb_group").addClass('arrow');
																	}
														});
			
		}
		
		jQuery('.thumb-entry').click(onThumbClicked);
		
		

	}
);
	

