/*
OMRON INDUSTRIAL AUTOMATION GLOBAL JAVASCRIPT INCLUDE
Copyright 2008. All rights reserved.

Created by Voormedia - WWW.VOORMEDIA.COM

*/

/* TOP NAVIGATION MENU */
var TopMenu = {
	menuId : null,
	arrMenuStatus : new Array(), 
	menuTimeout : 0,
	menuTimeoutID : null,
	
	// initalize event listeners
	init :function(){
		if(BrowserDetect.browser == "Firefox" && BrowserDetect.version < 3 && BrowserDetect.OS == "Linux") {
			// In Firefox for Linux below 3.0 a bug prevents the submenus from being displayed above flash files.
			// Don't show submenus for these browsers if there is a flash billboard on the homepage.
			if (document.getElementsByClassName('flashbillboard').size() > 0) return;
		}
		if($("topmenu") != null){
			$("topmenu").getElementsByClassSelector(".menuitem").each(function(n){
				Event.observe(n, 'mouseover', function(){TopMenu.show(n);});
				Event.observe(n, 'mouseout', function(){TopMenu.hide(n);}); 
				if($('sub' + n.id) != null){
					subMenu = $('sub' + n.id)
					Event.observe(subMenu, 'mouseover', function(){TopMenu.show(n);}); 
					Event.observe(subMenu, 'mouseout', function(){TopMenu.hide(n);}); 
				}
			});
		}
	},
	
	show : function(menuItem){
		if (this.menuTimeoutID!=menuItem.id) this.hideNow();
		this.menuId = menuItem.id
		if(this.menuId != ""){
			var lSubMenu = $('sub' + this.menuId);
			if(typeof(lSubMenu) != "undefined"){
				lSubMenu.style.left = menuItem.offsetLeft + 'px';
				if (this.arrMenuStatus[this.menuId] != 'show') {
					lSubMenu.addClassName('show'); 
					menuItem.addClassName('highlight'); 
					this.arrMenuStatus[this.menuId] = 'show';
				}
			}
		}
		clearTimeout(this.menuTimeout);
	},

	hide : function(menuItem){
		this.menuId = menuItem.id;
		if (navigator.userAgent.indexOf('Safari')!=-1) { //safari doesn't like the timeout with flash
			this.hideNow(); 
		} else {
			this.menuTimeout = setTimeout("TopMenu.hideNow()",200);
			this.menuTimeoutID = this.menuId;
		}
	},

	hideNow : function(){
		var lSubMenu = $('sub' + this.menuId);
		if(typeof(lSubMenu) != "undefined"){
			if (this.arrMenuStatus[this.menuId] == 'show') {
				lSubMenu.removeClassName('show'); 
				$(this.menuId).removeClassName('highlight'); 
				this.arrMenuStatus[this.menuId] = 'hide';
			}
		}
		this.menuTimeoutID = null;
	}
};


/* CATALOGUE BAR */
var CatalogueBar = {
	timer : 0,
	tab_index : null,
	tab_sets : null,
	tab_set : null,
	
	// initalize event listeners
	init : function(){
		this.tab_sets = document.getElementsByClassName("tabs");
		this.tab_sets.each(function(tab_set,i){
				tab_set.getElementsByClassSelector(".tab").each(function(n, x){
				Event.observe(n, 'mouseover', function(){CatalogueBar.show(n,i);});
				Event.observe(n, 'mouseout', function(){CatalogueBar.hide(n,i);});
				Event.observe(n, 'click', function(){location.href=n.getElementsByTagName("a")[0].href;});
				block_id = eval("x+1");
				if($("block" + block_id) != null){
						Event.observe($("block" + block_id),'mouseover',function(){CatalogueBar.show(n,i);}); 
						Event.observe($("block" + block_id),'mouseout',function(){CatalogueBar.hide(n,i);});				
				}
			});		
		});
	},
	
	show : function(menu_tab, tabset_index){
		clearTimeout(this.timer);
		if(this.tab_index!=0 && this.tab_index!=menu_tab.id) this.hide_now();
		menu_tab.id = "menu_tab_active";
		var tab_index;
		$A(menu_tab.parentNode.getElementsByTagName("TD")).each(function(t,i){if(t.id=="menu_tab_active"){tab_index=i+1;$break;}});
		var menu_block = $("block"+tab_index);
		if(menu_block != undefined){
			menu_tab.addClassName('clicked');
			menu_block.removeClassName("hidden"); //show the block so we can discover its size
			menu_block.style.left="-1000px";
			var submenuPosX = menu_tab.offsetLeft; // position the menu at the same horizontal position as the tab
			var menuBlockWidth = menu_block.offsetWidth;
			var tabBlockWidth = this.tab_sets[tabset_index].offsetWidth;
			if (BrowserDetect.browser == "Firefox") submenuPosX=submenuPosX-1; // firefox fix
			// move the block left if it is too wide
			if(submenuPosX+menuBlockWidth>tabBlockWidth) {
				submenuPosX = tabBlockWidth-menuBlockWidth;
				if (BrowserDetect.browser == "Safari" && parseInt(BrowserDetect.version)<522) submenuPosX+=1; // for for safari versions lower then 3.0
			}
			submenuPosX = Math.max(0,submenuPosX); // at least 0
			w = menu_block.getWidth();
			menu_block.style.left = submenuPosX + 'px';
			if (BrowserDetect.browser=="Safari") { menu_block.style.width = w; }
			if (BrowserDetect.browser!="Safari") { // background repeat goes wrong in safari so lets skip it
				menu_block.getElementsByTagName("DIV")[0].style.backgroundPosition = (menu_tab.offsetLeft-submenuPosX) + 'px bottom';
			}
		}else if(menu_tab != null){
			menu_tab.addClassName('tabover');
		}
		menu_tab = null;
		menu_block = null;
		this.tab_index = tab_index;
	}, 

	hide : function(menu_tab){
		this.timer = setTimeout("CatalogueBar.hide_now()",100);
	},

	hide_now : function(){
		if(this.tab_index != null){
			var menu_tab = $("menu_tab_active");
			var menu_block = $("block" + this.tab_index);
			if(menu_block != undefined) menu_block.addClassName("hidden");
			menu_tab.removeClassName('clicked');
			menu_tab.removeClassName('tabover');
			menu_tab.id="";
			this.tab_index = null;
		}
	}
};


