/* 
 *
 * Created by Alexandr Trubnikov
 * alexandr@trubnikov.info
 * 
 */
var Proto = {
    version:'1.00 beta',
    UI:{},
    path:(function () {
		 var js = /proto-ui\.js(\?.*)?$/; 
		return $$('head script[src]').findAll(function(s) { 
			return s.src.match(js);})[0].src.replace(js,"")})(),
    include:function(modName)
    {
        if(typeof Proto[modName] == "undefined" && typeof Proto.UI[modName] == "undefined")
        {
            	document.write('<script type="text/javascript" src="'+
		this.path+'modules/'+modName+'.js"><\/script>');
        }
    },
    modules:[
    'utils',
    'autopassword',
    'InfinityCarousel',
    'cal',
    'Clock',
    'tabs',
    'datetime',
    'spinner',
    'switcher',
    'widget',/**/
    'notify',
    'Menu',
    'Dialog',
    'select2href'
    ],
    load:function()
    {
	this.modules.each(function(m){
		this.include(m);
	}.bind(this));
    }
}


Object.extend(Date.prototype, {
    monthnames: ['January','February','March','April','May','June','July','August','September','October','November','December'],
    daynames: ['Sunday','Monday','Tuesday','Wednesday','Thursday','Friday','Saturday'],
    
    myformat: function(f){
        if (!this.valueOf()) { return '&nbsp;'; }
        var d = this;
        var formats = {
            'yyyy' : d.getFullYear(),
            'mmmm': this.monthnames[d.getMonth()],
            'mmm':  this.monthnames[d.getMonth()].substr(0, 3),
            'mm':   (d.getMonth()+1).toPaddedString(2) ,
            'dddd': this.daynames[d.getDay()],
            'ddd':  this.daynames[d.getDay()].substr(0, 3),
            'dd':   d.getDate().toPaddedString(2),
            'hh':   d.getHours().toPaddedString(2),//h = d.getHours() % 12 ? h : 12,
            'nn':   d.getMinutes().toPaddedString(2),
            'ss':   d.getSeconds(),
            'a/p':  d.getHours() < 12 ? 'a' : 'p'
        };
        return f.gsub(/(yyyy|mmmm|mmm|mm|dddd|ddd|dd|hh|nn|ss|a\/p)/i,
            function(match) { return formats[match[0].toLowerCase()]; });
    }
});





    var parseDateString = function(i)
         {
				var rg = /:|-| |\./;
				var rg2 = /,0(\d)/;
				var str = i.gsub(rg,",").gsub(rg2,",#{1}");
				try { eval('var d = new Date('+str+')'); }
				catch (e){ return (new Date()) }
				d.setMonth(d.getMonth()-1);
				//document.title= i+" :: "+d;
				return(d);
         }
Proto.load();   


Object.extend(window, {
    alert: function(message){
    if(!document.loaded){
    document.observe("dom:loaded", function() {

		(function(){Proto.UI.notify(message,{type:'error'});}).delay(1);

 	
 }); }
 else
 {
 Proto.UI.notify(message,{type:'error'});
 }
    }
  });


 

