$j(function() {
	if (document.getElementById('landing')){		//For productHome.aspx
		$j.Avaya.SifrConfig.masterReplace($j.Avaya.SifrConfig.gothamLight,{
		   selector: '#landing h2',
		   css: {
				'.sIFR-root': { 
					'color': '#404040', 
					'font-size': 18,
					'leading' : 0
				}
		   },
		   selectable: false
		});
		
		$j.Avaya.SifrConfig.masterReplace($j.Avaya.SifrConfig.gothamLight,{
			selector: '#content div.section h4',
			css: {
				'.sIFR-root': {
					'font-size' : 18
				},
				'a' : {
					'text-decoration' : 'none',
					'color': '#4b6e8a'
				},
				'a:hover':{
					'color' : '#cc0000'
				}
			},
			selectable: false
		});
		
		$j.Avaya.SifrConfig.masterReplace($j.Avaya.SifrConfig.gothamLight,{
			selector: '#sifrHeader',
			css: {
				'.sIFR-root': {
					'font-size' : 30,
					'color' : '#cc0000'
				}
			},
			selectable: false
		});
		
		if (document.getElementById('marqueeReplace')){ 
			$j.Avaya.SifrConfig.masterReplace($j.Avaya.SifrConfig.gothamLight,{
			   selector: '#content h1',
			   css: {
					'.sIFR-root': { 
						'color': '#cc0000', 
						'font-size': 30,
						'letter-spacing' : -1
					}
			   },
			   selectable: false
			});
			
			$j.Avaya.SifrConfig.masterReplace($j.Avaya.SifrConfig.gothamLight,{
			   selector: '#marqueeReplace p',
			   css: {
					'.sIFR-root': { 
						'color': '#404040', 
						'font-size': 16
					}
			   },
			   selectable: false
			});
		} 
	} else if (document.getElementById('results')){		//For productSubCat.aspx
		$j.Avaya.SifrConfig.masterReplace($j.Avaya.SifrConfig.gothamLight,{
		   selector: '#content h1',
		   css: {
				'.sIFR-root': { 
					'color': '#cc0000', 
					'font-size': 30,
					'letter-spacing' : -1
				}
		   },
		   selectable: false
		});
		$j.Avaya.SifrConfig.masterReplace($j.Avaya.SifrConfig.gothamLight,{
		   selector: '#pageHeader p',
		   css: {
				'.sIFR-root': { 
					'color': '#404040', 
					'font-size': 16
				}
		   },
		   selectable: false
		});
			$j.Avaya.SifrConfig.masterReplace($j.Avaya.SifrConfig.gothamLight,{
		   selector: '.tout h4',
		   css: {
				'.sIFR-root': { 
					'color': '#404040', 
					'font-size': 17,
					'leading' : 3,
					'cursor': 'pointer'
				}
		   },
		   selectable: false
		});
	} else {		//For the rest of the prodcut pages
		$j.Avaya.SifrConfig.masterReplace($j.Avaya.SifrConfig.gothamLight,{
		   selector: '#content h1',
		   css: {
				'.sIFR-root': { 
					'color': '#cc0000',
					'letter-spacing': -1,
					'font-size': 30
				},
				
				'p' : {
					'font-size':20
				}
		   },
		   selectable: false
		});

		
		
		$j.Avaya.SifrConfig.masterReplace($j.Avaya.SifrConfig.gothamLight,{
		   selector: '.tout h4',
		   css: {
				'.sIFR-root': { 
					'color': '#404040', 
					'font-size': 17,
					'leading' : 3,
					'cursor': 'pointer'
				}
		   },
		   selectable: false
		});
		$j.Avaya.SifrConfig.masterReplace($j.Avaya.SifrConfig.gothamLight,{
		   selector: '.toutwhite h4',
		   css: {
				'.sIFR-root': { 
					'color': '#FFFFFF', 
					'font-size': 17,
					'leading' : 3
				}
		   },
		   selectable: false
		});
		$j.Avaya.SifrConfig.masterReplace($j.Avaya.SifrConfig.gothamLight,{
		   selector: '.rightCol .rightCol h4',
		   css: {
				'.sIFR-root': { 
					'color': '#404040', 
					'font-size': 16
				}
		   },
		   selectable: false
		});
		$j.Avaya.SifrConfig.masterReplace($j.Avaya.SifrConfig.gothamLight,{
		   selector: '#content p.sifr-text',
		   css: {
				'.sIFR-root': { 
					'color': '#404040', 
					'font-size': 14
				},
				'a' : {
					'text-decoration' : 'none',
					'color': '#7596b1'
				},
				'a:hover':{
					'color' : '#cc0000'
				}
		   },
		   selectable: false
		});
		
		$j.Avaya.SifrConfig.masterReplace($j.Avaya.SifrConfig.gothamLight,{
		   selector: '#flashHome h2',
		   css: {
				'.sIFR-root': { 
					'color': '#587892', 
					'font-size': 22
				}
		   },
		   selectable: false
		});
	}
	
	
	var productInput = $j('#productFinder').find('input');
	
	if (productInput.length>0){
		new $j.Avaya.SuggestSeach({input:productInput,dataSource:'_assets/json/productSuggest/',left:-20,top:10});
	}
	
	if (document.getElementById('selectionList')){
		new $j.Avaya.AZList();
	}
});

