var ragenate = function() {}


var showmegamenu = false;
var currentmegamenu = 0;
var hidemegamenuTimerid = 0;

function clearmegamenu() {
        showmegamenu = false;
        if (document.getElementById('mega_menu_'+currentmegamenu)) {
             document.getElementById('mega_menu_'+currentmegamenu).style.display='none';
        }
        if (document.getElementById('mega_menu_trigger_'+currentmegamenu)) {
             document.getElementById('mega_menu_trigger_'+currentmegamenu).className=document.getElementById('mega_menu_trigger_'+currentmegamenu).className.replace(' menu_selected_hover','');
        }
        currentmegamenu = 0;
        var objMegaMenuBG =  document.getElementById('mega_menu_bg_overlay');
            objMegaMenuBG.style.display = 'none';
        onmegamenuitem();
}
function onmegamenuitem() {
       if (hidemegamenuTimerid!=0) {clearTimeout(hidemegamenuTimerid);}hidemegamenuTimerid = 0;
}
function offmegamenuitem() {
      
        if (hidemegamenuTimerid!=0) {clearTimeout(hidemegamenuTimerid);}hidemegamenuTimerid = setTimeout ( "clearmegamenu()", 1000 );
}

function showMegaMenu(id,objTrigger) {

        showmegamenu = true;
        newmenu = id;
        
        if (currentmegamenu != id) {
            clearmegamenu();
        }

        if (document.getElementById('mega_menu_'+currentmegamenu) && currentmegamenu != id) {
               document.getElementById('mega_menu_'+currentmegamenu).display='none';
               document.getElementById('mega_menu_'+id).display='block';
        } else {
            if (currentmegamenu != id) {
                if (document.getElementById('mega_menu_'+id)) {
                    document.getElementById('mega_menu_'+id).display='block';
                    currentmegamenu = id;
                }
            }
        }

		if (document.getElementById('mega_menu_'+id)) {


                        var objMegaMenuBG =  document.getElementById('mega_menu_bg_overlay');
                            objMegaMenuBG.style.display = 'block';
                            objMegaMenuBG.style.position = 'absolute';

			var objMegaMenu =  document.getElementById('mega_menu_'+id);
                            objMegaMenu.style.display='block';
                            objMegaMenu.style.left = -9999+'px';

			var objWidth = objMegaMenu.offsetWidth;
			var objHeight = objMegaMenu.offsetHeight;

                       objTrigger.className=objTrigger.className.replace(' menu_selected_hover','');

			objTrigger.className+=' menu_selected_hover';

			var objContentHeader = document.getElementById('menu_container');
                            
			var posX = ragenate.getPosX(objTrigger);

			var posXEnd = posX+objWidth;
                                objMegaMenuBG.style.left = (posX-90)+'px';
                                objMegaMenuBG.style.top  = (ragenate.getPosY(objContentHeader)+28)+'px';
                                objMegaMenuBG.style.zIndex = 1;
                                objMegaMenuBG.style.width = ragenate.wdpad(objMegaMenu)+'px';
                                objMegaMenuBG.style.height = ragenate.htpad(objMegaMenu)+'px';
                                objMegaMenu.style.zIndex=10000;
				objMegaMenu.style.left = (posX-90)+'px';
				objMegaMenu.style.top  = (ragenate.getPosY(objContentHeader)+28)+'px';

		}
}

