var MYAPP = MYAPP || {};
(function ($,MYAPP,window) {
//    RONB.ui  = RONB.ui || {};
	MYAPP.$ = $;
    MYAPP.urls = MYAPP.urls || {};
    MYAPP.urls.ajaxless = '/';
    MYAPP.utils =  MYAPP.utils || {};
	var dataCollection = {};
//    RONB.swfs = {};
    // UTILITIES
	
	function setData(field,data){
		dataCollection[field] = data;
		return data;
	}

	function getData(field){
		return dataCollection[field];
	}

	function deleteData(field){
		return delete dataCollection[field];
	}

	function clearData(){
		dataCollection = {};
		return true;
	}
	
	//if (!console) console = {log: function(){}, d: function(){}};
    MYAPP.dbg = {
        DEBUG:false,
        log: function (o) {
            if (!MYAPP.dbg.DEBUG) return MYAPP.dbg;

            console && console.log(o);
            return MYAPP.dbg;
        },
        dir: function (o) {
            if (!MYAPP.dbg.DEBUG) return MYAPP.dbg;
            console && console.dir(o);
            return MYAPP.dbg;
        },
		debugPretext : function (str){
			MYAPP.dbg.log(str);
		}
    }

    MYAPP.utils.listExplorer  = function (li,strategic) {//strategic(element, key, li) {return transformed(element)}
        var key,
            temp;
        for (key in li) {
            if (li.hasOwnProperty(key)){
                temp = strategic(li[key],key, li);
                if (typeof temp !== 'undefined'){ li[key] = temp;}
            }
        }
    }
	
	MYAPP.utils.cookies = (function (){
		
		function createCookie(name,value,options) {
			var strCookie = '',
				days,t;
			options = options || {};

			if (typeof options.expires === 'number') {
				days = options.expires, t = options.expires = new Date();
				t.setDate(t.getDate() + days);
			}			
			
			strCookie = [
				encodeURIComponent(name), '=',
				options.raw ? value : encodeURIComponent(value),
				options.expires ? '; expires=' + options.expires.toUTCString() : '', // use expires attribute, max-age is not supported by IE
				options.path ? '; path=' + options.path : '',
				options.domain ? '; domain=' + options.domain : '',
				options.secure ? '; secure' : ''
			].join('');
			window.document.cookie = strCookie;
			return strCookie;
		}

		function readCookie(name) {
			var nameEQ = name + '=',
				ca = window.document.cookie.split(';'),
				i,L, c;
			ca = window.document.cookie.split(';');
			for(i=0, L = ca.length;i < L;i++) {
				c = ca[i];
				while (c.charAt(0)==' ') c = c.substring(1,c.length);
				if (c.indexOf(nameEQ) == 0) return c.substring(nameEQ.length,c.length);
			}
			return false;
		}

		function eraseCookie(name) {
			createCookie(name,'',{expires:-1});
		}
		return {
			createCookie: createCookie,
			readCookie  : readCookie,
			eraseCookie : eraseCookie
		}
		
	})();

	//NAMESPACE GENERATOR
	MYAPP.namespace = function (ns_str) {
						var parts = ns_str.split('.'),
							parent = MYAPP,
							L = parts.length,
							i;
						for (i = 0; i < L; i+=1){
							if (typeof parent[parts[i]] === "undefined") {
								parent[parts[i]] = {};
							}
							parent = parent[parts[i]];
						}
						return parent;
					}

	MYAPP.data = {
				setData: setData,
				getData: getData,
				deleteData: deleteData,
				clearData: clearData
			}

})($,MYAPP,window);
