/*
Title: Utility Javascript
Author: designkitchen, inc.
*/

//IE var
var ie = document.all?true:false;

//Rotating module
var moduleTimer=0;
var timeBeforeSwitch=10; // # of seconds before news items rotate.
function initTimer(numberOfItems) {
	moduleTimer=0;
	if(document.getElementById("forward1")) {
		incrementTimer(numberOfItems);
	} 
}
function incrementTimer(numberOfItems) {
	if (moduleTimer < timeBeforeSwitch) {
		setTimeout("incrementTimer("+numberOfItems+")", "1000");
		moduleTimer++;
	} else {
		initTimer(numberOfItems);
		rotateForw(document.getElementById("forward1"), "1", numberOfItems);
	}
		
}

// This is used to open links in external windows. The HTML syntax is as follows:
// <a href="document.html" rel="external">external link</a>
function externalLinks() {
 if (!document.getElementsByTagName) return;
 var anchors = document.getElementsByTagName("a");
 for (var i=0; i<anchors.length; i++) {
   var anchor = anchors[i];
   if (anchor.getAttribute("href") &&
       anchor.getAttribute("rel") == "external")
     anchor.target = "_blank";
 }
}
var globalObj=null;
var flashExpanded = false;
var newHeight=null;
function getArray() {
	var fa = document.getElementsByTagName("object");
	var fArray = new Array();
	for(var x=0; x < fa.length; x++) {
		fArray.push(fa[x].id);
	}
	return fArray;	
}
function expandCollapse(v) {
	var fArray = getArray();
	for(var y=0; y < fArray.length; y++) {
		var obj = document.getElementById(fArray[y]);
		//Collapse //////////////////////////////////
		if(obj.style.height.substring(0,3) > flashHeight) {
			if(ie) {
				finishTransition(flashHeight);
			} else {
				new Effect.Morph(obj, {
					style: 'height:'+flashHeight+'px', 
					duration: 0.15,
					delay:0.6,
					transition: Effect.Transitions.sinoidal
				});
			}
			flashExpanded = false;
		} else {
			//Expand //////////////////////////////////
			if(obj.id != "motoMediaPlayer") {
				newHeight=parseFloat(flashHeight) + parseFloat(growLength);
				if(ie) {
					finishTransition(newHeight);
				} else {
					new Effect.Morph(obj, {						
						style: 'height:'+newHeight+'px', 
						duration: 0.8,
						delay:0.2,
						transition: Effect.Transitions.sinoidal
					});
					flashExpanded = true;
				}
			}				
		}
	}
}
function finishTransition(heightVal) {
	var fArray = getArray();
	for(var y=0; y < fArray.length; y++) {
		var obj = document.getElementById(fArray[y]);
		if(obj.id != "motoMediaPlayer")
			obj.style.height=heightVal+'px';
	}
}
//javascript:OpenSite('http://business.motorola.com/publicsafety/secondnature/site.html');
function OpenSite(url) {
	if(url) 
	{
		document.getElementById('siteContainer').src=url;
		document.getElementById('siteContainerWrapper').style.display='';
		document.getElementById('siteContainer').style.display='';
	} else {
		document.getElementById('siteContainer').src='';
		document.getElementById('siteContainerWrapper').style.display='none';
		document.getElementById('siteContainer').style.display='none';
	}	
}
function external(url) {
	window.location.href = url;
}
var animatingCarousel = false;
function rotateForw(obj, carouselId, numberOfElements) {
	
	moduleTimer=0;
	if(!animatingCarousel){
		animatingCarousel=true;
		var control = document.getElementById( "forward_"+carouselId );
		var carousel = document.getElementById( "carousel_"+carouselId );
		var carouselPosition = carousel.style.left;
		var leftInt = parseInt(carouselPosition);
		
		
		//alert( carousel.descendants() );//carousel.getWidth()  //carousel.hasClassName('two')
		//alert( parseInt(carousel.getStyle('width').replace(/px/,""))  );
		//var myWidth = parseInt(carousel.getStyle('width').replace(/px/,""));
		/// IE isnt' liking the dynamic width so using the conditional below.
		/*var myWidth = 552;
		carousel.hasClassName('two') ? myWidth = 368 : "";
		carousel.hasClassName('three') ? myWidth = 552 : "";
		carousel.hasClassName('four') ? myWidth = 736 : "";
		carousel.hasClassName('five') ? myWidth = 920 : "";
		*/
		var myWidth = 552;
		numberOfElements==2 ? myWidth = 368 : "";
		numberOfElements==3 ? myWidth = 552 : "";
		numberOfElements==4 ? myWidth = 736 : "";
		numberOfElements==5 ? myWidth = 920 : "";
		numberOfElements==6 ? myWidth = 1104 : "";
		numberOfElements==7 ? myWidth = 1288 : "";
		numberOfElements==8 ? myWidth = 1472 : "";
		numberOfElements==9 ? myWidth = 1662 : "";
		
		
		if (leftInt > (184-myWidth) ) {
			new Effect.Move(carousel, {
				duration: 0.3, x: -184, y: 0, mode: 'relative',
				transition: Effect.Transitions.linear,
				afterFinish: function(){
					animatingCarousel = false;
				}
			});
		} else {
			new Effect.Move(carousel, {
				duration: 0.6, x: (myWidth-184), y: 0, mode: 'relative',
				transition: Effect.Transitions.linear,
				afterFinish: function(){
					animatingCarousel = false;
				}
			});
		}
	}
}
function rotateBack(obj, carouselId) {
	
	if(!animatingCarousel){
		animatingCarousel=true;
		var control = document.getElementById( "back_"+carouselId );
		var carousel = document.getElementById( "carousel_"+carouselId );
		var carouselPosition = carousel.style.left;
		var leftInt = parseInt(carouselPosition);
		if (leftInt < 0) {
			new Effect.Move(carousel, {
				duration: 0.3, x: 184, y: 0, mode: 'relative',
				transition: Effect.Transitions.linear,
				afterFinish: function(){
					animatingCarousel = false;
				}
			});
		} else {
			new Effect.Move(carousel, {
				x: 0, y: 0, mode: 'relative',
				transition: Effect.Transitions.linear,
				afterFinish: function(){
					animatingCarousel = false;
				}
			});
		}
	}
}

