function PCSMenuGroup(){
	this.Items = new Array();
	this.Index=null;
	this.Menu=null;
	this.GroupId=null;
	this.MenuDiv=null;
	this.Loader=null;
	this.Active=false;
	this.HideTimerID=null;
	this.MinWidth=150;
	this.MaxHeight='';
	this.RightAlign=false;
	this.XOffset=0;
	this.YOffset=0;
	this.OriginalMinWidth=150;
	this.OriginalMaxHeight='';
	this.OriginalRightAlign=false;
	this.OriginalMatchSrcElementWidth=false;
	this.srcElement=null;
	this.Visible=false;
	this.SubGroup=null;
	this.ParentGroup=null;
	this.LoadByCallback=false;
	this.LoadByCallbackTarget='';
	this.LoadByCallbackArguments=null;
	this.MatchSrcElementWidth=false;
	this.InnerHTML='';
	this.ExternalURL='';
	this.Height='';
	this.LeaveOpen=false;
	this.Opening=false;
	this.ExpandDirection='ExpandLeft';
	this.LoadByCallbackAssembly='';
	this.LoadByCallbackNamespace='';
	this.LoadByCallbackMethod='';
	this.ShowDropShadow=true;
	this.Props=new Array();
	this.Props = ['GroupId','MatchSrcElementWidth','RightAlign','LeaveOpen','ShowDropShadow','Height','MinWidth','MaxHeight','XOffset','YOffset',
		'InnerHTML','ExternalURL','ExpandDirection','LoadByCallback','LoadByCallbackTarget','LoadByCallbackAssembly','LoadByCallbackNamespace',
		'LoadByCallbackMethod','LoadByCallbackArguments']
}
PCSMenuGroup.prototype.Init=function (props){
    for(var i=0;i<props.length;i++){
		if(props[i]) this[this.Props[i]] = props[i];
	}
    this.OriginalMinWidth = this.MinWidth;
    this.OriginalMaxHeight = this.MaxHeight;
    this.OriginalRightAlign = this.RightAlign;
    this.OriginalMatchSrcElementWidth = this.MatchSrcElementWidth;
    this.LoadByCallbackArguments=eval(this.LoadByCallbackArguments);
}
PCSMenuGroup.prototype.Hide=function(){
	if(this.Active || this.SubGroup) return;
	var Group = this;
	this.MenuDiv.style.visibility='hidden';
	this.Menu.removeEvent(this.MenuDiv,'mouseleave', function(){Group.BeginHide()});
	this.Menu.removeEvent(this.MenuDiv,'mouseenter', function(){Group.StopHide()});
	this.Menu.removeEvent(this.srcElement,'mouseleave', function(){Group.BeginHide()});
	this.Menu.removeEvent(this.srcElement,'mouseenter', function(){Group.StopHide()});
	this.Visible=false;
	if(this.Menu.onCollapse != null && typeof(this.Menu.onCollapse == 'function')){
		this.Menu.onCollapse(this);
	}
	if(this.ParentGroup!=null){
		this.ParentGroup.SubGroup=null;
		if(!this.ParentGroup.Active) Group.ParentGroup.BeginHide();
	}else{
		//this.Menu.CallbackArguments='';
	}
	if(!this.ParentGroup && this.srcElement.id){
		if(typeof(PCSHoverlinkMouseOut) != 'undefined') PCSHoverlinkMouseOut(this.srcElement.id);
		if(this.srcElement.prevClassName){
			this.srcElement.className = this.srcElement.prevClassName;
			this.srcElement.clicked=false;
		}
	}
	this.ParentGroup=null;
}
PCSMenuGroup.prototype.ForceHide=function(){
	var Group = this;
	this.MenuDiv.style.visibility='hidden';
	this.Menu.removeEvent(this.MenuDiv,'mouseleave', function(){Group.BeginHide()});
	this.Menu.removeEvent(this.MenuDiv,'mouseenter', function(){Group.StopHide()});
	this.Menu.removeEvent(this.srcElement,'mouseleave', function(){Group.BeginHide()});
	this.Menu.removeEvent(this.srcElement,'mouseenter', function(){Group.StopHide()});
	this.Visible=false;
	this.Opening=false;
	this.ParentGroup=null;
	this.SubGroup=null;
	//this.Menu.CallbackArguments='';
	if(typeof(PCSHoverlinkMouseOut) != 'undefined' && this.srcElement.id) PCSHoverlinkMouseOut(this.srcElement.id);
	if(this.srcElement.prevClassName){
		this.srcElement.className = this.srcElement.prevClassName;
		this.srcElement.clicked=false;
	}
}
PCSMenuGroup.prototype.Reposition=function(){

	if(this.MatchSrcElementWidth && ((this.MinWidth==0 || this.MinWidth==null || this.MinWidth=='null') || (this.MinWidth > 0 && this.srcElement.offsetWidth >= this.MinWidth))){
		this.MinWidth=this.srcElement.offsetWidth;
	}
	/*
	if(this.MatchSrcElementWidth){
		if(this.MinWidth==0 || this.MinWidth==null || this.MinWidth=='null'){
			this.MinWidth=this.srcElement.offsetWidth;
		}else if(this.MinWidth > 0 && this.srcElement.offsetWidth >= this.MinWidth){
			this.MinWidth=this.srcElement.offsetWidth;
		}
	}
	*/

	if(this.MinWidth > 0) this.MenuDiv.style.width=this.MinWidth+'px';

	if(!this.Height){
		if (this.MenuDiv.offsetHeight > this.MaxHeight && this.MaxHeight > 0){
			this.MenuDiv.style.overflowY='auto';
			this.MenuDiv.style.height=this.MaxHeight+'px';
		}
	}else{
		this.MenuDiv.style.height=this.Height+'px';
	}
	
	var xy=this.GetCoordinates(this.srcElement);
	var x = xy[0];
	var y = xy[1];
	
	var ch=document.body.clientHeight;
	var cw=document.body.clientWidth;

	var st=document.body.scrollTop;
	var sl=document.body.scrollLeft;
	
	if(this.ParentGroup){
		this.MenuDiv.style.zIndex=(this.ParentGroup.MenuDiv.style.zIndex*1) + 2;
		if(this.ExpandDirection=='ExpandRight'){
			x+=this.ParentGroup.MenuDiv.offsetWidth-4;
		}else{
			x-=this.ParentGroup.MenuDiv.offsetWidth + (this.MenuDiv.offsetWidth - this.ParentGroup.MenuDiv.offsetWidth);
			x+=2;
		}
	}else{
		y+=this.srcElement.offsetHeight;
	}
	
	if(this.RightAlign && !this.ParentGroup) x = (x-this.MenuDiv.offsetWidth) + this.srcElement.offsetWidth + this.Menu.DropShadowOffset;
	var xoff = x + this.XOffset;
	var yoff = 0;
	if(this.ParentGroup){
		yoff = (y+this.MenuDiv.offsetHeight-st>=ch) ? -((y+this.MenuDiv.offsetHeight-st)-ch): 0;
	}else{
		yoff = (y+this.MenuDiv.offsetHeight-st>=ch) ? -(this.srcElement.offsetHeight+this.MenuDiv.offsetHeight)+2: 0;
	}
	var itop = y + yoff + this.YOffset;
	if(itop<0) itop=0;
	
	this.MenuDiv.style.left=Math.min(cw-this.MenuDiv.offsetWidth,Math.max(2,xoff))+sl;
	this.MenuDiv.style.top=itop;
}