/* FAMILY TABLE */
var FamilyTable = {
	groupTable : null,
	colId : 0,
	currentId : 0,
	rowId : 0,
	headingHeight : 0,
	rowHeight : 0,
	links	: new Array(),
	colids	: new Array(),
	separators : new Array(),
	lastseparator : 0,
	timeout : null,
	
	init : function(){
		if($("grouptable")!=null){
			this.groupTable = $("grouptable");
			setTimeout("FamilyTable.align()", 200);
		}
	},
	
	align : function(){

		if ($("groupnames")){
			this.headingHeight = $("groupheading").getHeight();
			$("grouptitles").getElementsByClassSelector(".separator").each(function(n,i){
				lSeparatorId = parseInt(n.id.substr(n.id.indexOf("separator")+9));
				FamilyTable.separators[i] = lSeparatorId;
			});
			FamilyTable.lastseparator = FamilyTable.separators[FamilyTable.separators.length-1];
			$("grouptitles").getElementsByClassSelector(".valuecell").each(function(n,i){
				lColId = parseInt(n.className.substr(n.className.indexOf("col")+3));
				FamilyTable.colids[i] = lColId;
				FamilyTable.links[lColId] = n.getElementsByTagName("a")[0].href;
				lElImageCell = $("groupimages").getElementsByClassSelector(".col"+lColId)[0];
				if(lElImageCell!=null){
					if(lElImageCell.getHeight() <= 50)lElImageCell.height = 50;
					if((n.clientHeight + lElImageCell.getHeight()) >= FamilyTable.headingHeight){
						FamilyTable.headingHeight = (n.getHeight() + lElImageCell.getHeight());
					}else{
						lElImageCell.height = FamilyTable.headingHeight - n.getHeight();
					}
				}
			});
			
//			if (BrowserDetect.browser == "Explorer" && parseInt(BrowserDetect.version)>=7) this.headingHeight++;
			$("groupheading").height = this.headingHeight;
			//Height adjustment
			if($("groupheading").getHeight() != this.headingHeight) $("groupheading").height = ($("groupheading").height - ($("groupheading").getHeight() - this.headingHeight));
			lElHeaders = $("groupnames").getElementsByClassSelector(".nameRow");
			lElHeaders.each(function(n){
				this.rowId = n.id.substr(n.id.indexOf("attributeNameRow") + 16);
				this.rowHeight = n.getHeight();
				lElValueRow = $($$("div#grouptable div.values tr.row"+this.rowId)[0]);
				lElValueRow.getElementsByClassSelector(".valuecell").each(function(r){
					if(r.getHeight() > this.rowHeight) this.rowHeight = r.getHeight();
					r.height = this.rowHeight;
				});
				n.height = this.rowHeight;
			});
			/* Once the table cells are aligned, show the table by removing the jstransparent class. (defined in jsonly.css)
			This class will only hide the table from view if Javascript is enabled on the client, therefore behaving unobtrusively when JS is not supported. */
			this.groupTable.removeClassName("jstransparent");
		}
		// Initalize event listeners after resizing the table.
		$("grouptable").getElementsByClassSelector(".valuecell").each(function(n){
			Event.observe(n, 'mouseover', function(){FamilyTable.mouseOver(n);}); 
			Event.observe(n, 'mouseout', function(){FamilyTable.timeout = setTimeout("FamilyTable.mouseOut()", 100);}); 
			Event.observe(n, 'click', function(){FamilyTable.mouseClick(n);}); 
		});
	},

	mouseOver : function(valueCell){
		if(this.timeout != null){
			clearTimeout(this.timeout);
			this.mouseOut();
		}
		this.colId = parseInt(valueCell.className.substr(valueCell.className.indexOf("col")+3));
		if(this.colId == this.currentId) return;
		// this is specificaly only for the first cell, to highlight the right border of the labels, instead of the seperator
		if ($("scrollhandle").scrollLeft==0 && this.colId ==1){
			$("groupheading").addClassName("mouseover");
				elBox = $("groupnames").getElementsByClassSelector(".nameRow");
				elBox.each(function(n){ 
					n.addClassName("mouseover");
				});
		}
		$("separator" + this.colId).addClassName("separator_mouseover");
		if($("separator" + (this.colId+1))){
			$("separator" + (this.colId+1)).addClassName("separator_mouseover");
		} else {
			for(var i=0;i<FamilyTable.colids.length-1;i++){
				if(this.colId==FamilyTable.colids[i]){
					$("separator" + (FamilyTable.colids[i+1])).addClassName("separator_mouseover");
				}
			}
		}
		if($("grouptitles").getElementsByClassName("col"+(this.colId+1))==""){
			$("separator" + (FamilyTable.lastseparator)).addClassName("separator_mouseover");
		}
		$(this.groupTable.getElementsByClassName("last col"+this.colId)[0]).addClassName("mouseover");
		$$("div#grouptable div.values th.col"+this.colId)[0].addClassName("mouseover");
	},

	mouseOut : function() {
		// this is specificaly only for the first cell, to remove the highlighted right border of the labels, instead of the seperator
		if($("groupheading").hasClassName("mouseover")){		
			$("groupheading").removeClassName("mouseover");
				elBox = $("groupnames").getElementsByClassSelector(".nameRow");
				elBox.each(function(n){
					n.removeClassName("mouseover");
				});
		}
		//
		if($("separator" + this.colId)!=null){
			$("separator" + this.colId).removeClassName("separator_mouseover");
			if($("separator" + (this.colId+1))){
				$("separator" + (this.colId+1)).removeClassName("separator_mouseover");
			} else {
				for(var i=0;i<FamilyTable.colids.length-1;i++){
					if(this.colId==FamilyTable.colids[i]){
						$("separator" + (FamilyTable.colids[i+1])).removeClassName("separator_mouseover");
					}
				}
			}
			if($("grouptitles").getElementsByClassName("col"+(this.colId+1))==""){
				$("separator" + (FamilyTable.lastseparator)).removeClassName("separator_mouseover");
			}
			$(this.groupTable.getElementsByClassName("last col"+this.colId)[0]).removeClassName("mouseover");
			$$("div#grouptable div.values th.col"+this.colId)[0].removeClassName("mouseover");
		}
	},

	mouseClick : function(valueCell) {
		if(typeof(this.links[this.colId]) == "undefined") {
			this.mouseOver(valueCell);
		}
		document.location.href = this.links[this.colId];
	}
};


