
/****************************************************************************

  This file is part of the GamesCast.tv Website

	GamesCast.tv coded by Steve "GreasedScotsman" Huff, 
	Copyright 2010 Steve Huff
	
	It is distributed under the terms of the 
	GNU General Public License
		
***************************************************************************/

function gctvChatOpen(username) {

	$(".gctvchat").css("margin-top", "10px");
	$(".gctvchat").slideDown(500);
	$(".gctvopen").hide();
	$(".gctvclose").show();

	$(".gctvopen").delay(501,function(){
		$("#gctvchatframe").attr('src',"http://webchat.quakenet.org/?channels=gamescast"); //+username);
	});
}

function showChatOpen() {

	var layout = $("#gctvlayout").val();
	var scwidth = $(".showchat").data("scwidth");
	var scheight = $(".showchat").data("scheight");
	
	var sID = $("#currentshow").val();
	var noMatchMsg = /(No chat exists)/;
	var noneAvailMsg = /(No Show Chat Available)/;
	var sameNetMsg = /(same network)/;
	var popoutMsg = /(Popout)/;
	var openShowChat = 0;
	
	$.get("showchat.php", { sID: sID, layout: layout, scwidth: scwidth, scheight: scheight }, 
		function(data) {
			$("#showchatframe").html(data);
			
			if ($("#joinplaceholder").html().match(noneAvailMsg)) { 
				openShowChat = 0;
			} else {
			
				if (data.match(noMatchMsg)) { 
					chatHeight = "50px"; 
					openShowChat = 1;
				} else if (data.match(sameNetMsg)) {
					chatHeight = "80px"; 
					openShowChat = 1;
				} else if (data.match(popoutMsg)) {
					chatHeight = "50px"; 
					openShowChat = 1;
				} else { 
					chatHeight = scheight; 
					openShowChat = 1;
				}
			}

			if (openShowChat == 1) {
				$(".showopen").hide();
				$(".showclose").show();
				$("#showchatframe").show();
	
				$(this).delay(5,function(){
					$(".showchat").show().animate({"height": chatHeight }, "slow");
					//alert("Chat height is: "+chatHeight+"\nData:\n\n"+data);
				});
			}
		}
	);

}

$(document).ready(function() {
	$(".showchat").data("scwidth", $(".showchat").css("width")); // store the original CSS value for width
	$(".showchat").data("scheight", $(".showchat").css("height")); // store the original CSS value for height
	$(".gctvchat").hide();
	$(".showchat").hide();
	$(".showclose").hide();
	$(".gctvclose").hide();

	$("#joinplaceholder").click(function() {
		showChatOpen();
		$(".showchat").css("margin-top", "10px");
		
	});

	$(".showclose").click(function() {

	$("#showchatframe").fadeOut(400).html("");
		$(this).delay(100,function(){
			$(".showclose").hide();
			$(".showchat").animate({"height": "0px" }, "slow");
			$(".showopen").show();
			$(".showchat").css("margin-top", "0px");
		});
	});

	$(".gctvclose").click(function() {
		
		$("#gctvchatframe").attr('src',"");

		$(this).delay(100,function(){
			$(".gctvclose").hide();
			$(".gctvchat").slideUp(500);
			$(".gctvopen").show();
			$(".gctvchat").css("margin-top", "0px");
		});
	});
	
	$("#chatpoplink").click(function() {
		var chatInfo = $("#chatpoplink").attr("alt").split("||");
		popoutShowChat(chatInfo[0], chatInfo[1]);
	});
	
	$("#gctvpoplink").click(function() {
		var chatInfo = $("#gctvpoplink").attr("alt");
		popoutGCTVChat(chatInfo);
	});
	

});
 
// EOF
