window.addEventListener("load",function(){

window.yassev = {

m_enable: true,

m_colors: {  // normal state        // delta to active state
	red:	[[0.45, 0.0, 0.0],		[0.55, 0.3, 0.2]], 
	green:	[[0.0, 0.6, 0.0],		[0.0, 0.3, 0.0]], 
	blue:	[[0.0, 0.3, 1.0],		[0.3, 0.5, 0.0]] 
},


update_indicator: function(presetid)
{
	var ind = document.getElementById("yass_status_color_indicator");
	if(ind)
	{
		var col = this.m_colors[presetid];
		var s = 
		ind.selectedpreset = presetid;
		if(!yass.m_pref.enabled) ind.style.backgroundColor = "#bbbbbb";
		else this.glow_indicator(0);
	}

	var icon = document.getElementById("yass_status_image"); 
	if(icon) icon.setAttribute("style","opacity:"+((yass.m_pref.enabled)?"1.0":"0.5")+";");
},

two_octals: function(f) // f must be in range of 0 to 1
{
	f *= 255.0;
	return ("0" + (f.toFixed() - 0).toString(16)).slice(-2);
},

glow_indicator: function(f)
{
	var c = document.getElementById("yass_status_color_indicator");
	var rgb = this.m_colors[c.selectedpreset];
	var a = [rgb[0][0]+rgb[1][0]*f,rgb[0][1]+rgb[1][1]*f,rgb[0][2]+rgb[1][2]*f];
	var oct = this.two_octals;
	c.style.backgroundColor = "#"+ oct(a[0]) + oct(a[1]) + oct(a[2]);
},

popup: function(thi,ev)
{
	if(ev.button != 0) return;
	var menu = document.getElementById("yass_status_popup");
	menu.showPopup(thi,-1,-1,'popup','topleft','bottomleft');
},

popup_showing: function(thi)
{
	var menu = document.getElementById("yass_status_popup");
	var presetid = yass.m_prefservice.getCharPref("extensions.yass.selectedpreset");
	var list = ["red","green","blue"];
	for(var i in list) 
		document.getElementById("yass-statusbarmenu-"+list[i]).hidden = (list[i].indexOf(presetid)>=0);


	document.getElementById("yass-statusbarmenu-enable").setAttribute(
		"checked",
		yass.m_prefservice.getCharPref("extensions.yass.enabled"));
},

toggle_enable: function(sw)
{
	yass.toggle_enable(sw);
},

show_preferences: function()
{
	// show preferences dialog
	window.openDialog("chrome://yass/content/options.xul","yass options","chrome,dialog,toolbar");
},

end:0
};

},false);