/* OMNI TABS */
var OmniTab = {
	tabsContainer : null, tabSets : new Array(), subtabSets : new Array(), currentTabIndex : new Array(), currentSubtabIndex : new Array(), selectFirstTab : false,
	
	// initalize event listeners
	init : function(){
		document.getElementsByClassName("tabcontainer").each(function(t){
			OmniTab.currentSubtabIndex[t.id] = new Array();
			OmniTab.getTabIndexFromCookie(t.id);
			OmniTab.selectFirstTab = t.className.indexOf("noneselected")==-1;
			OmniTab.tabsContainer = t.getElementsByClassName('tabs')[0];
			OmniTab.tabSets[t.id] = (OmniTab.tabsContainer.tagName=="UL"? $A(OmniTab.tabsContainer.getElementsByTagName('li')) : $A(OmniTab.tabsContainer.getElementsByTagName('td')));
			
			if(OmniTab.selectFirstTab && OmniTab.tabSets[t.id].length > 0){
				OmniTab.currentTabIndex[t.id] = OmniTab.getTabIndex(OmniTab.tabSets[t.id][0], t.id);
			}else{OmniTab.currentTabIndex[t.id] = -1;}
			OmniTab.show(OmniTab.tabSets[t.id], OmniTab.currentTabIndex[t.id], t.id);
			OmniTab.tabSets[t.id].each(function(n){
				Event.observe(n, 'mouseover', function(){OmniTab.mouseOver(n, t.id);}); 
				Event.observe(n, 'mouseout', function(){OmniTab.mouseOut(n, t.id);}); 
				Event.observe(n, 'click', function(){OmniTab.mouseClick(OmniTab.tabSets[t.id], n, t.id);return false;});
			});
			/* Once the info table has been initialized, show the table by removing the jshidden class. (defined in jsonly.css)
			This class will only hide the table from view if Javascript is enabled on the client, therefore behaving unobtrusively when JS is not supported. */
			OmniTab.initSubtabs(t.id);
			t.removeClassName('jshidden');
		});
	},

	initSubtabs : function(container_id){
		if($(container_id) != null){
			OmniTab.subtabSets[container_id] = new Array();
			$(container_id).getElementsByClassSelector(".tabcontent").each(function(t){
				var subtabContainer = $(t.id).getElementsByClassSelector(".tabssub");
				if(subtabContainer != ""){
					tabIndex = t.id.substr(t.id.indexOf(container_id)+container_id.length);
					OmniTab.subtabSets[container_id][t.id] = $A(subtabContainer[0].getElementsByTagName("a"));
					if(OmniTab.currentSubtabIndex[container_id][tabIndex] == undefined || $(container_id+OmniTab.currentSubtabIndex[container_id][tabIndex]) == null) OmniTab.currentSubtabIndex[container_id][tabIndex] = OmniTab.getTabIndex(OmniTab.subtabSets[container_id][t.id][0], container_id);
					OmniTab.subtabSets[container_id][t.id].each(function(s){
						Event.observe(s, 'click', function(){OmniTab.mouseClick(OmniTab.subtabSets[container_id][t.id], s, container_id);return false;});		
					});
					OmniTab.show(OmniTab.subtabSets[container_id][t.id], OmniTab.currentSubtabIndex[container_id][tabIndex], container_id);
				}
			});
		}
	},
	
	mouseOver : function(el, tabsetId){
		index = this.getTabIndex(el, tabsetId);
		if(index != this.currentTabIndex[tabsetId]){
			el.addClassName("tabover");
		}
	},
	
	mouseOut : function(el, tabsetId){
		index = this.getTabIndex(el, tabsetId);
		if(index != this.currentTabIndex[tabsetId]) el.removeClassName("tabover");
	},
	
	mouseClick : function(tabSet, el, tabsetId){
		this.showContent(tabSet, this.getTabIndex(el, tabsetId), tabsetId);
	},
	
	show : function(tabSet, currentTabIndex, tabsetId){
		tabSet.each(function(n){
			n = $(n);
			var contentDiv = $(tabsetId + OmniTab.getTabIndex(n, tabsetId));
			if(contentDiv != null){
				if(OmniTab.getTabIndex(n, tabsetId) == currentTabIndex){
					contentDiv.removeClassName('hidden');
					n.addClassName('selected');
					if(li=n.up('li')){
						li.addClassName('selected');
					}
				}else{
					contentDiv.addClassName('hidden');
					n.removeClassName('selected');
					n.removeClassName('tabover');
					if(li=n.up('li')){
						li.removeClassName('selected');
					}
				}
			}
		});
	},
	
	showContent : function(tabSet, currentTabIndex, tabsetId){
		tabSet[0].tagName == "TD" ?  tab = "Tab" : tab = "Subtab";
		eval("this.current" + tab + "Index = currentTabIndex;");
		this.show(tabSet, currentTabIndex, tabsetId);
		Cookie.create(tabsetId + tab, currentTabIndex);
		if(tab=="Tab") Cookie.create(tabsetId + 'Tab_page', window.location.href); 
	},
	
	getTabIndex : function(el, tabsetId){
		a = (el.tagName == "TD" || el.tagName == "LI" ?  $(el.getElementsByTagName('a')[0]) : el);
		return a.href.substr(a.href.indexOf('#' + tabsetId)+(tabsetId.length+1));
	},
	
	getTabIndexFromCookie : function(tabsetId){
		if(Cookie.read(tabsetId + 'Tab') != null && Cookie.read(tabsetId + 'Tab_page') != null){
			if(Cookie.read(tabsetId + 'Tab_page') == window.location.href){
				this.currentTabIndex[tabsetId] = Cookie.read(tabsetId + 'Tab');
				if(Cookie.read(tabsetId + 'Subtab') != null && Cookie.read(tabsetId + 'Subtab').substring(0, Cookie.read(tabsetId + 'Subtab').indexOf("_")) == this.currentTabIndex[tabsetId]){
					this.currentSubtabIndex[tabsetId][this.currentTabIndex[tabsetId]] = Cookie.read(tabsetId + 'Subtab');
				}
			}
		}
	}
};

