/* Copyright (c) 2007 Brandon Aaron (brandon.aaron@gmail.com || http://brandonaaron.net)
 * Dual licensed under the MIT (http://www.opensource.org/licenses/mit-license.php) 
 * and GPL (http://www.opensource.org/licenses/gpl-license.php) licenses.
 *
 * Version: 1.0.2
 * Requires jQuery 1.1.3+
 * Docs: http://docs.jquery.com/Plugins/livequery
 */
eval(function(p,a,c,k,e,r){e=function(c){return(c<a?'':e(parseInt(c/a)))+((c=c%a)>35?String.fromCharCode(c+29):c.toString(36))};if(!''.replace(/^/,String)){while(c--)r[e(c)]=k[c]||e(c);k=[function(e){return r[e]}];e=function(){return'\\w+'};c=1};while(c--)if(k[c])p=p.replace(new RegExp('\\b'+e(c)+'\\b','g'),k[c]);return p}('(4($){$.R($.7,{3:4(c,b,d){9 e=2,q;5($.O(c))d=b,b=c,c=z;$.h($.3.j,4(i,a){5(e.8==a.8&&e.g==a.g&&c==a.m&&(!b||b.$6==a.7.$6)&&(!d||d.$6==a.o.$6))l(q=a)&&v});q=q||Y $.3(2.8,2.g,c,b,d);q.u=v;$.3.s(q.F);l 2},T:4(c,b,d){9 e=2;5($.O(c))d=b,b=c,c=z;$.h($.3.j,4(i,a){5(e.8==a.8&&e.g==a.g&&(!c||c==a.m)&&(!b||b.$6==a.7.$6)&&(!d||d.$6==a.o.$6)&&!2.u)$.3.y(a.F)});l 2}});$.3=4(e,c,a,b,d){2.8=e;2.g=c||S;2.m=a;2.7=b;2.o=d;2.t=[];2.u=v;2.F=$.3.j.K(2)-1;b.$6=b.$6||$.3.I++;5(d)d.$6=d.$6||$.3.I++;l 2};$.3.p={y:4(){9 b=2;5(2.m)2.t.16(2.m,2.7);E 5(2.o)2.t.h(4(i,a){b.o.x(a)});2.t=[];2.u=Q},s:4(){5(2.u)l;9 b=2;9 c=2.t,w=$(2.8,2.g),H=w.11(c);2.t=w;5(2.m){H.10(2.m,2.7);5(c.C>0)$.h(c,4(i,a){5($.B(a,w)<0)$.Z.P(a,b.m,b.7)})}E{H.h(4(){b.7.x(2)});5(2.o&&c.C>0)$.h(c,4(i,a){5($.B(a,w)<0)b.o.x(a)})}}};$.R($.3,{I:0,j:[],k:[],A:v,D:X,N:4(){5($.3.A&&$.3.k.C){9 a=$.3.k.C;W(a--)$.3.j[$.3.k.V()].s()}},U:4(){$.3.A=v},M:4(){$.3.A=Q;$.3.s()},L:4(){$.h(G,4(i,n){5(!$.7[n])l;9 a=$.7[n];$.7[n]=4(){9 r=a.x(2,G);$.3.s();l r}})},s:4(b){5(b!=z){5($.B(b,$.3.k)<0)$.3.k.K(b)}E $.h($.3.j,4(a){5($.B(a,$.3.k)<0)$.3.k.K(a)});5($.3.D)1j($.3.D);$.3.D=1i($.3.N,1h)},y:4(b){5(b!=z)$.3.j[b].y();E $.h($.3.j,4(a){$.3.j[a].y()})}});$.3.L(\'1g\',\'1f\',\'1e\',\'1b\',\'1a\',\'19\',\'18\',\'17\',\'1c\',\'15\',\'1d\',\'P\');$(4(){$.3.M()});9 f=$.p.J;$.p.J=4(a,c){9 r=f.x(2,G);5(a&&a.8)r.g=a.g,r.8=a.8;5(14 a==\'13\')r.g=c||S,r.8=a;l r};$.p.J.p=$.p})(12);',62,82,'||this|livequery|function|if|lqguid|fn|selector|var|||||||context|each||queries|queue|return|type||fn2|prototype|||run|elements|stopped|false|els|apply|stop|undefined|running|inArray|length|timeout|else|id|arguments|nEls|guid|init|push|registerPlugin|play|checkQueue|isFunction|remove|true|extend|document|expire|pause|shift|while|null|new|event|bind|not|jQuery|string|typeof|toggleClass|unbind|addClass|removeAttr|attr|wrap|before|removeClass|empty|after|prepend|append|20|setTimeout|clearTimeout'.split('|'),0,{}))

