/* 
 * Dreamki document objects manipulation functions
 */
var doc;

$(document).ready(function() {
    
    doc = new DreamkiDocument();
    
});

function DreamkiDocument () {

    var self = this;

    self.footer = $('.footer-main-wrap');
    self.loaderClass = "dreamki-loader";
    self.loader = $('<div class="' + self.loaderClass + '"></div>');
    
    self.footerHide = function() {
	if (!self.footer.siblings('.bottom').hasClass('no-footer'))
	    self.footer.siblings('.bottom').addClass('no-footer');
	self.footer.hide();
    }

    self.footerShow = function() {
	if (self.footer.siblings('.bottom').hasClass('no-footer'))
	    self.footer.siblings('.bottom').removeClass('no-footer');
	self.footer.show();
    }

    self.submitFormOnEnter = function(form, callback) {
	form.find('input').keypress(function(event) {
	    if ((event.which && event.which == KEY.RETURN) || (event.keyCode && event.keyCode == KEY.RETURN)) {
		if ($.isFunction(callback))
		    callback();
		else
		    form.submit();
	    }
	});
    }

    self.hasLoader = function(obj) {
	return obj.find('.' + self.loaderClass).length;
    }

    self.showLoader = function(obj) {
	obj.find('.' + self.loaderClass).show();
    }

    self.hideLoader = function(obj) {
	obj.find('.' + self.loaderClass).hide();
    }

    self.getLoader = function (obj) {
	return obj.find('.' + self.loaderClass).eq(0);
    }
/*
    var sendAuthenticateRequest = false;
    var timeSinceLastRequest = null;
    $(document).ready(function(){
	$(document).ajaxStart(function(){

	    var currentTime = new Date().getTime();
	    
	    // if just 5 seconds passed since last request, no need to re-send it
	    if (timeSinceLastRequest !== null && (currentTime - timeSinceLastRequest) < 5000) {
		return;
	    }

	    if (!sendAuthenticateRequest){
		userSignin = false;
		sendAuthenticateRequest = true;
		$.ajax({
		    url: ,
		    type: 'post',
		    dataType: 'json',
		    timeout: 12000,
		    success: function(data) {
			if (data.isAuthenticated == false){
			    $('#signinDialog').dialog('open');
			} else {
			    sendAuthenticateRequest = false;
			}
			timeSinceLastRequest = new Date().getTime();
		    }
		});
	    } else {
		userSignin = true;
		sendAuthenticateRequest = false;
	    };
	});
    });*/
}

