function hpInit() {
	addLocaleSelectorEvents();
}

Element.extend(
	{
		hide: function() 
		{
			return this.setStyle('display', 'none');
		},
		
		show: function() 
		{
			return this.setStyle('display', '');
		}
	});

	var DropdownMenu = new Class({	
		initialize: function(element)
		{
			$A($(element).childNodes).each(function(el)
			{
				if(el.nodeName.toLowerCase() == 'li')
				{
					$A($(el).childNodes).each(function(el2)
					{
						if(el2.nodeName.toLowerCase() == 'ul')
						{
							$(el2).hide();
							
							el.addEvent('mouseover', function()
							{
								el2.show();
								return false;
							});
	
							el.addEvent('mouseout', function()
							{
								el2.hide();
							});
							new DropdownMenu(el2);
						}
					});
				}
			});
			return this;
		}
	});

Window.onDomReady(function(){
		homeReady = true; //
	});

/* =======[ BEGIN BROWSER DETECTION ]========================== */
var agt=navigator.userAgent.toLowerCase();
var is_major = parseInt(navigator.appVersion);
var is_ie	= (agt.indexOf("msie") != -1);
var is_ie6  = (is_ie && (is_major == 4) && (agt.indexOf("msie 6.")!=-1) );
var is_ie7  = (is_ie && (is_major == 4) && (agt.indexOf("msie 7.")!=-1) );
var is_ie8  = (is_ie && (is_major == 4) && (agt.indexOf("msie 8.")!=-1) );
var is_win  = ( (agt.indexOf("win")!=-1) || (agt.indexOf("16bit")!=-1) );
/* =======[ END BROWSER DETECTION ]========================== */


/* =======[ BEGIN GLOBAL VARIABLES ]========================== */
var supportPgType = '';
var supportText = '';
var hp_sup_flag = null;
var jawsIndex = 0;
var tabTimer = null;
var histTimer = null;
var homeReady = false;
var hp_explore_img_num;
var HHO = 0;
var SMB = 1;
var LEB = 2;
var GHE = 3;
var GA = 4;
/* =======[ END GLOBAL VARIABLES ]========================== */