/*$j.Avaya.SuggestSeach = function(options) {
	var settings = $j.extend({
		timeoutLen : 300,
		dataSource: "",
		qs: "",
		input: "",
		offsetLeft:0,
		id: "finderSuggest",
		maxNumber : 10
	}, options);
	
	var currentHREF = "";
	var timeout = null;
	var noBlur = false;
	var $s = settings.input;
	//$s.before('<div class="suggestList" id="'+settings.id+'"><ul><li><a href="javascript:void(0);">asdf</a></li></ul></div>');
	var $suggestList = $j("#" + settings.id);		
	
	hide();
	
	$j("a", $suggestList).live("mouseover", function(e) {
		noBlur = true;
		
		var target = $j(e.target);
		if(e.target.nodeName.toLowerCase() == "strong") {
			target = $j(e.target).parents("a");
		}
		$suggestList.find("li.active").removeClass("active");
		
		target.addClass("active");
	});
	
	$j("a", $suggestList).live("mouseout", function(e) {
		noBlur = false;
	});
	
	$s.blur(function(e) {
		if(!noBlur) {
			hide();		
		}
	});
	
	$s.click(function() {
		hide();				 
	});
	
	var active = null;
	$s.keydown(function(e) {
		if(e.keyCode == 13) {
			e.preventDefault(e);
		}		  
	});
	
	$s.keyup(function(e) {
		var inpt = this;
			
		if(e.keyCode == 13) {
			hide();
			if(currentHREF != "") {
				document.location = currentHREF;
			}
		} else if(e.keyCode == 38 || e.keyCode == 40) {
			if(e.keyCode == 40) {
				if(active == null) {
				$suggestList.find("li:first").addClass("active");
				} else if(active != null) {
					active.removeClass("active");	
					var next = active.next("li");
					if(next.get(0) != null) {
						next.addClass("active");
					} else {
						$suggestList.find("li:first").addClass("active");
					}
				} 
			} else if(e.keyCode == 38) {
				if(active == null) {
				$suggestList.find("li:last").addClass("active");
				} else if(active != null) {
					active.removeClass("active");	
					var prev = active.prev("li");
					if(prev.get(0) != null) {
						prev.addClass("active");
					} else {
						$suggestList.find("li:last").addClass("active");
					}
				}
			} 
			
			active = $suggestList.find("li.active");
			
			if(active.get(0) != null) {
				setValue(active.find("a"));
			} else {
				active = null;	
			}
			
		} else if($j(inpt).val() == ""){
			clearTimeout(timeout);
			hide();
			
		} else {
			clearTimeout(timeout);
			timeout = setTimeout(function() {

					var term = $j(inpt).val();
					var resultList = "<ul>";
					var count = 0;
					for(var i in PRODUCTLIST) {
						if(i.toLowerCase().search(new RegExp(term.toLowerCase())) != -1 && count < settings.maxNumber ) {
							resultList += '<li><a href="'+PRODUCTLIST[i].url+'">' + highlightQuery(term, i) + '</a></li>';			
							count++;
						}
					}
					
					resultList += "</ul>";
					if(resultList != "<ul></ul>") {
						$suggestList.html(resultList);
						show();
					} else {
						$suggestList.html("");
						currentHREF = "";
						hide();
					}
					active = null;
									
			}, settings.timeoutLen);	
			
		}
	});
	
	function setValue(target) {
		$s.val("");
		
		var val = target.html();
		val = val.replace(/(<strong>)|(<STRONG>)/, "");
		val = val.replace(/(<\/strong>)|(<\/STRONG>)/, "");
		
		currentHREF = target.attr("href");
		$s.val(val);
	}
	
	function hide() {
		$suggestList.css({left: -10000});
		$suggestList.html("");
	}
		
	function show() {
		$suggestList.css({left: settings.offsetLeft});
	}
	
	// highlights the querystring text (qs) in a particular result (val)
	function highlightQuery(qs, val) {
		var strng = qs;

		var splitty = strng.split("");
		var regexStrng = "(";
		for(var i=0; i<splitty.length; i++) {
			regexStrng += "[" + splitty[i].toLowerCase() + "|" + splitty[i].toUpperCase() + "]{1}[\\s]*";
		}
		regexStrng += ")";
		
		var regex = new RegExp(regexStrng);
		var searchTerm = val;
		
		return searchTerm.replace(regex, "<strong>$1</strong>");
	}	
}
*/
$j.Avaya.AZList = function(params){
	var self = this;
	
	var settings = $j.extend({
		id : '#selectionList',
		selectedIndex : 0,
		sections : '#content div.letter'
	},params);
	
	var div = $j(settings.id);
	var list = div.find('ul');
	var items = list.find('li');
	var sections = $j(settings.sections);
	var selected = settings.selectedIndex;
	
	items.eq(selected).addClass('active');
	_getSection();
	
	$j(settings.id +' li').live('click',function(e){
		e.preventDefault();
		
		if (this.className.search(/\s*empty/) != -1) return;
		
		var li = this;
		
		items.each(function(i){
			this.className = this.className.replace(/\s*active/,'');
			
			if (this == li){
				li.className = li.className + ' active';
				selected = i;
			}
			
		});
		
		_getSection();
	});
	
	function _getSection(){
		var selector = items.eq(selected).find('a').html().toLowerCase();
		
		if ((selector.length >= 2 && selector != '0-9') || selector == 'allen' || selector == 'wszystkie' || selector == 'all' || selector == 'alle' || selector == 'tous' || selector == 'todo'  || selector.indexOf('??')>0 || selector.indexOf("m") == 2){
		
			sections.each(function(){
				if (this.className.search(/\s*active/) == -1 && this.className.search(/\s*empty/) == -1){
					this.className = this.className + ' active';
				}
			});
			
		} else {
			
			sections.each(function(){
				this.className = this.className.replace(/\s*active/, '');
			});
			
			var section = $j('#section_' + selector);
			section.addClass('active');
			
		}
		
		$j.Avaya.Page.Sizing.resize();
	}
}