/* RELATED EXPERT AREA TABS */
var RelatedTab = {
	tabsContainer : null, tabSets : new Array(), subtabSets : new Array(), currentTabIndex : new Array(), currentSubtabIndex : new Array(), selectFirstTab : false,
	
	// initalize event listeners
	init : function(){
		document.getElementsByClassName("relatedtabcontainer").each(function(t){
			RelatedTab.currentSubtabIndex[t.id] = new Array();
			RelatedTab.getTabIndexFromCookie(t.id);
			RelatedTab.selectFirstTab = t.className.indexOf("noneselected")==-1;
			RelatedTab.tabsContainer = t.getElementsByClassName('relatedtabs')[0];
			RelatedTab.tabSets[t.id] = (RelatedTab.tabsContainer.tagName=="UL"? $A(RelatedTab.tabsContainer.getElementsByTagName('li')) : $A(RelatedTab.tabsContainer.getElementsByTagName('td')));
			
			if(RelatedTab.selectFirstTab){
				if($(t.id+RelatedTab.currentTabIndex[t.id])==null) RelatedTab.currentTabIndex[t.id] = 1;
				while($(t.id+RelatedTab.currentTabIndex[t.id])==null && RelatedTab.currentTabIndex[t.id] < RelatedTab.tabSets[t.id].length)
					RelatedTab.currentTabIndex[t.id]++;
			}else{RelatedTab.currentTabIndex[t.id] = -1;}
			RelatedTab.show(RelatedTab.tabSets[t.id], RelatedTab.currentTabIndex[t.id], t.id);
			RelatedTab.tabSets[t.id].each(function(n){
				Event.observe(n, 'mouseover', function(){RelatedTab.mouseOver(n, t.id);}); 
				Event.observe(n, 'mouseout', function(){RelatedTab.mouseOut(n, t.id);}); 
				Event.observe(n, 'click', function(){RelatedTab.mouseClick(RelatedTab.tabSets[t.id], n, t.id);return false;});
			});
			/* Once the info table has been initialized, show the table by removing the jshidden class. (defined in jsonly.css)
			This class will only hide the table from view if Javascript is enabled on the client, therefore behaving unobtrusively when JS is not supported. */
			RelatedTab.initSubtabs(t.id);
			t.removeClassName('jshidden');
		});
	},

	initSubtabs : function(container_id){
		if($(container_id) != null){
			RelatedTab.subtabSets[container_id] = new Array();
			$(container_id).getElementsByClassSelector(".tabcontent").each(function(t){
				var subtabContainer = $(t.id).getElementsByClassSelector(".tabssub");
				if(subtabContainer != ""){
					tabIndex = t.id.substr(t.id.indexOf(container_id)+container_id.length);
					RelatedTab.subtabSets[container_id][t.id] = $A(subtabContainer[0].getElementsByTagName("a"));
					if(RelatedTab.currentSubtabIndex[container_id][tabIndex] == undefined || $(container_id+RelatedTab.currentSubtabIndex[container_id][tabIndex]) == null) RelatedTab.currentSubtabIndex[container_id][tabIndex] = RelatedTab.getTabIndex(RelatedTab.subtabSets[container_id][t.id][0], container_id);
					RelatedTab.subtabSets[container_id][t.id].each(function(s){
						Event.observe(s, 'click', function(){RelatedTab.mouseClick(RelatedTab.subtabSets[container_id][t.id], s, container_id);return false;});		
					});
					RelatedTab.show(RelatedTab.subtabSets[container_id][t.id], RelatedTab.currentSubtabIndex[container_id][tabIndex], container_id);
				}
			});
		}
	},
	
	mouseOver : function(el, tabsetId){
		index = this.getTabIndex(el, tabsetId);
		if(index != this.currentTabIndex[tabsetId]){
			el.addClassName("tabover");
		}
	},
	
	mouseOut : function(el, tabsetId){
		index = this.getTabIndex(el, tabsetId);
		if(index != this.currentTabIndex[tabsetId]) el.removeClassName("tabover");
	},
	
	mouseClick : function(tabSet, el, tabsetId){
		this.showContent(tabSet, this.getTabIndex(el, tabsetId), tabsetId);
	},
	
	show : function(tabSet, currentTabIndex, tabsetId){
		tabSet.each(function(n){
			n = $(n);
			var contentDiv = $(tabsetId + RelatedTab.getTabIndex(n, tabsetId));
			if(contentDiv != null){
				if(RelatedTab.getTabIndex(n, tabsetId) == currentTabIndex){
					contentDiv.removeClassName('hidden');
					n.addClassName('selected');
					if(li=n.up('li')){
						li.addClassName('selected');
					}
				}else{
					contentDiv.addClassName('hidden');
					n.removeClassName('selected');
					n.removeClassName('tabover');
					if(li=n.up('li')){
						li.removeClassName('selected');
					}
				}
			}
		});
	},
	
	showContent : function(tabSet, currentTabIndex, tabsetId){
		tabSet[0].tagName == "TD" ?  tab = "Tab" : tab = "Subtab";
		eval("this.current" + tab + "Index = currentTabIndex;");
		this.show(tabSet, currentTabIndex, tabsetId);
		Cookie.create(tabsetId + tab, currentTabIndex);
		if(tab=="Tab") Cookie.create(tabsetId + 'Tab_page', window.location.href); 
	},
	
	getTabIndex : function(el, tabsetId){
		a = (el.tagName == "TD" || el.tagName == "LI" ?  $(el.getElementsByTagName('a')[0]) : el);
		return a.href.substr(a.href.indexOf('#' + tabsetId)+(tabsetId.length+1));
	},
	
	getTabIndexFromCookie : function(tabsetId){
		if(Cookie.read(tabsetId + 'Tab') != null && Cookie.read(tabsetId + 'Tab_page') != null){
			if(Cookie.read(tabsetId + 'Tab_page') == window.location.href){
				this.currentTabIndex[tabsetId] = Cookie.read(tabsetId + 'Tab');
				if(Cookie.read(tabsetId + 'Subtab') != null && Cookie.read(tabsetId + 'Subtab').substring(0, Cookie.read(tabsetId + 'Subtab').indexOf("_")) == this.currentTabIndex[tabsetId]){
					this.currentSubtabIndex[tabsetId][this.currentTabIndex[tabsetId]] = Cookie.read(tabsetId + 'Subtab');
				}
			}
		}
	}
};