/* =======[ BEGIN PRODUCT AJAX CALL ]========================== */
function getProduct() {
	
	var customerSegment = (_Ck_.get('hp_cust_seg_sel')) ? _Ck_.get('hp_cust_seg_sel') : 'HHO';
	RT.stop();
	
	if(!IsThumbnail){		
		
		var products = hpAbsDir+"products.html";	
		var beginVar = '<!-- BEGIN PRODUCTS ACCORDION -->'; var endVar = '<!-- END PRODUCTS ACCORDION -->';

		if(GetContentByToken){		
			GetContentByToken(products, false, 'dynamicArea', false, '', 'Error...', beginVar, endVar);
			
			RT.isExtLinkEvents = true;
			RT.playSpeed = 6000;
			RT.load('mainWideColumn', 'blockAccordion', accImgs);			
			
				$('#blockAccordion').hoverAccordion({
				  activateitem: (window[customerSegment]+1),
				  speed: 'fast',
				  onHoverExpand: function(a){ RT.linksEvent(a.className); },
				  onClickExpand: function(a){ RT.linksEvent(a.className); }
			});
								
			RT.addControlersEvent();
			
			$('.linksUnit a').click(function(){
				var cls = this.className.split(' '); 
				if(cls[1] && cls[1] == 'sw'){
					setCk(product_cookie, 'software'); 
					setCk('hp_cust_seg_sel', 'LEB'); 
				}else{ 
					if(cls[0].toUpperCase() == 'LEB' && _Ck_.get(product_cookie)) { _Ck_.set(product_cookie, "false"); _Ck_.del(product_cookie); }
					setCk('hp_cust_seg_sel', cls[0].toUpperCase());
				}					
			});	
			
			$('#blockAccordion .linksUnit a').mousedown(function(){
				var cls = this.className.split(' ');
				s_objectID=objIDver("gw/us/en/welcomeOV2/msg-1/l1/"+cls[0]+"/link:"+this.firstChild.nodeValue.substr(0,34)+"/fixed"); s_hp_fixObjectID(s_objectID);				
			});
			
			$('#rt_controls').css('top', 390);
			try  
			{
			RT.play();			
		}
			catch(err){}						
		}
	
	} else {  // Thumbnail version	
		
		var products = hpAbsDir+"products_thumbnail.html";
		var beginVar = '<!-- BEGIN PRODUCTS THUMB -->';
		var endVar = '<!-- END PRODUCTS THUMB -->';
		//activeThumb = 'HHO';
		
		if(GetContentByToken){		
			GetContentByToken(products, false, 'dynamicArea', false, '', 'Error...', beginVar, endVar);

			RT.playSpeed = 6000;
			RT.load('messaging', 'productTabs', msgImgs);
			RT.play();
	
			$("#productTabs a").hoverIntent({ sensitivity: 3, interval: 200, over: changeThumbsEvent, timeout: 200, out: function(){} });
			$("#productTabs a").focus(changeThumbsEvent);			
			
			$('.productTile a').click(function(){ 
				var cls = this.className.split(' '); 
				if(cls[1] && cls[1] == 'sw'){
					setCk(product_cookie, 'software'); 
					setCk('hp_cust_seg_sel', 'LEB'); 
				}else{ 
					if(cls[0].toUpperCase() == 'LEB' && _Ck_.get(product_cookie)) { _Ck_.set(product_cookie, "false"); _Ck_.del(product_cookie); }
					setCk('hp_cust_seg_sel', cls[0].toUpperCase());
				}	
			});	
			
			$('#productTab'+customerSegment).addClass('productTabSelected');
			
			$('#productThumbnails a').mousedown(function(){
				var cls = this.className.split(' ');
				s_objectID=objIDver("gw/us/en/welcomeOV2/msg-1/l1/"+cls[0]+"/thumb:"+this.lastChild.firstChild.nodeValue.substr(0,34)+"/fixed"); s_hp_fixObjectID(s_objectID);				
			});
			
			RT.addToLinksEvent = function(){
				changeThumbs(RT.imgs[RT.index].segment);
			}
			thumbRefresh = true;
			changeThumbs(customerSegment);			
		}
	}
}
/* =======[ END PRODUCT AJAX CALL ]========================== */



/* =======[ BEGIN SUPPORT AJAX CALL ]========================== */

function getSupport() {

	var beginVar = '<!-- BEGIN SUPPORT -->';
	var endVar = '<!-- END SUPPORT -->';
	var supCk = _Ck_.get('hp_sup_opt');
	if(supCk != null) supCk=unescape(supCk);
	GetContentByToken(hpAbsDir+'welcome_support.html', false, 'dynamicArea', false, '', 'Error...', beginVar, endVar);
	drawGMNButton();	
	if(supCk){
		supportSelectedRadio = supCk.split('|')[0];
		ckSupText = supCk.split('|')[1];
	}
	if (!supCk || !supportSelectedRadio) {
		toggleSupportBottom(false);
	}else{
		// User has already visited this tab and clicked on a radio button so no need to gray-out the bottom part
		$('#'+supportSelectedRadio).attr('checked', true);
		supportPgType = (supportSelectedRadio=='drivers') ? 's-002' : 's-001';		
		if ( hp_sup_flag == 'sp' && ckSupText ){
			supportText = ckSupText.replace(/\+/g,' ');
			hp_sup_flag = null;
			supportSessionCk('', 'sup_txt');
		}
	}
	$('#productInfo').attr('value', supportText);
	$('.supportContentBlock a').click( function(){ if(supportPgType){ this.href = this.href.replace(/h_pagetype=s-00(\d)/,'h_pagetype='+supportPgType); } else return; } );
}

/* =======[ END SUPPORT AJAX CALL ]========================== */


/* =======[ BEGIN EXPLORE AJAX CALL ]========================== */

