// JavaScript Document
var fadebox = "<div class='FadeFrame' id='FadeFrame'>Loading...<br />Please Wait...<br /><img src='/images/loading1.gif' height='32' width='32' alt='Loading' border='0' /></div>";
var fadesendbox = "<div class='FadeFrame' id='FadeFrame'>Sending...<br />Please Wait...<br /><img src='/images/loading1.gif' height='32' width='32' alt='Loading' border='0' /></div>";

$(document).ready(function(){


	function submit_contact_form(){
		$(fadesendbox).appendTo("#ContactForm");
		$("#ContactForm").fadeTo(1000, 1, function() {		
			$.post("/include/postcontact.php",
						 $("#frmContactUs").serialize(),
						 function(data) {
								$("#ContactForm").fadeTo(100, 1);
								$("#ContactForm").html(data);
								$("#FadeFrame").remove();
								$(".btnSubmitContact").click(submit_contact_form);
						 }
			);
		});
	};
	
	$(".btnSubmitContact").click(submit_contact_form);
	
	
	
	//SHOW PLAYER CARDS//
	function close_player_card() {  
		$("#PlayerFrame:visible").fadeOut("fast");
	};

	function show_player_card() {  
		$("#PlayerFrame:visible").fadeOut("fast");
		var playerid = $(this).attr("player");
		
		$.get("/include/showplayer.php", { player: playerid },
					function(data) {
					 $("#PlayerFrame").html(data);
					 $("#PlayerFrame").fadeIn("normal"); 
					 $(".btnClosePlayer").click(close_player_card);            
					}
		);
	};	


	function show_small_calendar_event() {
  	var day = $(this).attr("day");
  	var month = $(this).attr("month");
  	var year = $(this).attr("year");
    
  	$("#EventsFrame:visible").slideUp("fast");
		
		$.ajax({
			type: "GET",
			url: "/include/calsm/callist.php",
			data: "day="+day+"&month="+month+"&year="+year,
			success: function(data){
      	$("#EventsFrame").html(data);
        $("#EventsFrame").slideDown("normal");
			},
			error: function(data, status, error) {
        $("#EventsFrame").html("<div class='boxError'>Error: "+error+"</div>"+data);
        $("#EventsFrame").slideDown("normal");
			}
		});
  };
  //--- end show small calendar events
	

	function navigate_calendar_sm(){
		var month = $(this).attr("month");
		var year = $(this).attr("year");
		
		$("#EventsFrame").fadeOut('fast');
		$("#CalendarFrame").fadeOut("fast", function() {
			$("#CalendarFrame").html("<div class='SubTitle'>Loading...<br />Please Wait</div>");
		
			$.get("/include/calsm/calendar.php", { month: month, year: year },
						function(data) {
							$("#CalendarFrame").html(data);
							$("#CalendarFrame").fadeIn("normal");
							$(".lnkCalNavSm").click(navigate_calendar_sm);
							$(".lnkShowEventSm").click(show_small_calendar_event);
						}
				);
		});
	};


	function navigate_calendar(){
		var month = $(this).attr("month");
		var year = $(this).attr("year");
			
		$("#EventsFrame").fadeOut('fast');
		$("#ScheduleFrame").fadeOut("fast", function() {
			$("#ScheduleFrame").html("<div class='SubTitle'>Loading...<br />Please Wait</div>");
		
			$.get("/include/callg/calendar.php", { month: month, year: year },
						function(data) {
							$("#ScheduleFrame").html(data);
							$("#ScheduleFrame").fadeIn("normal");
							$(".lnkCalNavLg").click(navigate_calendar);
							$(".btnCalPopup").click(load_calendar_popup);
						}
				);
		});
	};
	
	
	function load_calendar_popup() {  
		$("#PopupFrame:visible").fadeOut("fast");
		var calid = $(this).attr("cal");
		
		$.get("/include/callg/calpopup.php", { id: calid },
					function(data) {
					 $("#PopupFrame").html(data);
					 $("#PopupFrame").fadeIn("normal");  
					 $(".btnClosePopup").click(close_popup);           
					}
		);
	};
		
	function close_popup() {  
		$("#PopupFrame:visible").fadeOut("fast");
		$("#PopupFrame2:visible").fadeOut("fast");
	};	
	
	$(".lnkCalNavSm").click(navigate_calendar_sm);
	$(".lnkShowEventSm").click(show_small_calendar_event);

	$(".lnkCalNavLg").click(navigate_calendar);
	$(".btnCalPopup").click(load_calendar_popup);
	$(".btnClosePopup").click(close_popup);
	$(".btnShowPlayer").click(show_player_card);
	$(".btnClosePlayer").click(close_player_card);
	
});