/* COLLAPSING DIVS FOR EG. INTERESTING TO KNOW */
var Collapser = {
	container : null, divs : null, open_divs : [1],
	
	init : function(div_id){
		if($(div_id) != null){
			this.container = $(div_id);
			this.headers = $A(this.container.getElementsByTagName('h4'));
			this.headers.each(function(n,i){
				Collapser.do_trigger_image(n,i);
				Collapser.update(n,i);
				Event.observe(n, 'click', function(){Collapser.toggle(n, i);return false;});
			});
		}
	},
	
	do_trigger_image : function(el,i){
		if($A(el.getElementsByTagName("div")) == ''){
			trigger_image = $(document.createElement("div"));
			el.insertBefore(trigger_image,el.firstChild);
			var sp1_content = document.createTextNode("This is a new span element. ");
		}else{
			trigger_image = el.getElementsByTagName("div")[0];
		}
		trigger_image.className = (this.open_divs[i] ? "minus" : "plus");
	},
	
	update : function(el,i){
		var section = $(el).next();
		if(this.open_divs[i]){
			section.removeClassName("jsnodisplay");
		}else{
			section.addClassName("jsnodisplay");
		}
		this.do_trigger_image(el,i);
	},
	
	toggle : function(el,i){
		this.open_divs[i] ? this.open_divs[i] = 0 : this.open_divs[i] = 1;
		this.update(el,i);
	}

};


