// Universal AJAX Calls for HuddleFish

// Code to do some basic page setup
// This will also be called after each widget reload
function page_load()
{
  $(this).HFInit();
  // $(function() {
  
    // $(document).HFInit();
  
    //// Universal Uploadify Call
    //$('#uploadify_test').uploadify({
    //    'uploader'  : '/js/uploadify/uploadify.swf',
    //    'script'    : '/js/uploadify/uploadify.php',
    //    'cancelImg' : 'cancel.png',
    //    'auto'      : true,
    //    'folder'    : '../../../uploads',
    //    'method'		:	'POST',
    //    'onComplete':	function(event, queueID, fileObj, response, data) {
    //        alert(response);
    //    }
    //});
  
    // Change all "create_dialog" classes to calls to create_dialg()
/*
    $('.create_dialog').click(function(e) {
      e.preventDefault();
      create_dialog($(this).attr('href'));
    });
*/
    
		// Handle the date pickers
/*
		$(".date_picker").datepicker({
			dateFormat:	'mm/dd/yy',
      showOn: 'button',
      buttonImage: '/images/calendar.gif',
      buttonImageOnly: true
    });    
*/
    
    //// Initialize tinymce
    //$('textarea.tinymce').tinymce({
    //   script_url : '/js/tinymce/tiny_mce.js',
    //   theme : "advanced",
    //   theme_advanced_buttons1 : "bold,italic,underline,forecolor,separator,cleanup,undo,redo,copy,paste,separator,link,unlink,separator,code",
    //   theme_advanced_buttons2 : "",
    //   theme_advanced_buttons3 : "",
    //   theme_advanced_toolbar_location : "top"
    //});
    
    
    // JS corner rounding (see dialog.js for definition)
    // round_corners();
  // });
}

if (typeof console == 'undefined'){
  console = {
    log:function(stuff){}
  }
}


// Run page_load when the page first loads
$(function($){

/*
	var f = $("#content_loaded_field");
	if (f.val() == "1"){
		f.val("0");
		window.location.href = window.location.href;
		return;
	}
	else {
		f.val("1");
	}
*/

	$(document).HFInit();
	$("body").removeClass("not_loaded");
});

function s(num)
{
  return num == 1 ? '' : 's';  
}

function url_title(str)
{
    str = str.toLowerCase(); //change everything to lowercase
    str = str.replace(/^\s+|\s+$/g, ""); //trim leading and trailing spaces
    str = str.replace(/[_\s]+/g, "-"); //change all spaces and underscores to a hyphen
    str = str.replace(/[^a-z0-9-]+/g, ""); //remove all non-alphanumeric characters except the hyphen
    str = str.replace(/[-]+/g, "-"); //replace multiple instances of the hyphen with a single instance
    str = str.replace(/^-+|-+$/g, ""); //trim leading and trailing hyphens
 
    return str;
}
