// JavaScript Document
//FF debug function
function fbl(msg){
	if(typeof(console)!=='undefined' && typeof(console.log)!=='undefined')
		console.log( msg );
	return false;
}

function hideEmptyTabs(override){
	var tabId = "L3menu";
	if(typeof(override)!=="undefined")
		tabId = override;

	$('#'+tabId+' li:nth-child(1) a span').each(function(){
		if($(this).html()==""){
			$(this).parent().parent().css('display','none');
			return true;
		}
	});
	return false;
}

function showproductcategoriesitem(itemobj) {
	$("#productcategoriesleftmain").find(".productcategoriesoptionover").removeClass("productcategoriesoptionover");
	itemobj.addClass("productcategoriesoptionover");
	$("#productcategoriesright").children().hide();
	$('#'+itemobj.attr('optiontargetid')).show();
}

// initialize tooltip function
function initToolTips(){
	$("a.toolTipLink, label.toolTipLink, select.optionTooltip option").tooltip({
		// tweak the position
		position: 'top left',
		offset: [0, 282],
		predelay:500,
		// use the "slide" effect
		effect: 'slide'
	});
}

//Left Nav Bar Shared Component Load
function bottleSearchAccordion() {
	//bottle search accordion
	$('.tubeAccord .handle').click(function(){
	/*
		if($(this).parent().attr('rel')) {
			$('.handleContent').removeClass('on');
			$('.tubeAccord .handle').removeClass('accordionActive');
		}
	*/
		//fbl('bottleSearchAccordion called');
		//$('#tubeAccord div.mainCheckBox input').removeClass('noText').addClass('noText');
		//$('#emailOptions124').removeClass('noText').addClass('noText'); //new comment
		$('#tubeAccord>div>input').removeClass('noText').addClass('noText'); //ie fix, tkt# WSR-240
		$(this).next().toggleClass('on');
		$(this).toggleClass('accordionActive');
	});
}