/* COUNTRY SELECT */
function recieveDataFromFlash(flashregion){ // This is the only function call from flash
	CountrySelect.display_html(flashregion);
}

var CountrySelect = {

	init: function(){
		if($("countrylist") != null){
			$A($("countrylist").getElementsByTagName("LI")).each(function(l){
				var country_code = l.id.substring(7);
				var a = l.getElementsByTagName("A")[0];
				Event.observe(l, "mouseover", function(){CountrySelect.region_select(country_code, "on");});
				Event.observe(l, "mouseout", function(){CountrySelect.region_select(country_code, "off");});
				Event.observe(l, "click", function(){CountrySelect.region_click(country_code);return false;});
			});
		}
		if($('noflashcountrymap') != null){
			var map_type = $('noflashcountrymap').className;
			$A($('noflashcountrymap').getElementsByTagName("area")).each(function(a){
				var region_code = a.id.substring(12);
				Event.observe(a, "click", function(){this.blur();CountrySelect.region_click(region_code);if(map_type=="country")return false;});
				if(a.className.indexOf("hasmap")!=-1){
					// var region_name = a.className.substring(a.className.indexOf("hasmap")+7);
					Event.observe(a, "click", function(){CountrySelect.no_flash_map(region_code);return false;});
				}
			});
		}
		if($('resetbutton')!=null){
			$('resetbutton').getElementsByClassSelector(".backbutton-top").each(function(d){
				if(d.getElementsByTagName("A").length > 0)
				Event.observe(d.getElementsByTagName("A")[0], "click", function(){CountrySelect.back_to_map(); return false;});
			});
		}
	},

	region_click: function(region){
		this.display_html(region);
		this.send_data('PageClicked',region);
	},

	region_select: function(region, state){
		this.send_data('PageMouseOver'+region,state)
	},

	back_to_map: function(){
		this.send_data('SelectedMap','world');
		this.send_data('PageClicked','none');
		this.hide_all('countrylist');
		this.hide_all('countryinfo');
		this.hide_all('resetbutton');
		this.no_flash_map('world');
	},

	send_data: function(flash_variable,flash_data){ // send data to flash
		if ($("countryselect")!=null) {
			$("countryselect").SetVariable(("/:"+flash_variable),flash_data);
		}
	},

	no_flash_map: function(region_code){	
		if ($('noflashworld')!=null && $('noflash' + region_code)!=null) {
			if (region_code=="world")  {
				if ($('noflashworld').removeClassName('hidden')) { $('noflashworld').addClassName('visible')}
				if ($('noflashEU').removeClassName('visible')) { $('noflashEU').addClassName('hidden')}
			}
			if (region_code=="EU") {
				if ($('noflashworld').removeClassName('visible')) { $('noflashworld').addClassName('hidden')}
				if ($('noflashEU').removeClassName('hidden')) { $('noflashEU').addClassName('visible')}
    		}
		}
	},

	display_html: function(region){
		if (region!= null && region!='') {
			this.switch_info(('info-'+region),'countryinfo');
			this.switch_info(('list-'+region),'countrylist');
			this.switch_info(('button-'+region),'resetbutton');
		}
	},

	switch_info: function(region,box){	
		if($(region)!=null && $(box)!=null) {	
			CountrySelect.hide_all(box);
			$(region).removeClassName("hidden");
		}
	},

	hide_all: function(box){
		if ($(box)!=null){
			$A($(box).getElementsByTagName('div')).each(function(d){
				$(d.id).addClassName("hidden");
			});
		}
	}
};

