var $j = jQuery;

/*

Function: sameHeight

Sets all matched elements to the largest height.

Parameters:

	c - Css selector to match.
	scope - Optional css selector. 
		If present the matched elements of c that are children of scope will be the same height.
		
 */
function sameHeight(c, scope){

	if (scope){
		$j(scope).each(function(){
			var set = $j(this).find(c);
			sameHeight(set);
			
		});
	}
	else {
		var h = 0;
		
		$j(c).each(function(){
			var th = $j(this).height()
			h = (th > h)? th : h;
			
		});
		
		$j(c).height(h);	
	}
}

/*

Function: hyphenToBr

Replaces any hyphens in the matched elements with <br /> tags.

Parameters:

	c - Css selector to match.
	
*/
function hyphenToBr(c){
	$j(c).each(function(){
		var el = $j(this);
		var text = el.text();
		var html = text.replace(/-/g, '<br />-');
		el.html(html);
		
	});
	
}

$j(function(){
	$j('#siteSearchTxt').bind('focus', function(){
		var text = $j(this).val();
		text = $j.trim(text);
		
		if (text == this.defaultValue){
			$j(this).val('');
		}
		
	}).bind('blur', function(){
		var text = $j(this).val();
		text = $j.trim(text);
		
		if (text == ''){
			$j(this).val(this.defaultValue);
		}
		
	});

});

$j(function(){
	$j('#siteHeaderBotCategories li:has(ul)').bind('mouseover', function(){
		$j(this).find('div.drop').slideDown();
		
	}).bind('mouseleave', function(){
		$j(this).find('div.drop').stop(true, true).hide();
		
	});
	
});

$j(function(){
	$j('#siteHeaderBotLogin td').each(function(){
		var children = this.childNodes;
		
		for (var i=0; i<children.length; i++){
			var node = children[i];
			if (node.nodeName && node.nodeName == '#text'){
				this.removeChild(node);
			}
		}
		
	});
	
});

$j(function(){
	$j('#siteNewsTicker').coolTicker();
});