(function($) {
	var cache = [];
	// Arguments are image paths relative to the current page
	$.preLoadImages = function() {
		var args_len = arguments.length;
		for (var i = args_len; i--;) {
			var cacheImage = document.createElement('img');
			cacheImage.src = arguments[i];
			cache.push(cacheImage);
		}
	}

	/*-- l1 subnavigation --*/
	$.fn.subNav = function(settings) {
		var config = {'config1': false, 'config2': 5000};

		if (settings)
			$.extend(config, settings);

		this.each(function() {
			$(this).prepend('<li class="subNavHeader">Categories</li>');
			$(this).append('<li class="subNavFooter"></li>');
			var menu = {
				"link" :  $(this).find('a.subSelection'),
				"content" : $('.subContent')
			}
			var reset = function() {
				$(menu["link"]).removeClass('subActive');
				$(menu["content"]).removeClass('subContentActive');
			}
			$(menu["link"]).click(function() {
				if($(this).attr('href')=="#") {
				return false;
				}
			});
			var t;
			var firstTime = true;
			$(menu["link"]).mouseenter(function() {
				clearInterval(t);
				var k = $(this);
				if(firstTime) {
					firstTime = false;
					reset();
					$(this).addClass('subActive');
					$('.subContent#'+$(this).attr('rel')).addClass('subContentActive');		
				} else {	
					t = setInterval(function () {						
						reset();
						$(k).addClass('subActive');
						$('.subContent#'+$(k).attr('rel')).addClass('subContentActive');
					}, 400);	
				}
				return false;
			}).mouseleave(function() {
				clearInterval(t);
			});
		});
	} /* --END l1 subnavigation-- */


	/* --Carousel widget-- */
	$.fn.beckmanCarousel = function(settings) {
		var config = {'slideshow': false, 'duration': 5000};

		if (settings)
			$.extend(config, settings);

		this.each(function() {
			var obj = $(this);
			var carousel = { "length" : obj.find('img').length , "current" : 1, 'containerWidth': obj.find('img').width(), 'containerHeight': obj.find('img').height() };
			
			for( var i=0; i < carousel['length']; i++) {
				var j = i+1;
				//mapping the location of each marketing piece
				carousel['pos'+j] = carousel['containerWidth']*i;
			}
			//click handler for both prev and next button
			obj.find('a.prev').click(function() {

				clearInterval(slideF);
				clearInterval(slideB);
				carousel['current']--;
				if(carousel['current']<=1)
					carousel['current']=1;

				//mapping where to go 
				carousel['goto'] = carousel['pos'+carousel['current']];
				//Animate to appropriate location
				obj.find('.scroll').animate( {left: '-'+carousel['goto']}, 500, function() {
					//do nothing
				});	
			});

			obj.hover(function() {
				obj.find('.bannerNavigation').stop().animate({
					top: '0'
				});
			}).mouseleave(function() {
				obj.find('.bannerNavigation').stop().animate({
					top: '-100px'
				});
			});
			obj.find('a.next').click(function() {
				clearInterval(slideF);
				clearInterval(slideB);
				carousel['current']++;	
				if(carousel['current']>=carousel['length'])
					carousel['current']=carousel['length'];

				//mapping where to go 
				carousel['goto'] = carousel['pos'+carousel['current']];
				//Animate to appropriate location
				obj.find('.scroll').animate( {left: '-'+carousel['goto']}, 500, function() {
					//do nothing
				});	
			});

			if(config.slideshow) {
				$('.bannerNavigation').stop().delay(500).animate({
					top: '-100px'
				});
				var slideB;
				var back = function() {
					carousel['current']--;
					if(carousel['current']<=1) {
						carousel['current']=1;
						clearInterval(slideB);
						slideF = setInterval(fore, config.duration);
					}
					//mapping where to go 
					carousel['goto'] = carousel['pos'+carousel['current']];
					//Animate to appropriate location
					obj.find('.scroll').animate( {left: '-'+carousel['goto']}, 500, function() {
						//do nothing
					});	
				}
				var fore = function() {
					carousel['current']++;	
					if(carousel['current']>=carousel['length']) {
						carousel['current']=carousel['length'];
						clearInterval(slideF);
						slideB = setInterval(back, config.duration);
					}
					//mapping where to go 
					carousel['goto'] = carousel['pos'+carousel['current']];
					//Animate to appropriate location
					obj.find('.scroll').animate( {left: '-'+carousel['goto']}, 500, function() {
						//do nothing
					});	
				}
				var slideF = setInterval(fore, config.duration);
			}

			if(carousel['containerHeight']<150)
				carousel['containerHeight']=150+"px";

			// disabling this, It's longer needed. Since there's only one single image banner throughout the site.
			/*
			$(this).css({
				width: carousel['containerWidth'],
				height: carousel['containerHeight']
			});
			*/
		});
    } /* -- END Carousel widget --*/


	/* --Centrifugation module-- */
	$.fn.centrifuge = function(settings) {
		var config = {'item': 5, 'speed' : 200, 'close':false};
	 
		if (settings)
			$.extend(config, settings);

		this.each(function(idx, i) {
			var menu = {
				"handle" :  $(this).find('.handle'),
				"width" : $(this).find('.panel').width(), 
				"wrapper" : $(this).find('li'), 
				"child" : $(this).find('div.innerItem'),
				"count" : 0,
				"hiddenWrapper" : $(this).find('.hiddenWrapper')
			};


			for (i=0;i<=menu['wrapper'].length;i++) {	
				// $(menu['hiddenWrapper'][i]).css('z-index',20-i)
				$(menu['wrapper'][i]).attr('rel', i).css({
					'left': menu['width']*i,
					'z-index': i
				});
			}

			if(config.close) {
				$('a.closecent').live('click', function() {
					reset();
				});
				$(menu["wrapper"]).parent().append('<a href="javascript:void(0);" class="closecent"></a>')
			}

			$(menu['wrapper']).each(function(i) {
				menu["content"+i] = {
					handle: $(this).find('.handle'),
					inner: $(this).find('div.innerItem'),
					position: $(this).css('left'),
					prev: $(this).find('a.prev'),
					next: $(this).find('a.next'),
					container: $(this).find('.innerWrapper'),
					width: $(this).find('div.innerItem').outerWidth(),
					curr: 1,
					set: 1
				}

				if(menu["content"+i]['inner'].length>config.item) {
					menu["content"+i]['set'] = Math.ceil(menu["content"+i]['inner'].length/5);
					$(menu["content"+i]['next']).click(function() {
						if(menu["content"+i]['curr']>=menu["content"+i]['set']) {
							//do nothing
						} else {
							$(menu["content"+i]['container']).stop().animate({
								marginLeft: '-='+menu["content"+i]['width']*config.item+'px'
							}, config.speed, function(){});

							menu["content"+i]['curr']++;
						}
						return false;
					});
					$(menu["content"+i]['prev']).click(function() {
						if(menu["content"+i]['curr']<=1) {
							
						} else {
						$(menu["content"+i]['container']).stop().animate({
							marginLeft: '+='+menu["content"+i]['width']*config.item+'px'
						}, config.speed, function() {});
							menu["content"+i]['curr']--;
						}
						return false;
					});
				} else {
					menu["content"+i]['next'].hide();
					menu["content"+i]['prev'].hide();
				}
			});

			function reset() {
				$(menu['wrapper']).each(function(i) {
					$(this).find('a.panel').removeClass('active');
					$(this).stop().animate({
						left: menu['content'+i]['position']
					});

					$(menu["content"+i]['container']).stop().animate({
						marginLeft: '0px'
					}, config.speed, function() {});
					menu["content"+i]['curr'] = 1;
				});
			}

			//item specific hover
			$(menu["child"]).mouseenter(function() {
				if($(this).find('.additionalInfo').length>0) {
					$(this).find('.additionalInfo').show();
					$(this).stop().animate({
						height: "267px"
					}, 0, function() {
						//do nothing
					});
				}
			}).mouseleave(function() {
				if($(this).find('.additionalInfo').length>0) {
					$(this).find('.additionalInfo').hide();
					$(this).stop().animate({
						height: "153px"
					}, 0, function() {
						//do nothing
					});
				}
			});

			//large image (category) hover
			var cTo;
			$(menu["handle"]).mouseenter(function() {

				//IF empty, DONT expand!
				if($(this).find('.innerItem').length == 0){
					$(this).find('a').remove();
					$(this).find('.hiddenWrapper').css("padding", "5px 0").css("border","none");
					return false;
				}

				clearInterval(cTo);
				var that = this;
				cTo = setInterval(function(){
					$(that).parent().find('.bookend').css('display','block');
					$(that).find('a.panel').addClass('active');
					var thisWrapper = $(that).parent();
					var others = $(thisWrapper).siblings('li');
					$(thisWrapper).stop().animate({
						left: '0px'
					}, config.speed, 'easeOutCubic', function() {
						//do nothing
					});
					menu['count']++;
					//console.log($(others));
					$(others).stop().animate({
						left: '750px'
					}, config.speed+800, 'easeOutCubic', function() {
						//do nothing
					});
				},400); //hover timout speed
			}).mouseleave(function() {
				clearInterval(cTo);
				if( $(this).find('a.panel').hasClass('active') ){
					$(this).parent().find('.bookend').css('display','none');
					if(!config.close)
						reset();
				}
			});
		});
	}/* --END Centrifugation module-- */


	/* --Level 3 navigation-- */
	$.fn.level3Nav = function(settings) {
		var config = {'tabWrapper': '.L3menuContent'};

		if (settings)
			$.extend(config, settings);

		$(config['tabWrapper']+' > div').css('display','none');

		this.each(function() {
			var obj = $(this);
			var nav = obj.children().children().children();
			var menu = { "length" : nav.length};
			$(nav).each(function(i) {
				$(obj).find("a").live("click", function(event) {
					var r = $(this).attr('rel');
					$(config['tabWrapper']+' > div').css('display','none');
					$(obj).find("a").parent().removeClass('active');
					$(this).parent().addClass('active');

					if($(this).attr('href').indexOf('#')=='-1') { // for ajax content
						$('#'+$(this).attr('rel')).css('display','block');
						return true; // (TR) no ajax, load the page instead
/*
						var href = $(this).attr('href')+' #'+$(this).attr('rel');
						$(config['tabWrapper']).load(href, function(j) {
							bottleSearchAccordion(); //turn on accordion
							//For gallery
							$(".productcategoriesoption").bind("mouseenter", function() {
								showproductcategoriesitem($(this));
							});
						});
						$('input:checkbox, input:radio').addClass('noText')
*/;
					} else { // for hide/show
						$('#'+$(this).attr('rel')).css('display','block');
					}

					if($('#'+r+' .subContent#overview-subcontent')) { //if it has overview, defaults to that
						$('#'+r+' .subContent').removeClass('subContentActive');
						$('#'+r+' .subContent#overview-subcontent').addClass('subContentActive');
					} else { //if not show first one
						$('#'+r+' a.subSelection:eq(0)').addClass('subActive');
						$('#'+r+' .subContent:eq(0)').addClass('subContentActive');
					}

					return false;
				});// end click
			}); // out of nav scope

			//removing hash (#) tab highlighting to eliminate pages scrolling down
			/*
			var l = window.location.hash;
			if(l) {
				var h = l.substr(1);
				if($(this).find('a[rel='+h+']').length=='0')
					$(this).find('a:eq(0)').click();
				else
					$(this).find('a[rel='+h+']').click();
			} else {
				$(this).find('a:eq(0)').click();
			}
			*/
			
			//new method will use a URL variable "t"  ex: ./whatever.html?t=tab-0
			//it will ignore single digit (character) options
			if(typeof($.query)!=="undefined"){
				var T = $.query.get('t');
				if(T.length > 1) {
					if($(this).find('a[rel='+T+']').length=='0')
						$(this).find('a:eq(0)').click();
					else
						$(this).find('a[rel='+T+']').click();
				} else {
					$(this).find('a:eq(0)').click();
				}
			}
			
		});
	} /* -- END Level 3 navigation-- */


	/* --selectorFix-- */
	$.fn.selectorFix = function(settings) {
		var config = {'someConfig_maybespeed': 500};

		if (settings)
			$.extend(config, settings);

		this.each(function(k) {
			var obj = {
				"select" : $(this),
				"width" : $(this).width()
			};

			$(this).css('display','none');
			$(this).after("<span class='selectReplacementWrapper'><ul class='selectReplacement'>"+"</ul></span>");
			$(this).next().css({
				width : $(this).width(),
				marginTop : $(this).css('margin-top'),
				marginLeft : $(this).css('margin-left'),
				marginBottom : $(this).css('margin-bottom'),
				marginRight : $(this).css('margin-right')
			});

			$(this).next().find('ul').css({
				height: '20px',
				width: $(this).width()
			});

			$(this).next().find('ul').click(function() {
				$(this).css('height','auto');
			}).mouseleave(function() {
				$(this).css('height','20px');
			});

			$(this).find('option').each(function(i) {
				if(i!=0)
					$(this).parent().next().find('ul').append('<li alt="'+$(this).attr('value')+'">'+$(this).html()+'</li>');
				else
					$(this).parent().next().find('ul').append('<li alt="'+$(this).attr('value')+'" class="firstSelelection">'+$(this).html()+'</li>');
				//$(this).next().append(i);
			});

			$(this).next().find('ul li').click(function() {
				var v = $(this).attr('alt');
				//console.log($(this).parent().parent().prev().find('option[value='+v+']'));
				$(this).parent().parent().prev().find('option[value='+v+']').attr('selected','selected');
				$(this).parent().parent().prev().val(v);
			});

			$('ul.selectReplacement li').hover(function() {
				$(this).addClass('active');
			}).mouseout(function() {
				$(this).removeClass('active');
			});
		});
	} /* --END selectorFix-- */
})(jQuery);