function getExplore() {
	
	GetContentByToken(hpAbsDir+'explore.html', false, 'dynamicArea', false, '', 'Error...', '<!-- BEGIN EXPLORE -->', '<!-- END EXPLORE -->');	
	//Add mouse-over behavior of links
	$('#mainNarrowColumn a').hoverIntent( function(){exploreSwap( this.id.substring( 11, this.id.length ) );}, function(){} );
	$('#mainNarrowColumn a').focus( function(){delay_exploreLink(true, this.id.substring( 11, this.id.length ))} );	
	$('#mainNarrowColumn a').click( function(){setCk('hp_cust_seg_sel', this.className.toUpperCase()); saveHist(getHash(hp_explore_img_num)); }, function(){} );

	if(hp_explore_img_num)
		$('#mainWideColumn').html('<img id="exploreMain" name="exploreMain" src="'+hpCoreDir+hpImgDir+explore_src[hp_explore_img_num]+'" alt="'+explore_alt[hp_explore_img_num]+'" usemap="#expSegImgMap_' + hp_explore_img_num +'" height="425" width="683">'+explore_map[hp_explore_img_num]);
	hp_explore_img_num = null;
	preLoadExplore();
}
/* =======[ END EXPLORE AJAX CALL ]========================== */


/* =======[ BEGIN EXPLORE CODE ]========================== */


function preLoadExplore() {
	exploreImageCurrent = -1;
	if ((explorePreloadCount > 0) && (explorePreloadCount == explorePreloadImage.length)) return;  //Skip preloading if the user has already viewed this tab
	
	for(var i=0; i<explore_src.length; i++){
		explorePreloadImage[i] = new Image;
		explorePreloadImage[i].onload = function(){explorePreloadCount++;};   // When the image is loaded, increment the preloaded counter
		explorePreloadImage[i].src = hpCoreDir+hpImgDir+explore_src[i];
	}
}

function exploreSwap(imgNumber) {
	hp_explore_img_num = imgNumber;
	if ( (explorePreloadCount == explorePreloadImage.length) && (imgNumber != exploreImageCurrent) ) {
		var mainNodeImg = $('#exploreMain');
		$('#mainWideColumn').empty().html(mainNodeImg).children().after(explore_map[imgNumber]);
		mainNodeImg.attr('useMap', '#expSegImgMap_' + imgNumber);
		mainNodeImg.attr('src', explorePreloadImage[imgNumber].src);
		mainNodeImg.attr('alt', explore_alt[imgNumber]);		
		slideLeft('#mainWideColumn', 500);
		exploreImageCurrent = imgNumber;
	}
}

//Fix for focus lost
var linkTimer=null;
function delay_exploreLink(_v,imgNumber) {
	if (linkTimer) {
		clearTimeout(linkTimer);
		linkTimer = null;
	}	
	if(_v)
		linkTimer = setTimeout('exploreSwap('+imgNumber+');',400);
}

function slideLeft(element, speed, func){
	var getWidth = $(element).parent().width();
    var setWidth = - getWidth;
	$(element).show();	
	$(element).css('left', setWidth);	
	 setWidth = setWidth + getWidth;				
	$(element).animate({left: setWidth}, speed, func);
	$('#JAWSUpdate').attr('className', 'jaws'+(jawsIndex++));
	return false;
}

/* =======[ END EXPLORE CODE ]========================== */


/* =======[ BEGIN SUPPORT CODE ]========================== */

var supportSelectedRadio = null;
function drawGMNButton() {
	// This function decides whether or not to draw the "product detection" button.
	// This button has its own FORM. Nested html forms are invalid, so it is moved into right position in this function.
	var str = "";
	if( is_ie && is_win && (is_ie6 || is_ie7)){
		str = '<div>\n\
			<h3 class="bold" style="font-size: 120%;">Or automatically detect products</h3>\n\
			<div class="topSpaceSmall bottomSpace"></div>\n\
			<div style="text-align:right">\n\
			<form action="http://h20270.www2.hp.com/ediags/gmn2/index.aspx" method="get" name="productDetect" id="productDetect" class="zeroMargin">\n\
			<input type="submit" name="detectProducts" class="grayButton" tabindex="46" value="Start Detection &raquo;">\n\
			<input type="hidden" name="lc" value="en">\n\
			<input type="hidden" name="cc" value="us">\n\
			</form>\n\
			<div class="small topSpace linkColor">&raquo;&nbsp;<a href="http://h20270.www2.hp.com/ediags/gmn2/index.aspx?about=yes" tabindex="46">About automatic product detection</a></div>\n\
			</div>\n\
			</div>';
		$('#supportProductSearch').css('borderRight', '1px solid #999');
	}
	if (str != "") {
		var btnNode = $("#supportProductDetect");		
		if (btnNode.length > 0) {
			btnNode.css('display', 'block').css('top', document.getElementById("supportProductSearch").offsetParent.offsetTop + "px").html(str);	
		}
	}
}

