	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
	>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
	*/
	(document.location.href.search("debug=true") != -1) ? $j.Avaya.global.debug = true : $j.Avaya.global.debug = false;

	/* 
	>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
		EVENT: DOM READY
	>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
	*/
	$j(function() {		
		$j.Avaya.global.Tracking = new $j.Avaya.Tracking();
		
		$j.Avaya.global.CustomSelects = [];
		$j('body').addClass('hasJS');

		$j.Avaya.Page.Sizing.init();
		$j.Avaya.Page.MastNav.init();
		
		new $j.Avaya.Page.Footer();
		new $j.Avaya.CustomSelect($j('#mastheadCountrySelect select'), {maxHeight:350, truncateDisplay:14});
	
		// registered status... turn off if in debug so it doesn't annoy us.
		if($j.Avaya.global.debug) {
			$j.Avaya.global.isRegistered = true;
		}
		
		$j.Avaya.global.ToolTip = new $j.Avaya.ToolTip({location:'NE', yOffset: 50, xOffset: -20, fixedRef:$j('#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.cookie('usePopup','true');
			window.open('http://www.avaya.com/usa/partner-locator/','PartnerLocator','width=620,height=450,top=250,left=300,scrollbars=yes');
		});
		*/
		
		$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.cookie('usePopup','true');
			window.open('/services.aspx','ServicesPopup','width=585,height=500,top=250,left=300,scrollbars=yes');
		});
		
	});	
	
	$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(window).resize(function(){
		$j.Avaya.Page.Sizing.resize();
	});
	
	$j.Avaya.Item = {
		truncate: 50
	}
	
	$j.Avaya.Page = {
		region: 'United States',
		minHeight: 700,
		minWidth: 950,
		Section: {
			id : 'home'
		}
	};
	
	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();
		},
		
		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.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();
				});
			});
			
			this.flippedClass = 'flippedSubNav';
			
		/*****Sign In Code
			var signInTrigger = $j('div.signIn a:eq(0)');
			signInTrigger.click(function() {
				$j.get("/_assets/inc/signIn.html", function(response) {
					var signInHTML = response;
					if(!$j('#signInBox').get(0))
						$j('div#page').append(signInHTML);
					var $signInBox = $j('div#signInBox');
					$signInBox.css('left', '530px');
					$signInBox.css('display', 'block');
					$j(document).click(function(e) {
						var tar = $j(e.target);	
						var parents = tar.parents();
						if(!parents.is('#signInBox, .signIn')) {
							$signInBox.hide();
						}						
						return true;
					});
					var $submitButton = $signInBox.find('button');
					$submitButton.click(function(e) {
						var userMail = $j('input#email').val();
						userMail = trim(userMail);
						if(!$j.Avaya.validateEmail(userMail)) {
							alert("Please enter a valid email address");
							return false;
						}
						var userPwd = $j('input#password').val();
						userPwd = trim(userPwd);
						var isValid = userPwd;
						if(isValid) {
							document.location = document.location;	
						} else {
							alert("Username/Passowrd incorrect");						
						}
					});
				});	
				
			});
		*****/	
		},
		
		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: #666666; }',
					'a:hover { color: #CC0000; }'
				]
			}
			$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,
					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
		},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.opts = this.select.find('option');
		var liString = '';
		this.currentIndex = 0;
		
		this.opts.each(function(index){
			if (this.selected) { self.currentIndex = index; }
			var extraClass = "";
			if(index == 0) { 
				extraClass = " first";
			} else if(self.opts.length - 1== index) {
				extraClass = " last";	
			}
			liString += '<li class="selectOpt_' + index + extraClass + '">'+this.innerHTML+'</li>';
		});
		
		this.list.append($j(liString));
		
		
		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.listItems = this.list.find('li');
		this.listItems.eq(this.currentIndex).addClass('selected');
		
		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)){
					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').live('mouseover',function(e){
			$j(this).addClass('hovered');
		}).live('mouseout',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.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.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;
					}
				});
			} 
		}
		
		$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;
			//Empty
			this.list.empty();
			this.listItems.empty();
			
			this.opts = this.select.find('option');
			var liString = '';
		
			var len = this.opts.length;
			
			this.opts.each(function(index){
				if(index == 0) {
					liString += '<li class="selectOpt_'+index+' first">'+this.innerHTML+'</li>';
				} else if(index == len -1) {
					liString += '<li class="selectOpt_'+index+' last">'+this.innerHTML+'</li>';
				} else {
					liString += '<li class="selectOpt_'+index+'">'+this.innerHTML+'</li>';
				}
			});
			
			this.list.append($j(liString));
			
			this.listItems = this.list.find('li');
			this.listItems.eq(this.currentIndex).addClass('selected');
			
			this.setScrollPane();
			
			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({});
				this.scrollPane[0].scrollTo('li.selected');
			}
			
			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;
			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.listItems.eq(this.currentIndex).removeClass('selected'); //remove selected class from old item
			
			var newItem = this.listItems.eq(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.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, isSelected){
		var element = $j(params.element);
		var isSelected = isSelected;
		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)">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();
			}
		});
		
		//current.each(function(index) {
			
			//current.data("xLink", current.html());
			//current.html("");
		//});
		
				
		if (selected.get(0)){
			_setClear();
		}
		
		//alert(isSelected);
		
		if (isSelected == 1){
			//alert('is selected');
			_open();
		} else {
			_close();
		}
		
		function _open(){
			if (locked) return;
			locked = true;
			element.addClass('open');
			if(_checkSelected()) {
				list.slideDown(200,function(){							   
					locked = false;
				});
			} else {
				listPartial.hide();
				moreDiv.show();
				_moreResults();
				list.slideDown(200,function(){							   
					locked = false;
				});
			}
		}
		
		function _close(){
			if (locked) return;
			locked = true;
			list.slideUp(200,function(){	
				element.removeClass('open');
				locked = false;
				moreDiv.hide();
			});
		}
		
		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;
				});				   
			});
		}
		
		function _setClear() {
			current.addClass('has-current');
			var clearLinkHREF = selected.parents("li").find("a.clearButton").attr("href");
			var clearLink = '<a class="clearButton" href="'+clearLinkHREF+'">[x]</a>';
			
			current.html('<span>'+selected.html()+'</span>'+clearLink+'<div class="clear"></div>');
			var clearTrigger = current.find('a');
			selected = element.find('a.selected');
			var clearPresent = selected.parent().find('a.clearButton');
			if(!clearPresent.get(0)) {
				_removeClear();
				selected.parent().append(clearLink + '<div class="clear"></div>');
				clearPresent = selected.parent().find('a.clearButton');
			}

		}
		
		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
		},options);
		
		var $mainLIs = $j("#utilityBar > li");
		var $mainAs = $j("#utilityBar > li > a");
		var _locked = false;
		var $shareListLIs = settings.container.find("ul.util-share a");
		
		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);
			});
		}
		
		
		// EVENTS 
		$mainLIs.hover(function(){
			_show(this);
		},function(){
			_hide(this);
		});
		
		
		settings.emailBtn.click(_showEmailPopup);
		settings.container.find("a.print").click(_print);
		settings.emailOverlay.find("a.overlay-close").click(_hideEmailPopup);
		//settings.emailOverlay.find("a.button").click(_validate);
		settings.emailOverlay.find("form").submit(_validate);
		
		// PRIVATE
		function _show(tar) {

			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());
				$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("_")[1], pageinfo);
		}
		function _showEmailPopup() {
			_locked = true;
			settings.emailOverlay.show();
			
			$j.Avaya.SifrConfig.masterReplace($j.Avaya.SifrConfig.gothamLight,{
			   selector: '#emailAFriend h3',
			   css: {
					'.sIFR-root': { 
						'color': '#666', 
						'font-size': 18
					}
			   }
			});
		}
		function _hideEmailPopup() {
			_locked = false;
			
			settings.emailOverlay.hide();
			var fields = $j("#emailAFriend input, #emailAFriend textarea");
			$j("#emailAFriend label").removeClass("red");
			fields.val("");
			
			_hide();
		}
		function _print() {
			window.print();	
		}
		function _validate(e) {
			e.preventDefault(e);
			
			var fields = $j("#emailAFriend input, #emailAFriend textarea");
			$j("#emailAFriend label").removeClass("red");
			
			isValid = true;
			fields.each(function(index, itm) {
				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 !
				_hideEmailPopup();
			}
		}
		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'];
		
		$resultControls.click(function(e){
			e.preventDefault();
			_toggle(e.target);
		});
		
		_checkQueryString();
		
		function _toggle(tar){
			currentTar = tar;
			$resultControls.each(function(){
				this.className = this.className.replace(/\s*on/g,'');
			});
			
			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'));
				}
			}
		}
	}
	
	$j.Avaya.Validation = function(params){
		
		var settings = $j.extend({
			form : null,
			wrapperClass : 'form-section'
			
		},params);
		
		if (settings.form==null) return;
		
		var required = settings.form.find('select.required, input.required');
		var rfs = [];
		var allerrs = '';
		
		function _checkRequired(){
			
			for (var i=0;i<rfs.length;i++){
				var field = rfs[i].check();
	
				if (!field.valid){
					allerrs += field.text +', ';
				}
			}
		}
		
		function _setRequired(){
			
			rfs = [];
			
			required.each(function(){
				var $this = $j(this);
				var parent = this.parentNode;
				
				while (parent.className.indexOf(settings.wrapperClass)==-1){
					parent = parent.parentNode;
				}
	
				rfs.push(new $j.Avaya.RequiredField({field:$this,wrapper:$j(parent)}));
			});
			
		}
		
		_setRequired();
		
		//returns false if no errors or the string if there are
		this.getRequiredString = function(){
			allerrs = '';
			
			_checkRequired();
			
			if (allerrs != ''){
				allerrs = allerrs.replace(/\s*\,\s*$/,'.');
				return 'Please enter a valid ' + allerrs;
			}
	
			return false;
		}
		
		this.updateRequired = function(){
			required = settings.form.find('select.required, input.required');
			
			_setRequired();
		}
		
	}
	
	$j.Avaya.RequiredField = function(params){
		
		var settings = $j.extend({
			field : null,
			wrapper : null
		},params);
		
		if (settings.field==null) return;
		
		var name = settings.field.attr('name');
		var label = settings.wrapper.find('label').eq(0).html();
		var text = label.replace(/<span.*>.*<\/span>\s/g,'');
		
		this.check = function(){
			
			var obj = {
				valid : false,
				name : name,
				value : settings.field.val(),
				text : text
			};
			
			if (obj.value != ''){
				obj.valid = true;
				settings.wrapper.removeClass('error-state');
			}
			else 
			{
				settings.wrapper.addClass('error-state');
			}
	
			return obj;
		}
	}
	
	//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: {
			newCollection: '<span class="bold">Reminder: </span><br />You must register to create a new collection.',
			renameCollection: '<span class="bold">Reminder: </span><br />You must register to rename a collection.',
			deleteCollection: '<span class="bold">Reminder: </span><br />You must register to delete a collection.',
			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.'
		},
		Form: {
			illegalCharacter: 'Please check your entries for any < or > that might be present.'
		}
	}
	
	$j.Avaya.Tracking = function(options){
		/*
		var settings = $j.extend({
			pageName : 'pageName'
		},params);
		
		
		this.events = {
			SD : {
				open : "SD-Open",
				close : "SD-Close",
				addItem : "SD-AddItem",
				copyItem : "SD-CopyItem",
				delItem : "SD-DeleteItem",				
				rename : "SD-RenameCollection",
				print : "SD-Print",
				share : "SD-Share",
				trySD : "SD-Try",
				help : "SD-Help",
				recommends : "SD-Recommends",
				addCol : "SD-AddCollection",
				delCol : "SD-DeleteCollection",
				register : "SD-Register"
				
			},
			Finder : {
				
			}
		}
		*/
		
		this.pageView = function(pageName){
			/*s.pageName = "New Page";
			s.prop1 = "some value";

			void(s.t());
			console.log("PAGE VIEW: ", pageName);*/
		}
		
		this.clickEvent = function(eventName){
			/*s = s_gi('myreportsuiteid');
			s.linkTrackVars = "prop1,eVar1,events";
			s.linkTrackEvents = "event1";
			
			s.prop1 = "some value";
			s.eVar1 = "another value";
			s.events = "event1";
			
			//s.prop15 = settings.pageName;
			//s.prop16 = clickEvent;
			//s.prop17 = s.prop15 + "|" + s.prop16;
			
			s.tl(this, 'o', 'My Link Name');
			
			console.log("CLICK EVENT: " + eventName);*/
		}	
	}