
generic = {     
	init: function() { 
		//MK: ie bug? generic.events.target = $$("BODY")[0];  
	 	this.env.debug = this.env.query("debug"); 
	 	if (this.env.debug && this.env.isIE) console.drawWin(); 
	},
	env: { 
		isIE : !!(typeof(ActiveXObject) == 'function'),
		isIE6 : !!(!!(typeof(ActiveXObject) == 'function') && (/MSIE\s6\.0/.test(navigator.appVersion))),
		isFF : Prototype.Browser.Gecko,
		isFF2 : !!(typeof(navigator.product) != 'undefined' && navigator.product == 'Gecko' && !((document.childNodes) && (!navigator.taintEnabled)) && navigator.userAgent.toLowerCase().split(' firefox/')[1].split('.')[0] == '2'),
		isFF3 : !!(typeof(navigator.product) != 'undefined' && navigator.product == 'Gecko' && !((document.childNodes) && (!navigator.taintEnabled)) && navigator.userAgent.toLowerCase().split(' firefox/')[1].split('.')[0] == '3'),
		isMac    : !!(/macppc|macintel/.test(navigator.platform.toLowerCase())),
		isSafari : !!(/Safari/.test(navigator.userAgent)),
		
		domain : window.location.protocol + "//" + window.location.hostname,
		
		query: function(key) {
			if (typeof generic.env.parsedQuery == "undefined") {
				generic.env.parsedQuery = window.location.href.toQueryParams();
			}
			var result = generic.env.parsedQuery[key] || null;
			return result; 
		},
		
		debug: false
		
	}, 
	helpers: { 
		div: new Element("div") //used by Widget class, Prototype way is needed for IE
	},
	events: {
		target: document,
		fire: function(args) {
			console.log("generic.events.fire: "+args.event + " / " + args.msg);  
			if (!args) return;
			var e = args.event; 
			var msg = (typeof args.msg == "undefined") ? null : args.msg; 
			generic.events.target.fire(e, {msg:msg});
		},
		observe: function(evt, func) {
			if (!evt || !func) return; 
			generic.events.target.observe(evt, function(e){   
			     func(e.memo.msg);
			});
		}	
	},
	rbKeys: {
		hash: (typeof jsResourceBundle == "undefined" ? {} : jsResourceBundle),  
		get: function(key) {
		    var val = this.hash[key];
		    val = (typeof val == "undefined") ? "" : val;
		    return val; 
		}
	} 
} 

		  

//utils 
generic.mixin = function(defaultObj, addValuesObj) {
	if (!defaultObj) return {};
	if (!addValuesObj) return defaultObj;
	var newObj = defaultObj;
	for (var prop in addValuesObj) {
		newObj[prop] = addValuesObj[prop];
	} 
	return newObj; 
}

generic.updateProperties = function(obj) {   
	if (!obj) return;
	for (prop in obj) {  
    	   	this[prop] = obj[prop];
    	}  
}

generic.hexToRGB = function(hex) {
	var rgb = [];
	var h = cutHex(hex);
	rgb.push( parseInt( h.substring(0,2),16) );
	rgb.push( parseInt( h.substring(2,4),16) );
	rgb.push( parseInt( h.substring(4,6),16) ); 
	//console.log("hexToRGB: "+hex+" = "+rgb[0]+" "+rgb[1]+" "+rgb[2]);
	return rgb;
	
	function cutHex(h) {return (h.charAt(0)=="#") ? h.substring(1,7):h} 
}
	
	
//debug	
if (typeof console == "undefined") { 
    console = {
	tracen : 0,
	win : {},
 	drawWin: function() {  
		outp = document.createElement("DIV");
		outp.id = "console-window";
		outp.style.cssText = "position:absolute;top:10px;right:10px;width:400px;height:400px;padding:5px;overflow-x:hidden;overflow-y:scroll;background-color:#ffffff;color:#000000;font-size:12px;border:1px solid red;z-index:9999";
		document.body.appendChild(outp);  
		this.win = $(outp.id);
	  },
	  log: function(s) {
	   	this.tracen++;
		s = (typeof(s) == "undefined") ? "undefined" : s.toString().replace(/\</gi, "&lt;").replace(/\>/gi, "&gt;");
		this.win.innerHTML = "<b>" + this.tracen + "</b>. " + s + "<br/>" + this.win.innerHTML;
	   }	
    } 	
       
} 

 