var animatingProdSol = false;
function toggleProdSol() {
	if (!animatingProdSol){
		animatingProdSol=true;
		//var head = document.getElementById( "head" );
		var list = document.getElementById( "list" );
		if(list.style.display == "none"){//getStyle('display') //style.display
			$('head').addClassName("open");
			Effect.BlindDown(list, { duration: 0.5,
			afterFinish: function(){
				animatingProdSol = false;
			} });
		}else{
			$('head').removeClassName("open");
			Effect.BlindUp(list, { duration: 0.5,
			afterFinish: function(){
				animatingProdSol = false;
			} });
		}
	}
}

var categoryViewer = Class.create({
	initialize: function() {
		this.buttons = $$('.browser .buttons a');
		this.categories = $$('.browser .products dl');
		this.categoryViewer();
	},
	categoryViewer: function() {
		for (var i=0;i<this.buttons.length;i++) {
			Event.observe(this.buttons[i], 'click', this.toggleCategory.bind(this));
		}
	},
	toggleCategory: function(event) {
		// get button ancor: fix for clicking on an element within the <a/>
		var myButton = Event.element(event).inspect() == '<strong>' || Event.element(event).inspect() == '<span>' ? Event.element(event).ancestors()[0] : Event.element(event) ;
		if (myButton.getAttribute('rel') == 'all') {
			// ALL Button pressed
			for (var i=0;i<this.categories.length;i++) {
				i==0 ? this.categories[i].addClassName("first") : this.categories[i].removeClassName("first");//first class only to first element...
				this.openCategory( this.categories[i] );
			}
			for (var b=0; b<this.buttons.length; b++) {
				if(this.buttons[b] != myButton) {
					this.deactivateButton( this.buttons[b] );
				} else {
					this.activateButton( myButton );
				}
			}
		}else{
			// Category Button pressed
			for (var i=0;i<this.categories.length;i++)
			{
				for (var u=0; u<this.categories[i].classNames().toArray().length; u++) 
				{
					if( this.categories[i].classNames().toArray()[u] == myButton.getAttribute('rel') )
					{
						this.categories[i].addClassName("first");//set as first.
						this.openCategory( this.categories[i]);
						this.activateButton( myButton );
						//now close all the other categories
						for (var ix=0; ix<this.categories.length; ix++) {
							if( i != ix ) {
								this.closeCategory(this.categories[ix]);
								//deactivate other buttons
								for (var b=0; b<this.buttons.length; b++) {
									if( this.buttons[b] != myButton ){
										this.deactivateButton( this.buttons[b] );
									}
								}
							}
						}
						this.activateButton(this.categories[i]);
					}
				}
			}
		}
	},
	openCategory: function(myElement) {
		//myElement.visible() ? alert("open") :"";
		//Effect.BlindDown(myElement, { duration: .5 });
		Element.show(myElement);
	},
	closeCategory: function(myElement) {
		//myElement.visible() ? "":alert("close");
		//Effect.SlideUp(myElement, { duration: .5 });
		Element.hide(myElement);
	},
	activateButton: function(myLink) {
		myLink.ancestors()[0].addClassName("active");
	},
	deactivateButton: function(myLink) {
		myLink.ancestors()[0].removeClassName("active");
	}
});

