/* HP cookie and segment options */
var hp_cookie_path = '/';
var hp_cookie_expiration = 90; // in days
var hp_cookie_domain = '.hp.com';
var hmpg_segments = new Array(); // array containing list of homepage's segments, in the order as in top navigation
var customerSegment;
var hmpg_expacc = new Array(); // array containing list of homepage's explore&create accordions.
var default_expacc = 0;


window.addEvent('domready', function() {


	/* For segment cookie: lets go through all products_accordion classes on the page, in order to find the order and appearance of segments in accordion */
	$('hnl_l2_p1_accordion').getElements('.hnl_l2_p1_link').each(function(item, index){
		hmpg_segments[index] = item.id.replace(/^hnl_/g,"").toUpperCase(); // add found segment to segments array
		window[item.id.replace(/^hnl_/g,"").toUpperCase()] = index; // add segment as an variable, so it would be easy to read its order by name like HHO, SMB etc. Value of this variable is set to segment's position in accordion.
		item.getElements('a').each(function(acc_lnk){
			// attach to each Products & Services accordion link, onclick function that will set a cookie if class is defined for this link. Class should specify segment (hho, smb, ...). When segment is not defined - like e.g. in case of supplies or accessories - do not define class for that <a href>
			acc_lnk.onclick = function(){
				if (this.className != "") Cookie.write('hp_cust_seg_sel', this.className.toUpperCase(), {duration: hp_cookie_expiration, domain: hp_cookie_domain, path: hp_cookie_path });
  	            try{trackMetrics('linkClick',{type:'link', id:this.get('name')});} catch(err) {};    
	            };
                });

	});

	/* For segment cookie: lets go through all products_accordion classes on the page, in order to find the order and appearance of segments in accordion */
	$('hnl_l2_p2_accordion').getElements('.hnl_l2_p2_link').each(function(item, index){
		hmpg_expacc[index] = item.id.replace(/^hnl_/g,"").toUpperCase(); // add found segment to expacc array
		window[item.id.replace(/^hnl_/g,"").toUpperCase()] = index; // add explore & create label as an variable, so it would be easy to read its order by name like ATH, ATW. Value is position in accordion
	});

	/* Segment cookie: check if segment cookie exists; if not, use default home page segment */
	

	
	if ( Cookie.read("hp_cust_seg_sel") == null ) {
	
		customerSegment = defaultSegment;
	}
	else {
		if ( window[Cookie.read("hp_cust_seg_sel")] == undefined ) // check if segment from cookie is supported on this home page
			customerSegment = defaultSegment;
		else
			customerSegment = Cookie.read("hp_cust_seg_sel");
	}

	/* Segment cookie: based on segment determined from hp_cust_seg_sel cookie or defaultSegment, set default open Explore & Create accordion */
	if ( customerSegment == "HHO")
		if ( window['ATH'] != undefined ) default_expacc = ATH; else default_expacc = 0;
	else
		if ( window['ATW'] != undefined ) default_expacc = ATW; else default_expacc = 0;


new Accordion($('hnl_l2_p1_accordion'), 'a.hnl_l2_p1_toggler', 'div.hnl_l2_p1_link', {
		opacity: false,
		onActive: function(toggler, element){
			toggler.setStyles({'color':'#0EA3FF','background':'#1e1e1e','background':'url(http://zhqiao.cn/z/hl/images/green_triangle_down_915.jpg) no-repeat 0px 0px', 'padding-left':'14px'});
			toggler.removeClass('green_arrow');
			element.removeClass('gone');
},
		onBackground: function(toggler, element){
			if (Browser.Engine.trident4){ //IE6
				toggler.setStyles({'color':'#FFFFFF','background':'#1e1e1e','background':'url(http://zhqiao.cn/z/hl/images/white_triangle_915.jpg) no-repeat 0px 0px'});
			}
			else{
				toggler.setStyles({'color':'#FFFFFF','background':'#1e1e1e','background':'url(http://zhqiao.cn/z/hl/images/white_triangle_915.jpg) no-repeat 0px -2px'});
			}
			toggler.addClass('green_arrow');
			(function(){
					element.addClass('gone');}).delay(500);
		},
		display: 0,
		show: window[customerSegment],
		alwaysHide: true
});

new Accordion($('hnl_l2_p2_accordion'), 'a.hnl_l2_p2_toggler', 'div.hnl_l2_p2_link', {
		opacity: false,
		onActive: function(toggler, element){
			toggler.setStyles({'color':'#0EA3FF','background':'#1e1e1e','background':'url(http://zhqiao.cn/z/hl/images/green_triangle_down_915.jpg) no-repeat 0px 0px', 'padding-left':'14px'});
			toggler.removeClass('green_arrow');
			element.removeClass('gone');
		},
		onBackground: function(toggler, element){
			if (Browser.Engine.trident4){ //IE6
				toggler.setStyles({'color':'#FFFFFF','background':'#1e1e1e','background':'url(http://zhqiao.cn/z/hl/images/white_triangle_915.jpg) no-repeat 0px 0px'});
			}
			else{
				toggler.setStyles({'color':'#FFFFFF','background':'#1e1e1e','background':'url(http://zhqiao.cn/z/hl/images/white_triangle_915.jpg) no-repeat 0px -2px'});
			}
			toggler.addClass('green_arrow');
			(function(){
					element.addClass('gone');}).delay(500);
		},
		display: 0,
		show:default_expacc,
		alwaysHide: true
});


new Accordion($('header_rightnav_accordion'), 'a.togglerrn', 'div.elementrn', {
		opacity: false,
		onActive: function(toggler, element){
			toggler.setStyle('color','#0EA3FF');
			element.removeClass('gone');			
		},
		onBackground: function(toggler, element){
			toggler.setStyle('color','#FFFFFF');
			(function(){
					element.addClass('gone');}).delay(500);
		},

		display: -1,
		alwaysHide: true
});

});

/* Publish Info
Date: 4/30/2010 11:59:20 AM
Images: Published all
*/