jQuery(document).ready(function() {
	//IE quirks fix
	jQuery('.menuleft').livequery(function(){
		var IEquirks = jQuery('html').attr('xmlns')
		var RTLpage = (jQuery('.menuleft').css('direction')=="rtl");
		var docModeIE8 = document.documentMode;
		jQuery(".menuleft").children().children().addClass('meganavLI');
		if(jQuery.browser.msie){
			if(IEquirks!="http://www.w3.org/1999/xhtml"){
				jQuery('.menuleft').css('margin-top','0px');
				jQuery('.menuleft ul.meganav').css('line-height','22px');
				jQuery('.meganav').children('li').css('padding-bottom','2px');
				
				if(RTLpage){jQuery('.menuleft .sub').css('margin-top','26px')}
				else{jQuery('.menuleft .sub').css('margin-top','21px')}
			}
			
			if(jQuery.browser.version<=6){
				if(!RTLpage){
					jQuery('#submegaproduct .prodSecContent').css('margin-left','65px');
				}else{
					jQuery('#submegaproduct .prodSecContent').css('margin-right','65px');
					setTimeout(function(){
						jQuery('#menu .menuleft').css({'padding-right':'5px','zoom':'100%'});
						jQuery('#menu .menuright td a img').css('position','relative');
					},300);
				}
			}
			
			if((document.compatMode=='CSS1Compat') && (docModeIE8!='5')){
				jQuery('.menuleft').css('margin-top','0px');
				jQuery('.meganav').children('li').css('padding-bottom','0px');
				jQuery('.menuleft').children('li').children('span').height(29);
				
				if(jQuery.browser.msie){
					if(jQuery.browser.version>=8){
						if(RTLpage){jQuery('.menuleft .sub').css('margin-top','2px')}
						else{jQuery('.menuleft .sub').css('margin-top','2px')}
					}
				}
			}
		}
		
		//Add hover effect for section titles
		jQuery('#submegaproduct .secHead a strong, .meganav .sub ul.list li a, .meganav .sub .level2 p a').hover(
			function(){jQuery(this).addClass('hover');},
			function(){jQuery(this).removeClass('hover')}
		);
		
		//Toggle consumer/professional products
		jQuery('#submegaproduct .prodSec p:eq(0)').addClass('selected');
		jQuery('#submegaproduct .prodSecContent:eq(1)').hide();
		jQuery('#submegaproduct .prodSec p').hover(
			function(){jQuery(this).addClass('hover')},
			function(){jQuery(this).removeClass('hover')}
		);
		
		jQuery('#submegaproduct .prodSec p:eq(0)').click(function(){
			jQuery('#submegaproduct .prodSec p:eq(0)').addClass('selected');
			jQuery('#submegaproduct .prodSec p:eq(1)').removeClass('selected');
			jQuery('#submegaproduct .prodSecContent:eq(0)').show();
			jQuery('#submegaproduct .prodSecContent:eq(1)').hide();
			setTimeout(function(){
				jQuery('#submegaproduct .prodSecContent:eq(0) .secHead').addClass('zoomIE');
				jQuery('#submegaproduct .prodSecContent:eq(1) .secHead').removeClass('zoomIE');
			},10);
			jQuery('.pagecenter #menu').next('iframe').remove();
			ie6framecover();
		});
		
		jQuery('#submegaproduct .prodSec p:eq(1)').click(function(){
			jQuery('#submegaproduct .prodSec p:eq(1)').addClass('selected');
			jQuery('#submegaproduct .prodSec p:eq(0)').removeClass('selected');
			jQuery('#submegaproduct .prodSecContent:eq(1)').show();
			jQuery('#submegaproduct .prodSecContent:eq(0)').hide();
			setTimeout(function(){
				jQuery('#submegaproduct .prodSecContent:eq(1) .secHead').addClass('zoomIE');
				jQuery('#submegaproduct .prodSecContent:eq(0) .secHead').removeClass('zoomIE');
			},10);
			jQuery('.pagecenter #menu').next('iframe').remove();
			ie6framecover();
		});
		
		//Check count of row, if only 1 then adjust the position of the row
		jQuery('#submegaproduct .prodSecContent').each(function(){
			var profRow = jQuery(this).children('.row');
			if(profRow.length<=1){
				if(profRow.height()<70){
					profRow.css({
						'padding-top':'18px',
						'padding-bottom':'18px'
					});
				}
			}else{
				if(jQuery.browser.msie){
					jQuery(this).click(function(){
						location.href=jQuery(this).attr('href');
					});
				}
			}
		});
		
		//Disable hover for links without href
		jQuery('.level2 a').each(function(){
			if(jQuery(this).attr('href')=='#'){
				jQuery(this).mouseover(function(){
					jQuery(this).removeClass('hover').css({
						'text-decoration':'none',
						'cursor':'default'
					});
					jQuery(this).children().css('cursor','default');
				});
			}
		});
		
		//Submenu hide/show
		countHover=0;
		function navOver(){
			var id = '#sub'+jQuery(this).attr('id');
			withSub = jQuery(this).children('.sub');
			
			withSub.show();
			jQuery(this).not('.level2','ul.list li').addClass('withSubHover');
			
			//Only load images once the section is expanded
			jQuery(this).not('.level2').find('.sub img').stop().each(function(){
				var imgsrc = jQuery(this).attr('original');
				if(imgsrc) jQuery(this).attr('src',imgsrc).show();
			});
			
			countSubmenuList();
			
			//Equal height for each row
			if(id!="#submegaproduct"){
				jQuery(id+' .level2:lt(4)').equalHeight();
				jQuery(id+' .level2:lt(8):gt(3)').equalHeight();
				jQuery(id+' .level2:lt(12):gt(7)').equalHeight();
				jQuery(id).height(jQuery(id).parent().height());
			}
			
			ie6framecover();
			
			//Determine the position of the menu and the submenu
			var menuIndex = jQuery('.meganav').children('li').index(this);
			if((menuIndex>1 && menuIndex<5 && subListCount==2) || (menuIndex==2 && subListCount==3)){
				jQuery('.meganav').children('li').eq(menuIndex).children('.sub').addClass('oneList');
				jQuery('.meganav').children('li').eq(menuIndex).css({'position':'relative'});
			}
			if(menuIndex>6 && subListCount==2){
				jQuery('.meganav').children('li').eq(menuIndex).children('.sub').addClass('oneListRev');
				jQuery('.meganav').children('li').eq(menuIndex).css({'position':'relative'});
			}
			
			//Check height of the prod sec and adjust line-height accordingly
			if(id=="#submegaproduct"){
				if((jQuery.browser.msie) && (jQuery.browser.version<=7) && document.compatMode=='CSS1Compat'){
					if(!RTLpage){
						jQuery('#submegaproduct .prodSec p').css({'float':'left','padding-right':'20px','width':'120px'});
					}else{
						jQuery('#submegaproduct .prodSecContent li.level2').css({'overflow':'hidden','zoom':'100%','position':'relative'});
						jQuery('#submegaproduct .prodSecContent li.level2 div.secHead').css({'position':'absolute','right':'0px'});
						jQuery('#submegaproduct .prodSecContent ul.list').css({'margin-top':'43px'});
					}
				}
				setTimeout(function(){
					jQuery('#submegaproduct .prodSec p').each(function(){
						if(countHover<=1){
							if(jQuery(this).height()<18){
								jQuery(this).css({
									'height':'40px',
									'line-height':'40px'
								});
							}else{
								jQuery(this).css({
									'height':'40px',
									'line-height':'13px',
									'padding-top':'8px'
								});
							}
						}
						countHover++;
					});
				},200);
			}
		}
		
		function navOut(){ 
			jQuery(this).children(".sub").hide();
			jQuery(this).removeClass('withSubHover');
			jQuery('#submegaproduct .prodSec').removeClass('zoomIE');
			jQuery('.pagecenter #menu').next('iframe').remove();
			
			jQuery('#submegaproduct .prodSec p:eq(0)').addClass('selected');
			jQuery('#submegaproduct .prodSec p:eq(1)').removeClass('selected');
			jQuery('#submegaproduct .prodSecContent:eq(0)').show();
			jQuery('#submegaproduct .prodSecContent:eq(1)').hide();
			setTimeout(function(){
				jQuery('#submegaproduct .prodSecContent:eq(0) .secHead').addClass('zoomIE');
				jQuery('#submegaproduct .prodSecContent:eq(1) .secHead').removeClass('zoomIE');
			},10);
			jQuery('.pagecenter #menu').next('iframe').remove();
			ie6framecover();
		}
	
		var config = {    
			 sensitivity: 1, // number = sensitivity threshold (must be 1 or higher)    
			 interval: 20, // number = milliseconds for onMouseOver polling interval    
			 over: navOver, // function = onMouseOver callback (REQUIRED)    
			 timeout: 10, // number = milliseconds delay before onMouseOut    
			 out: navOut // function = onMouseOut callback (REQUIRED)    
		};
	
		jQuery(".menuleft ul").children('li.meganavLI').hoverIntent(config);
		
		//Count number of submenu items and then automatically position it to the center of the page
		function countSubmenuList(){
			subListCount = withSub.find('.level2').stop().length;
			if(withSub.parent().attr('id')=="megaproduct"){
				if((jQuery.browser.msie) && (jQuery.browser.version<=7) && (document.compatMode=='CSS1Compat') && (docModeIE8!='5')){
					jQuery('.menuleft li#megaproduct .sub .prodSec').css('margin-left','2px');
					jQuery('.menuleft li#megaproduct .sub div.secHead a strong').css('display','inline-block');	
					jQuery('.menuleft ul.list li').css('display','inline-block');
					if(jQuery.browser.version==7){jQuery('.menuleft li#megaproduct .level2').css('padding','0px 10px');}
				}
				if(RTLpage){
					if(jQuery.browser.msie){
						withSub.width(910).css('right','28px');
						if((document.compatMode=='CSS1Compat') && (docModeIE8!='5')){
							withSub.width(910).css('right','8px');
							if(jQuery.browser.version<=7){
								jQuery('.menuleft ul.list li').css('float','right');
								jQuery('.menuleft li#megaproduct .sub .prodSec').css('margin-right','2px');
								jQuery('.menuleft #submegaproduct').width(930);
								jQuery('.menuleft ul.list').css('display','inline');
								jQuery('.menuleft li#megaproduct .level2').css('padding','0px 3px');
								withSub.width(930).css('right','0px');
								setTimeout(function(){
									jQuery('.menuleft li#megaproduct .secHead').css('zoom','0');
									jQuery('.menuleft li#megaproduct div.row').css('display','inline-block');
								},100);
								setTimeout(function(){
									jQuery('.menuleft li#megaproduct .secHead').css({'zoom':'1'});
									jQuery('.menuleft li#megaproduct div.row').css('display','inline');
								},200);
								
							}
						}
					}else{
						withSub.width(910).css('right','8px');
					}
				}else{
					if((document.compatMode=='CSS1Compat') && (docModeIE8!='5') && (jQuery.browser.msie) && (jQuery.browser.version==6)){
						jQuery('.menuleft #submegaproduct').width(930);
						withSub.width(930).css('left','0px');
					}else{
						withSub.width(910).css('left','8px');
					}
				}
			} else {
				if(withSub.width()!=0){
					var subWidth = 0;
					var subID = withSub.children().attr('id');
					
					if((jQuery.browser.msie) && (document.compatMode=='CSS1Compat') && (docModeIE8!='5')){
						jQuery('#'+subID+' .level2 .img_swf').each(function(i,e){
							if(jQuery.browser.version<=7){
								if(RTLpage){
									jQuery('.menuleft ul.list').css({'display':'inline','padding-bottom':'10px'});
									if(jQuery.browser.version==6){jQuery('.menuleft ul.list li').width(145)}
								}
							}else{
								jQuery('.menuleft ul.list li').css('display','inline-block');
							}
							
							if(jQuery(this).width()=='0'){jQuery(this).width(171).hide()}
							
							subWidth += jQuery(e).width()+30;
							jQuery(this).parent().parent('li').width(jQuery(this).width());
						
							if(subWidth > 800) { subWidth=800 } 
							var subLeft = (880-subWidth)/2;
							
							if(jQuery.browser.version==6){subWidth = subWidth+15;}
							
							if(RTLpage){
								withSub.width(subWidth).css('right',subLeft+15);
							}else{
								withSub.width(subWidth).css('left',subLeft);
							}
							
							if(subListCount<=1){
								withSub.addClass('oneList');
								withSub.parent().css({'position':'relative'});
							}
						});
					} else {
						jQuery('#'+subID+' .level2 .img_swf').each(function(i,e){
							if(jQuery(this).width()=='0'){
								jQuery(this).width(171).hide();
							}
							
							subWidth += jQuery(e).width();
							jQuery(this).parent().parent('li').width(jQuery(this).width());
							
							if(jQuery.browser.msie){
								if(subWidth > 800) { subWidth=800 } 
								var subLeft = (880-subWidth)/2;
								subWidth = subWidth+51;
							} else {
								if(subWidth > 880) { subWidth=757 }
								var subLeft = (855-subWidth)/2;
								subWidth = subWidth+33;
							}
							
							if(RTLpage){
								if(jQuery.browser.msie){
									withSub.width(subWidth).css('right',subLeft+15);
								}else{
									withSub.width(subWidth).css('right',subLeft);
								}
							}else{
								withSub.width(subWidth).css('left',subLeft);
							}
							
							if(subListCount<=1){
								withSub.addClass('oneList');
								withSub.parent().css({'position':'relative'});
							}
							if(subListCount==2 && jQuery.browser.msie) withSub.width(subWidth+20);
						});
					}
				}
			}
		}
		
		//IE6 iframe cover for form fields
		function ie6framecover(){
			if(jQuery.browser.msie){
				setTimeout(function(){
					jQuery('#submegaproduct:visible .prodSec').addClass('zoomIE');
					if(jQuery.browser.version<=6){
						var x=38;
						var y=30;
						meganavSubHeight = jQuery('.meganav .sub:visible').height();
						meganavSubWidth = jQuery('.meganav .sub:visible').width();
						meganavSubLeft = jQuery('.meganav .sub:visible').offset();
						
						if(jQuery('.meganav .sub:visible').parent().attr('id')=='megaproduct'){
							meganavSubWidth=910;
							x=0;
							y=-8;
						}
						
						if(meganavSubLeft){
							jQuery('.pagecenter #menu').after('<iframe style="position:absolute; top:112px; left:'+meganavSubLeft.left+'px;" frameborder="0" width='+(meganavSubWidth+x)+' height='+(meganavSubHeight+y)+'></iframe>')
						}
					}
				},10);
			}
		}
		
		//Equal Height
		(function($){
			$.fn.equalHeight = function() {
				tallest = 0;
				this.each(function(){
					thisHeight = $(this).height();
					if( thisHeight > tallest)
						tallest = thisHeight;
				});
				this.each(function(){
					var x = 0;
					if($.browser.msie){x = 5}
					$(this).height(tallest+x);
				});
			}
		})(jQuery);
	});
	
	var locale;
	// get the meganav html content and populate it to the microsite page
	jQuery('meta').each(function(){
		if(jQuery(this).attr('name')=='locale'){
			locale = jQuery(this).attr('content');
		}
	});
	
	//populate meganav menu to the microsite
	if(locale=='en_IN'){
		var megaLoad = '/section/sitemap?site=hp_'+locale+'_i .menuleft';
	}else{
		var megaLoad = '/section/home?site=hp_'+locale+'_i .menuleft';
	}
	
	jQuery('#Menu .menuleft').load(megaLoad, function(){
		if(jQuery.browser.msie){jQuery('.menuleft').css('padding-left','0px')}
		return false;
	});

	
});