var productViewer = Class.create({
	initialize: function() {
		this.products = $$('.browser .products dd ul li');
		this.toolTiper = $$('.browser .products .productViewer');
		this.closeButton = document.getElementById('productViewerCloseBtn'); //$$('.browser .products .productViewer a.close')[0];
		this.previousSelection = false;
		this.myAnimation = false;
		this.relUrl = "../../";
		this.productDataLocation = this.relUrl+'xml/moto-products.xml';
		this.productData = {"products":[]}
		this.initiated = true;
		this.pulldownImages = [];
		/*this.productData = Object.extend({
			products: []
		}, arguments[1] || {});*/		
		this.productViewer();
	},
	productViewer: function() {
		this.loadProductsData();//this will activate the other functionality after the data is loaded. 
		this.listenToMe();//
	},
	listenToMe: function() {
		
		//listen for click on all products.
		for (var i=0;i<this.products.length;i++) {
			Event.observe(this.products[i], 'click', this.startViewer.bind(this));//pulldown menu listner
			//Event.observe(this.products[i], 'click', this.startScroller.bind(this));//page scroller listner
		}
		//listen for click on close Viewer button.
		Event.observe( this.closeButton, 'click', this.closeViewer.bind(this) );
	},
	redraw: function(element){
		//Force Redraw. http://ajaxian.com/archives/forcing-a-ui-redraw-from-javascript
		//element = $(element);
		//alert(element);
		var n = document.createTextNode(' ');
		element.appendChild(n);
		(function(){n.parentNode.removeChild(n)}).defer();
		return element;
	},
	startScroller: function(event) {
		//define selected product <li> element.
		var myProductElement = Event.element(event).inspect() == '<img>' || Event.element(event).inspect() == '<span>' ? Event.element(event).ancestors()[1] : Event.element(event).ancestors()[0];
		
		if (!this.initiated){
			//another duplicate scroll to try and kick it in on teh frist click
			Effect.ScrollTo(myProductElement.ancestors()[0], {offset:-190});//, { duration: .5 } //, {offset:-190}	
			this.initiated = true;//true
			//alert('x');
		}
		
	},
	startViewer: function(event) {
		

		//define selected product <li> element.
		var myProductElement = Event.element(event).inspect() == '<img>' || Event.element(event).inspect() == '<span>' ? Event.element(event).ancestors()[1] : Event.element(event).ancestors()[0];
		
		//attempt at resolving a fustrating ui render / flash memory bug
		this.redraw( Event.element(event).ancestors()[2] );
		//attempt2 - hide flash
		//$("flasharea").hide();  
		var myExpandedHeight = (parseInt(flashHeight) + parseInt(growLength));
		//alert(myExpandedHeight);
		flashExpanded ? $("hacksaw").setStyle({ display: '', height:myExpandedHeight }) : $("hacksaw").setStyle({ display: '', height:(flashHeight) });
		$("flasharea").setStyle({ visibility: 'hidden' });
		
		//alert(window.scrollTop);// or document.scrollTop
		
		//toggle viewer only if it isn't currently animationg
		if (this.myAnimation == false){
			if( this.previousSelection == myProductElement ){
				//toggle Viewer shut if clicking the previousSelection again.
				myProductElement.removeClassName("active");
				this.closeViewer();
				this.previousSelection = false;
				$("hacksaw").setStyle({ display: 'none' });
				$("flasharea").setStyle({ visibility: 'visible' });
			}else{
				
				//display Viewer and close first if already open. 
				if(document.getElementById('productViewer').style.display == 'none'){//document.getElementById('productViewer').getStyle('display')
					//scroll to the postioin on the page
					this.initiated ? Effect.ScrollTo(myProductElement.ancestors()[0]):"";
					
					this.showViewer(myProductElement);
				}else{
					var self = this;
					this.myAnimation = Effect.BlindUp(document.getElementById('productViewer'), { duration: .35, afterFinish: function(){
						this.myAnimation = false;
						
						//scroll to the postioin on the page
						self.initiated ? Effect.ScrollTo(myProductElement.ancestors()[0]):"";
						
						self.showViewer(myProductElement);
					} });
				}
				this.previousSelection = myProductElement;
			}	
		}else{
			//still animating - do nothing
		}
	},
	showViewer: function(myProductElement){
		//deactivate current product selection.
		this.unactivateProducts();
		
		
		if (this.insertProductData(myProductElement)){
			//add active class to selected Product
			myProductElement.addClassName("active");
			
			//move Viewer under myProductElement(<li>) parent(<ul>). 
			myProductElement.ancestors()[0].insert( {after:document.getElementById('productViewer') } );
			
			//position Viewer arrow
			var xOffset = (parseInt(myProductElement.previousSiblings().length) * 155) + ((157/2)-8);//the width of the myProductElement can be dynamic but this gives more control...
			document.getElementById('productViewerArrow').style.backgroundPosition = xOffset+"px top";
			
			//show Viewer 
			//document.getElementById('productViewer').style.display = "block";
			var self = this;
			this.myAnimation = Effect.BlindDown(document.getElementById('productViewer'), { duration: .6, afterFinish: function(){
				self.myAnimation = false;
				$("hacksaw").setStyle({ display: 'none' });
				$("flasharea").setStyle({ visibility: 'visible' });
			}, transition: Effect.Transitions.sinoidal });//  , transition: Effect.Transitions.spring //Effect.Transitions.Bounce //Effect.Transitions.BouncePast //Effect.Transitions.SwingTo
		}else{
			this.myAnimation = false;
		}
	},
	closeViewer: function(event) {
		var self = this;
		this.myAnimation = Effect.BlindUp(document.getElementById('productViewer'), { duration: .35, afterFinish: function(){
			self.unactivateProducts();
			self.myAnimation = false;
			self.previousSelection = false;
		} });
	},
	unactivateProducts: function(){
		//remove active class from curret selection, err - from all products...
		for (var a=0; a<this.products.length; a++) { 
			if( this.products[a].hasClassName("active") ){
				this.products[a].removeClassName("active");			
			}
		}
	},
	loadProductsData: function(){
		var self = this;
		new Ajax.Request(this.productDataLocation, {
			method: 'get',
			onSuccess: function(transport) 
			{
				//alert(transport.responseText);
				self.parseProductData(transport.responseText);
			}
		});
	},
	parseProductData: function(data){
		
		//this.listenToMe();
		//create xml object. see: http://www.w3schools.com/Xml/xml_parser.asp
		try //Internet Explorer
		{
			xmlDoc=new ActiveXObject("Microsoft.XMLDOM");
			xmlDoc.async="false";
			xmlDoc.loadXML( data );
		} catch(e) {
			try //Standard - Firefox, Mozilla, Opera, Safari etc.
			{
				parser=new DOMParser();
				xmlDoc=parser.parseFromString( data, "text/xml");
			} catch(e) {
				alert(e.message);
				return;
			}
		}
		
		//define this.productData['productIdString']={json data} using ternary operator method to allow blank values... but all fields still must be present even if blank..
		var myProducts = xmlDoc.getElementsByTagName("product");
		
		//First populate pulldown image array and preload. its own loop is only way it works?@!?>!?!
		for(var p=0; p<myProducts.length; p++){ this.pulldownImages.push( (myProducts[p].getElementsByTagName("imageDetail")[0].childNodes[0] && myProducts[p].getElementsByTagName("imageDetail")[0].childNodes[0].nodeValue!='' ? ("../../images/products/productPulldown/"+myProducts[p].getElementsByTagName("imageDetail")[0].childNodes[0].nodeValue) : "blank.gif")  ); } 
		preloadImages( this.pulldownImages );
		
		//Populate Data Objects
		for(var p=0; p<myProducts.length; p++){
			
			this.productData.products[ myProducts[p].getElementsByTagName("id")[0].childNodes[0].nodeValue ]  = {
				"id":myProducts[p].getElementsByTagName("id")[0].childNodes[0].nodeValue,
				"category":myProducts[p].getElementsByTagName("category")[0].childNodes[0] ? myProducts[p].getElementsByTagName("category")[0].childNodes[0].nodeValue : "",
				"name":myProducts[p].getElementsByTagName("name")[0].childNodes[0] ? myProducts[p].getElementsByTagName("name")[0].childNodes[0].nodeValue : "",
				"description":myProducts[p].getElementsByTagName("description")[0].childNodes[0] ? myProducts[p].getElementsByTagName("description")[0].childNodes[0].nodeValue : "",
				"image":myProducts[p].getElementsByTagName("image")[0].childNodes[0] && myProducts[p].getElementsByTagName("image")[0].childNodes[0].nodeValue!='' ? myProducts[p].getElementsByTagName("image")[0].childNodes[0].nodeValue : "blank.gif",
				"imageDetail":myProducts[p].getElementsByTagName("imageDetail")[0].childNodes[0] && myProducts[p].getElementsByTagName("imageDetail")[0].childNodes[0].nodeValue!='' ? myProducts[p].getElementsByTagName("imageDetail")[0].childNodes[0].nodeValue : "blank.gif",
				"link":{
					"label":myProducts[p].getElementsByTagName("link")[0].getElementsByTagName("label")[0].childNodes[0] ? myProducts[p].getElementsByTagName("link")[0].getElementsByTagName("label")[0].childNodes[0].nodeValue : "",
					"url":myProducts[p].getElementsByTagName("link")[0].getElementsByTagName("url")[0].childNodes[0] ? myProducts[p].getElementsByTagName("link")[0].getElementsByTagName("url")[0].childNodes[0].nodeValue : ""
				},
				"related":[],
				"contact":[],
				"phone":myProducts[p].getElementsByTagName("phone")[0].childNodes[0] ? myProducts[p].getElementsByTagName("phone")[0].childNodes[0].nodeValue : false,
				"actionTitle":myProducts[p].getElementsByTagName("actionTitle")[0] ? myProducts[p].getElementsByTagName("actionTitle")[0].childNodes[0].nodeValue : "HOW TO BUY"
			}
			//populate contact array.
			for(var ca=0; ca<myProducts[p].getElementsByTagName("contact")[0].getElementsByTagName("link").length; ca++){
				this.productData.products[ myProducts[p].getElementsByTagName("id")[0].childNodes[0].nodeValue ].contact[ca] = {
					"label":myProducts[p].getElementsByTagName("contact")[0].getElementsByTagName("link")[ca].getElementsByTagName("label")[0].childNodes[0] ? myProducts[p].getElementsByTagName("contact")[0].getElementsByTagName("link")[ca].getElementsByTagName("label")[0].childNodes[0].nodeValue : "",
					"url":myProducts[p].getElementsByTagName("contact")[0].getElementsByTagName("link")[ca].getElementsByTagName("url")[0].childNodes[0] ? myProducts[p].getElementsByTagName("contact")[0].getElementsByTagName("link")[ca].getElementsByTagName("url")[0].childNodes[0].nodeValue : ""
				}
			}
			//populate related array.
			for(var ra=0; ra<myProducts[p].getElementsByTagName("related")[0].getElementsByTagName("link").length; ra++){
				this.productData.products[ myProducts[p].getElementsByTagName("id")[0].childNodes[0].nodeValue ].related[ra] = {
					"label":myProducts[p].getElementsByTagName("related")[0].getElementsByTagName("link")[ra].getElementsByTagName("label")[0].childNodes[0].nodeValue,
					"url":myProducts[p].getElementsByTagName("related")[0].getElementsByTagName("link")[ra].getElementsByTagName("url")[0].childNodes[0].nodeValue
				}
			}
		}
	},
	insertProductData: function(myElement){
		var myId = myElement.firstDescendant().readAttribute('rel');
		
		if(this.productData.products[myId]){//if this has data update pulldown innerHTML
			document.getElementById('pimg').innerHTML = "<img src=\""+this.relUrl+"images/products/productPulldown/"+this.productData.products[myId].imageDetail+"\" alt=\"Motorola Product\" />";
			document.getElementById('pdesc').innerHTML = this.productData.products[myId].description;
			document.getElementById('paction').innerHTML = "<a href=\""+this.productData.products[myId].link.url+"\" onClick=\"return dcsMultiTrack('WT.ti', 'Explore "+this.productData.products[myId].category+" Navigation: "+this.productData.products[myId].name+"','WT.cg_n', 'Explore Navigation: "+this.productData.products[myId].category+"', 'WT.cg_s', '"+this.productData.products[myId].name+"', 'DCSext.action', 'Explore Nav: Business Product and Service;"+this.productData.products[myId].category+";"+this.productData.products[myId].name+";"+this.productData.products[myId].link.label+"', 'WT.si_n','Explore Business Product and Services Selection','WT.si_x','3', 'DCSext.b2bexplorenav', '"+this.productData.products[myId].link.label+"');\">"+this.productData.products[myId].link.label+" <img src=\""+this.relUrl+"images/icons/carrot-blueoncharcole.gif\" alt=\"more\" /></a>";
			
			//live 
			//onClick="return dcsMultiTrack('WT.ti', 'Explore Devices Navigation: Mobile Computers','WT.cg_n', 'Explore Navigation: 
			//Devices', 'WT.cg_s', 'Mobile Computers', 'DCSext.action', 'Explore Nav: Business Product and Service;Devices;Mobile 
			//Computers;Learn more about Mobile Computers', 'WT.si_n','Learn more about Mobile Computers'
			//,'WT.si_x','3', 'DCSext.b2bexplorenav', 'Learn more about Mobile Computers');"
			
			//sample
			//onClick="return dcsMultiTrack(‘WT.ti’, ‘Explore Devices Navigation: Mobile Computers’,’WT.cg_n’, ‘Explore Navigation:  
			//Devices’, ‘WT.cg_s’, ‘Mobile Computers’, ‘DCSext.action’, ‘Explore Nav: Business Product and Service;Devices;Mobile  
			//Computers;Learn More about Mobile Computers', 'WT.si_n','Explore Business Product and Services  
			//Selection','WT.si_x','3', 'DCSext.b2bexplorenav', 'Learn More about Mobile Computers');" 
						
			//this.productData.products[myId].name //category
			//document.getElementById('pcontactphone').innerHTML = this.productData.products[myId].phone;
			
			document.getElementById('actionTitle').innerHTML = this.productData.products[myId].actionTitle;
			
			var contactData=this.productData.products[myId].phone ? "<p>"+this.productData.products[myId].phone+"</p>" : ""; 
			for(var ra=0; ra<this.productData.products[myId].contact.length; ra++){ 
				if(this.productData.products[myId].contact[ra].label != ''){
					contactData = contactData + "<a href=\""+this.productData.products[myId].contact[ra].url+"\" onClick=\"return dcsMultiTrack('WT.ti', 'Explore "+this.productData.products[myId].category+" Navigation: "+this.productData.products[myId].name+"','WT.cg_n', 'Explore Navigation: "+this.productData.products[myId].category+"', 'WT.cg_s', '"+this.productData.products[myId].name+"', 'DCSext.action', 'Explore Nav: Business Product and Service;"+this.productData.products[myId].category+";"+this.productData.products[myId].name+";"+this.productData.products[myId].contact[ra].label+"', 'WT.si_n','Explore Business Product and Services','WT.si_x','3', 'DCSext.b2bexplorenav', '"+this.productData.products[myId].contact[ra].label+"');\">"+this.productData.products[myId].contact[ra].label+" <img src=\""+this.relUrl+"images/icons/carrot-blueoncharcole.gif\" alt=\"more\" /></a>\n";
				}
			}
			document.getElementById('pcontact').innerHTML = contactData;
			
			var relatedData=''; 
			var col1 = "";
			var col2 = "";
			var col3 = "";
			for(var ra=0; ra<this.productData.products[myId].related.length; ra++){
				//relatedData = relatedData + "<li><a href=\""+this.productData.products[myId].related[ra].url+"\">"+this.productData.products[myId].related[ra].label+"</a></li>\n";
				//if((ra % 3)==2){ relatedData = relatedData + "<li class='clear'></li>" }
				
				// return dcsMultiTrack(
					//'WT.ti', 'Explore Devices Navigation: Mobile Computers',
					//'WT.cg_n', 'Explore Navigation: Devices', 
					//'WT.cg_s', 'Mobile Computers', 
					//'DCSext.action', 'Explore Nav: Business Product and Service;Devices;Mobile Computers;Wearable Computers', 
					//'WT.si_n','Explore Business Product and Services',
					//'WT.si_x','3', 
					//'DCSext.b2bexplorenav', 'Wearable Computers'
					//);
				
				
				
				switch(ra % 3)
				{
				case 0:
				  col1 = col1 + "<a href=\""+this.productData.products[myId].related[ra].url+"\" onClick=\"return dcsMultiTrack('WT.ti', 'Explore "+this.productData.products[myId].category+" Navigation: "+this.productData.products[myId].name+"','WT.cg_n', 'Explore Navigation: "+this.productData.products[myId].category+"', 'WT.cg_s', '"+this.productData.products[myId].name+"', 'DCSext.action', 'Explore Nav: Business Product and Service;"+this.productData.products[myId].category+";"+this.productData.products[myId].name+";"+this.productData.products[myId].related[ra].label+"', 'WT.si_n','Explore Business Product and Services','WT.si_x','3', 'DCSext.b2bexplorenav', '"+this.productData.products[myId].related[ra].label+"');\">"+this.productData.products[myId].related[ra].label+"</a>\n";
				  break;    
				case 1:
				  col2 = col2 + "<a href=\""+this.productData.products[myId].related[ra].url+"\" onClick=\"return dcsMultiTrack('WT.ti', 'Explore "+this.productData.products[myId].category+" Navigation: "+this.productData.products[myId].name+"','WT.cg_n', 'Explore Navigation: "+this.productData.products[myId].category+"', 'WT.cg_s', '"+this.productData.products[myId].name+"', 'DCSext.action', 'Explore Nav: Business Product and Service;"+this.productData.products[myId].category+";"+this.productData.products[myId].name+";"+this.productData.products[myId].related[ra].label+"', 'WT.si_n','Explore Business Product and Services','WT.si_x','3', 'DCSext.b2bexplorenav', '"+this.productData.products[myId].related[ra].label+"');\">"+this.productData.products[myId].related[ra].label+"</a>\n";
				  break;
				case 2:
				  col3 = col3 + "<a href=\""+this.productData.products[myId].related[ra].url+"\" onClick=\"return dcsMultiTrack('WT.ti', 'Explore "+this.productData.products[myId].category+" Navigation: "+this.productData.products[myId].name+"','WT.cg_n', 'Explore Navigation: "+this.productData.products[myId].category+"', 'WT.cg_s', '"+this.productData.products[myId].name+"', 'DCSext.action', 'Explore Nav: Business Product and Service;"+this.productData.products[myId].category+";"+this.productData.products[myId].name+";"+this.productData.products[myId].related[ra].label+"', 'WT.si_n','Explore Business Product and Services','WT.si_x','3', 'DCSext.b2bexplorenav', '"+this.productData.products[myId].related[ra].label+"');\">"+this.productData.products[myId].related[ra].label+"</a>\n";
				  break;
				default:
				}
			}
			col1 = "<li>"+col1+"</li>";
			col2 = "<li>"+col2+"</li>";
			col3 = "<li>"+col3+"</li>";
			relatedData = col1 + col2 + col3;
			document.getElementById('prelated').innerHTML = relatedData;
			
			document.getElementById('prelatedtitle').innerHTML = relatedData=='' ? "" : "Or go directly to related categories:";//this can potentially be dynamic,
			this.productData.products[myId].related.length == 0 ? document.getElementById('prelatedtitle').style.display='none' : document.getElementById('prelatedtitle').style.display='';

			return true;
		}else{//if this dosent have data return false and don't continue.
			return false;
		}
	}
});





/* Image Preloader */
function preloadImages(image_url) //image_url is an array, includes image path!
{
	//alert(image_url);
	if (document.images)
	{
		for(var i=0; i< (image_url.length-1); i++)
		{
	 		preload_image_object = new Image();
			preload_image_object.src = image_url[i];
		}
		return true;
	}
}






/* fix for search input field cursor in ff2 */
/*var inputWrapperDiv = $$('.nav_search');

//if (YAHOO.ext.util.Browser.isGecko) {
inputWrapperDiv.style.display = 'none';
inputWrapperDiv.style.overflow = 'auto';
setTimeout(function() {inputWrapperDiv.style.display = 'block';}, 10);
//}*/