function toggleSupportBottom(visible) {
	var tabIndex = 46;
	var unClickable = document.getElementById('unClickable');
	if (!visible) {
		document.productQuery.h_query.disabled = true;
		document.getElementById("supportSubmitBtn").disabled = true;
		if ( document.getElementById("detectProducts") )
			document.getElementById("detectProducts").disabled = true;
		$('#supportLeftColumn a').attr("tabIndex", "-1");
		unClickable.style.display = 'block';
		unClickable.style.height = (unClickable.offsetParent.offsetHeight - unClickable.offsetTop) + 'px';
	} else {
		if (unClickable.style.display == 'block') {
			// If bottom part is grayed-out then activate it else skip
			document.productQuery.h_query.disabled = false;
			document.getElementById("supportSubmitBtn").disabled = false;
			if ( document.getElementById("detectProducts") )
				document.getElementById("detectProducts").disabled = false;
			$('#supportLeftColumn a').attr("tabIndex", tabIndex);
			unClickable.style.display = 'none';
		}
	}
}

//Begin Empty text field validation
function validText() {
	if  (document.productQuery.h_query.value == "" || document.productQuery.h_query.value == document.productQuery.h_query.defaultValue) {
	} return true;
}
	
// Clear text box information function
function clearText(textInfo){
	if (textInfo.value == textInfo.defaultValue)
		textInfo.value = "" ;	
}

// Begin Form Validation
function validateForm(){
	if (!validText())
	return false;
	if ( document.productQuery.h_pagetype[0].checked==false && document.productQuery.h_pagetype[1].checked==false )
		 document.productQuery.h_pagetype[1].checked = true;	
	return true;
}

var activeSeg = 'None';
var tabtimerID=null;

function delay_changeTab(_v,func,linkID) {
	if(func != activeTab){
		if(_v){
			tabtimerID = setTimeout( "simulateClick('"+linkID+"');", 400 );
		} else {
			if(tabtimerID) {
				clearTimeout(tabtimerID);
				tabtimerID=null;
			}
		}
	}
}

function supportSessionCk(v,o) {
	var ckVal = [];
		ckVal = (_Ck_.get('hp_sup_opt')) ? _Ck_.get('hp_sup_opt').split('|') : ['',''];
	if(v, o == 'sup_opt'){ 
		ckVal[0] = escape(v);
	}else if(v, o == 'sup_txt'){
		ckVal[1] = escape(v);
	}
	document.cookie = "hp_sup_opt="+ ckVal[0]+"|"+ckVal[1] +"; " + ((hp_cookie_domain) ? "; domain=" + hp_cookie_domain : "") + ((hp_cookie_path) ? "; path=" + hp_cookie_path : "");
}

window.onbeforeunload = function(){		
	if(supportText){
		saveHist(addHash('sp'));
		supportSessionCk(escape(supportText.replace(/ /g,'+')), 'sup_txt');
	}else{ return; }
}
/* =======[ END SUPPORT CODE ]========================== */

/* =======[ BEGIN TAB FUNCTIONS ]========================== */

function simulateClick(linkID) {
	if(tabtimerID) {
		clearTimeout(tabtimerID);
		tabtimerID=null;
	}
	var linkNode = document.getElementById(linkID);
	if ( document.createEvent ) {
		var evt = document.createEvent("MouseEvents");
		evt.initMouseEvent("click", true, true, window, 0, 0, 0, 0, 0, false, false, false, false, 0, null);
		linkNode.dispatchEvent(evt);
		location.href = linkNode.href;
	} else {
		linkNode.click();
	}
}

