/* File: gui.js Author: Ryan Duran | J&C Consultants 2009
 * ------------------------------------------------------------------------------------------------*
 * Description: Includes all of our gui related elements for the site
 *-------------------------------------------------------------------------------------------------*/


$(document).ready(  function()
		{
	var animated = false;
	var panel_object = new Object();
	$("#invite_message").hide();
	
	function InitGui()
	{
		$("#menu div ul").hide();
		
		// RD: fill the content area of values to test the responsiveness of server script
		//SendHttpRequest('.panel_container', 'display', 'tblusers', 'lastname');
		PreloadImageData();
		return true;
	}
	
	InitGui();
	
/*--------------------------------------------------------------------------------------------
 * SendHttpRequest() - RD: sends data request with provided parameters to server script (ajax)
 *-------------------------------------------------------------------------------------------*/
	function SendHttpRequest(objID, method, tblname, params)
	{
		$(objID).html("");
	  var http_data  = $.post("server.php?method="+ method +"&table="+ tblname +"&params="+ params +"", function(data)
			   {    $(objID).html(data);   });

		return true;
	}
	
	/*--------------------------------------------------------------------------------------------
	 * RenderTxt() - RD: Renders text to a specified html object within a form
	 *-------------------------------------------------------------------------------------------*/
		function RenderTxt(from_obj, to_obj)
		{
			var val = document.getElementById(from_obj).value;
			document.getElementById(to_obj).value = val;
			return true;
		}
	
	/*--------------------------------------------------------------------------------------------
	 * PreloadImageData() - RD: preloads image for displaying quicker in client area
	 *-------------------------------------------------------------------------------------------*/
		function PreloadImageData()
		{
			if(document.images)  {
			var ImageArray = new Array( $("body").children().length );
			var Images = new Image();
			
			//alert($("body").children().length)
			}
			return true;
		}
	
	
	/*- Process Events for GUI---------------------------------------------------------------*/
		
	/*--------------------------------------------------------------------------------------------------
	* RD - tab based gui control / events
	*--------------------------------------------------------------------------------------------------*/
	$("#tabs div").hide(); 
	$("#tabs div:first").show(); 
	
	$("#tabs a").click( function()
			{
		         $("#tabs div").hide(); 
		        
		         $("#tabs ul li").css("background-color", "#FFFFCC");
		         $(this).parent().css("background-color", "white");
		       
		         var current_tab = $(this).attr("id");
		         $(current_tab).fadeIn("slow");
			});
	
	
	/*--------------------------------------------------------------------------------------------------
	* RD - Invitation Panel On Registration page
	*--------------------------------------------------------------------------------------------------*/
	$("#invites").hide();
	$("#add_invite a").click( function() 
			{
		      var current_height = $("#reg_panel_content").css("height");
		 
		      $("#invites").hide();
		      $("#invites").show("slow");
		      
		      
		      $("#reg_panel_content").append(
                      " <div id='invites' > " +
                      " <table class='content_register_invites' border='0' > " +
                      " <tr> " +
                      " <td align='center' >First Name:</td><td align='right' ><input type='text' name='invite_firstname' /> </td> " +
                      " <td align='center' >Last Name: </td><td align='right' ><input type='text' name='invite_lastname' /></td> " +
                      " <td align='center' >Email: </td><td align='right' ><input type='text' name='invite_email' /></td> " +
                      " </tr> " +
                      " </table> " +
                      "</div>");
		
			});
	
	/*--------------------------------------------------------------------------------------------------
	* Show Preview  rd: this is the dynamic window that appears and populates that data within its container
	*--------------------------------------------------------------------------------------------------*/
	$("#preview").hide();

    $("#msg_preview").click( function() 
    		 {
     
    	      
    	      $("#preview").animate( { left: "10", top: "-200", width: "500", height: "300", opacity: "0.9f" }, 800 );
    	      
    	      $("#preview").show();
             });
    

    $("#close").click( function() 
    		 {
     
    	      
    	      $("#preview").animate( { left: "0", top: "0", width: "0", height: "0", opacity: "0.0f" }, 800 );
    	      
    	      $("#preview").hide();
             });
    
    
	
	/*--------------------------------------------------------------------------------------------------
	* RenderTabs() - rd: resets the base images of the main tab objects within the advisor header
	*--------------------------------------------------------------------------------------------------*/
	function RenderTabs(tab_obj)
	{
		var imgDir = "images/";
		var currentObj = null;
		
		// Create array of images contained within the menu object
		var imgs = new Array($(tab_obj).children().length);
		//var imgObj[6] = new Image();
		
		for(var k=0; k <= imgs.length; k++ )
		{
			//currentObj = imgs[k].id;
			//imgs[k].src = imgDir + currentObj + "_off.png";
		}
		
		return true;
	}
	
	
	RenderTabs("#menu", null);
	
	$("#menu img").click( function()
			{
		        $(this).attr("src", "images/nav2_tab_advisors3.png");
			});
	
	$(".check_custom").click( function()
			{
		         
		         $("#invite_message").fadeIn("slow");
			});
	
	$(".check_standard").click( function()
			{
		         
		         $("#invite_message").fadeOut("slow");
			});

	

	    });