
$(document).ready(function(){






//$('#nav').vAlign();


/* History Slideshow ------------- */

var numImg;
var newWidth;
var position;
var currentPosition;
var currentLimit;
var moveMe = $("#history-slide");

numImg = $('#history-slide > .thumb').not('.clearit').size();
newWidth = ( numImg * 304 ) + ( (numImg-1) * 24);

$('#history-slide').width(newWidth);

currentLimit = (newWidth * (-1)) + 962;

	
	
	


$('.inner-slide-show .next').click(function() {
	position = moveMe.position();
	currentPosition = position.left;
	
	
	if (currentPosition <= currentLimit)
	  {
	  
		  
		  
			  $('#history-slide').animate({
			    
			     "left": "0", "opacity": 1
			    
			  }, 500, function() {
			    // Animation complete.
			    
			  });
		 
		  
	  }
	  else
	    {
		    if ($('#history-slide').is(':animated'))
		    {
		    
		    } else {
	    
			    $('#history-slide').animate({
			      
			       "left": "-=328px", "opacity": 1
			       
			       
			    
			    }, 500, function() {
			      // Animation complete.
			      
			      
			      
			    });
	        };
	    };
	    
  return false;
});

$('.inner-slide-show .previous').click(function() {
	position = moveMe.position();
	currentPosition  = position.left;
	currentLimit = currentLimit+2;
		
	if (currentPosition >= 0)
	  {
		  $('#history-slide').animate({
		    
		     "left": currentLimit, "opacity": 1
		    
		  }, 500, function() {
		    // Animation complete.
		  
		  });
	  }
	  else
	    {
	    
		    if ($('#history-slide').is(':animated'))
		    {
		    
		    } else {
		    
			    $('#history-slide').animate({
			      
			       "left": "+=328px", "opacity": 1
			      
			    }, 500, function() {
			      // Animation complete.
			     
			    });
			};
	    };
	    
  return false;
});

/* End History Slideshow ------------- */


/* Projects Slideshow ------------- */

var numSlides;
var currentSlide;
var currentNumSlides;
var currentShow;

var targetCounter;
var targetCounterValue;
var totalCount;
var targetCaption;
var currentCaptionEq;
var currentCaption;


numSlides = $('.project-slide').length;

currentSlide = numSlides;

while (currentSlide>=1)
  {
 
  currentSlide--;
 
  currentNumSlides = $('.project-slide').eq(currentSlide).children('img').not('.clearit').length;
  newWidth = ( currentNumSlides * 632 ) + ( (currentNumSlides-1) * 24);
  $('.project-slide').eq(currentSlide).width(newWidth);
  
  $('.project-slide').eq(currentSlide).parent().parent() .find('.total-count').text(currentNumSlides);
  
  targetCaption = $('.project-slide').eq(currentSlide).parent().parent() .find('.slide-caption');
  currentCaption = $('.project-slide').eq(currentSlide) .find('img').not('.clearit').eq(0);
  currentCaption = $(currentCaption).attr("alt");
  $(targetCaption).text(currentCaption);
  
 
  }



$('#projects .next').click(function() {

currentShow = $(this).parent().parent().parent() .find(".project-slide");

if ($(currentShow).is(':animated'))
{

} else {

	targetCounter = $(this).parent().parent() .find('.current-count');
	targetCaption = $(this).parent().parent() .find('.slide-caption');
	
	targetCounterValue = $(targetCounter).text();
	targetCounterValue = parseInt(targetCounterValue, 10) + 1;

	totalCount = $(this).parent().parent() .find('.total-count').text();
	totalCount = parseInt(totalCount);
	
	if (targetCounterValue > totalCount)
	  {
		  $(targetCounter).text('1'); 
		  targetCounterValue = 1;
		 
	  }
	else
	  {
		  $(targetCounter).text(targetCounterValue); 
	  };
	
	currentCaptionEq = targetCounterValue - 1;
	currentCaption = $(this).parent().parent().parent() .find('img').not('.clearit').eq(currentCaptionEq);
	currentCaption = $(currentCaption).attr("alt");
	$(targetCaption).text(currentCaption);
	
	
	
	 
	currentLimit = (currentShow.width() * (-1)) + 634; // was 632 before ie8 fix
	
	position = $(currentShow).position();
	currentPosition = position.left;
	
	
	
	if (currentPosition <= currentLimit)
		  {
			  $(currentShow).animate({
			    
			     "left": "0", "opacity": 1
			    
			  }, 500, function() {
			    // Animation complete.
			    
			  });
		  }
		  else
		    {
				  
			    $(currentShow).animate({
			      
			       "left": "-=656px", "opacity": 1
			       
			    }, 500, function() {
			      // Animation complete.
			   
			    });
				
		    };
	    
	};	    
	return false;
});

$('#projects .previous').click(function() {

currentShow = $(this).parent().parent().parent() .find(".project-slide");

if ($(currentShow).is(':animated'))
{

} else {


	targetCounter = $(this).parent().parent() .find('.current-count');
	targetCaption = $(this).parent().parent() .find('.slide-caption');
	
	targetCounterValue = $(targetCounter).text();
	targetCounterValue = parseInt(targetCounterValue, 10) - 1;

	totalCount = $(this).parent().parent() .find('.total-count').text();
	totalCount = parseInt(totalCount);
	
	if (targetCounterValue < 1)
	  {
		  $(targetCounter).text(totalCount); 
		  targetCounterValue = totalCount;
	  }
	else
	  {
		  $(targetCounter).text(targetCounterValue); 
	  };
	  
	  currentCaptionEq = targetCounterValue - 1;
	  //alert(currentCaptionEq);
	  currentCaption = $(this).parent().parent().parent() .find('img').not('.clearit').eq(currentCaptionEq);
	  currentCaption = $(currentCaption).attr("alt");
	  $(targetCaption).text(currentCaption);

	
	 
	currentLimit = (currentShow.width() * (-1)) + 632;
	
	position = $(currentShow).position();
	currentPosition = position.left;
	
	
	
	if (currentPosition >= 0)
		  {
			  $(currentShow).animate({
			    
			     "left": currentLimit, "opacity": 1
			    
			  }, 500, function() {
			    // Animation complete.
			    
			  });
		  }
		  else
		    {
		  	    $(currentShow).animate({
		  	      
		  	       "left": "+=656px", "opacity": 1
		  	      
		  	    }, 500, function() {
		  	      // Animation complete.
		  	     
		  	    });
		  	   
		    };
	};
	return false;
});


/* End Projects Slideshow ------------- */




$(".featured-photo").hover(
	function () {		
		$(".color", this).fadeIn(150);
		//$(".snippet", this).fadeIn(200);
		
	
		
	}, 
	function () {
		$(".color", this).fadeOut(150);
		//$(".snippet", this).fadeOut(200);
		
		
			
	}
);



$(".scroll").click(function(event){
		//prevent the default action for the click event
		event.preventDefault();

		//get the full url - like mysitecom/index.htm#home
		var full_url = this.href;

		//split the url by # and get the anchor target name - home in mysitecom/index.htm#home
		var parts = full_url.split("#");
		var trgt = parts[1];

		//get the top offset of the target anchor
		var target_offset = $("#"+trgt).offset();
		var target_top = target_offset.top;

		//goto that anchor by setting the body scroll top to anchor top
		$('html, body').animate({scrollTop:target_top}, 500);
	});
	
	
	
	// westgate additions
	var target_sect;
	var hover_html;
	
	$("#directory-map area").hover(
		function () {		
				if (typeof mojoEditor  == "undefined" )
				{
					target_sect = $(this).attr('id');
					
					hover_html = $("#directory-list ." + target_sect).html();
					$("#replace_html .replace_me").eq(0).html(hover_html); 
					$("#directory-list").fadeTo(10, 0);
					$("#replace_html").fadeIn(100);
					
					
					$("#map-hover-wrap ." + target_sect).fadeIn(50);
				}
			
		}, 
		function () {
				if (typeof mojoEditor  == "undefined" )
				{
				
					
					//$("#directory-list li").not("." + target_sect).fadeTo(100, 1).removeClass('hovering-top');
					$("#replace_html").fadeOut(10);
					$("#directory-list").fadeTo(100, 1);
					
					
					$("#map-hover-wrap ." + target_sect).fadeOut(50);
					$("#directory-list ." + target_sect).removeClass('hovering');
			
				}
		}
	);
	
	
	$("#directory-list li").hover(
		function () {		
			if (typeof mojoEditor  == "undefined" )
			{
				target_sect = $(this).attr('class');
				
				$("#map-hover-wrap ." + target_sect).fadeIn(50);
				$("#directory-list ." + target_sect).addClass('hovering');
			}
		}, 
		function () {
			
			if (typeof mojoEditor  == "undefined" )
			{
				$("#map-hover-wrap ." + target_sect).fadeOut(50);
				$("#directory-list ." + target_sect).removeClass('hovering');
			}
		}
	);
	
	
	
	


});