ragenate = { 
	
	m_site_url : '',
	m_cms_url : '',
		
	/* Ragenate Variables */ 	
		
	m_refreshed : true,
	m_frameset_id : "ragenate_content_frameset",
	m_left_frame_id : "ragenate_left_frame",
	m_size : "210",
	m_no_frames : false,
	
	/* Redirect Functions */
	
	set_site_url : function(href) {this.m_site_url = href;},	
	set_cms_url : function(href) {this.m_cms_url = href;},
	
	get_contentframe : function() {
		var cFrame = this.get_frame('ragenate_content_frame');
		 try {
		  if (cFrame.visibilityContent && !cFrame.removeMe) {
		    return cFrame.visibilityContent;
		  }
		 } catch (e) {}
		 if (cFrame) {return cFrame;} else {return this;}
	},
 
	refresh_leftframe : function() {this._refresh(this.get_frame('ragenate_left_frame'));}, 
	
	refresh_topframe : function() {this._refresh(this.get_frame('ragenate_top_frame'));},	
	
	$t : function(id) {return(top.frames[id] || window.frames[id]);},		
	
	go_to_cl : function(id,lhref,chref) { 
		if (id!='') {			
			var rHITEMS = this.get_frame('ragenate_top_frame').ragenate.$_('ragenate_header_menu_items');
			if (rHITEMS) {
				var liITEMS = rHITEMS.getElementsByTagName('li');
				for (var i=0;i<liITEMS.length;i++) {
					var liITEM = liITEMS[i];
					if (liITEM) {						
						if (liITEM.id=='mnu_'+id) {	
							liITEM.className = liITEM.className.replace('normal','selected');	
						} else {
							liITEM.className = liITEM.className.replace('selected','normal');
						}
					}
				}
			}			
		}
		if (lhref!='') {this.go_to_leftframe(lhref);}
		if (chref!='') {this.go_to_contentframe(chref);}		
	},
		
	go_to_contentframe : function (href) {this._go_to(this.is_framed() ? this.get_contentframe() : this, href);},
	
	go_to_leftframe : function (href) {this._go_to(this.get_frame('ragenate_left_frame'), href);},
	
	go_to_topframe : function(href) {this._go_to(this.get_frame('ragenate_top_frame'), href);},
	
	go_to : function(href) {return this.go_to_contentframe(href);},
	
	go_to_top : function(href) {this._go_to(top, href);},
	
	_refresh : function (target) {
		if (typeof target == 'string') {target = this.$_(target);} 	
		try {target.location.reload();} catch (e) { }
	},

	_go_to : function (target, href) {
		if (typeof target == 'string') {target = this.$_(target);}		
		try {target.location = href;} catch (e) {alert(e.message);}
	},
	
	/* Input Functions */
	
	turn_autocomplete_off : function() {
		try {
			var inputs = document.getElementsByTagName('INPUT');
			for (var i = 0; i < inputs.length; i++) {
				inputs[i].setAttribute('autocomplete', 'off');
			}
		} catch (e) {}
	},	
	
	get_frame_x : function() {
		var frmset = this.$_(this.m_frameset_id, top.document);
		return parseInt(frmset.cols);
		var frm = this.get_frame_element(this.m_left_frame_id);
		var x = 0;
		if (frm) {
			x = frm.clientWidth;
			if (x == 0)	x = parseInt(this.m_size);
		}
		return x;
	},
	 
	$ff : function(id,f) {
		
			var i = 0;
			for (i = 0;i < f.frames.length;i++) {
			
				if (f.frames[i].frameElement &&
					f.frames[i].frameElement.id == id)
				{
					return f.frames[i];
				}				
				var ff = this.$ff(id, f.frames[i]);	
				if (ff) {return ff;}
				 
			}
		
		return false;
	},
	
	get_frame : function(id) {return(this.$ff(id,top));},
	
	get_frame_element : function(id) {
		var f = this.$ff(id, top);
		if (f && f.frameElement) {return f.frameElement;}
		return false;
	},	
	
	is_framed : function() {
		var cFrame = this.get_frame('ragenate_content_frame');
		var lFrame = this.get_frame('ragenate_left_frame');
		var tFrame = this.get_frame('ragenate_top_frame');
		return !this.m_no_frames && cFrame && lFrame && tFrame;
	},		
	
	has_class : function(elem,classname) {
		if (typeof elem == 'string') {elem = this.$_(elem);}	
		var classes = elem.className.split(" ");
	    var len = classes.length;
		for (var i=0; i<len; i++) {
			if (classes[i] == classname) {return true;}
		}
		return false;
	},		
		
	get_parent_class : function(elem,classname) {
		if (typeof elem == 'string') {elem = this.$_(elem);}
		while (elem) {
			if (this.has_class(elem, classname)) {
				return elem;
			}
			elem = elem.parentNode;
		}
		return(NULL);
	},	
		
	get_parent_id : function(elem,id) {
		if (typeof elem == 'string') {elem = this.$_(elem);}	
		while (elem) {
			if (elem.id == id) {return elem;}
			elem = elem.parentNode;
		}
	},
		
	get_parent_tag_by_name : function(elem,tag) {
		if (typeof elem == 'string') {elem = this.$_(elem);}	
		while (elem) {
			if (elem.tagName == tag) {return elem;}
			elem = elem.parentNode;
		}
		return(NULL);
	},
		
	get_form : function(elem) {
		if (typeof elem == 'string') {elem = this.$_(elem);}	
		return(this.get_parent_tag_by_name(elem,'FORM'));
	},
		
	/* Browser Functions */
		
	is_ie6: function() {return(/msie|MSIE 6/.test(navigator.userAgent));},
	is_ie: function() {return(navigator.appName.indexOf("Microsoft")!=-1?1:0);},
	is_chrome: function() {return(navigator.userAgent.toLowerCase().indexOf('chrome') > -1);},
			
	/* Event Handling */
		
	attachEvt : function(target,eventname,handler) {		
	 	if (typeof target == 'string') {target = this.$_(target);}
	
	 	if ( target.addEventListener ) {
    		target.addEventListener(eventname, handler, false);
    	} else if ( target.attachEvent ) { 
         target.attachEvent("on" + eventname, handler);
    	} else { 
   	 		target["on" + eventname] = handler;
    	} 
	},
	
	/* Page Loading */ 
	
	load : function(url) {this.go_to_contentframe(url);},
	
	/* Window Functions */
	
	sizeWin : function() {
		var w = h = 0;
		if(!window.innerWidth) {
			if(!(document.documentElement.clientWidth == 0)) {
				w = document.documentElement.clientWidth;
				h = document.documentElement.clientHeight;
			} else {
				w = document.body.clientWidth;
				h = document.body.clientHeight;
			}
		} else {
			w = window.innerWidth;
			h = window.innerHeight;
		}
		return {width:w,height:h};
	},
	centerWin : function() {
		var hWnd = (arguments[0] != null) ? arguments[0] : {width:0,height:0};
		var _x = _y = offsetX = offsetY = 0;
		
		if(!window.pageYOffset) {
			if(!(document.documentElement.scrollTop == 0)) {
				offsetY = document.documentElement.scrollTop;
				offsetX = document.documentElement.scrollLeft;
			} else {
				offsetY = document.body.scrollTop;
				offsetX = document.body.scrollLeft;
			}
		} else {
			offsetX = window.pageXOffset;
			offsetY = window.pageYOffset;
		}
		_x = ((this.sizeWin().width-hWnd.width)/2)+offsetX;
		_y = ((this.sizeWin().height-hWnd.height)/2)+offsetY;
		return{x:_x,y:_y};
	},		
	
	/* COMMON FUNCTIONS */
	
	$_  : function(id,d) {			
		var obj = null;	
		if (!d) {d = document;}
		if( d.layers ) {obj = d.layers[id];} 
		else if( d.all ) {obj = d.all[id];} 
		else if( d.getElementById ) {obj = d.getElementById(id);}
		return(obj);
	},
	$c_ : function(elem) {return(document.createElement(elem));},
	
	getPosY : function(obj) {
		if (typeof obj == 'string') {obj = this.$_(obj);}
		var curtop = 0;
	    if(obj.offsetParent)
	        while(1) { 
	          curtop += obj.offsetTop;
	          if(!obj.offsetParent) break;
	          obj = obj.offsetParent;
	        }
	    else if(obj.y)  curtop += obj.y;
	    return curtop;
	},
	
	getPosX : function(obj) {
            var curleft = curtop = 0;
            if (typeof obj == 'string') {obj = this.$_(obj);}
            
	    if(obj.offsetParent) {
                do {
                    curleft += obj.offsetLeft;
                    curtop += obj.offsetTop;
		} while (obj = obj.offsetParent);             
	    }
	    else if(obj.x) {curleft += obj.x;}
	    return(curleft);
	},
	
	center: function(obj) { 
		if (typeof obj == 'string') {obj = this.$_(obj);}
		var objWidth = obj.offsetWidth;
		var objHeight = obj.offsetHeight;
		var objPoint = this.centerWin({width:objWidth,height:objHeight});		
		obj.style.position = 'absolute';
		var newX = -(objWidth/2);
		var newY = -(objHeight/2);
		if (objPoint.x>=0 ) {obj.style.left = '50%';obj.style.marginLeft = newX+'px';}
		if (objPoint.y>=0 ) {obj.style.top = '50%';obj.style.marginTop = newY+'px';}
		//alert(newY);
	},
	getPos : function(obj) {return([this.getPosX(obj),this.getPosY(obj)]);},
	$o_ : function(obj,level) { 
		if (typeof obj == 'string') {obj = this.$_(obj);} 
		obj.style.opacity = level/100;
		obj.style.filter = 'alpha(opacity='+level+')';
	},
	show: function(obj) {
		if (typeof obj == 'string') {obj = this.$_(obj);}
		obj.style.display='block';
	}, 
	hide: function(obj) {
		if (typeof obj == 'string') {obj = this.$_(obj);}
		obj.style.display='none';
	},
	
	/* Style Functions */
	wdpad : function(obj) {
		if (typeof obj == 'string') {obj = this.$_(obj);}
                if (obj) {

			var padWidth = parseInt(this.css(obj,'paddingLeft','padding-left'),10);
                            padWidth+= parseInt(this.css(obj,'paddingRight','padding-right'),10);
                            padWidth+= parseInt(this.css(obj,'marginLeft','margin-left'),10);
                            padWidth+= parseInt(this.css(obj,'marginRight','margin-right'),10);
                            padWidth+= obj.offsetWidth;
			return(padWidth);
		}
		return(0);
	},
	htpad : function(obj) {
		if (typeof obj == 'string') {obj = this.$_(obj);}
		if (obj) {
			
			var padHeight = parseInt(this.css(obj,'paddingTop','padding-top'),10);
                            padHeight+= parseInt(this.css(obj,'paddingBottom','padding-bottom'),10);
                            padHeight+= parseInt(this.css(obj,'marginTop','margin-top'),10);
                            padHeight+= parseInt(this.css(obj,'marginBottom','margin-bottom'),10);
                            padHeight+= obj.offsetHeight;
			return(padHeight);
		}
		return(0);
	},
	nextZIndex : function() { 
		var allElems = document.getElementsByTagName? document.getElementsByTagName("*"): document.all;
		var maxZIndex = 0;
		for(var i=0;i<allElems.length;i++) {
			var elem = allElems[i];
			var cStyle = null;
			if (elem.currentStyle) {cStyle = elem.currentStyle;}
			else if (document.defaultView && document.defaultView.getComputedStyle) {
				cStyle = document.defaultView.getComputedStyle(elem,"");
			}
			var sNum;
			if (cStyle) {sNum = Number(cStyle.zIndex);} 
			else {sNum = Number(elem.style.zIndex);}
			if (!isNaN(sNum)) {
				maxZIndex = Math.max(maxZIndex,sNum);
			}
		}
		return(maxZIndex);
	},
	
	css: function(el, cssproperty,csspropertyNs){
		var doc = this.ipdoc(el);		
		if (el.style[cssproperty]) {
	        return el.style[cssproperty];
	    } else if (el.currentStyle) { 
	        return el.currentStyle[cssproperty];
	    } else if (doc.defaultView && doc.defaultView.getComputedStyle) {
	        return doc.defaultView.getComputedStyle(el,null).getPropertyValue(csspropertyNs);
	    } else {
	        return null;
	    }
	},
	
	/* IFRAME Functions */
	
	ifbody : function(iframe) {
		var idoc = this.ifdoc(iframe);
		if (idoc!=null && idoc.body) {
		return(idoc.body);
		}
		return(null);
	},
	
	ipdoc : function(elem) {
		if (typeof elem == 'string') {elem = this.$_(elem);}
		var doc = elem;      
	   while(!doc.location)
	      doc = doc.parentNode;
	   return doc;
	},
	
	ifdoc : function(iframe) { 
		if (typeof iframe == 'string') {iframe = this.$_(iframe);}
		if ( iframe.contentDocument ) { 
		    var innerDoc = iframe.contentDocument;
		} else if ( iframe.contentWindow ) { 
		    var innerDoc = iframe.contentWindow.document;
		} else {
			return(null);
		}
		return(innerDoc);
	},
	
	oniframeload : function(iframe, f) {
		if (typeof iframe == 'string') {iframe = this.$_(iframe);}
		var innerDoc = null;
	
		if ( iframe.contentDocument ) { 
		    var innerDoc = iframe.contentDocument;
		} else if ( iframe.contentWindow ) { 
		    var innerDoc = iframe.contentWindow.document;
		} 
		 
		var	d = innerDoc, 
			D = 'DOMContentLoaded',  
			u = window.navigator.userAgent.toLowerCase(),
			v = parseFloat(u.match(/.+(?:rv|it|ml|ra|ie)[\/: ]([\d.]+)/)[1]);

		function init(e) {
		
			if (!document.loaded) {
				document.loaded = true;
				
				f((e.type && e.type == D) ? e : {
					type: D,
					target: d,
					eventPhase: 0,
					currentTarget: d,
					timeStamp: +new Date,
					eventType: e.type || e
				});
			}
		}
		if (/webkit\//.test(u) && v < 525.13) {

			(function () {
				if (/complete|loaded/.test(d.readyState)) {
					init('khtml-poll');
				} else {
					setTimeout(arguments.callee, 10);
				}
			})();

		} else if (/msie/.test(u) && !window.opera) {

			d.attachEvent('onreadystatechange',
				function (e) {
					if (d.readyState == 'complete') {
						d.detachEvent('on'+e.type, arguments.callee);
						init(e);
					}
				}
			); 

		} else if (d.addEventListener && 
			(/opera\//.test(u) && v > 9) ||
			(/gecko\//.test(u) && v >= 1.8) ||
			(/khtml\//.test(u) && v >= 4.0) ||
			(/webkit\//.test(u) && v >= 525.13)) {
						 
			d.addEventListener(D,
				function (e) {
				 	if (arguments.callee.done) return;				 
				 	arguments.callee.done = true;
					d.removeEventListener(D, arguments.callee, false);
					init(e);
				}, false
			);
			
			iframe.addEventListener('load',
					function (e) {
					 	if (arguments.callee.done) return;				 
					 	arguments.callee.done = true;
						d.removeEventListener(D, arguments.callee, false);
						init(e);
					}, false
				);
		
		} else { 

			var oldonload = iframe.onload;
			iframe.onload = function (e) {
				init(e || window.event);
				if (typeof oldonload == 'function') {
					oldonload(e || window.event);
				}
			};

		}
	},
	
	/* Dialog Functions */
	
	modal: function(id,title,summary,src,ctype) {
		
		var oDialog = this.$c_('div');
			oDialog.id = 'rdlg_'+id;
			oDialog.style.position = 'absolute';
			oDialog.style.left = 0+'px';
			oDialog.style.top = 0+'px';
			oDialog.style.height = 0+'px';
			oDialog.style.overflow = 'auto';
			oDialog.style.zIndex = this.nextZIndex(); 			
			oDialog.className = 'ragenate_dialog';			
			
			this.$o_(oDialog,0);
			
		var oDialogBG = this.$c_('div');
			oDialogBG.id = 'rdlg_bg_'+id;	
			oDialogBG.style.height = 0+'px';
			oDialogBG.style.overflow = 'auto';
			oDialogBG.className = 'ragenate_dialog_bg'; 
			
		var oDialogContainer = this.$c_('div');
			oDialogContainer.id = 'rdlg_container_'+id;
			oDialogContainer.style.height = 0+'px'; 
			oDialogContainer.className = 'ragenate_dialog_container';			 			
						
		var oDialogHead = this.$c_('div');
			oDialogHead.id = 'rdlg_header_'+id;
			oDialogHead.className = 'ragenate_dialog_header';
			 
		var oDialogTitle = this.$c_('div');
			oDialogTitle.id = 'rdlg_title_'+id;
			oDialogTitle.className = 'ragenate_dialog_title';
			oDialogTitle.appendChild(document.createTextNode(title));
		
			oDialogHead.appendChild(oDialogTitle);
			
		var oDialogSummary = this.$c_('div');
			oDialogSummary.id = 'rdlg_summary_'+id;
			oDialogSummary.className = 'ragenate_dialog_summary';
			oDialogSummary.appendChild(document.createTextNode(summary));
		
		var oDialogContent = this.$c_('div');
			oDialogContent.id = 'rdlg_content_'+id;
			oDialogContent.className = 'ragenate_dialog_content';
		
		var oDialogIFrame = this.$c_('iframe');
			oDialogIFrame.id = 'rdlg_iframe_'+id;
			oDialogIFrame.className = 'ragenate_dialog_iframe';
			oDialogIFrame.style.height = 0+'px';  
			oDialogIFrame.style.overflow = 'auto';
			oDialogIFrame.src = src;
			oDialogIFrame.setAttribute('src',src);
			oDialogIFrame.setAttribute('scrolling','auto');
			oDialogIFrame.setAttribute('border','0');
			oDialogIFrame.setAttribute('marginwidth','0');
			oDialogIFrame.setAttribute('marginheight','0');
			oDialogIFrame.setAttribute('frameborder','no');
			oDialogContent.appendChild(oDialogIFrame);
			
		var oDialogFooter = this.$c_('div');
			oDialogFooter.id = 'rdlg_footer_'+id;
			oDialogFooter.className = 'ragenate_dialog_footer';
			
			oDialog.appendChild(oDialogBG);
			
			oDialogContainer.appendChild(oDialogHead);
			oDialogContainer.appendChild(oDialogSummary);
			oDialogContainer.appendChild(oDialogContent);
			oDialogContainer.appendChild(oDialogFooter);			
			
			oDialog.appendChild(oDialogContainer);
			
			document.body.appendChild(oDialog);
			
						 
			this.oniframeload(oDialogIFrame,function(e) {
				var oBody = ragenate.ifbody(oDialogIFrame);
				if (ragenate.is_ie6()) {oBody.style.display='inline';}
					
				var marginTop = parseInt(ragenate.css(ragenate.ifbody(oDialogIFrame),'marginTop','margin-top'),10) || 0;
				var marginBottom = parseInt(ragenate.css(ragenate.ifbody(oDialogIFrame),'marginBottom','margin-bottom'),10) || 0;
				var scrollHeight = parseInt(ragenate.ifbody(oDialogIFrame).scrollHeight,10) || 0; 
				
				var actualHeight = marginTop+marginBottom+scrollHeight;
				if (ragenate.is_chrome()) {actualHeight-=(marginTop+marginBottom);}
				 
				if (actualHeight>300) {actualHeight=300;}
				oDialogIFrame.style.height = actualHeight+'px';
				
				var paddingLeft = parseInt(ragenate.css(oDialog,'paddingLeft','padding-left'),10) || 0;
				var paddingRight = parseInt(ragenate.css(oDialog,'paddingRight','padding-right'),10) || 0;
				var paddingTop = parseInt(ragenate.css(oDialog,'paddingTop','padding-top'),10) || 0;
				var paddingBottom = parseInt(ragenate.css(oDialog,'paddingBottom','padding-bottom'),10) || 0;
				var dialogContainerHeight = parseInt(oDialogContainer.scrollHeight,10) || 0;
				var dialogHeight = parseInt(oDialog.scrollHeight,10) || 0;
				
				oDialogContainer.style.height = dialogContainerHeight+'px';															
				oDialogContainer.style.width = (oDialog.offsetWidth-(paddingLeft+paddingRight))+'px';
				
				var paddingSpacing = paddingTop+paddingBottom;
				if (!ragenate.is_ie6()) {paddingSpacing-=paddingTop;}
				
				oDialog.style.height = (dialogHeight-paddingSpacing)+'px';				
				oDialog.style.opacity = oDialog.style.filter = '';
				
				oDialogBG.style.width = oDialog.offsetWidth+'px'; 
				oDialogBG.style.height = oDialog.offsetHeight+'px';
				oDialogBG.style.overflow = oDialog.style.overflow = 'hidden';				
				
				ragenate.center(oDialog);				
				ragenate.$o_(oDialogBG,50);
			});
		
	}
}