PCSMenuGroup.prototype.SetText=function(val){
	this.MenuDiv.innerHTML = this.Menu.Decode(val);
}
PCSMenuGroup.prototype.DisplayCallbackLoadingMessage=function(message){
	var loadingmessage;
	if(!message) message = 'Loading...';
	loadingmessage = '<TABLE id="' + this.GroupId + '_loader" cellpadding=0 cellspacing=0 border=0 ';
	loadingmessage += 'style="width: 100%; height: 100%;"';
	loadingmessage += '><TR><TD valign="center" align="center" style="padding: 5px">' + message + '&nbsp;<IMG align="absmiddle" src="' + this.Menu.BaseImagePath + 'loading.gif"></TD></TR></TABLE>';
	this.SetText(loadingmessage);
}
PCSMenuGroup.prototype.ToggleLoading=function(blnOn,message){
	if(!document.getElementById(this.Loader.id)) return;
	if(message) document.getElementById(this.Loader.id + 'label').innerText = message;
	document.getElementById(this.Loader.id).style.display=(blnOn ? 'inline' : 'none');
	if(document.getElementById(this.GroupId + '_iframe')){
		document.getElementById(this.GroupId + '_iframe').style.display=(blnOn ? 'none' : 'inline');
	}
}
PCSMenuGroup.prototype.BuildMenu=function(){

	this.MenuDiv=document.createElement("DIV");
	this.MenuDiv.style.position='absolute';
	this.MenuDiv.style.visibility='hidden';
	this.MenuDiv.style.zIndex=9000;
	this.MenuDiv.className = this.Menu.GroupCssClass;
	if(this.ShowDropShadow){
		this.MenuDiv.style.filter = "progid:DXImageTransform.Microsoft.dropshadow(OffX='" + this.Menu.DropShadowOffset + 
			"', OffY='" + this.Menu.DropShadowOffset +"', Color='silver', Positive='true')"
	}
	var menu = this.Menu;
	
	var row=null;
	var cell=null;
	var leftimg=null;
	var rightimg=null;
	var hasLeftImage=false;
	var hasRightImage=false;
	var maxLeftImageWidth=0;
	var maxRightImageWidth=0;
	
	for(var mi in this.Items){
		if((this.Items[mi].LeftImageUrl!='' || this.Items[mi].ShowLeftArrow) && this.Items[mi].Visible){
			hasLeftImage=true;
			break;
		}
	}
	
	for(var mi in this.Items){
		if((this.Items[mi].RightImageUrl!='' || this.Items[mi].ShowRightArrow) && this.Items[mi].Visible){
			hasRightImage=true;
			break;
		}
	}
	
	var table = document.createElement("TABLE");
	table.id = this.GroupId;
	table.cellpadding=0;
	table.cellspacing=menu.GroupCellSpacing;
	table.border=0;
	table.style.width="100%";
	for(var i=0; i<this.Items.length;i++){
		
		var item = this.Items[i];
		
		if(item.Visible){
		
			row = document.createElement("TR");
			row.id='Group'+this.Index+'_Item'+item.Index;
			if(item.Seperator && item.Text == ''){
				row.sep='1';
				cell = document.createElement("TD");
				cell.className = menu.SeperatorCssClass;
			}else{
				
				cell = document.createElement("TD");
				
				if(item.Seperator){
					row.sep='1';
					cell.className = menu.SeperatorCssClass;
				}else{
					cell.className = menu.ItemCssClass;
				}
				
				leftimg=null;
				rightimg=null;
				
				if(hasLeftImage && (item.ShowLeftArrow || item.LeftImageUrl != '')){
					leftimg = document.createElement("IMG")
					leftimg.border=0;
					leftimg.align='absmiddle';
					if(item.ShowLeftArrow){
						leftimg.width='15px';
						leftimg.height='10px';
						leftimg.src=menu.LeftArrowImageURL;
					}else{
						leftimg.width=item.LeftImageWidth;
						leftimg.height=item.LeftImageHeight;
						leftimg.src=item.LeftImageUrl;
					}
					if(maxLeftImageWidth<leftimg.width)maxLeftImageWidth=leftimg.width;
				}
				
				if(hasRightImage && (item.ShowRightArrow || item.RightImageUrl != '')){
					rightimg = document.createElement("IMG")
					rightimg.border=0;
					rightimg.align='absmiddle';
					if(item.ShowRightArrow){
						rightimg.width='15px';
						rightimg.height='10px';
						rightimg.src=menu.RightArrowImageURL;
					}else{
						rightimg.width=item.RightImageWidth;
						rightimg.height=item.RightImageHeight;
						rightimg.src=item.RightImageUrl;
					}
					if(maxRightImageWidth<rightimg.width)maxRightImageWidth=rightimg.width;
				}
				
				cell.innerHTML = (hasLeftImage ? '<DIV style="float: left; text-align:left;" class="' + this.Menu.LeftImageCssClass + '">' + (leftimg ? leftimg.outerHTML : '') + "</DIV>" : '') + 
					'<DIV style="float: left; text-align:left;" class="' + this.Menu.ItemLabelCssClass + '">' + item.Text + '</DIV>' +
					(hasRightImage ? '<DIV style="float: right; text-align:right;" class="' + this.Menu.RightImageCssClass + '">' + (rightimg ? rightimg.outerHTML : '') + "</DIV>" : '');
				
				if(!row.sep==1){
					cell.onmouseenter=menu.MenuId+".HandleEvent('mouseover')";
					cell.onmouseleave=menu.MenuId+".HandleEvent('mouseout')";
					row.onclick=menu.MenuId+".HandleEvent('click',this.id)";
				}
			}
			row.appendChild(cell);
			table.appendChild(row);
		}		
	}
		
	if(this.InnerHTML != '' && this.Items.length == 0){
		setHTML(this.Menu.Decode(this.InnerHTML), this.MenuDiv);
		//this.MenuDiv.innerHTML=this.InnerHTML;
	}else{
		
		this.Loader = document.createElement('table');
		var row = document.createElement('tr');
		var col = document.createElement('td');
		this.Loader.style.display='none';
		this.Loader.id=this.GroupId+'_loader';
		this.Loader.style.width='100%';
		this.Loader.style.height='100%';
		col.valign='middle';
		col.align='center';
		col.innerHTML = '<SPAN id="' + this.Loader.id + 'label">Loading...</SPAN>&nbsp;<IMG height="16" src="../images/loading.gif" width="16" align="absMiddle" border="0">'
		row.appendChild(col);
		this.Loader.appendChild(row);
		this.MenuDiv.innerHTML=table.outerHTML;
		this.MenuDiv.appendChild(this.Loader);
	}
	
	document.body.insertBefore(this.MenuDiv, document.body.firstChild);
	
	if(hasLeftImage && maxLeftImageWidth>0){
		table = document.getElementById(this.GroupId);
		for(var i=0;i<table.rows.length;i++){
			row = table.rows[i];
			if(!row.sep){
				for(var ii=0; ii<row.cells.length;ii++){
					cell = row.cells[ii];	
					cell.firstChild.style.width=maxLeftImageWidth;
				}
			}
		}
	}
	
	if(hasRightImage && maxRightImageWidth>0){
		table = document.getElementById(this.GroupId);
		for(var i=0;i<table.rows.length;i++){
			row = table.rows[i];
			if(!row.sep){
				for(var ii=0; ii<row.cells.length;ii++){
					cell = row.cells[ii];
					cell.style.height='100%';
					cell.valign='middle';
					cell.children(cell.children.length-1).style.width=maxRightImageWidth;
				}
			}
		}
	}
	
	return this.MenuDiv;
	
}