/* POPUP WINDOW FUNCTIONALITY */
var Popup = {
	largeVisualURL: "",
	
	open : function(mStrUrl, mStrWindowName, mStrProperties, mBlReturnValue){
		var lIntHeight	= 0;
		var lIntWidth	= 0;
		var lIntStart	= 0;
		var lStrTemp	= "";
		if (mStrProperties.search("height") > 0) {
			lStrTemp = mStrProperties.substring(mStrProperties.search("height") + 7);
			if (lStrTemp.search(",") > 0) {
				lIntStart  = mStrProperties.search("height") + 7
				lIntHeight = mStrProperties.substring(lIntStart, lStrTemp.search(",") + lIntStart); 
			} else {
				lIntHeight = lStrTemp;
			}
		}
		if (mStrProperties.search("width") > 0) {
			lStrTemp = mStrProperties.substring(mStrProperties.search("width") + 6);
			if (lStrTemp.search(",") > 0) {
				lIntStart  = mStrProperties.search("width") + 6
				lIntWidth = mStrProperties.substring(lIntStart, lStrTemp.search(",") + lIntStart); 
			} else {
				lIntWidth = lStrTemp;
			}
		}
		if (screen) {
			w = screen.availWidth;
			h = screen.availHeight - 25;
		}
		var lIntLeftPos = (w - lIntWidth) /2;
		var lIntTopPos	= (h - lIntHeight)/2;	
		var lObjOpenWindow = window.open(mStrUrl, mStrWindowName, mStrProperties + ",top=" + lIntTopPos + ",left=" + lIntLeftPos);
		lObjOpenWindow.focus();
	
		if (mBlReturnValue) return lObjOpenWindow;
	},

	downloadCentre : function(mStrURL){
		this.open(mStrURL,'downloadcentre','dependent=yes,toolbar=no,status=yes,menubar=no,location=no,personalbar=no,hotkeys=no,scrollbars=auto,resizable=no,width=900,height=700',false);
	},

	visual : function(popupURL, a, type, width, height, params){
		if(width == "") width = 700;
		if(height == "") height = 500;
		if(params != "") params = ("&" + params);
	
		var visualWin = this.open(popupURL + '?visual='+escape(a).replace(/\+/g, '%2B')+'&type='+type+'&height='+height+'&width='+width+params, 'visualWin', 'width='+(width+20)+',height='+(height+30)+',location=no,menubar=no,resizable=no,status=no,toolbar=no', false);
	}
};

/* IE6/7 ITEM IMAGE LINK FIX */
var ExplorerLinks = {
	
	init: function (){
		if (navigator.appName == 'Microsoft Internet Explorer') {
			this.listener(this.elinkclasses);
		}
	},
	
	listener: function(class_array){
		for (var i=0;i<class_array.length;i++){
			document.getElementsByClassName(class_array[i]).each(function(n){
				Event.observe(n, 'click', function() {location.href=n.getElementsByTagName("a")[0].href;});
			});
		}
	},
	
	elinkclasses:  [
		'leaditem',
		'relateditem',
		'expertareaitem',
		'applicationitem',
		'productitem',
		'cataloguegroup'
	]
};


