

try{
/**
	browser detection
*/	
	Prototype.Browser.IE6=Prototype.Browser.IE && parseInt(navigator.userAgent.substring(navigator.userAgent.indexOf("MSIE")+5))==6;
	
	document.observe("dom:loaded", function() {
	(function(){	
		
		/*
			Setup main navigation
		*/
		
		var primaryNav = new MainNavigation('sw-primaryNav');
		
		
	/*
		script matching the heights of .matchHeight elements
		
		this script will search the page for all matchHeight elements 
		and match the height of boxes positioned at the same level
	*/
		var boxes = $$(".matchHeight");
		
		var length = boxes.length;
		var i = 0;
		
		while ( i < length) {
			//console.log(i + " - "+ length);
			var list = [];
			var top = boxes[i].cumulativeOffset().top;
			var height = 0;
			do{
				list.push(boxes[i]);
				var myHeight = boxes[i].getHeight();
				height = (height > myHeight)? height : myHeight;
			   //console.log(i + "-" + boxes[i].positionedOffset().top);
				i++;
			}
			while(i < length && top == boxes[i].cumulativeOffset().top );
			
			if(list.length > 1){
				for(var j=0;j < list.length;j++){
					if(Prototype.Browser.IE6){
						list[j].style.height = height+'px';
					}else{
						list[j].style.minHeight = height+'px';
					}
					
				}
			}
			
		};
		
		
		/*
			Align tertiary nav
		*/
		
		var nav = $('sw-tertiaryNav');
		if(nav){
			var els = $('sw-tertiaryNav').childElements();
			if(nav.getHeight() > els[0].getHeight()){
				// multiline nav so match it
				var width = 0;
				
				for(var i=0;i < els.length; i++){
					var myWidth = els[i].getWidth();
					width = (width > myWidth)? width : myWidth;
				}
				//console.log('width: '+width)
				
				for(var i=0;i < els.length;i++){
					els[i].style.width = (width+5)+'px';
				}
			}
		}
		
		/*
			general input scripts
		*/
		
		$$('input').each(function(e,i){
			e.observe('focus', function(event){
				e.addClassName('focus');
			});
			e.observe('blur', function(event){
				e.removeClassName('focus');
			}); 
		})
		
		
	}())
	});

}catch(e){}






/**
	Open close boxes
*/
function openClose(el){
	function hasClass(ele,cls) {
		return ele.className.match(new RegExp('(\\s|^)'+cls+'(\\s|$)'));
	}
	function addClass(ele,cls) {
		if (!hasClass(ele,cls)) ele.className += " "+cls;
	}
	function removeClass(ele,cls) {
		if (hasClass(ele,cls)) {
			var reg = new RegExp('(\\s|^)'+cls+'(\\s|$)');
			ele.className=ele.className.replace(reg,' ');
		}
	}
	function next(n){
		do n = n.nextSibling;
		while (n && n.nodeType != 1);
		return n;
	}
	
	var c = el;
	while(c){
		c = next(c);
		if(c && hasClass(c,"openClose-content")){
			if(hasClass(el,"openClose-open")){
				c.style.display="none";
				removeClass(el,"openClose-open");
				addClass(el,"openClose-closed");
			}else{
				c.style.display="";
				removeClass(el,"openClose-closed");
				addClass(el,"openClose-open");
			}
			break;
		}
	}
}
