$(function () {			
	
	$(".formbuttons").show();
	$(".jscheck_alert").hide();
	function controlRemoveHandler(){
		$(".errorMessage").hide("highlight",{},500);	
	}
	$(".controlRemove").bind('click', controlRemoveHandler);
	$.blockUI.defaults.css.border = 'none'; 
	$.blockUI.defaults.baseZ = '1105'; 
	$.blockUI.defaults.css.backgroundColor = 'transparent'; 
	$.blockUI.defaults.message = '<img src="/images/loading.gif">'; 
	$.blockUI.defaults.overlayCSS.backgroundColor = '#000000';
	$.blockUI.defaults.overlayCSS.opacity = '.1';
	$.blockUI.defaults.fadeIn = '0';
	$.blockUI.defaults.fadeOut = '0';
	$("#home-hero").scrollable( {size: 1} ).circular().autoscroll({ autoplay: true, interval: 17000 });
	
				
	loadProfileTabs=function () {
		$('.profileTabs').tabs({
			create: function(event, ui) { 
				var $panel = $(ui.panel);		
				 if ($panel.is(":empty")) {
					 $panel.append("<div class='tab-loading'><br><br><center><img src='/CFIDE/scripts/ajax/resources/cf/images/loading.gif'/></center><br><br></div>")
				 }			
			},		   
			load: function(event, ui) {
				$(ui.panel).find(".tab-loading").remove();
				$("a.tabLink").bind('click', linkInTab);
				$(".inlineForm").bind('submit', formInTab);
				initProfileDivInTab();
			},
			select: function (e, ui) {
				  $(ui.panel).html("<div class='tab-loading'><br><br><center><img src='/CFIDE/scripts/ajax/resources/cf/images/loading.gif'/></center><br><br></div>");
			},
			cache: false,
    		ajaxOptions: {cache: false}			
		});
	
	}
	
	linkInTab=function() {
		$('.ui-tabs-panel:visible').html("<br><br><center><img src='/CFIDE/scripts/ajax/resources/cf/images/loading.gif'/></center><br><br>");
		$('.ui-tabs-panel:visible').load(this.href, function() {
			$("a.tabLink").bind('click', linkInTab);
			$(".inlineForm").bind('submit', formInTab);
			initProfileDivInTab();
		});
		return false;
	}
	
	linkInDiv=function() {

		var gotoLink=$(this).attr("href");
		var loadUpDiv=$(this).closest(".profileDivInTab");

		$(loadUpDiv).html("<br><br><center><img src='/CFIDE/scripts/ajax/resources/cf/images/loading.gif'/></center><br><br>");
		$(loadUpDiv).load(gotoLink, function() {
			$("a.divLink").unbind('click');
			$("a.divLink").bind('click', linkInDiv);
		});  
		return false;		
	}
	
	formInTab=function() {
		$.ajax({ // create an AJAX call...
			  data: $(this).serialize(), // get the form data
			  type: $(this).attr('method'), // GET or POST
			  url: $(this).attr('action'), // the file to call
			  success: function(response) { // on success..
			  $('.ui-tabs-panel:visible').html(response); // update the DIV
			  $("a.tabLink").bind('click', linkInTab);
			  $(".inlineForm").bind('submit', formInTab);
			  initProfileDivInTab();
			}
			});
		return false; // cancel original event to prevent form submitting
		
	}
	
	formInDialog=function() {
		var form = $(this), oldSubmit = form[0].onsubmit;
    	form[0].onsubmit = null;
		var ret = oldSubmit.call(this);
		
		if (ret) {
		  $.ajax({ // create an AJAX call...
				data: $(this).serialize(), // get the form data
				type: $(this).attr('method'), // GET or POST
				url: $(this).attr('action'), // the file to call
				success: function(response) { // on success..
				$('#profileDialog').html(response); // update the DIV
				$(".inlineDialogForm").bind('submit', formInDialog);
			  }
			  });
		      return false; // cancel original event to prevent form submitting
		} else {
		      return false;
		}
		
	}
	
	initProfileDivInTab=function() {
	
		$(".profileDivInTab").each(function(){
			$(this).html("<br><br><center><img src='/CFIDE/scripts/ajax/resources/cf/images/loading.gif'/></center><br><br>");
			$(this).load($(this).attr("href"), function() {
				$("a.divLink").unbind('click');  // there's multiple profileDivInTabs - if you don't unbind the clicks first there will be multiple bindings //
				$("a.divLink").bind('click', linkInDiv);
			});
		});
	}
	
	$( "#profileDialog" ).dialog({
		autoOpen: false,
		height:450,
		width:550,
		modal:true,
	    zIndex:100
		
	});
	
	openProfileDialog=function(name,profileID,showButtons) {
		$( "#profileDialog" ).dialog( "option", "title", name );
		if (showButtons == 1) {
			$( "#profileDialog" ).dialog( "option", "buttons", { "close": function() { $(this).dialog("close"); }, 
					"view full profile >": function() { 
												$( "#profileDialog" ).html("<br><br><br><br><center><img src='/CFIDE/scripts/ajax/resources/cf/images/loading.gif'/></center><br><br><br><br>");
												window.location="/profile/profile.cfm?profileID="+$(this).attr("profileID"); 
											} 
					} );
		}
		$( "#profileDialog" ).attr("profileID", profileID);
		$( "#profileDialog" ).html("<br><br><br><br><center><img src='/CFIDE/scripts/ajax/resources/cf/images/loading.gif'/></center><br><br><br><br>");		
		$( "#profileDialog" ).load("/profile/profile.cfm?profileID="+profileID+"&noFrame=1", function() {
			loadProfileTabs();
			$(".inlineDialogForm").bind('submit', formInDialog);
		});
		$( "#profileDialog" ).dialog("open");
	}
	
	loadURLInProfileDialog=function(url) {
		$( "#profileDialog" ).html("<br><br><br><br><center><img src='/CFIDE/scripts/ajax/resources/cf/images/loading.gif'/></center><br><br><br><br>");		
		$( "#profileDialog" ).load(url, function() {
			loadProfileTabs();
		});
	}
	
	loadMessageAndCloseProfileDialog=function(message) {
		$( "#profileDialog" ).html("<br /><br /><br /><br /><br /><font style='font-family:Arial; color:#FF0000; font-size:16px; font-weight:bold;'><p align='center'>"+message+"</p></font>");		
		$('#profileDialog').fadeOut('slow', function() {
		  // Animation complete.
		  $( "#profileDialog" ).dialog("close");
		});
	}
	

});
