var elementInDocument = function(element) {
    while (element) {
        if (element == document) {
            return true;
        }
        element = element.parentNode;
    }
    return false;
}

$(document).ready(function() {
	
	$("a#business").hover(function() {

		bounce($(this), 175, 185);
		
	}, function() {
		
		$(this).clearQueue();
		
		$(this).animate({ "top": "185px" }, 400);
		
	});
	
	$("a#leisure").hover(function() {

		bounce($(this), 160, 170);
		
	}, function() {
		
		$(this).clearQueue();
		
		$(this).stop(true, true).animate({ "top": "170px" }, 400);
		
	});
	
	$("#corporate_content, #incentive_content, #meeting_content").css("opacity", 0);
	
	$("#corporate_top .content").hover(function() {
		
		$(this).stop(true, true).animate({ "opacity": "1" }, 300);
		
	}, function() {
		
		$(this).stop(true, true).animate({ "opacity": "0" }, 300);
		
	});

	  $(".agent_comment").hide();
	  //toggle the componenet with class msg_body
	  $(".agent_comment_title").click(function()
	  {
		$(this).next(".agent_comment").slideToggle(500);
	  });
	  
	  $(".drop_content").hide();
	  //toggle the componenet with class msg_body
	  $(".dropper").click(function()
	  {
		$(this).next(".drop_content").slideToggle(500);
	  });

	$("#image_container ul#image_nav li:eq(0)").css("color", "#dd1717");
	
	$("#image_container ul#image_nav li").click(function() {
		
		$("#image_container ul#image_nav li").css("color", "#666");
		
		$(this).css("color", "#dd1717");
		
		var id = $(this).attr("id").substr(5);
		
		$("#image_container ul#images li").stop(true, true).fadeOut(350);
		
		$("#image_container ul#images li#photo_" + id).stop(true, true).fadeIn(350);
		
	});
	
	$(".testimonial_item").hide();
	
	$("#testimonial_1").show();
	
	$("#t_prev").hide();
	
	var numT = $(".testimonial_item").length;
	
	numT = Number(numT);
	
	$("#t_next").click(function() {

		var currId = $(".selected_t").attr('id');
		
		var idNum = currId.substring(12);
		
		var next = Number(idNum) + 1;
		
		//alert("CurrID: " + currId + ", Id Num: " + idNum + ", Next: " + next + ", Num T: " + numT);
		
		$(".testimonial_item").hide();
		
		if (next < numT) {
			
			$("#" + currId).removeClass('selected_t');
			
			$("#testimonial_" + next).addClass('selected_t').fadeIn(350);
			
		} else if (next == numT) {
			
			$("#t_next").hide();
			
			$("#t_prev").show();
			
			$("#" + currId).removeClass('selected_t');
			
			$("#testimonial_" + next).addClass('selected_t').fadeIn(350);
			
		} else {

		}
		
		$("#t_prev").show();
		
		return false;
		
	});
	
	$("#t_prev").click(function() {
		
		var currId = $(".selected_t").attr('id');
		
		var idNum = currId.substring(12);
		
		var prev = Number(idNum) - 1;
		
		// alert(idNum);
		
		$(".testimonial_item").hide();
		
		if (prev > 1) {
			
			$("#" + currId).removeClass('selected_t');
			
			$("#testimonial_" + prev).addClass('selected_t').fadeIn(350);
			
		} else if (prev == 1) {
			
			$("#t_prev").hide();
			
			$("#t_next").show();
			
			$("#" + currId).removeClass('selected_t');
			
			$("#testimonial_" + prev).addClass('selected_t').fadeIn(350);
			
		} else {
			
			$("#t_prev").hide();
			
			$("#t_next").show();
			
		}
		
		$("#t_next").show();
		
		return false;
		
	});
	
});

function bounce(ob, val1, val2) {
		
	ob.animate({ "top": val1 + "px" }, 400).animate({ "top": val2 + "px" }, 400).animate({ "top": val1 + "px" }, 400).animate({ "top": val2 + "px" }, 400).animate({ "top": val1 + "px" }, 400).animate({ "top": val2 + "px" }, 400).animate({ "top": val1 + "px" }, 400).animate({ "top": val2 + "px" }, 400).animate({ "top": val1 + "px" }, 400).animate({ "top": val2 + "px" }, 400).animate({ "top": val1 + "px" }, 400).animate({ "top": val2 + "px" }, 400).animate({ "top": val1 + "px" }, 400).animate({ "top": val2 + "px" }, 400);

}