//onLoad
$(document).ready(function() {
	//Flag setter
	var countryCodeFULL = document.cookie.split("wsrcookie=");
	if(countryCodeFULL.length > 1) {
		var countryCode = countryCodeFULL[1].substr(3,2);
		$('#header em.flag').attr('id',countryCode);
	}
	
	//turn this off on production
	//$('#BCI_Main_last-modified').show();

	$(".subLeftNav").subNav({});
	$('input:checkbox, input:radio').addClass('noText');
	$(".centrifuge").centrifuge({'speed':600,'close':false});
	$('.overlay').append('<div class="close"><a href="javascript:void(0);"></a></div>'); // adding close button
	$('.overlay').each(function() {
		var w = $(this).width();
		var h = $(this).height();
		// browser can not get w/h from elements set to display:none (always == 0)
		// do not set w/h when 0, will have to rely on a css class for w/h then
		if(w > 0 && h > 0){
			$(this).wrapInner('<div class="iframeShim" style="width:'+w+'px;height:'+h+'px;"></div>');
			$(this).prepend('<iframe width="'+w+'" height="'+h+'" frameborder="0" border="0" src="about:blank"/>');
		}else{
			$(this).wrapInner('<div class="iframeShim"></div>');
			$(this).prepend('<iframe frameborder="0" border="0" src="about:blank"/>');
		}
	});
	// search tip handler
	$('a.search-tip').click(function() {
		$('.search-tip-holder').toggleClass('display-tip');
	});
	$('.search-close').click(function() {
		$('.search-tip-holder').removeClass('display-tip');
	});

	var pageState = {};
	pageState['contracted'] = false;
	pageState.AddressView = 0;

	//overlay link onClick(s) (show)
	$("a[rel].overlaylink").overlay({
		mask: {
			color: '#000000',
			opacity: 0.5
		},
		left: "center",
		top: "10%",
		onLoad: function() {
			//added to fix re-display of overlays
			$('.shadow>div').each(function(){
				if($(this).css('display') == "block"){
					var shownDivId = $(this).attr('id');
					$(shownDivId +' .iframeShim').css('display','block');
				}
			});
			//re-init tool tips for overlays
			initToolTips();
			//end add
			if(ie6)
				$('.shadow iframe').css('display','block');
			else
				$('.shadow iframe').css('display','none');
		},
		onBeforeClose: function(){ /*added to fix #1214*/
			try {
				hideAll();
			} catch (ignore) {};
		}
	});

	$('.addressAccordion h4').click(function(){
		$('.addressAccordion .info').addClass('hide')
		$(this).next().removeClass('hide');
	});

	$('a.collapsible').click(function(){
		pageState['hide'] = $(this).attr('title');
		pageState['show'] = $(this).html();
		pageState['contentHide'] = $(this).siblings('.swap').attr('title');
		pageState['contentShow'] = $(this).siblings('.swap').html();
		$(this).toggleClass('viewAddressToggle');

		if(pageState.AddressView==0) {
			$('.confirmAddress').slideDown('fast');
			pageState.AddressView = 1;
			$(this).attr('title', pageState['show'] );
			$(this).html(pageState['hide']);
			$(this).siblings('.swap').attr('title', pageState['contentShow'] );
			if (pageState['contracted']) {
				//do nothing
			} else {
				$(this).siblings('.swap').html(pageState['contentHide']);
			}
		} else {
			$('.confirmAddress').slideUp('fast');
			pageState.AddressView = 0;
			$(this).attr('title', pageState['show'] );
			$(this).html(pageState['hide']);
			$(this).siblings('.swap').attr('title', pageState['contentShow'] );
			if (pageState['contracted']) {
				//do nothing
			} else {
				$(this).siblings('.swap').html(pageState['contentHide']);
			}
		}
		return false;
	});

	$('select.selectAContract').change(function(){
		if($(this).val()!="") {
			$('.swap').html("<em class='check'></em>You've selected Contract # "+$('select.selectAContract :selected').text());
			pageState['contracted'] = true;
		} else {
			$('.swap').html("");	
			pageState['contracted'] = false;
		}
	});

	$('.quickOrderOption h5 input').click(function(){
		$('.quickOrderOptionContent').removeClass('active');
		$(this).parent().next('.quickOrderOptionContent').addClass('active');
	});
	
	$(".productcategoriesoption").bind("mouseenter", function() {
		showproductcategoriesitem($(this));
	});

	showproductcategoriesitem($("#productcategoriesoptioninit"));
	$('#L3menu').level3Nav();
	$('#TabLabels').level3Nav({'tabWrapper':'.Tabs'});

	// initialize tooltip; moved to function:
	initToolTips();

	$("a.htmlTip").tooltip({
		tip: '.tooltipHtml',
		// use the "slide" effect
		offset: [0, 124],
		predelay:500,
		effect: 'slide',
		relative: true
	});

	$('a.collapsible').each(function(idx, i) {
		if($(this).hasClass('noClick')){
			//do nothing
		}else{
			$(this).click();
		}
	});
	//Handle small app region loading
	$('.small-apps[href]').each(function() {
		$(this).load($(this).attr('href'));
	});
	//Set Schedule Order
	$('input[name=freeShipping]').change(function(){
		if($(this).val()=="yes"){
			$('.freeshippingChoice').slideDown();
		} else {
			$('.freeshippingChoice').slideUp();
		}
		return false;
	});
	//Order Tracking : Expand/Contrac table search result
	$('a.tableExpander').click(function(){
		$(this).toggleClass('expand');
		$(this).parent().parent().toggleClass('open');
		$(this).parent().parent().next().toggleClass('active');
		return false;
	});
	//Order Tracking : Email : used previous
	$('a.fetchPreviousEmail').click(function(){
		$(this).next().toggleClass('active');
		return false;
	});
	$('a.insideTableExpand').click(function(){
		pageState['insideTableLinkHTML'] = $(this).attr('title');
		$(this).attr('title',$(this).html());
		$(this).html(pageState['insideTableLinkHTML']);

		$(this).toggleClass('tableActive');
		$(this).next().toggleClass('on');
		$(this).parent().parent().parent().parent().toggleClass('borderMe');
		return false;
	});

	//ecom : handles offer code overlay for logged in user
	$('input[name=contractOrOfferCode]').focus(function(){
		if($(this).val()==1) {
			$('input[name=apple]').attr('disabled','disabled');
			$('.offerCodeApply').removeClass('display');
		} else {
			$('input[name=apple]').attr('disabled','');
			$('.offerCodeApply').addClass('display');
		}
	});

	bottleSearchAccordion(); //turn on accordion
	//Invoke Carousel
	$('.marketing-object').beckmanCarousel({'slideshow': true, 'duration':6000});

	//Input box value handler
	var obj = {};
	$('.global_search').focus(function() {
		obj = {'old' : $(this).val(), 'new' : ''};
		$(this).val('');
	}).blur(function() { //TODO: blur for 1.2.6 jquery or focusout for newer version 
		if($(this).val()=='')
			$(this).val(obj['old'])
	});

	$('a.searchLink').click( function(){
		$('.searchLinkResult').css('display','block');
		return false;
	});

	if($.browser.msie && $.browser.version < 7){
		//IE6 input exception
		 try {
			//works since IE6SP1 this fixes image caching issue in ie6. It works wonder.
			document.execCommand("BackgroundImageCache", false, true)
		} catch(acold) {
			/*many will complain, just ignore*/
		}
		$(document).pngFix();
	}

	//IE drop-down auto width "fix"
	if($.browser.msie){
		//IE drop down width fixes
		//product pages & warranty page
		var selectors = ['select#item-selection','select#SiteItems'];
		for(i=0;i<selectors.length;i++){
			if( $(selectors[i]).length>0){
				$(selectors[i]).mouseover(function(){
	 				//only runs for the first <select>
	 				var oW = $(this).width();
					$(this).css("width", "auto");
					var autoWidth = $(this).width();
	
					//ONLY make them bigger, not smaller.
					if( autoWidth < parseInt(oW) )
						$(this).css("width", oW);
					else
						$(this).css("width", autoWidth+"px");
	
					$(this).unbind('mouseover');
				});
			}
		}
		//techdocs page fix
		//1-4
		if( $("#techPubSearchForm .handleContent:eq(0) select").length>0){
			//only selects 1=4
			for(s=1;s<5;s++){
				var toW;
				var tfoW = 0;
				$("#techPubSearchForm .handleContent:eq(0) select:eq("+s+")").mouseenter(function(){
	 				if(tfoW==0) {
	 					toW = $(this).css("width");
	 				}
					$(this).css("width", "auto");
      				tfoW++;
				}).blur(function(){
					$(this).css("width", toW);
				}).change(function(){
					$(this).css("width", toW);
				});
			}
		}
		
	}
	//END IE only code
/*
//this is removed, as it is causing the omniture lib to lock up IE8 upon a link being clicked
	$('#leftnav').each(function() {
		$(this).load($(this).attr('href'));
	});
*/
/*
	//This is the same as the block below, disabling -- RE 1/26
	//Also removed from bci_left_nav.js
	$('.bottomLeftNavHandle a.leftnavHandle').live('click', function() {
		$(this).next().slideToggle('fast', function() {
			$(this).parent().toggleClass('expandedLeft');
		});
		return false;
	});
*/
	if($('.bottomLeftNavHandle a.leftnavHandle')) {
		$('.bottomLeftNavHandle a.leftnavHandle').live('click', function() {
			$(this).next('.bottomleftNavSubmenu').slideToggle('fast', function() {
				$(this).parent().toggleClass('expandedLeft');
				$(this).toggleClass('expandedMain');
			});
			return false;
		});
	}

	var ie6 = false;
	if ($.browser.msie && $.browser.version < 7)
		ie6 = true; 

	//survey icon
	//acceptable portions of the domain name to show the survey icon:
	var okNames = ["dev","sit","uat","beta","localhost"];
	

	//default to false in order to hide the icon
	var interanlReviewIcon = false;
	//note: ALL CSS for this icon is begins with: #surveyLink

	for(n=0;n<okNames.length;n++){
		if( location.hostname.indexOf(okNames[n]) != -1 ){
			interanlReviewIcon = true;
		}
	}

	var reviewHTML = "<div id='surveyLink'><a href='javascript:void(0);'>&nbsp;</a></div>";
	if(interanlReviewIcon){
		
		if(ie6){
			if($('#footnotes').length > 0){
				$('#footnotes').append(reviewHTML);
			}else if($('#sidebar').length > 0) {
				$('#sidebar').append(reviewHTML);
			}else if($('.gridOverlay').length > 0) {
				var winHeight = $(window).height();
				$('.gridOverlay').append(reviewHTML);
				$('#surveyLink a').css("margin-top","300px").css("z-index","99");
			}else{
				return false;
			}
			
			$('#surveyLink').css('float','right').css("margin-top","10px");
			$('#surveyLink a').addClass("bgImage");
		}else{
			$('body').append(reviewHTML);
			$('#surveyLink a').addClass("bgImage");
		}

		$('#surveyLink a').click(function(){
			window.open('http://guest.cvent.com/d/ddqgsh/3B','surveyWindow','width=850, height=600, scrollbars=yes, toolbar=no, addressbar=no, menubar=no');
		});
	}

	//END survey icon


	//Assign FAQ / QA events
	$('.questionAnswer .question').click(function(){
		if ( $(this).next('.answer').css('display') == "none"  ) {
			$(this).parent().find('ul').removeClass('qaOpen');
			$('.answer').slideUp('fast');
			$('.question').children().children().removeClass('boldQA');
			$(this).children('ul').addClass('qaOpen');
			$(this).children().children().addClass('boldQA');
			$(this).next('.answer').slideDown('fast');
		}
	}).hover(function(){
		if ( $(this).next('.answer').css('display') == "block"  )
			return false;
		$(this).css('text-decoration','underline');
	},function(){
		$(this).css('text-decoration','');
	});

	//Newsletter Past issue show / hide
	$('.issueListing .issueHandle').click(function(){
		if ( $(this).parent().next('.issueDetail').css('display') == "none" ) {
			$('.issueListing .issueDetail').slideUp('fast');
			$(this).parent().next('.issueDetail').slideDown('fast');
		}
	});



/***Start Code for NEW L3 pages as of 3/1/2011***/
	if( $(".l3subCatWrapper").length > 0){

		$('.l3subCatWrapper').click(function(){
			//if a 'GO' link do something else first
			if($(this).children('a.l3subCatGo').length>0){
				var goHere = $(this).children('a.l3subCatGo').attr('href');
				if(typeof(goHere)!=="undefined")
					location.href = goHere;
				return false;
			}

			var showhide = $(this).find('.l3subCatViewHide span').text();

			//reset all border colors
			$('.l3subCatWrapper').removeClass('l3subCatActive');
			//reset all icons
			$('.l3subCatViewHideIcon').removeClass('l3subCatHideIcon l3subCatViewHideIconHover l3subCatHideIconHover').next('span').text('View');
			//hide all containers
			$('.l3subCatItemContainer').hide(); //NO animation; or:
			//$('.l3subCatItemContainer').slideUp(300); //Slide UP animation
			//reset shadow
			$('.l3subCatShadow').css('height','');


			if(showhide == "View"){
				//set "left" if it is a list
				if( $( $(this).children('.l3subCatViewHide').attr('rel') ).hasClass('l3subCatItemContainerList') ){
					$(this).parent().children('.l3subCatItemContainer').each(function(i){
						if( $(this).hasClass('l3subCatItemContainerList') ){
							var newLeft = parseInt( $(this).outerWidth() ) * i + (i * $(this).parent().children('.l3subCatSpacer').width() );
							$(this).css('left', newLeft);
						}
					});
				}

				//$( $(this).children('.l3subCatViewHide').attr('rel') ).show(); //NO animation
				$( $(this).children('.l3subCatViewHide').attr('rel') ).slideDown(300); //Slide DOWN animation
				$(this).find('.l3subCatViewHide span').text('Hide');
				$(this).find('.l3subCatViewHideIcon').addClass('l3subCatHideIcon l3subCatHideIconHover');
				$(this).addClass('l3subCatActive').children('.l3subCatShadow').css('height','0'); //no toggle, ie sucks
			}else{
				$(this).find('.l3subCatViewHideIcon').addClass('l3subCatViewHideIconHover');
			}
			return false;
		}).hover(function(){
			var showhide = $(this).find('.l3subCatViewHide span').text();
			$(this).children('.l3subCatViewHide, .l3subCatGo').addClass('l3subCatViewHideHover');
			$(this).addClass('l3subCatWrapperHover');
				if(showhide == "View")
					$(this).find('.l3subCatViewHideIcon').addClass('l3subCatViewHideIconHover');
				else
					$(this).find('.l3subCatViewHideIcon').addClass('l3subCatHideIconHover');
			if($(this).find('.l3subCatGoIcon').length>0)
				$(this).find('.l3subCatGoIcon').addClass('l3subCatGoIconHover');
		}, function(){
			var showhide = $(this).find('.l3subCatViewHide span').text();
			$(this).children('.l3subCatViewHide, .l3subCatGo').removeClass('l3subCatViewHideHover');
			$(this).removeClass('l3subCatWrapperHover');
				if(showhide == "View")
					$(this).find('.l3subCatViewHideIcon').removeClass('l3subCatViewHideIconHover');
				else
					$(this).find('.l3subCatViewHideIcon').removeClass('l3subCatHideIconHover');
			if($(this).find('.l3subCatGoIcon').length>0)
				$(this).find('.l3subCatGoIcon').removeClass('l3subCatGoIconHover');
		});

		$('.l3itemHolder').hover(function(){
			$(this).find('.l3itemTitle').addClass('l3itemTitleHover');
			$(this).addClass('l3itemOnTop').children('.l3itemMenu').slideDown(150);
		}, function(){
			$(this).find('.l3itemTitle').removeClass('l3itemTitleHover');
			var l3holder = $(this);
			$(this).children('.l3itemMenu').slideUp(150, function(){
				l3holder.removeClass('l3itemOnTop');
			});
		});
		//Set default item click
		$('.l3itemInfo').click(function(){
			var goHere = $(this).children('.productLink').attr('href');
			if(typeof(goHere)!=="undefined")
				location.href = goHere;
			return false;
		});
		//prevent default if the image is actually clicked... (also for "go" links)
		//$('a.productLink, a.l3subCatGo').click(function(e){
		//	e.preventDefault();
		//	return false;
		//});
		//END default item click

	}

	var ie6 = false;
	if($.browser.msie && $.browser.version < 7)
		ie6 = true;
	//read page, set variable elements(seperators)
	if( $(".l3subCatItemContainer").length > 0){
		//Number of items per row:
		var numPerRow = 4;
		var sepLine = "<div class='itemSepLine'></div>";
		if(ie6)
			sepLine = "<div style='margin:0;padding:0;height:0;clear:both;'></div>";
		$(".l3subCatItemContainer").each(function(i){
			var holderCount = $(this).children(".l3itemHolder").length;
			var sepCount = Math.floor( holderCount / numPerRow );
			if(sepCount > 0 && holderCount > numPerRow)
				for(s=0;s<sepCount;s++)
					$(this).children(':nth-child('+ ( (s+1) * numPerRow + s ) +')').after(sepLine);
		});
	}
/***END Code for NEW L3 pages as of 3/1/2011***/

//BEGIN Training Page event triggers
	if( $('.teHolder').length > 0 ){
		$('.teHolder').hover(function(){
			//no matter what, "highlight" text & hover the LI
			$(this).children('a').children('span').addClass('teIconTextHover');
			$(this).parent().addClass('teItemHover');

			if($(this).children('a').children('div').hasClass('teGoIcon'))
				$(this).children('a').children('div').addClass('teGoIconHover');
			else if($(this).children('a').children('div').hasClass('teViewIcon'))
				$(this).children('a').children('div').addClass('teViewIconHover');
			else
				$(this).children('a').children('div').addClass('teHideIconHover');
		}, function(){
			//no matter what, UN-"highlight" text & UN-hover the LI
			$(this).children('a').children('span').removeClass('teIconTextHover');
			if($(this).next('.teOptions').css('display') != "block")
				$(this).parent().removeClass('teItemHover');

			if($(this).children('a').children('div').hasClass('teGoIcon'))
				$(this).children('a').children('div').removeClass('teGoIconHover');
			else if($(this).children('a').children('div').hasClass('teViewIcon'))
				$(this).children('a').children('div').removeClass('teViewIconHover');
			else
				$(this).children('a').children('div').removeClass('teHideIconHover');
		}).click(function(){
			var viewHide = $(this).find('.teIcon span').text();
			if(viewHide == "View"){
				$(this).find('.teIcon span').text('Hide');
				$(this).find('.teIcon div').removeClass().addClass('teHideIcon teHideIconHover');
			} else if(viewHide == "Hide"){
				$(this).find('.teIcon span').text('View');
				$(this).find('.teIcon div').removeClass().addClass('teViewIcon teViewIconHover');
			}
			var goHere = $(this).children('a.teIcon').attr('href');
			if($(this).next().hasClass('teOptions'))
				$(this).next('.teOptions').toggle();
			else if(typeof(goHere)!=="undefined")
				location.href = goHere;
			return false;
		});
	}
//END Training Page event triggers

});//END OnLoad!!!?!

