// JScript File

// Search box
jQuery(function($) {

	$('.search .search_button').bind('click', function(e){
	    fireSearch();
	    e.preventDefault();
	});

	$('.search .search_input').bind('keyup', function(e) {
	    if(e.keyCode==13){
		fireSearch();
	    	e.preventDefault();
	    }
	});

	function fireSearch(btn, event, URL) {
	    var searchTerm = $('.search_input').attr("value");

	    searchTerm = "/pages/home/search.aspx?s=" + searchTerm;
	    // navigate the url with the value as query string
	    top.location=searchTerm;
	}
});

// center the nav

$(document).ready(function(){
    centerNav();
    $('input:text').hint();
    $('textarea').hint();
    $('input:password').hint();
	$('.navOn3').each(function() {
        var currentClass = $(this).parent().attr("class");
        $(this).parent().attr("class", currentClass + " hasChildren");
    });
    
    evenHeights('ul#rocNationsTeam li');
});

function centerNav(){
	var ulEl = $('#main_navigation').width();
	var liEl = $('#main_navigation li').width();
	var numLis = $('#main_navigation').children().length;	
	var ulWidth = liEl * numLis;	
	var navPadding = ((ulEl - ulWidth) / 2) + 'px';	
	$('#main_navigation').css({'padding-left' : navPadding});
}

function replacecarriagereturn(element,replaceWith) {   
    // for each element found matching this selector
    $(element).each(function(){
	// this particular selector instance's content
	var elementHTML = $(this).text() 

	// escape the characeters to show any carriage returns as %A0
	elementHTML = escape(elementHTML);  

	// if any carriage returns are found then remove them
	if(elementHTML.indexOf("%0D%0A") > -1)  
	{   
	    elementHTML=elementHTML.replace("%0D%0A",replaceWith);  
	}  
	else if(elementHTML.indexOf("%0A") > -1)  
	{   
	    elementHTML=elementHTML.replace("%0A",replaceWith);  
	}  
	else if(elementHTML.indexOf("%0D") > -1)  
	{   
	    elementHTML=elementHTML.replace("%0D",replaceWith);  
	}  

	// unescape the characeters
	elementHTML = unescape(elementHTML); 

	// put the filtered text back into this element
	$(this).text(elementHTML);
    });

    // cufon replace 
    Cufon.replace(element, {hover: true});
}

// FUNCTION TO FIND LARGEST ITEM AND APPLY TO ALL MATCHED ELEMENTS
    function evenHeights(selector) {
    
        // set max height to 0
        var max = 0;
        var item = 0;
        
        // iterate through each matched element and get its height
        $(selector).each(
            function() {
                var item = $(this).height();
                
                // compare the current largest height to the current items height
                // if the item is larger, reset the max height to the items height
                if ( max < item )  {
                    max = item;
                }
        });
        
        // create the style declaration
        var cssHeights = 'min-height: ' + max + 'px;height: auto !important; height: ' + max + 'px;';
        // apply the style declaration to each matched element
        $(selector).attr('style',cssHeights);
    }