function tabChanged(tabName){
	RT.stop();
	
	var hashArray = window.location.hash.split('_');
	if(hashArray[1] || hashArray[2] || hashArray[3]){
		//rememberMe = true;
		hp_explore_img_num = hashArray[1];
		hp_sup_flag = hashArray[3];
	}	
	if(tabName != activeTab ) {
		if(!supportText){
			supportText = ($('#productInfo').length > 0) ? $('#productInfo').attr('value') : '';
		}else{
			supportText = (activeTab == 'Support')? $('#productInfo').attr('value') : supportText;	
		}	
		if(tabtimerID) {
			clearTimeout(tabtimerID);
			tabtimerID=null;
		}
		// save tab change in history		
		saveHist(tabName);
		
		$('#tab'+activeTab+'Link span').html(' - Tab');

			if(activeTab == 'Product' && IsSupportTab) { $('#grayDividerB').css('borderRight', '2px solid #CCCCCC'); /*$('.grayDivider').not('#grayDividerC').css('borderRight', '2px solid #CCCCCC');*/ }
			else if(activeTab == 'Support') { $('#grayDividerA').css('borderRight', '2px solid #CCCCCC'); /*$('.grayDivider').not('#grayDividerA').css('borderRight', '2px solid #CCCCCC');*/ }
	

		$("#tabNav a").css({ fontSize: '100%', color: '#FFF'}).parent().css('marginTop', '').parent().css('background', '');
		
		// Highlight new tab			
		if(tabName == 'Product') {
			$('#grayDividerA').css('borderRight', '0px');
			
			if(IsSupportTab) $('#grayDividerB').css('borderRight', '2px solid #CCCCCC');

		}else if(tabName == 'Support') { 
			$('#grayDividerB').css('borderRight', '0px');
			$('#grayDividerA').css('borderRight', '2px solid #CCCCCC');

			$("#tabProduct").css('paddingLeft', '20px');		
			
		}else if(tabName == 'Explore') { 
			$('#grayDividerA').css('borderRight', '0px');	
			if(IsSupportTab) $('#grayDividerB').css('borderRight', '0px');
			
		}
		
		$('#tab'+tabName+'Link span').html(' - Tab Selected');
		$("#tab"+tabName+"Link").css({ fontSize: '120%', color: '#000'}).parent().css('marginTop', '16px').parent().css('background', '#FFF');		
		// Metrics	
		
		if (typeof s_sendAnalyticsEvent == "function") {
			if(tabName == 'Product'){ s_screen="shop for products"; s_sendAnalyticsEvent("",d_pageName);}
			else if(tabName == 'Support'){ s_screen="support & drivers"; s_sendAnalyticsEvent("",d_pageName);}
			else if(tabName == 'Explore'){ s_screen="explore & create"; s_sendAnalyticsEvent("",d_pageName);}
		}		

		activeTab = tabName; 
		eval('get'+tabName+'()');
	}
	return false;
}

/* =======[ END TAB FUNCTIONS ]========================== */



/* =======[ BEGIN COUNTRY DROP-DOWN ]========================== */
	
	var toggleMenu = true;
	var closeMenuTimer = null;
	var mainEle = document.getElementById("localeSelectorMain");
	var sfEls = document.getElementById("localeSelector").getElementsByTagName("LI");	
	var navPrim = getElementsByClass('nav_primary', document.getElementById("localeSelector"));
	var secLink = getElementsByClass('sec_link', document.getElementById("localeSelector"));
	var sfElsByLinkClass = getElementsByClass('nav_link', document.getElementById("localeSelector"));

	$('localeSelectorContainer').addEvent('click', function(){ s_objectID=objIDver("gw/us/en/welcomeOV2/header/l1/none/country-selector/fixed"); s_hp_fixObjectID(s_objectID); });
