
if ($j.cookie('usePopup')=='true'){
	$j.Avaya.Page.Sizing.dontResize = true;
}

window.name = "ServicesPopup";

$j(function() {
	var $header = $j('#popupHeader');

	if ($j.cookie('usePopup')=='true'){
		$j("body").attr("id", "standalone");		
		$j('#masthead, #footer').remove();
		
		//$j.cookie('usePopup','false',{expires:-1});
	} else {
		$header.remove();
	}

	if($j("#techSpecs").get(0) != null) {
		$j.Avaya.SifrConfig.masterReplace($j.Avaya.SifrConfig.gothamLight,{
		   selector: 'h1',
		   css: {
				'.sIFR-root': { 
					'color': '#cc0000', 
					'font-size': 16
				}
		   },
		   selectable: false
		});
	} else {
	$j.Avaya.SifrConfig.masterReplace($j.Avaya.SifrConfig.gothamLight,{
	   selector: 'h1',
	   css: {
			'.sIFR-root': { 
				'color': '#404040', 
				'font-size': 16
			}
	   },
	   selectable: false
	});
	}
	
	var $print = $header.find('button.print');
	var $close = $header.find('button.close');
	
	$close.click(function(e){
		e.preventDefault();
		window.close();
	});
	
	$print.click(function(e){
		e.preventDefault();
		window.print();
	});
	
	var rightCol = $j('#content div.right-col');
	var links = rightCol.find('a');
	var lists = rightCol.find('ul');
	var maxLinks = 5;

	lists.each(function(){
		var $this = $j(this);
		var lis = $this.find('li');
		
		if (lis.length > maxLinks){
			
			lis.each(function(i){
				if (i > maxLinks - 1){
					$j(this).addClass('hidden');
				}
			});

			$this.append($j('<li><a class="toggler" href="javascript:void(0);">'+$j.Avaya.Messages.Filters.more+'</a></li>'));
		}
		
	});
	
	$j('a.toggler').live('click',function(e){
		e.preventDefault();
		var $this = $j(this);
		var lis = $this.parents('div.related-section').find('li');
		$this.parent('li').remove();
		revealLis(lis, function(){$j.Avaya.Page.Sizing.resize()}); 
	});
	
	function revealLis(lis,callback){
		lis.each(function(i){
			var $li = $j(this);
			if ($li.hasClass('hidden')){
				setTimeout(function(){
					$li.removeClass('hidden');
					revealLis(lis, callback);
				}, 25);
				return false;
			} else if ( i  == lis.length - 1 ){
				callback();
			}
		});
	}
});

