/* 
 *
 * 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',
    'accordion',
    'book',
    'corner',
    'galery',
    'editor',
    'compacttable',
    'stuck'
    ],
    load:function()
    {
	this.modules.each(function(m){
		this.include(m);
	}.bind(this));
    }
}


Object.extend(Date.prototype, {
    monthnames: ['Январь','Февраль','Март','Апрель','Май','Июнь','Июль','Август','Сентябрь','Октябрь','Ноябрь','Декабрь'],
    daynames: ['Sunday','Monday','Tuesday','Wednesday','Thursday','Friday','Saturday'],
    
    myformat: function(f){
        if (!this.valueOf()) { return ""; }
        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()]; });
    }
});





function nullIfIsNan(v)
{
    if(isNaN(Number(v))){
    return(0);
    }else{return(Number(v))}
}
 var parseDateString= function(i)
         {
				if(!i){return new Date()}
				var rg = /:|-| |\./;
				var rg2 = /,0(\d)/;
				var str = i.gsub(rg,",");
				str=str.gsub(rg2,",#{1}");
				try { 
				    eval("var ar =["+str+"];"); 
				    if(nullIfIsNan(ar[2])>0){ ar[1]=Number(ar[1])-1; }
				   
				    var d = new Date(nullIfIsNan(ar[0]),nullIfIsNan(ar[1]),nullIfIsNan(ar[2]),nullIfIsNan(ar[3]),nullIfIsNan(ar[4]))
				    
				    }
				catch (e){ alert(e) }
				var rg3 = /\:/;
				if(!rg3.test(i) &&!( isNaN(Number(ar[3])) || isNaN(Number(ar[4]))) ){ d.setDate(d.getDate()-1)}
				//document.title= str+" :: "+d;
				return(d);
         }



Proto.load();   

if (!/MSIE (5\.5|6).+Win/.test(navigator.userAgent)) {
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'});
 }
    }
  });

}

 