//	$('#localeSelectorContainer .sec_link').click(function(){ s_objectID=objIDver("gw/us/en/welcomeOV2/header/l1/none/country-selector/fixed"); s_hp_fixObjectID(s_objectID); });
	
	var sfHover = function() { 
		for (var i=0; i<sfEls.length; i++) {
			sfEls[i].onmouseover=function() {
				this.className+=" sfhover";
			}
			sfEls[i].onmouseout=function() {
				this.className = this.className.replace('sfhover', '');
			}			
		}
		for (var i=0; i<sfElsByLinkClass.length; i++)	{
			sfElsByLinkClass[i].onmouseover=function() {
				this.style.backgroundColor='black';
			}
			sfElsByLinkClass[i].onmouseout=function() {
				this.style.backgroundColor='#333';
			}
		}
	}
	
	var addLocaleSelectorEvents = function(){
		
		for (var p=0; p<navPrim.length; p++){
			navPrim[p].getElementsByTagName('A')[0].onclick = function(){ return false; };
		}		
		
		mainEle.onfocus = function(){
			for (var i=0; i<sfEls.length; i++) {
				if (sfEls[i].id == 'nav_main')
						sfEls[i].className = sfEls[i].className.replace('sfhover', '');				
			} toggleMenu = true;	
		}		
		
		mainEle.onclick = function(){
			for (var i=0; i<sfEls.length; i++) {
				//add the sfhover class to all list in localeSelector
				if (sfEls[i].id == 'nav_main'){
					if(toggleMenu == true){
						sfEls[i].className+=" sfhover";
						toggleMenu = false;
					}else{
						sfEls[i].className = sfEls[i].className.replace('sfhover', '');
						toggleMenu = true;			
					}					
				}				
				if (sfEls[i].className.indexOf('nav_primary') != -1){								
					sfEls[i].onclick = function(){												
						this.className+=" sfhover";	
							
						for(var i=0; i<secLink.length; i++){
							secLink[i].onfocus = function(){ 
								if(this.className.indexOf('firs_of_last') != -1){
									closeMenu(false);
								}
								
								if(this.className.indexOf('before_last_of_last') != -1){
									closeMenu(false);
								}								
								this.style.backgroundColor = '#000'; 
							}
							
							secLink[i].onblur = function(){
								
								if(this.className.indexOf('last_of_sec_opt') != -1){
									closeMenu(true);
									for (var p=0; p<navPrim.length; p++){
										navPrim[p].className = navPrim[p].className.replace('sfhover', '');						
									}
								}
								this.style.backgroundColor = '#333'; 
							}
						}
					}
					
					sfEls[i].getElementsByTagName('A')[0].onfocus = function(){
						
						closeMenu(false);
						for (var p=0; p<navPrim.length; p++){
							navPrim[p].className = navPrim[p].className.replace('sfhover', '');						
						}
						this.style.backgroundColor = '#000000';
					}
					
					sfEls[i].getElementsByTagName('A')[0].onblur = function(){
						if(this.className.indexOf('last_opt') != -1){
							closeMenu(true);
						} this.style.backgroundColor = '#333';
					}					
				}				
				sfEls[i].className.replace('sfhover', '');
			}
			return false;		
		}			
	}
	
	function exitMenu(){
		for (var i=0; i<sfEls.length; i++) {
			sfEls[i].className = sfEls[i].className.replace('sfhover', '');
		}
		document.getElementById("localeSelectorMain").focus();
		toggleMenu = true;
	}
	
	function closeMenu(_v){
		if(closeMenuTimer) {
			clearTimeout(closeMenuTimer);
			closeMenuTimer = null;
		}
		if(_v)
			closeMenuTimer = setTimeout('exitMenu()',10);		
	} 
	
	function getElementsByClass(searchClass,node,tag) {
		var classElements = new Array();
		if (node == null)
				node = document;
		if (tag == null)
				tag = '*';
		var els = node.getElementsByTagName(tag);
		var elsLen = els.length;
		var pattern = new RegExp("(^|\\s)"+searchClass+"(\\s|$)");
		var j = 0;
		for (i = 0; i < elsLen; i++) {
			if (pattern.test(els[i].className) ) {
				classElements[j] = els[i];
				j++;
			}
		}
		return classElements;
	}
	
/* =======[ END COUNTRY DROP-DOWN ]========================== */

// 20081009