/* COOKIE HANDLING CLASS */
var Cookie = {
	
	create : function(name, value){
		if(arguments.length > 2){
			var days = arguments[2];
			var date = new Date();
			date.setTime(date.getTime()+(days*24*60*60*1000));
			var expires = "; expires="+date.toGMTString();
		}
		else var expires = "";
		document.cookie = name+"="+value+expires+"; path=/";
	},

	read : function(name){
		var nameEQ = name + "=";
		var ca = document.cookie.split(';');
		for(var i=0;i < ca.length;i++){
			var c = ca[i];
			while (c.charAt(0)==' ') c = c.substring(1,c.length);
			if (c.indexOf(nameEQ) == 0) return c.substring(nameEQ.length,c.length);
		}
		return null;
	},

	erase : function(name){
		this.create(name,"",-1);
	}
};


var BrowserDetect = {
	init: function () {
		this.browser = this.searchString(this.dataBrowser) || "An unknown browser";
		this.version = this.searchVersion(navigator.userAgent)
			|| this.searchVersion(navigator.appVersion)
			|| "an unknown version";
		this.OS = this.searchString(this.dataOS) || "an unknown OS";
	},
	searchString: function (data) {
		for (var i=0;i<data.length;i++)	{
			var dataString = data[i].string;
			var dataProp = data[i].prop;
			this.versionSearchString = data[i].versionSearch || data[i].identity;
			if (dataString) {
				if (dataString.indexOf(data[i].subString) != -1)
					return data[i].identity;
			}
			else if (dataProp)
				return data[i].identity;
		}
	},
	searchVersion: function (dataString) {
		var index = dataString.indexOf(this.versionSearchString);
		if (index == -1) return;	
		return parseFloat(dataString.substring(index+this.versionSearchString.length+1));
	},
	dataBrowser: [
		{string: navigator.vendor,subString: "Apple",identity: "Safari"},
		{prop: window.opera,identity: "Opera"},
		{string: navigator.vendor,subString: "KDE",identity: "Konqueror"},
		{string: navigator.userAgent,subString: "Firefox",identity: "Firefox"},
		{string: navigator.vendor,subString: "Camino",identity: "Camino"},
		{/* for newer Netscapes (6+) */ string: navigator.userAgent,subString: "Netscape",identity: "Netscape"},
		{string: navigator.userAgent,subString: "MSIE",identity: "Explorer",versionSearch: "MSIE"},
		{string: navigator.userAgent,subString: "Gecko",identity: "Mozilla",versionSearch: "rv"},
		{ /* for older Netscapes (4-) */ string: navigator.userAgent,subString: "Mozilla",identity: "Netscape",versionSearch: "Mozilla"}
	],
	dataOS: [
		{string: navigator.platform,subString: "Win",identity: "Windows"},
		{string: navigator.platform,subString: "Mac",identity: "Mac"},
		{string: navigator.platform,subString: "Linux",identity: "Linux"}
	],
	supported: function(){
	/* 	this statement must be kept up to date as the browser requirements change. At the moment, supported browsers are:
		Internet Explorer 5.5 and newer (Windows), Firefox 1 and newer (Mac & Windows), Safari all versions (Mac & Windows)
	*/
		return 	(this.OS == "Windows" && this.browser == "Explorer" && parseFloat(this.version) >= 5.5) ||
				(this.browser == "Firefox" && parseInt(this.version) >= 1) ||
				(this.browser == "Safari")
	}
};


/* GENERAL PAGE FUNCTIONS */
var Page = {
	// removes the dotted boxes around a hyperlink or certain form elements when clicked in Firefox
	remove_focus : function(){
		$A(document.links).each(function(n){
			Event.observe(n, "focus", function(){if(this.blur)this.blur();});
		});
		$A(document.getElementsByTagName("INPUT")).each(function(n){
			if(n.type == "image" || n.type == "radio" || n.type == "submit")
				Event.observe(n, "focus", function(){if(this.blur)this.blur();});
		});
	}
};

/* INITIALIZATION - On DOM ready */
function init(){
	Page.remove_focus();
	TopMenu.init();

	Collapser.init('interesting');
	CountrySelect.init();
}

/* INITIALIZATION - On Window load (DOM loaded + images loaded) */
function init_post(){
	FamilyTable.init();
	OmniTab.init();
	RelatedTab.init();
	CatalogueBar.init();
	ExplorerLinks.init();
}

BrowserDetect.init();
if(BrowserDetect.supported()){
	/* call init function as soon as DOM is loaded (happens earlier than window.onload event) - only works with LowPro extension for Prototype */
	Event.onReady(init)
	/* only call init_post function if something must be initialized *after* images are loaded */
	Event.observe(window, "load", init_post);
}