PCSMenuGroup.prototype.StopHide=function(){
	this.Active=true;
	clearTimeout(this.HideTimerID);
	this.HideTimerID=null;
}
PCSMenuGroup.prototype.BeginHide=function(){
	var Group = this;
	this.HideTimerID=window.setTimeout(function (){Group.Hide();},this.Menu.CollapseDelay);
	this.Active=false;
}
PCSMenuGroup.prototype.GetCoordinates= function (el){
    var parent=null;
    var coords=[];
    var box;
    if (el.getBoundingClientRect){
        box=el.getBoundingClientRect();
        var scrollTop=document.documentElement.scrollTop || document.body.scrollTop;
        var scrollLeft=document.documentElement.scrollLeft || document.body.scrollLeft;
        var x=box.left+scrollLeft;
        var y=box.top+scrollTop-1;
        return [x,y];
    } else if (document.getBoxObjectFor){
        box=document.getBoxObjectFor(el); 
        coords=[box.x-2,box.y-2];
    } else {
        coords=[el.offsetLeft,el.offsetTop];
        parent=el.offsetParent;
        if (parent!=el){
            while (parent){
                coords[0]+=parent.offsetLeft;
                coords[1]+=parent.offsetTop;
                parent=parent.offsetParent;
            }
        }
    }
    if (window.opera){
        parent=el.offsetParent;
        while (parent && parent.tagName!="BODY" && parent.tagName!="HTML"){
            coords[0]-=parent.scrollLeft;
            coords[1]-=parent.scrollTop;
            parent=parent.offsetParent;
        }
    }else {
        parent=el.parentNode;
        while (parent && parent.tagName!="BODY" && parent.tagName!="HTML"){
            coords[0]-=parent.scrollLeft;
            coords[1]-=parent.scrollTop;
            parent=parent.parentNode;
        }   
    }
    return coords;
}