$(document).ready(function(){

	$("#who-we-are-sub-nav li").hover(
		function(){
			$(this).addClass("hover");
		},
		function(){
			$(this).removeClass("hover");
		}
	);
	$("#who-we-are-sub-nav li").click(function(){
		$("#who-we-are-sub-nav li.selected").removeClass("selected");
		$(this).addClass("selected"); 
		
		// gets the index of the <li> which inherently matches up
		// to the index of the bio below
		var index = $("#who-we-are-sub-nav li").index(this);
		var selectedBio = $(".bio:eq(" + index + ")");
		
		// sets the bio-pic src = to the hidden image inside of the selected bio
		$(".bio-pic").attr("src", selectedBio.find("img.hidden").attr("src"));
		
		// this is a hacky way to remove the hairline around the about us tag
		// will have to remove this if that image ever changes to include border
		if($(this).hasClass("header")){
			$(".bio-pic").addClass("no-border");
		}else{
			$(".bio-pic").removeClass("no-border");
		}
		
		$(".bio.selected").removeClass("selected");
		selectedBio.addClass("selected");
	});
	$("#who-we-are-sub-nav li:eq(0)").addClass("selected");
	$(".bio:eq(0)").addClass("selected");
	// stop link from following
	$("#who-we-are-sub-nav a").click(function(event){
		event.preventDefault();
	});
  
  
	// when related poster rail badge is clicked, the hidden variable is set to the "selected poster"
	// this is the link between the related poster and the slideshow, which is loaded in via AJAX
	$('.related-poster').click(function(){
		$('#selected-poster').val($(this).find('img').attr('related'));
	});
  
  
  // include poster gallery
  $("#poster-gallery-logo, .featured-poster, .related-poster, .launch-gallery").click(function(){
    var relatedID = $(this).attr('related');
    if(!relatedID){
      relatedID = $(this).find('.related-poster-thumb').attr('related');
    }

    $.ajax({
      type: 'get',
      cache: false,
      url: $('#templateURL').val() + '/slideshow.php',
      data: 'related='+relatedID,
      success: function(result){
        $("#slideshow-container").html(result);
      }
    });
    
    //$("#slideshow-container").load($('#templateURL').val() + '/slideshow.php', function(){
    //});
      
    return false;
  });
  
  
  $('.special-divider').replaceWith('<div class="special-divider"></div>');
    
});


// fixes fade issue with IE
(function($) {
	$.fn.customFadeIn = function(speed, callback) {
		$(this).fadeIn(speed, function() {
			if(jQuery.browser.msie)
				$(this).get(0).style.removeAttribute('filter');
			if(callback != undefined)
				callback();
		});
	};
	$.fn.customFadeOut = function(speed, callback) {
		$(this).fadeOut(speed, function() {
			if(jQuery.browser.msie)
				$(this).get(0).style.removeAttribute('filter');
			if(callback != undefined)
				callback();
		});
	};
})(jQuery);