$(window).load(function(){

	var current_page = $('body').attr('id');
	var home_slide_num_img=2;
	var home_slide_count=0;
	
	function home_slideshow()
		{
			//alert('home_slideshow');
			
			
			home_slide_num_img = $('#banner-wrap img').size() -1;
			//alert(home_slide_num_img);
			
			//if (typeof mojoEditor  == "undefined" )
			//{
			
				var t=setInterval(slide_it,4000);
			//}	
			
		}
		
	function slide_it()
	{
		//alert('rotateIt');
		
		//alert(home_slide_num_img);
		$('#banner-wrap img').eq(home_slide_count).fadeOut(500);
		home_slide_count++;
		if (home_slide_count > home_slide_num_img)
		{
			home_slide_count=0;
			//alert('reset');
		}
		$('#banner-wrap img').eq(home_slide_count).fadeIn(500);
		
		
		
	}

	if (current_page=='index')
	{
		
		var add_imgs = $('#banner-wrap').html() + '<img src="http://westgatetoledo.com/import/abbell/images/intro-banner2.jpg" class="hide" alt="banner-2"><img src="http://westgatetoledo.com/import/abbell/images/intro-banner3.jpg" class="hide" alt="banner-3"><img src="http://westgatetoledo.com/import/abbell/images/intro-banner4.jpg" class="hide" alt="banner-4"><img src="http://westgatetoledo.com/import/abbell/images/intro-banner5.jpg" class="hide" alt="banner-5">';
		
		$('#banner-wrap').html(add_imgs);
		
		$('#banner-wrap').fadeIn(300, function() {
	        
	        	home_slideshow();
	      
	      });
	      
	  }
	//$('#banner').fadeIn(1500);

	
	
	
	
	
	
	
	

});



  

