	try { document.execCommand("BackgroundImageCache", false, true); } catch(e) {}

	$j = jQuery.noConflict(true);
	
	$j.Avaya = {
		global : {},
		SmartDockId : 0
	};
	
	window.name = "AvayaMain";
	
	sIFR.repaintOnResize = false;
	
	//stub for setting the dock id
	function setSmartDockId(value){
		$j.Avaya.SmartDockId = value;
	}
	
	/* 
	>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
		DEBUG
	>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
	*/
	$j.Avaya.global.debug = false;
	(document.location.href.search("debug=true") != -1) ? $j.Avaya.global.debug = true : $j.Avaya.global.debug = false;
	if (ISREGISTERED) {
	    $j.Avaya.global.isRegistered = true;
	}
    /* 
	>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
		EVENT: DOM READY
	>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
	*/
	$j(function() {		
		$j.Avaya.global.Tracking = new $j.Avaya.Tracking();
		
		$j.Avaya.global.CustomSelects = [];
		$j('body').addClass('hasJS');
		
		setTimeout(function() {
			var $select = $j('#mastheadCountrySelect select');
			
			new $j.Avaya.CustomSelect($select, {
				maxHeight:350,
				submitFunction: function() {
					// you could change the val on the select items to be a url, then go document.location = $select.val()
					document.location = $select.val();	
				},
				openAtTop : true
			});
		}, 10);

		$j.Avaya.Page.Sizing.init();
		$j.Avaya.Page.MastNav.init();
		
		new $j.Avaya.Page.Footer();
		new $j.Avaya.GlobalSearch();
		
		// registered status... turn off if in debug so it doesn't annoy us.
		if($j.Avaya.global.debug) {
			$j.Avaya.global.isRegistered = true;
		}
		
		if($j.Avaya.ToolTip) {
		$j.Avaya.global.ToolTip = new $j.Avaya.ToolTip({location:'NE', yOffset: 50, xOffset: -20, fixedRef:$j('#smartDock')});				
		}
		if($j.Avaya.SmartDock) {
		$j.Avaya.global.SmartDock = new $j.Avaya.SmartDock();
		}
		
		if (document.getElementById('utilityBar')){
			new $j.Avaya.UtilityBar();
		}

		$j('#partnerLocatorLink').click(function(e){
			e.preventDefault();
			$j.Avaya.Page.setPopupCookie();
			window.open(e.target.href,'PartnerLocator','width=639,height=510,top=250,left=300,scrollbars=yes,resizable=yes');
		});

		$j('.video-link').live('click',function(e){
			e.preventDefault();
			$j.Avaya.Page.setPopupCookie();
			window.open(e.target.href,'VideoPlayer', 'width=605,height=431,top=250,left=300,scrollbars=yes');
		});

        $j("#privacyLink").click(function() {
           setTimeout(function() {
            document.location = $j("a.privacyStatementLink").attr("href");
           }, 100);
	    });

		
		$j('button.button').live('mouseover',function(){
			$j(this).addClass('active');
		}).live('mouseout',function(){
			$j(this).removeClass('active');
		});
		
		$j('a.services-popup').live('click',function(e){
			e.preventDefault();
			$j.Avaya.Page.setPopupCookie();
			window.open(e.target.href,'ServicesPopup','width=605,height=500,top=250,left=300,scrollbars=yes');
	    });	
	    
	    $j('a.producttech-popup').live('click',function(e){
			e.preventDefault();
			$j.Avaya.Page.setPopupCookie();
			window.open(e.target.href,'ProductTechPopup','width=605,height=500,top=250,left=300,scrollbars=yes');
	    });
	
		if(typeof SESSION_EXPIRED != "undefined" && SESSION_EXPIRED == 1) {
			alert($j.Avaya.Messages.Session.expired);
		}
		
		//for SEO, address located in footer.html
		var hiddenAddress = document.getElementById('hiddenAddress');
		if (hiddenAddress){
			hiddenAddress.style.display = "none";
		}
		
		
	});
	
	$j(window).scroll(function(){
		if ($j.Avaya.global.ToolTip && $j.Avaya.global.ToolTip.checkOpen())
			$j.Avaya.global.ToolTip.killToolTip();
	});
	
	/* 
	>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
		EXTENSION: delegate
	>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
	*/
	$j.fn.delegate = function(eventType, rules) {
	  return this.bind(eventType, function(e) {
		var target = $j(e.target);
		for(var selector in rules)
		  if(target.is(selector)) {
			return rules[selector].apply(this, arguments)
		  }
	  })
	}
	$j.Avaya.global.ResizeTimeout;
	
	$j(window).resize(function(){
		clearTimeout($j.Avaya.global.ResizeTimeout);
		$j.Avaya.global.ResizeTimeout = setTimeout(function(){
			$j.Avaya.Page.Sizing.resize();
			setTimeout(function(){
		$j.Avaya.Page.Sizing.resize();
			},1);
		},200);
	});
	
	$j.Avaya.Item = {
		truncate: 50
	}
	
	$j.Avaya.Page = {
		region: 'United States',
		minHeight: 700,
		minWidth: 950,
		Section: {
			id : 'home'
		},
		setPopupCookie : function(){
			var date = new Date();
			date.setMinutes(date.getMinutes() + 5);
			$j.cookie('usePopup','true', {expires : date, path : "/", domain : "avaya.com"});
		}
	};
	
	if(typeof PAGETYPE != "undefined") {
		$j.Avaya.Page.Section.id = PAGETYPE;	
	}
	
	$j.Avaya.Page.Sizing = {
		
		init: function(){
			this.page = $j('#page');
			this.wrapper = $j('#wrapper');
			this.footer = $j("#footer");
			this.resize();
			this.timeout;
		},
		
		resize: function(){
			if (!this.page || !this.page.get(0) || $j.Avaya.Page.Sizing.dontResize) return;
			var windowHeight = $j(window).height();
			var wrapperHeight = this.wrapper.height();

			if (wrapperHeight<$j.Avaya.Page.minHeight && windowHeight<$j.Avaya.Page.minHeight){
				this.page.css({height:$j.Avaya.Page.minHeight});
				this.footer.css({position:'absolute', bottom:0});
			}
			else if (wrapperHeight+64>windowHeight){
				this.page.css({height:'auto'});
				this.footer.css({position:'static'});
			} 
			else {
				this.page.css({height:windowHeight});
				this.footer.css({position:'absolute', bottom:0});
			}

			var windowWidth = $j(window).width();
		    var pageWidth = windowWidth < $j.Avaya.Page.minWidth ? $j.Avaya.Page.minWidth : windowWidth;
		    this.page.width(pageWidth);		    
		}
	}

	$j.Avaya.Page.MastNav = {

		init: function(){
			var self = this;
			this.nav = $j('#mastheadNav');
			this.pointer = $j('#mastheadNavPointer');
			this.mainNavs = this.nav.find('li.mainNavs');
			this.subNavs = this.nav.find('li.subNavs');
			this.activeClass = 'active';
			this.flippedClass = 'flippedSubNav';
			this.liPadding = 30;
			this.showTimer = 100;
			this.hideTimer = 300;
			this.activeMain = this.activeSub = -1;
			this.showMainTimeout,this.showSubTimeout,this.hideMainTimeout,this.hideSubTimeout;
			this.sifr();
			
			if(this.nav.get(0) != null) {
				this.navIndicator();
			}
		/*****Bind Events*****/
			
			this.nav.bind('mouseleave',function(e){
				self.hideMain(self.nav.find('.'+self.activeClass).eq(0));
			});
			
			this.mainNavs.each(function(index){
				var $this = $j(this);
				$this.hover(function(e){
					self.showMain($this, index);
				},function(e){
					self.hideMain($this);
				});
			});
			
			this.subNavs.each(function(index){
				var $this = $j(this);
				$this.hover(function(e){
					self.showSub($this, index);
				},function(e){
					self.hideSub();
				});
			});
			
		},
		
		sifr : function(){
			var swf = $j.Avaya.SifrConfig.gothamBook;
			var options = {
				selector : '#mastheadNav ul p',
				css : [
					'.sIFR-root { text-align: center; font-weight: normal; }',
					'a { text-decoration: none; }',
					'a:link { color: #404040; }',
					'a:hover { color: #CC0000; }'
				],
				forceSingleLine : true
			}
			$j.Avaya.SifrConfig.masterReplace(swf,options);

		},
		
		navOrder: ['solutions','products','support','community','aboutus','myavaya'], //Lowercase no spaces
		
		navIndicator: function(){
			var page = $j.Avaya.Page.Section.id.replace(/\s/g,'').toLowerCase();
			$j('body').addClass(page);
			if (page && page!='home' && page!='resources'){
				var li;
				
				for (var i=0;i<this.navOrder.length;i++){
					if (page==this.navOrder[i]){
						li = this.mainNavs[i];
						break;
					}
				}
				
				if (li){
				var left = $j(li).position().left+this.liPadding+this.nav.find('ul').eq(0).position().left;
				this.pointer.css({left:left});
				}
				
			} else {
				this.pointer.hide();
			}
		},
		
		showMain:function(tar, index){
			var self = this;
			clearTimeout(this.hideMainTimeout);
			clearTimeout(this.showMainTimeout);

			// center menu
			//var titleWidth = tar.find("p").width();
			//var menuWidth = tar.find("ul:first").width();
			//tar.find("ul:first").css({marginLeft: (-(menuWidth - titleWidth)  / 2)+ 8})
			
			this.showMainTimeout = setTimeout(function(){
				if (!tar.hasClass(self.activeClass)){
					self.mainNavs.eq(self.activeMain).removeClass(self.activeClass);
					self.subNavs.eq(self.activeSub).removeClass(self.activeClass);
					tar.addClass(self.activeClass);
					self.activeMain = index;
					self.pointer.hide();
				}
			}, self.showTimer);
		},
		
		hideMain:function(tar){
			var self = this;
			clearTimeout(this.hideMainTimeout);
			clearTimeout(this.showMainTimeout);
			
			this.hideMainTimeout = setTimeout(function(){
				tar.removeClass(self.activeClass);
				self.pointer.show();
			}, self.hideTimer);
		},
		
		showSub:function(tar, index){
			var self = this;
			clearTimeout(this.hideSubTimeout);
			clearTimeout(this.showSubTimeout);
			
			this.showSubTimeout = setTimeout(function(){
				if(!tar.hasClass(self.activeClass)){
					self.subNavs.eq(self.activeSub).removeClass(self.activeClass).removeClass(self.flippedClass);
					tar.addClass(self.activeClass);
					if (!self.checkOffset(tar)) {
						tar.addClass(self.flippedClass);
					}
					self.activeSub = index;
				}
			}, self.showTimer);
		},
		
		hideSub:function(){
			var self = this;
			clearTimeout(this.showSubTimeout);
			
			this.hideSubTimeout = setTimeout(function(){
				self.subNavs.each(function(){
					$j(this).removeClass(self.activeClass).removeClass(self.flippedClass);
				})
			}, self.hideTimer);
		},
		
		hideAll:function(){
			this.mainNavs.eq(this.activeMain).removeClass(this.activeClass);
			this.subNavs.eq(this.activeSub).removeClass(this.activeClass);
		},
		
		checkOffset : function(tar){
			var 
				$window = $j(window),
				viewport = $window.width() + $window.scrollLeft(),
				returnVal = 1,
				ul = tar.children('ul');
				
			if (ul.width() + ul.offset().left > viewport) returnVal = 0;
			
			return returnVal;
		}
	}

	$j.Avaya.Page.Footer = function(){
		
		var footer = document.getElementById('footer');
		if (!footer || typeof PAGETYPE == 'undefined') return;
		
		var links = footer.getElementsByTagName('a');
		
		var linkOrder = [
			'partner',
			'contacts',
			'careers',
			'resourcelibrary',
			'sitemap',
			'termsofuse',
			'privactystatement'
		]
		
		var page = PAGETYPE.replace(/[\s-_]/g,'').toLowerCase();

		for (var i=0;i<linkOrder.length;i++){
			if (page == linkOrder[i]){
				links[i].className = links[i].className + ' red';
				break;
			}
		}
	}
	
	$j.Avaya.SifrConfig = {

		init: function(){
			sIFR.activate(this.gothamLight);
			sIFR.activate(this.gothamBook);
		},
		
		gothamLight: {
			src: '/_assets/swf/gothamLight.swf',
			ratios : [9, 1.27, 13, 1.18, 18, 1.14, 26, 1.13, 32, 1.11, 37, 1.1, 64, 1.09, 105, 1.08, 107, 1.07, 119, 1.08, 122, 1.07, 1.08]
		},
		
		gothamBook: {
			src: '/_assets/swf/gothamBook.swf'
		},
		
		masterReplace: function(swf,options){
			if (typeof(sIFR)=='object'){
				sIFR.replace(swf, {
					selector: options.selector,
					css: options.css,
                                        forceSingleLine : options.forceSingleLine,
					wmode: 'transparent'
				});
			}
		}
	}
	$j.Avaya.SifrConfig.init();

