/* Global Functions */

jQuery(document).ready(function() {
	jQuery('.fadeThis').append('<span class="hover"></span>').each(function () {
	  var $span = jQuery('> span.hover', this).css('opacity', 0);
	  jQuery(this).hover(function () {
	    $span.stop().fadeTo(200, 1);
	  }, function () {
	    $span.stop().fadeTo(300, 0);
	  });
	});
	
	jQuery('a#resetServerChk').live('click', function(e){
		e.preventDefault();
		jQuery("#hosting-status-wrapper").fadeOut(200, function(){
			jQuery("#chkSrvStatus").fadeIn(300);
			jQuery('#hosting-status-wrapper').empty();
			jQuery('#hosting-status-wrapper').append('<div id="hosting-status"><p id="chkTime"></p><div id="hosting-status-indicator"><div style="width: 255px; display: block; opacity: 1;" id="hosting-status-bar"></div></div><table id="hosting-status-info"><tbody><tr><td class="label">Host:</td><td><span class="good" id="status-host"></span></td></tr><tr><td class="label">FTP Status:</td><td><span class="good" id="status-ftp"></span></td></tr><tr><td class="label">Email Status:</td><td><span class="good" id="status-pop"></span></td></tr><tr><td class="label">HTTP Status:</td><td><span class="good" style="opacity: 1;" id="status-http"></span></td></tr></tbody></table></div>');			
		})
	})


// Get Page Name
var sPath = window.location.pathname;
var sPage = sPath.substring(sPath.lastIndexOf('/') - 1);
//alert(sPath);

switch(sPath)
{
case "/contact/":
	
	// setup ul.tabs to work as tabs for each div directly under div.panes
	jQuery("#flowtabs").tabs("#flowpanes > div", {});
	
	var api = $('.tabs').data('tabs')
	var chosenTabIndex = 0
	api.onClick(function(event,ui) 
	{ 
		chosenTabIndex=ui; 
		jQuery(".current_page_parent .sub-menu li").eq(chosenTabIndex).addClass("current_page_item");
	})
	
  break;
default:
}

});

jQuery(window).load(function(){
	jQuery("input.clearText").focus(function(){
		clearTextInput(this);
	}).blur(function(){
		checkInputField(this);
	})
	jQuery("input").each(function(i){
		this.txt = this.value;
	})
	jQuery("textarea.clearText").focus(function(){
		clearTextInput(this);
	}).blur(function(){
		checkInputField(this);
	});
	jQuery("textarea").each(function(i){
		this.txt = this.value;
	});
	jQuery("input.password").focus(function(){
		changePass(this);
	});
});

function showStatus(){
	
	host = jQuery("#host").val();
	
	jQuery("#chkSrvStatus").fadeOut(200, function(){
		jQuery("#hosting-status-wrapper").fadeIn(300, function(){
			jQuery("#status-host").append(host);
		})
	});
    
    
    jQuery("#hosting-status-bar").animate(
    {
        width: 0,
        opacity: 0.5
    }, 0, function ()
    {

        jQuery("#hosting-status-bar").animate(
        {
            width: "255px"
        }, 10000, "swing", function ()
        {            
            jQuery("#hosting-status-bar span").append("System check complete.");
            
            var chkDate = new Date();          
            chkDate = jQuery('<span>' + chkDate + '</span>');
            jQuery("p#chkTime").append(chkDate);
            
            jQuery("#hosting-status-bar").animate(
            {
                opacity: 1
            }, 400)
            
            jQuery("#hosting-status-wrapper").append('<div id="resetSrvChk">&raquo; <a href="#" id="resetServerChk">Check Another Server</a><div>');
            
            jQuery("#resetSrvChk").fadeIn(500);
        })
	            	

    	var status = new Array();
    	var ftp;
    	var pop;
    	var http;

		//Check all services using JSON data call
		jQuery.getJSON('http://www.modusdigital.com/server_check.php?host=' + host + '&callback=?', 
		{
			format: "json"
		},	
		function(serverChk){
	        
   			jQuery.each(serverChk, function(key, val){
				status[key] = val;      			
   			});
   			
			ftp = jQuery('<strong>' + status['FTP'] + '</strong>');
			pop = jQuery('<strong>' + status['SMTP'] + '</strong>');
			http = jQuery('<strong>' + status['HTTP'] + '</strong>');

	        jQuery("#hosting-status-bar").append("<span></span>");
	        jQuery("#hosting-status-bar span").css("text-shadow", "0px 0px 4px #098834");
	
			jQuery("#status-ftp").empty().append("Checking...");
	
	        jQuery("#status-http").animate(
	        {
	            opacity: 1
	        }, 1000, function ()
	        {
	            jQuery("#status-ftp").empty().append(ftp).addClass("good");
	            jQuery("#status-pop").empty().append("Checking...");
	            jQuery("#status-http").animate(
	            {
	                opacity: 1
	            }, 1000, function ()
	            {
	                jQuery("#status-pop").empty().append(pop).addClass("good");
	                jQuery("#status-http").empty().append("Checking...");
	                jQuery("#status-http").animate(
	                {
	                    opacity: 1
	                }, 500, function ()
	                {
	                    jQuery("#status-http").empty().append(http).addClass("good")
	                })
	            })
	        }); 
		})       
    })
}


//usage: form input text element onfocus="clearTextInput(this);" | Clears the form element of any default text and stores that text in a txt property
function clearTextInput(Input){
	if(!Input.txt)
		Input.txt = Input.value;
	if(Input.txt == Input.value)
		Input.value = "";
}
//usage: form input text element onblur="checkInputField(this)"; | Checks the form element and replaces it with default text if the field was left empty by the user
function checkInputField(Input){
	if(Input.value == "")
		Input.value = Input.txt;
} 

