var is = new BrowserCheck(); // Browser check

var PYPM_offsx = 0;
var PYPM_offsy = 22;

var PYPM_timerID = 0;
var PYPM_obuttonID = '';
var PYPM_omenuID = '';
var PYPM_biname0 = '';
var PYPM_biname1 = '';

var PYPM_objects = new Array();

function mhHover(obj, cls)
{
	PY_clearTimeout();
	PY_hidePopupMenu(PYPM_obuttonID, PYPM_omenuID);
	
	obj.className = cls;
}

function addItem(text,url)
{
	this.items[this.items.length] = new PY_MenuItem(text, url);
}

function PY_Menu(name, id, x,y,width)
{
	this.name=name;
	this.id=id;
	this.x=x;
	this.y=y;
	this.width=width;
	this.addItem=addItem;
	this.items=new Array();
	PYPM_objects[PYPM_objects.length]=this;
}

function PY_MenuItem(text, url)
{
	this.text=text;
	this.url=url;
}

function PY_drawButtons(bstr, estr, mstr)
{
	var i,o,bn;
	
	for (i=0;i<PYPM_objects.length;i++)
	{
		o = PYPM_objects[i];
		bid = "button_"+o.id;
		document.write(bstr+'<div id="'+bid+'" class="py_mb0" onmouseover="PY_showPopupMenu(this,\''+o.id+'\');" onmouseout="PY_setTimeout(this.id,\''+o.id+'\');">'+o.name+'</div>'+estr+((i==PYPM_objects.length-1) ? '' : mstr));
	}
}

function PY_drawPopups(img_name0, img_name1, img_w, img_h)
{
	var i,k,o,oo,bn;
	PYPM_biname0 = img_name0;
	PYPM_biname1 = img_name1;
	
	for (i=0;i<PYPM_objects.length;i++)
	{
		o = PYPM_objects[i];
		bid = "button_"+o.id;
		document.write('<div id="'+o.id+'" onmouseover="PY_clearTimeout();" onmouseout="PY_setTimeout(\''+bid+'\',\''+o.id+'\');" style="position:fixed;position:absolute;cursor:hand;z-index:10; width:'+o.width+';visibility:hidden;">');
		document.write('<table border="0" width="'+o.width+'" cellspacing="0" cellpadding="0" class="py_menu_panel"><tr><td>');
		document.write('<table border="0" width="100%" cellspacing="1" cellpadding="0">');
		for (k=0;k<o.items.length;k++)
		{
			oo = o.items[k];
			document.write('<tr><td width="100%" class="py_menu_item0" '+((is.ie && !is.opera) ? 'onmouseenter' : 'onmouseover')+'="PY_hover(this, \'1\');" '+((is.ie && !is.opera) ? 'onmouseleave' : 'onmouseout')+'="PY_hover(this, \'0\');" onclick="location.href=\''+oo.url+'\';"><img id="bullet" border="0" src="'+img_name0+'" width="'+img_w+'" height="'+img_h+'">'+oo.text+'</td></tr>');
		}
		document.write('</table></td></tr></table></div>');
	}
}

function PY_showPopupMenu(button_obj, menu_id)
{
	PY_clearTimeout();
	//alert(button_obj.id+" "+menu_id+" "+PYPM_omenuID+" "+PYPM_timerID);
	if (PYPM_omenuID!='' && PYPM_omenuID!=menu_id) PY_hidePopupMenu(PYPM_obuttonID, PYPM_omenuID);
	PYPM_obuttonID = button_obj.id;
	PYPM_omenuID = menu_id;
	
	button_obj.className = 'py_mb1';
	
	var menu_obj = document.getElementById(menu_id);
	if (is.ie5p && !is.opera)
	{
		menu_obj.style.filter="progid:DXImageTransform.Microsoft.Fade(duration=0.4)";
		menu_obj.filters[0].Apply();	
	}
	
	//alert(button_obj.offsetParent.offsetTop);
	var tobj = button_obj;
	var ox = PYPM_offsx + tobj.offsetLeft;
	var oy = PYPM_offsy + tobj.offsetTop;
	while (tobj.offsetParent) {ox+=tobj.offsetParent.offsetLeft; oy+=tobj.offsetParent.offsetTop; tobj = tobj.offsetParent;}
	//alert(ox+" "+oy);
	menu_obj.style.top = oy+'px';
	menu_obj.style.left = ox+'px';
	//alert(menu_obj.style.left+" "+menu_obj.style.top);
	menu_obj.style.position = "absolute";
	menu_obj.style.visibility="visible";
	
	if (is.ie5p && !is.opera) menu_obj.filters[0].Play();
}

function PY_hidePopupMenu(button_id, menu_id)
{
	if (button_id!="" && menu_id!="")
	{
		//alert(button_id+" "+menu_id+":hide");
		var button_obj = document.getElementById(button_id);
		var menu_obj = document.getElementById(menu_id);

		button_obj.className = 'py_mb0';
		menu_obj.style.visibility="hidden";
	
		if (menu_id==PYPM_omenuID)
		{
			PYPM_obuttonID='';
			PYPM_omenuID='';
		}
	}
}

function PY_setTimeout(button_id, menu_id)
{
	PYPM_timerID=setTimeout("PY_hidePopupMenu(\""+ button_id +"\", \"" +menu_id +"\")", 300);
}

function PY_clearTimeout()
{
	if (PYPM_timerID!=0) clearTimeout(PYPM_timerID);
	PYPM_timerID = 0;
}


function PY_hover(obj, cls)
{
	if (cls!="0" && is.ie5p && !is.opera)
	{
		obj.style.filter="progid:DXImageTransform.Microsoft.Fade(duration=0.4)";
		obj.filters[0].Apply();	
	}
	
	obj.className = 'py_menu_item'+cls;
	//alert(obj.getElementsByTagName("IMG"));
	var iobj = obj.getElementsByTagName("IMG");
	iobj[0].src = (cls=="0") ? PYPM_biname0 : PYPM_biname1;

	if (cls!="0" && is.ie5p && !is.opera) obj.filters[0].Play();
}

function PY_preloadImages() 
{
	var d=document;
	if(d.images)
	{
		if(!d.imgs) d.imgs=new Array();
    	var i = 0;
    	var j = d.imgs.length;
    	a = PY_preloadImages.arguments;
    	for(i=0; i<a.length; i++)
    		if (a[i].indexOf("#")!=0)
    		{ 
    			d.imgs[j]=new Image;
    			d.imgs[j].src=a[i];
    			j++;
    		}
	}
}

// BrowserCheck Object
function BrowserCheck()
{
	var b = navigator.appName
	if (b=="Netscape") this.b = "ns"
	else if (b=="Microsoft Internet Explorer") this.b = "ie"
	else this.b = b
	this.version = navigator.appVersion
	this.v = parseInt(this.version)
	this.ns = (this.b=="ns" && this.v>=4)
	this.ns4 = (this.b=="ns" && this.v==4)
	this.ns5 = (this.b=="ns" && this.v==5)
	this.ie = (this.b=="ie" && this.v>=4)
	this.ie4 = (this.version.indexOf('MSIE 4')>0)
	this.ie5 = (this.version.indexOf('MSIE 5')>0)
	this.ie5p = (this.ie && !this.ie4 && !this.ie5)
	this.min = (this.ns||this.ie)
	var re = /Opera\s*\d+\.\d+/i;
        this.opera = re.test(navigator.userAgent);
}