$(document).ready(function(){
	blink = function(){
		if ($(".res a").css("color") == "#f78f1e") {
			$(".res a").css("color","#000");
		} else {
			$(".res a").css("color","#f78f1e");
		}
	}
	
	// MENU
	$("ul.nav").superfish({
		animation : { opacity:"show", height:"show" }
	});
		
	$("ul.nav li:first").addClass("res");
	
	// SLIDESHOW
	// Append the prev/next buttons. These shouldn't show up if JS isn't enabled
	if($("#green_flash ul li").length) {
		$("#green_flash").append('<p><span id="sp" rel="-1">Prev</span> <span id="sn" rel="+1">Next</span></p>');
	}
	$("#green_flash ul li:gt(0)").hide();
	var n = 0;
	var t = $("#green_flash ul li").length-1;
					
	// Advance to the next image
	$("#green_flash p span").click(function(){
		var d = $(this).attr("rel");
		var s = eval(n + d);

		if($("#green_flash ul li:visible").is(":last-child") && d == "+1"){
			$("#green_flash ul li").hide();
			$("#green_flash ul li:eq(0)").show();
			n=0;
		}
		else if($("#green_flash ul li:visible").is(":first-child") && d == "-1"){
			$("#green_flash ul li").hide();
			$("#green_flash ul li:eq("+t+")").show();
			n=t;
		} else {
			//alert(s);
			$("#green_flash ul li").hide();
			$("#green_flash ul li:eq("+s+")").show();
			n=s;
		}
	});
	
	//NEW SLIDESHOW
	$("ul#newslideshow").cycle({
		fx: 'scrollHorz',
		speed: 5000,
		timeout: 4000,
		next: '.next_img',
		prev: '.prev_img',
		pause: 1
	});
	
	//KWICKS TAB - USED ON ACCOMMODATIONS SECTION
	$(".kwicks").kwicks({
		max:252,
		min:126,
		sticky:false,
		duration:100,
		defaultKwick:0,
		spacing:0
	});
	//CHECK ALL 3 DIVS HEIGHT AND SET HEIGHT TO GREATEST
	var h_array = Array($("#c1").height(), $("#c2").height(), $("#c3").height());
	h_array.sort(numberSorter);
	// $("#room_info").height(h_array[2] + 80);
	
	$("#kwick1 a, #kwick2 a, #kwick3 a").click(function() {
		
		which = $(this).parent().attr("id");
		if (which == "kwick1") { show = "#c1"; }
		else if (which == "kwick2") { show = "#c2"; }
		else if (which == "kwick3") { show = "#c3"; }
		
		if ($("#c1").css("display") == "block") {
			hide = "#c1";
		} else if ($("#c2").css("display") == "block") {
			hide = "#c2";
		} else if ($("#c3").css("display") == "block") {
			hide = "#c3";
		}
		
		$("#kwick1, #kwick2, #kwick3").removeClass("selected");
		$(this).parent().addClass("selected");
		
		// $(hide).fadeOut(100, function() {
		// 	$(show).fadeIn(100);
			// if (show == "#c3") {
			// 	$("#room_info").css("background-color", "#fff").fadeIn(100);
			// } else {
			// 	$("#room_info").css("background-color", "#000").fadeIn(100);
			// }
		// });
		$(hide).slideUp("slow", function() {
			if (show == "#c3") {
				$("#room_info").css("background-color", "#fff").fadeIn(100);
			} else {
				$("#room_info").css("background-color", "#000").fadeIn(100);
			}
			$(show).slideDown("slow");
		});
		
		return false;
	});
	
	// TESTIMONIALS PAGE
	$("#body_contain .testimonial a.more").click(function() {		
		//BASED ON CLICKED A TAG FIND PARENT P THEN TOGGLE NEXT P TAG IN DIV
		$($(this).parent()).next().slideToggle("slow");
	});
	$("#body_contain .testimonial a.close").click(function() {
		$($(this).parent().slideToggle("slow"));
	});
	
	
	// if ($.browser.msie) {
	// 	$("ul.nav li").wrapInner("<b></b>");
	// 	var timer = window.setInterval('blink()',500);
	// }
});
function numberSorter(a, b) {
	return a - b;
}


function changeSection(to) {
	$("#green_flash ul li").hide();
	$("#green_flash ul li:eq("+to+")").show();
}


//hidden form for the simon page
function openBForm() {
	if ($("#hiddenform").length == 0) {
		$('<div id="hiddenform"></div>').prependTo("#contain").hide().load("/eat/bachelor_form.php", function() {
			$("#hiddenform").slideToggle("slow");
		});
	}
}

function processHiddenForm() {
	var str = $("#hiddenform form").serialize();
	$.post('bachelor_form.php?submit_post=1', str, function(data) { $("#hiddenform").empty().prepend(data); });
}

function removeForm() {
	$("#hiddenform").empty();
	$('<div id="thanks"><h1>Thank You!</h1><p>Your submission was successful.</p><p>We look forward to serving you in the future at Palms Place.</p><a href="javascript:closeForm();" class="booknow" style="display:inline; padding:0 5px;">Close</a></div>').appendTo("#hiddenform");
}

function closeForm() {
	$("#hiddenform").slideToggle("slow", function() {
		$("#hiddenform").remove();
	});
}
