function gl_global() {
	//"use strict";
	//set all the options for sortable	
	this.originalOptions = {
	    update: function () {
	        var form = $('.sortable').sortable('serialize'),
	            url = base_url + "admin/houses/update_dimensions_positions/";
	        $.post(url, form, function (data) {

	        }, "text");//text is the response from the server
	    },
	    handle : ".handle"
	},
	this.houseOptions = { /* This is for sorting */
	        update: function () {
	            var form = $('.sortable').sortable('serialize'),
	                url = base_url + "admin/house_styles/update_elevation_positions/";
	            $.post(url, form, function (data) {
	            }, "text");//text is the response from the server
	        },
	        handle : ".handle"
	    },
	this.housePositionOptions = {   /* This is for sorting */
	        update: function () {
	            var form = $('.sortable').sortable('serialize'),
	                url = base_url + "admin/house_styles/updateHouseStylePosition/";
	            $.post(url, form, function (data) {
	            }, "text");//text is the response from the server
	        },
	        handle : ".handle"
	    },
	this.specificationOptions = {   /* This is for sorting */
	        update: function () {
	            var form = $('.sortable').sortable('serialize'),
	                url = base_url + "admin/specs/update_specification_position/";
	            $.post(url, form, function (data) {
	            }, "text");//text is the response from the server
	        },
	        handle : ".handle"

	    },
	this.tinyOptions = { //set options for TinyMCE
	        mode : "textareas",
	        editor_selector : "mceSimple",
	        plugins : "paste",
		    theme_advanced_buttons3_add : "pastetext,pasteword,selectall",
		    paste_cleanup_on_paste : true
		};

	//loads data into the form div
	this.showFormData = function (url, sort_options) {
	    $.post(url, {}, function (data) {
			if (!check_permissions(data)) {
				return false;
			}
	        $("#form").html(data).find(".sortable").sortable(sort_options);
	    }, "text");//text is the response from the server
	}

	this.validForm = function () {
	    var result = true;
	    $(".required").each(function (index) {
	        //get the value
	        var temp = $(this).val(),
	            fieldValue = trim(temp); //remove any spaces for validation

	        //remove any previous errors
	        if ($(this).hasClass("failed")) {
	            $(this).removeClass("failed");
	        }

	        //make sure required fields are not blank
	        if (fieldValue === "") {
	            $(this).addClass(" failed");
	            result = false;
	        }

	        //validate if it should be numeric only
	        if ($(this).hasClass("numeric")) {
	            if (isNaN(fieldValue)) {
	                $(this).addClass(" failed");
	                result = false;
	            }
	        }
	    });
	    return result;
	}

	this.resetFields = function (form) {
	    //loop through form resetting the input fields but not buttons etc
	    $(':input', form).not(':button, :submit, :reset, :hidden, :checkbox, :radio').val('');
	    $(':input', form).removeAttr("checked").removeAttr("selected");
	}

	this.updateData = function(url, post_data, callback) {
	    $("#display").fadeOut(500);
	    var series = [],
	        str = "",
	        arr = [];
			
			if(typeof post_data !== 'undefined')
			{
				arr = post_data;
			}
	
	    setTimeout(function () {
	        $.post(url, arr, function (data) {
	            $("#display").html(data).find(".sortable").sortable(this.housePositionOptions);
	            $("#display").fadeIn(900);

				if(typeof callback === 'function')
				{
					callback();
				}
				
	        }, "text");//text is the response from the server

	    }, 500);    //wait half a second before the ajax call so we can see the fade out

	    return false;
	}
	this.getClass = function () {
	    var type = document.getElementById("classname").innerHTML;
	    return type;
	}

	this.feedback = function (str) {
	    //display feedback
	    //reset any post request result
	    $(".result").html("");
	    $(".ajaxresult").css("visibilty", "visible");
	    $(".ajaxresult").html("<p>" + str + "</p>");
	}

	this.ajaxError = function (xhr, status) {
	    var message = "",
	        title = "";
	    if (xhr.status === 404) {
	        title = "404 Page Not Found";
	        message = "You should report this to the website administrator";
	    } else if (xhr.status === 500) {
	        title = "Internal Server Error";
	        message = "You should report this to the website administrator";
	    } else {
	        title = "Unhandled Exception";
	        message = "You should report this to the website administrator";
	    }
	    $("#dialogresult").html(message);

	    $("#dialogresult").dialog({
	        modal: true,
	        draggable: false,
	        show: "drop",
	        height: 300,
	        width: 450,
	        minHeight: 300,
	        minWidth: 450,
	        title: title,
	        buttons: {
	            "Ok": function () {
	                $(this).dialog("close");
	                $("#dialogresult").html("");
	                feedback("<p>Your last request could not completed");
	            }
	        }//end buttons
	    });//end dialog
	}

	function trim(stringToTrim) {
	    return stringToTrim.replace(/\s+/g, "");
	}
	
	return this;
};
var greatliving = new gl_global(); 

//init stuff
//activley look out for images so we can display with lightbox
$("#form a.image").live("click", function () {
    $(this).lightBox();
    //this clicks the link after setting the handler.
    $(this).click();
    return false;
});


//for  now
function check_permissions(result)
{
	return true;
}