/* 
	>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
		CLASS: CustomSelect
	>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
*/

	$j.Avaya.CustomSelect = function(sb,options){
		//if (!container) return;
		
	/*****Initialize*******/	
		sb.wrap('<div class="selectParent"></div>');
		this.container = sb.parents(".selectParent");
		
		this.select = sb;
		if (!this.select.get(0)) return;
		
		this.index = $j.Avaya.global.CustomSelects.length;
		$j.Avaya.global.CustomSelects.push(this);
		
		var self = this;
		this.isOpen = this.isFocused = 0;
		
		this.settings = $j.extend({
			maxHeight: 150,
			zIndex: 10,
			openZIndex: 50000,
			ignoredValue:false, //Options with ignored value will only be processed by javascript
			functions:'',
			submitFunction: false, //Click or enter on an option will submit the form, which calls the submitFunction if it is defined, opts with ignoredValue will not trigger submit
			openCallback : false,
			closeCallback : false,
			truncateDisplay:false,
			openAtTop : false
		},options);
		
		this.locked = false;
		this.parentForm = this.select.parent('form');
		
	/******Create DropDown*******/
		
		this.wrapper = $j('<div id="customSelect_'+this.index+'" class="selectWrapper"></div>');
		this.dropDown = $j('<div class="selectDropDown"></div>');
		this.listContainer = $j('<div class="selectScroller"></div>');
		this.list = $j('<ul class="selectList"></ul>');
		
		this.currentIndex = 0;
		this.opts = this.select.find('option');
		
		this.createList();
		
		var currentItem = this.opts[this.currentIndex].innerHTML;
		var wasTruncated = false;
		
		if (this.settings.truncateDisplay && currentItem.length > this.settings.truncateDisplay){
			currentItem = currentItem.substr(0,this.settings.truncateDisplay) + "...";		
			wasTruncated = "true";		
		}
			
		
		this.display = $j('<div class="selectDisplay"><span>'+currentItem+'</span></div>');
		this.displaySpan = this.display.find('span');
		if(wasTruncated) {
			this.displaySpan.addClass("truncated");	
		}
		
		this.listContainer.append(this.list);
		this.dropDown.append(this.listContainer);
		this.wrapper.append(this.display);
		this.wrapper.append(this.dropDown);
		this.container.append(this.wrapper);
		
		
		
		this.setScrollPane();

	/******Bind Events ******/
		
		$j(document).click(function(e){
			if (self.isOpen){
				var parent = '#customSelect_'+self.index;
				if (!$j(e.target).parents(parent).get(0) || e.target.nodeName.toLowerCase() == "p"){ //p is to fix the dropdown from not closing on the solutions home page
					self.close();
				}
			}
		}).keyup(function(e){
			if (self.isFocused||self.isOpen){
				self.changeValue();
				if (e.keyCode==9 || e.keyCode==13 || e.keyCode == 27){
					if (e.keyCode == 13){
						self.clickOption();
					}
					self.close();
				}
			}
		});
		
		this.display.click(function(){
			self.select.focus();
			self.isOpen ? self.close() : self.open();
		}).hover(function(){
			$j(this).addClass('hovered');
		},function(){
			$j(this).removeClass('hovered');
		});
		
		this.list.delegate('click',{
			'li' : function(e){
				e.preventDefault();
				self.clickOption(e.target);
				self.select.focus();
			}
		});
		
		this.list.find('li').hover(function(e){
			$j(this).addClass('hovered');
		},function(e){
			$j(this).removeClass('hovered');
		});
		
		this.select.focus(function(e){
			self.isFocused = true;
		}).blur(function(e){
			self.isFocused = false;
		});
	}

	/*******CustomSelect methods ******/
	
		$j.Avaya.CustomSelect.prototype.createList = function(){
			var self = this,
				liString = '';
			
			this.opts.each(function(i){
				var $this = $j(this);
				if (this.selected) { self.currentIndex = i; }
				
				var optgroup = $this.parents('optgroup');
				
				if (optgroup.length > 0 && $this.prev().length == 0){
					liString += '<li class="optGroup">'+optgroup.attr('label')+'</li>';				
				}
				
				liString += '<li class="selectOpt_' + i +'">'+this.innerHTML+'</li>';			
			});
			
			this.list.html(liString);
			
			this.listItems = this.list.find('li');
			
			this.listItems.eq(0).addClass('first');
			this.listItems.eq(this.listItems.length - 1).addClass('last');
			
			this.selectables = [];
			
			this.listItems.each(function(){
				if (this.className.indexOf('optGroup') == -1){
					self.selectables.push($j(this));
				}
			});
			
			this.selectables[this.currentIndex].addClass('selected');
			
			
		}
	
		$j.Avaya.CustomSelect.prototype.setScrollPane = function(){
			if (this.listContainer.height()>this.settings.maxHeight){
				this.listContainer.css({height:this.settings.maxHeight});
				this.scrollPane = this.listContainer.jScrollPane({});
			} else if (this.scrollPane){
				this.listContainer.css({height:'auto'}).jScrollPane();
			}
		}
	
	
		$j.Avaya.CustomSelect.prototype.resetScrollPane = function(){
			
			if (this.scrollPane){
				this.listContainer.jScrollPaneRemove();
			}
			
			this.setScrollPane();
			
		}
	
		$j.Avaya.CustomSelect.prototype.matchToDisplay = function(){
			var self = this;
			if (this.opts.eq((this.select.get(0).selectedIndex)).html() != this.displaySpan.html()){
				this.opts.each(function(index){
					if (this.innerHTML == self.displaySpan.html()){
						self.select.get(0).selectedIndex = index;
						self.changeValue();
						return false;
					}
				});
			} 
		}
		
		$j.Avaya.CustomSelect.prototype.matchToValue = function(val){
			var self = this;
			this.opts.each(function(i){
				if (this.value == val){
					self.select.get(0).selectedIndex = i;
					self.changeValue();
					return false;
				}
			});
		}
		
		$j.Avaya.CustomSelect.prototype.matchToIndex = function(){
			this.displaySpan.html(this.opts.eq((this.select.get(0).selectedIndex)).html());
		}
		
		//call after an option has been removed/added/edited
		$j.Avaya.CustomSelect.prototype.updateList = function(){
			this.locked = true;
			this.opts = this.select.find('option');
			this.createList();
			this.setScrollPane();

			this.list.find('li').hover(function(e){
				$j(this).addClass('hovered');
			},function(e){
				$j(this).removeClass('hovered');
			});
				
			this.locked = false;
		}
	
		$j.Avaya.CustomSelect.prototype.open = function(){
			if (this.isOpen || this.locked) return;
			this.wrapper.addClass('selectOpen');
			this.container.css({zIndex:1000});
			if (this.scrollPane) {
				this.scrollPane = this.listContainer.jScrollPane({});
				if (!this.settings.openAtTop){
				this.scrollPane[0].scrollTo('li.selected');
			}
				else {
					this.scrollPane[0].scrollTo('li:first');
				}
			}
			
			this.isOpen = true;
			
			if (typeof this.settings.openCallback == 'function'){
				this.settings.openCallback();
			}
		}

		$j.Avaya.CustomSelect.prototype.close = function(){
			if (!this.isOpen) {
				this.locked = false;
				return;
			}
			this.container.css({zIndex:100});
			this.wrapper.removeClass('selectOpen');
			this.isOpen = this.locked = false;
			
			if (typeof this.settings.closeCallback == 'function'){
				this.settings.closeCallback();
			}
		}

		$j.Avaya.CustomSelect.prototype.clickOption = function(tar){
			this.locked = true;
			
			if (tar && tar.className.indexOf('optGroup') != -1) return; //Always ignore optgroup clicks
			
			var select = this.select.get(0);
			var index;
			
			if (tar){
				index = parseInt(tar.className.split('_')[1]);
			} else {
				index = select.selectedIndex;
			}

			var value = select[index].value;
			
			if (this.settings.ignoredValue&&value.search(this.settings.ignoredValue) != -1){	
				
				if (typeof(this.settings.functions[value.replace(this.settings.ignoredValue + " ", "")])=='function'){
					
					this.settings.functions[value.replace(this.settings.ignoredValue + " ", "")]();
				
				}
				
			} else {
				select.selectedIndex = index;
				
				if (typeof(this.settings.submitFunction)=='function'){
					this.settings.submitFunction();
				}
				
				this.changeValue();
			}
			
			this.close();
		}

		$j.Avaya.CustomSelect.prototype.changeValue = function(){
			var index = this.select.get(0).selectedIndex;
			if (index==this.currentIndex) return;
			
			this.selectables[this.currentIndex].removeClass('selected'); //remove selected class from old item
			
			var newItem = this.selectables[index].addClass('selected');
			
			if (this.itemVisible(newItem)==false&&this.scrollPane){
				this.scrollPane[0].scrollTo('li.selected');
			}
			
			var truncated = newItem.html();
			
			this.displaySpan.removeClass("truncated");
			
			if (this.settings.truncateDisplay && newItem.html().length > this.settings.truncateDisplay){
				truncated = newItem.html().substr(0,this.settings.truncateDisplay) + "...";		
				this.displaySpan.addClass("truncated");
			} 
			
			this.displaySpan.html(truncated);
			this.display.data("Value",this.select.val());
			
			this.currentIndex = index;
		}

		//returns bool
		$j.Avaya.CustomSelect.prototype.itemVisible = function(item){
			if (!this.isOpen) return true;
			var pos = item.offset().top;
			var top = this.dropDown.offset().top;
			if (pos>top && pos+item.height()<top+this.dropDown.height()){
				return true;
			}
			return false;
		}
		
		$j.Avaya.CustomSelect.prototype.jumpToIndex = function(index){
			if (index<this.opts.length){
			
				this.select.get(0).selectedIndex = index;
				this.changeValue();
			
			}
		}
		
		$j.Avaya.CustomSelect.prototype.jumpToValue = function(value){
			var index = -1;
			
			this.opts.each(function(i){
				if (this.value==value){
					index = i;
					return false;
				}
			});
			
			if (index!=-1){
				this.select.get(0).selectedIndex = index;
				this.changeValue();
			}
			
			return index;
		}
		
		$j.Avaya.CustomSelect.prototype.editOptionText = function(index,text){
			this.opts.eq(index).html(text);
			this.updateList();
		}
		
		$j.Avaya.CustomSelect.prototype.truncateDisplay = function(){
			
		}
		
	/* 
	>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
		CLASS: ResultsFilter
	>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
	*/
	
	$j.Avaya.ResultsFilter = function(params, moreNum){
		var element = $j(params.element);
		var trigger = element.find('h3 a');
		var current = element.find('div.current');
		var list = element.find('ul');
		var listEntire = element.find('li > a');
		var listPartial = element.find('li:gt(' + (moreNum - 1) + ')');
		var selected = element.find('a.selected');
		element.append('<div class="moreFilter"><a href="javascript:void(0)">'+$j.Avaya.Messages.Filters.more+'</a></div>');
		var moreDiv = element.find('div.moreFilter');
		var clearAlltrigger = $j('div#clearAll > a');
		var locked = false;
		
		trigger.click(function(e){
			e.preventDefault();
			if (element.hasClass('open')){
				_close();
			} else {
				_open();
			}
		});
		
		if (selected.get(0)){
			_setClear();
		}
		
		function _open(){
			if (locked) return;
			locked = true;
			element.addClass('open');
			if(_checkSelected()) {
				list.slideDown(200,function(){							   
					locked = false;
					$j.Avaya.Page.Sizing.resize();
				});
			} else {
				listPartial.hide();
				moreDiv.show();
				_moreResults();
				list.slideDown(200,function(){							   
					locked = false;
					$j.Avaya.Page.Sizing.resize();
				});
			}
		}
		
		function _close(){
			if (locked) return;
			locked = true;
			list.slideUp(200,function(){	
				element.removeClass('open');
				locked = false;
				moreDiv.hide();
				$j.Avaya.Page.Sizing.resize();
			});
		}
		
		function _checkSelected() {
			var className = '';
			var num = '0';
			if(listEntire.length <= moreNum)
				return true;
			listEntire.each(function(index) {
				className = $j(this).attr('class');
				if(className == 'selected')
					num = index;
			});
			if(num > moreNum)
				return true
			else
				return false			
		}
		
		function _moreResults() {
			var moreTrigger = element.find('div.moreFilter a');
			moreTrigger.click(function(e) {
					listPartial.slideDown(200,function(){
						moreDiv.hide();
						locked = false;
					$j.Avaya.Page.Sizing.resize();
					});				   
			});
		}
		
		function _setClear() {
		    current.addClass('has-current');
			
			var selections = "";
			selected.parents("li").find("a.clearButton").each(function(index, itm) {
				selections += '<span>' + selected.eq(index).html() + '</span>';
				selections += '<a class="clearButton" href="'+$j(this).attr("href")+'">[x]</a>';
				selections += '<div class="clear"></div>';
			});
			current.html(selections);
		}
		
		function _removeClear() {
			element.find('li > a.clearButton').remove();
			element.find('li > div.clear').remove();
		}
	}
	
	/*
		>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
			CLASS: Utility Bar
		>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
	*/
	$j.Avaya.UtilityBar = function(options) {
		var settings = $j.extend({
			container: $j("#utilityBar"),
			emailBtn: $j("#utilityBar-Email"),
			emailOverlay: $j("#emailAFriend"),
			//utilSaveList: $j("#util-saveCollections"),
			smartdock: $j.Avaya.global.SmartDock,
			id: "emailAFriend"
		},options);
		
		var $mainLIs = $j("#utilityBar > li");
		var $mainAs = $j("#utilityBar > li > a");
		var _locked = false;
		var $shareListLIs = settings.container.find("ul.util-share a");
		var bodyHTML =  $j("#emailAFriend").find(".overlay-body").html();
		
		if(pageinfo) {
			$shareListLIs.each(function(index, itm) {
				var href = $j(itm).attr("href");
				href = href.replace("@@@PAGEHREF@@@", pageinfo.url);
				href = href.replace("@@@PAGETITLE@@@", pageinfo.title);
				href = href.replace("@@@BODYTEXT@@@", pageinfo.description);
				$j(itm).attr("href", href);
			});
		}
		
		$j('a.utilPartnerLocatorLink').live('click',function(e){
			e.preventDefault();
			$j.Avaya.Page.setPopupCookie();
			
			window.open(e.target.href,'PartnerLocator','width=639,height=450,top=250,left=300,scrollbars=yes,resizable=yes');
		});

		
		// EVENTS 
		$mainLIs.hover(function(){
			_show(this);
		},function(){
			_hide(this);
		});
		
		$mainAs.focus(function() {
			$mainAs.each(function() {
				_hide(this);					  
			});
			_show($j(this).parents("li"));					   
		});
		
		settings.container.find("a.print").click(_print);
		
		function initEmailActions() {
		settings.emailBtn.click(_showEmailPopup);
		settings.emailOverlay.find("a.overlay-close").click(_hideEmailPopup);
		//settings.emailOverlay.find("a.button").click(_validate);            
		settings.emailOverlay.find("form").submit(_validate);
		}
		initEmailActions();

		// PRIVATE
		function _show(tar) {

			$j.Avaya.global.ToolTip.hideToolTip();

			if(!_locked) {
				var $target = $j(tar);
				
				$target.addClass("on");
				var $saveList = $j("#util-saveList");
				
				$j("#util-saveList li:gt(0)").remove();
				$saveList.append($j("#item-manager").find("ul").html());
				if($j("#item-manager li").length == 1) {
					$saveList.find("a").html($j.Avaya.Messages.UtilBar.smartdock);
				}	
				$saveList.find("a").click(_addBookmark);
			}

		}
		function _hide(tar) {

			if(!_locked) {
				$mainLIs.removeClass("on");
			}

		}
		function _addBookmark(e) {
			e.preventDefault(e);
			
			settings.smartdock.addBookmark(e.target, $j(this).attr("href").split("_")[$j(this).attr("href").split("_").length-1], pageinfo);
		}
		function _showEmailPopup() {
			_locked = true;
			settings.emailOverlay.show();
			$j.Avaya.global.Tracking.pageView("Email","Show","Utility_Bar");
			$j.Avaya.SifrConfig.masterReplace($j.Avaya.SifrConfig.gothamLight,{
			   selector: '#emailAFriend h3',
			   css: {
					'.sIFR-root': { 
						'color': '#404040', 
						'font-size': 18
					}
			   }
			});
			
			$j("#"+settings.id).find("#msg").maxLength(1024);
		}
		function _hideEmailPopup() {
			_locked = false;
			
			$j.Avaya.global.Tracking.clickEvent("Utility_Bar_Email_Close");
			
			var $overlayBody = $j("#"+settings.id + " .overlay-body");
			if($overlayBody) {
				$j("#"+settings.id).removeClass("thankYou");
				$overlayBody.html(bodyHTML);
				initEmailActions();
			}
			
			settings.emailOverlay.hide();
			var fields = $j("#emailAFriend input, #emailAFriend textarea");
			$j("#emailAFriend label").removeClass("red");
			fields.val("");
			
			_hide();
		}
		function _print() {
			$j.Avaya.global.Tracking.pageView("Print","Print","Utility_Bar");
			//$j.Avaya.global.Tracking.clickEvent("Utility_Bar_Print");
			window.print();	
		}
		function _validate(e) {
			e.preventDefault(e);
			$j.Avaya.global.Tracking.clickEvent("Utility_Bar_Email_Submit");
			var fields = $j("#emailAFriend input, #emailAFriend textarea");
			$j("#emailAFriend label").removeClass("red");
			
			isValid = true;
			fields.each(function(index, itm) {
				itm.value = itm.value.split("<").join("");
				itm.value = itm.value.split(">").join("");
				if(($j(itm).hasClass("required") && $j(itm).val() == "") || ($j(itm).hasClass("email") && ! _validateEmail($j(itm).val()))) { 
					isValid = false;
					$j(itm).parents("tr").find("label").addClass("red");
				}
			});
			
			if(isValid) {
				// DO SEND HERE !
                                $j.Avaya.global.Tracking.pageView("Email","ThankYou","Utility_Bar");
				jsonParam = [
			                {
			                'yourname':$j('#yourname').val(),
			                'youremail':$j('#youremail').val(),
			                'colleaguename':$j('#colleaguename').val(),
			                'colleagueemail':$j('#colleagueemail').val(),
			                'msg':$j('#msg').val(),
			                'url':document.location.href
			                }
			            ];
		        //alert(JSON.stringify(jsonParam));	
		        var utilityBar = new UtilityBar();
			    utilityBar.SendEmail(JSON.stringify(jsonParam),function(params){
			    });
				//_hideEmailPopup();
				
				var closeBtn = '<div class="overlay-actions"><button class="button" id="close_'+settings.id+'" type="submit">' + $j.Avaya.Messages.EmailAvaya.close + '</button></div>';
				
				$j("#"+settings.id).addClass("thankYou");
				var $overlayBody = $j("#"+settings.id + " .overlay-body");
				var height = $overlayBody.height();
				$overlayBody.data("html", $overlayBody.html());
				$overlayBody.html($j.Avaya.Messages.EmailAvaya.sent + closeBtn);
				
				$overlayBody.height(height);
				
				$j('#close_'+settings.id).click(function(e) {
				_hideEmailPopup();
				});
				
				$j.Avaya.SifrConfig.masterReplace($j.Avaya.SifrConfig.gothamLight,{
				   selector: '#'+settings.id + ' .overlay-body h3',
				   css: {
						'.sIFR-root': { 
							'color': '#404040', 
							'font-size': 18
						}
				   }
				});
				
				$j.Avaya.SifrConfig.masterReplace($j.Avaya.SifrConfig.gothamLight,{
				   selector: '#'+settings.id + ' .overlay-body h2',
				   css: {
						'.sIFR-root': { 
							'color': '#cc0000', 
							'font-size': 18
						}
				   }
				});
			}
		}
		function _validateEmail(address) {
			var email = /^([a-zA-Z0-9])+([\.a-zA-Z0-9_-])*@([a-zA-Z0-9_-])+(\.[a-zA-Z0-9_-]+)+$/;
			if(!email.test(address)) {
				return false;
			}
			return true;
		}
	}
	
	/* 
		>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
			EXTENSION: Remove JScrollPane
		>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
	*/
	$j.fn.jScrollPaneRemove = function() {
		$j(this).each(function() {
			$this = $j(this);
			var $c = $this.parent();
			if ($c.is('.jScrollPaneContainer')) {
				$this.css(
					{
						'top':'',
						'height':'',
						'width':'',
						'padding':'',
						'overflow':'',
						'position':''
					}
				);
				$c.after($this).remove();
			}
		});
	}

	/*
		>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
			EXTENSION: Cookie
		>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
	*/
	$j.cookie = function(name, value, options) {
		if (typeof value != 'undefined') { // name and value given, set cookie
			options = options || {};
			if (value === null) {
				value = '';
				options = $.extend({}, options); // clone object since it's unexpected behavior if the expired property were changed
				options.expires = -1;
			}
			var expires = '';
			if (options.expires && (typeof options.expires == 'number' || options.expires.toUTCString)) {
				var date;
				if (typeof options.expires == 'number') {
					date = new Date();
					date.setTime(date.getTime() + (options.expires * 24 * 60 * 60 * 1000));
				} else {
					date = options.expires;
				}
				expires = '; expires=' + date.toUTCString(); // use expires attribute, max-age is not supported by IE
			}
			// NOTE Needed to parenthesize options.path and options.domain
			// in the following expressions, otherwise they evaluate to undefined
			// in the packed version for some reason...
			var path = options.path ? '; path=' + (options.path) : '';
			var domain = options.domain ? '; domain=' + (options.domain) : '';
			var secure = options.secure ? '; secure' : '';
			document.cookie = [name, '=', encodeURIComponent(value), expires, path, domain, secure].join('');
		} else { // only name given, get cookie
			var cookieValue = null;
			if (document.cookie && document.cookie != '') {
				var cookies = document.cookie.split(';');
				for (var i = 0; i < cookies.length; i++) {
					var cookie = $j.trim(cookies[i]);
					// Does this cookie string begin with the name we want?
					if (cookie.substring(0, name.length + 1) == (name + '=')) {
						cookieValue = decodeURIComponent(cookie.substring(name.length + 1));
						break;
					}
				}
			}
			return cookieValue;
		}
	};
	
	$j.fn.maxLength = function(max, charDisplay, charText){
		var $this;
		charText = (typeof charText == 'undefined') ? '' : ' ' + charText;
		charDisplay = (typeof charDisplay == 'undefined') ? null : charDisplay;
		var set = {
			max: function(m){ $this.data('charMax', m); },
			count: function(c) { $this.data('charCount', c); }
		}
	
		var get = {
			max: function(){ return $this.data('charMax'); },
			count: function() { return $this.data('charCount'); },
			remaining: function() { return $this.data('charMax') - $this.data('charCount'); }
		}
	
		return this.each(function(){
			$this = $j(this);
			set.max(max);
			set.count($this.val().length);
	
	
			$this.change(function(e) {
				actions(e);
			});
	
			function actions(e) {
				var code = e.keyCode;
	
				if(	code != 8 &&
					code != 9 &&
					!(code >= 16 && code <= 20) &&
					!(code >= 33 && code <= 40) &&
					!(code >= 44 && code <= 46) &&
					!(code >= 112 && code <= 123)
					){
	
					if(get.count() >= get.max()){
						return false;
					}
					else {
						var val = $this.val();
						if(val.length > get.max()) {
							$this.val(val.substring(0, get.max()));
						}
						set.count($this.val().length );
	
					}
				}
			}
			
			$this.keydown(function(e) {
				var code = e.keyCode;
				if(	code != 8 &&
					code != 9 &&
					!(code >= 16 && code <= 20) &&
					!(code >= 33 && code <= 40) &&
					!(code >= 44 && code <= 46) &&
					!(code >= 112 && code <= 123)
					){
						if($this.val().length == get.max()) {
							e.preventDefault(e);
						}
				}
			});
			
			$this.keyup(function(e){
				var val = $this.val();
				if(val.length > get.max()) {
					$this.val(val.substring(0, get.max()));
				}
				set.count($this.val().length);
	
			})
		});
	}
	
	
	$j.Avaya.QueryString = function(){

		var qs = window.location.search.substring(1);
		var pairs = qs.split("&");
		
		function _key(){
			var obj = {};
			
			for (var i=0;i<pairs.length;i++){
				var split = pairs[i].split("=");
				var key = decodeURIComponent(split[0]);
				var val =  decodeURIComponent(split[1]);
				obj[key] = val;
			}
			
			return obj;
		}
		
		this.key = _key();
	}
	
	$j.Avaya.ResultControls = function(params){
	
		var $resultControls = $j('#listView , #gridView');
		if ($resultControls.length!=2) return;
		
		var currentTar = false;

		var qs = new $j.Avaya.QueryString();
		var view = qs.key['view'];
		
		if ($j.Avaya.global.ToolTip && $j('#results').hasClass('listView')){
			$j.Avaya.global.ToolTip.lockToolTip();
		}
		
		$resultControls.click(function(e){
			e.preventDefault();
			_toggle(e.target);
		});
		
		$resultControls.each(function(){
			var $this = $j(this);
			if ($this.hasClass('on')){
				$j('#results').addClass(this.id);
				return false;
			}
		});
		
		_checkQueryString();
		
		function _toggle(tar){
			currentTar = tar;
			$resultControls.each(function(){
				this.className = this.className.replace(/\s*on/g,'');
			});
			
			if ($j.Avaya.global.ToolTip){
				$j.Avaya.global.ToolTip.lockToolTip();
				
				if (tar.id == "gridView"){
					$j.Avaya.global.ToolTip.unlockToolTip();
				}
			}
			
			tar.className = tar.className + ' on';
			document.getElementById('results').className = tar.id;
			
			if (typeof params.toggleCallback == 'function'){
				params.toggleCallback();
			}
			
			$j.Avaya.Page.Sizing.resize();
		}
		
		function _checkQueryString(){
			if (qs.key['view'])
			{
				if (view.search(/list/i)!=-1 && document.getElementById('listView')){
					_toggle(document.getElementById('listView'));
				} else if (view.search(/grid/i)!=-1 && document.getElementById('gridView')){
					_toggle(document.getElementById('gridView'));
				}
			}
		}
	}
	
	//probably later integrate into avaya.valigation//
	$j.Avaya.validateEmail = function(address) {
			var email = /^([a-zA-Z0-9])+([\.a-zA-Z0-9_-])*@([a-zA-Z0-9_-])+(\.[a-zA-Z0-9_-]+)+$/;
			if(!email.test(address)) {
				return false;
			}
			return true;
	}	
	
	$j.Avaya.Error = {
		SmartDock: {
			newCollectionRegister: '<span class="bold">Reminder: </span><br />You must register to create a new collection.',
			renameCollectionRegister: '<span class="bold">Reminder: </span><br />You must register to rename a collection.',
			deleteCollectionRegister: '<span class="bold">Reminder: </span><br />You must register to delete a collection.',
			registerToSave: '<span class="bold">Item added</span><br />You must register to permanently save your Smart Dock.',
			exceedItemLimit: '<span class="bold">Reminder: </span><br />You must register to add more than 5 items.',
			exceedItemLimitGeneric: 'You must register to add more items to your Smart Dock.',
			areYouSureBookmark: "Are you sure you want to delete this bookmark?",
			areYouSureCollection: "Are you sure you want to delete this collection?",
			exceedCollectionLimit: 'You cannot exceed 10 collections.',
			exceedRegItemLimit: 'You cannot have more than 35 items in a collection.',
			collectionNameExists: 'The collection name you have entered already exists. Please enter a new name.',
			duplicateItemExists: 'The collection you have chosen already contains this item.',
			mainNagMessage: '<span class="bold">This is your Smart Dock.</span><br />Click the bar to open.',
			addCta: 'Click to add this item to your Smart Dock.',
			defaultCollectionName: 'My Collection',
			currentCollection: 'Current Collection',
			genericFormError: 'Some fields contain errors, please correct and resubmit.',
			genericServerError: 'A problem occurred, please try again.',
			premiumContent: 'premium content',
			newCollection: 'New Collection',
			deleteCollection: 'Delete Collection',
			renameCollection: 'Rename Collection'
		},
		Form: {
			illegalCharacter: 'Please check your entries for any < or > that might be present.'
		},
		MyAvaya:{
			tabNotSaved: 'You have not saved your changes',
			topics: 'Topics of Interest',
			roles: 'Roles',
			rss: 'RSS Feeds',
			nothingSelected: '(nothing currently selected)',
			save: 'Save'
		},
		PartnerLocator : {
			noResults : 'No results found. Please uncheck or remove some parameters to expand your search',
			noProductSearch : 'Product Search is not yet available for the selected country. \nPlease try Quick Search or search by Partner Name instead.',
			visitWebsite : 'Visit website',
			sendEmail : 'Send Email',
			resultsFound : 'results found.'
		}
	}
	
	$j.Avaya.Messages = {
		UtilBar: {
			smartdock: "Smart Dock"
		},
		Finder: {
			more: "more filters",
			fewer: "fewer filters",
			cta: "What are you looking for?",
			productCta: "enter a product name: ",
			selectCta: "select: ",
			submitText: "submit"
		},
		Filters: {
			more: "more...",
			all: "All"
		},
		EmailAvaya: {
			sent: "<h2>Thank You.</h2><h3>A message has been sent</h3>",
			close: "close"
		},
		Session: {
			expired: "Your session has expired.\nYou must sign in again to use the Smart Dock and My Avaya."
		},
		ProServices : {
			more : "More",
			visitEvent : "Visit this event page",
			date : "Date: ",
			location : "Location: "
		}
	}
	
	$j.Avaya.Tracking = function(options){
		
		this.pageView = function(pageName, eventName, appName){
			s.pageName = pageName;
			s.prop15 = pageName;
			s.prop1 = appName;
			s.prop16 = eventName;
			s.prop17 = pageName + '|' + eventName;
			
			s.t();
		}
		
		this.clickEvent = function(eventName){
			s.tl(this, 'o', eventName);
		}	
			
		this.solutionFinder = function(businessNeed, industryNeed){
			s.pageName = "Solution Finder Results";
			s_account =	GetSiteCatalystAccount(window.location.toString());
			s.channel = Country_code + "|" + businessNeed + "/" + industryNeed;
			s.prop28 = businessNeed;
			s.prop30 = industryNeed;
			s.prop12 = s.channel + "/" + s.pageName;
			s.t();
		}
	}
	
	function getCollections() {
		var $cols = $j("#item-manager li a");
		var obj = [];
		$cols.each(function(index, itm) {
			obj.push({
				id: itm.href.split("_")[1],
				name: itm.innerHTML
			});					
		});
		
		return JSON.stringify(obj);	
	}

	function getSAccount() {
		return s_account;	
	}
	
	function addBookmark(collectionId, pageInfo) {
		if(typeof pageInfo == "string") {
			$j.Avaya.global.SmartDock.addBookmark("flash", collectionId, JSON.parse(pageInfo));
		} else {
			$j.Avaya.global.SmartDock.addBookmark("flash", collectionId, pageInfo);
		}
	}
	
	$j.Avaya.GlobalSearch = function(){
		
		if (!document.getElementById('mastheadSearch')) return;
		
		var _form = $j('#mastheadSearch form'),
			_input = _form.find('input:text'),
			_focused = 0;
			
		_form.submit(function(e){
			
			if (!_focused || _input.val() == ''){
				e.preventDefault();
			}
			
		});
		
		_input.focus(function(){
			_focused = 1;
			$j(this).val("");			
		});
		
	}
	
	function openPopup(url, height, width, hideNav, resize) {
		if(hideNav == 1) {
			$j.Avaya.Page.setPopupCookie();
		}
		if(url) {
			var height = height || 450;
			var width = width || 620;
			var resize = resize || "yes";
			window.open(url,'popup','width='+width+',height='+height+',top=250,left=300,scrollbars=yes,resizable=' + resize);
		}
	}

