/* Author: James Henry
	Date: July 2011 
*/


/* Slider for Highlights Section*/


	$(document).ready(function(){
		$("#highlights > ul").tabs({fx:{opacity: "toggle"}}).tabs("rotate", 5000, true);
	});




/*******************************************************************************************************************/




/* News Ticker for Latest Tweet Section*/

	    $(function () {
	        $('#js-news').ticker({
	            htmlFeed: false,
	            ajaxFeed: true,
	            feedUrl: 'tweets.xml',
	            feedType: 'xml',
	            controls: false
	        });
	    });


    
    
/*******************************************************************************************************************/    
    
    
    
    
    /* Sort Contents of a Table */
    
    $(function() {
       $("table#sortTableExample").tablesorter({ sortList: [[1,0]] });
     });
 
 
 

/*******************************************************************************************************************/     
     
     
     
     
     /* Make sure video popup only plays once for each person */
     
     $(document).ready(function() {
     	
     	var video = $.cookie('video');
     	
     	if( video !== 'viewed'){
     		$("#welcome").overlay({
     			top: 24,
     			mask: {
     				color: '#000',
     				loadSpeed: 200,
     				opacity: 0.9
     			},
     			closeOnClick: false,
     			load: true
     		});
     		
     		// SET COOKIE
     		
     		$.cookie('video', 'viewed', { expires: 300 })
     	};
     });
     
     

/*******************************************************************************************************************/



	
	/* Alert Close functionality */
	
	$(".alert-message").alert();
	
	
	

/*******************************************************************************************************************/
	
	
	
	
	
	/* Congratulations on new profile */
		$("#congrats").overlay({
			top: 14,
			mask: {
				color: '#000',
				loadSpeed: 200,
				opacity: 0.7
			},
			closeOnClick: false,
			load: true
		});
		



/*******************************************************************************************************************/




	$(document).ready(function() {
	    
	    $(".tabs > ul").tabs("section > section");
	    $(".accordion").tabs(".accordion > section", {tabs: 'header', effect: 'slide', initialIndex: 0});
	    
	});
	
	

/*******************************************************************************************************************/




	$("#changeEmail").validator();
	
	
	
	
/*******************************************************************************************************************/

	function submitData (id) {
		
		if(id == "displayName"){
			$.post("includes/ajaxSubmitData/"+id+".php", { displayName: document.displayNameForm.displayName.value, fb_id: document.displayNameForm.fb_id.value }, 
				function(output) {
					if(output == 'success'){
						$("#"+id+"Field").addClass('success');
						$(".submit_button").remove();
						$("#"+id).parent().html('<label>My Display Name:</label><span class="submit_status">Successfully Updated!</span>');
					} else {
						$("#"+id+"Field").addClass('fail');
						$(".submit_button").remove();
					}
				});
		} else if(id == "fullName"){
			$.post("includes/ajaxSubmitData/"+id+".php", { fullName: document.fullNameForm.fullName.value, fb_id: document.fullNameForm.fb_id.value }, 
				function(output) {
					if(output == 'success'){
						$("#"+id+"Field").addClass('success');
						$(".submit_button").remove();
						$("#"+id).parent().html('<label>My Full Name:</label><span class="submit_status">Successfully Updated!</span>');
					} else {
						$("#"+id+"Field").addClass('fail');
						$(".submit_button").remove();
					}
				});
		} else if(id == "emailAddress"){
			$.post("includes/ajaxSubmitData/"+id+".php", { emailAddress: document.emailAddressForm.emailAddress.value, fb_id: document.emailAddressForm.fb_id.value }, 
				function(output) { 
					if(output == 'success'){
						$("#"+id+"Field").addClass('success');
						$(".submit_button").remove();
						$("#"+id).parent().html('<label>My Email Address:</label><span class="submit_status">Successfully Updated!</span>');
					} else {
						$("#"+id+"Field").addClass('fail');
						$(".submit_button").remove();
					}
				});
		}
		
	
	}
	
	$(".edit_data").click( function editMemberData() {
	  	
	  	// Get parent node ID
	  	var id = "#" + $(this).parent().get(0).id + "Field";
	  	
	    $(id).toggleClass('disabled');
	    
	    var X = $(id).attr('disabled');
	    
	    if(X == true){
	    	$(id).removeAttr('disabled');
	    	$(id).removeClass('disabled');
	    	$(id).removeClass('success');
	    	$(this).parent().append('<button type="button" class="btn success submit_button" onClick="submitData($(this).parent().get(0).id);">Save</button>');
	    } else {
	    	$(id).attr('disabled', 'disabled');
	    	$(id).addClass('disabled');
	    	$(".submit_button").remove();
	    }
	    
	});
	
	
/*******************************************************************************************************************/


	$(".fieldInfo").hover(function () {
		$(this).parents('.spacer').children(".displayedFieldInfo").css('display', 'block');
	}, function () {
		$(".displayedFieldInfo").css('display', 'none');
	});
