// Homepage Scrolling Logos //

$(document).ready(function() {
	
	if( $(".Homepage-Col2 .logos").width() != null){
		InitPeopleRotator();
	}
	
});


function InitPeopleRotator(){
		
	$(".Homepage-Col2 .logos a.arrows").css( { display:"block" } );
	$(".Homepage-Col2 .logos a.arrows").css( { display:"block" } );
	$(".Homepage-Col2 .logos li").css( { width:"100px" } );

	var fullWidth = 0;
	var noItems = 0;
	var highest = 0;
	var itemMarginRight = 15;
	$(".Homepage-Col2 .logos li").each(
		function() {
			fullWidth += itemMarginRight + $(this).width();
			if( $(this).height() > highest ){
				highest = $(this).height();
			}
		}
	);
	
	$(".Homepage-Col2 .logos ul").width(fullWidth);
	
	var initMargin = $(".Homepage-Col2 .logos ul").css("margin-left");
	initMargin = parseFloat( initMargin.split("px") );
	
	$(".Homepage-Col2 .logos a.right").click(
		function(){
			var theMargin = $(".Homepage-Col2 .logos ul").css("margin-left");
			theMargin = theMargin.split("px");
			theMargin = parseFloat(theMargin);
			var moveTo = theMargin - 115;
			var maxNegMargin = initMargin - $(".Homepage-Col2 .logos ul").width() + 230;
			if( moveTo < maxNegMargin ){
				// extent reached
			}else{
				$(".Homepage-Col2 .logos ul").animate({ marginLeft: moveTo }, 10 );
			}
			return false;
		}
	);
	
	$(".Homepage-Col2 .logos a.left").click(
		function(){
			var theMargin = $(".Homepage-Col2 .logos ul").css("margin-left");
			theMargin = theMargin.split("px");
			theMargin = parseFloat(theMargin);
			var moveTo = theMargin + 115;
			if( moveTo > initMargin ){
				// extent reached
			}else{
				$(".Homepage-Col2 .logos ul").animate({ marginLeft: moveTo }, 10 );
			}
			return false;
		}
	);
	
}

// Resize panels //

jQuery(document).ready(function()
{

    colEq();
	// make a '.clickable' element activate the first link it contains (when clicking anywhere on it)
	 $(".clickable").biggerlink(); // requires: jquery.biggerlink.pack.js

    // usage: add the class 'rollover' to image elements
	$("input[type=image].rollover, a.rollover img, img.rollover").hover(function(){
		    $(this).attr("src",jQuery(this).attr("src").replace(/(\.[^.]+)$/, 'Hi$1'));
	    },function(){
		    $(this).attr("src",jQuery(this).attr("src").replace(/Hi(\.[^.]+)$/, '$1'));
	});


    if($("#Site-Search input[type=text]")[0].value != "")
        $("#Site-Search input[type=text]")[0].style.background = "#3e3e3e";

	$("#Site-Search input[type=text]").focus(function(){
	    this.style.background = "#3e3e3e";
	});

	$("#Site-Search input[type=text]").blur(function(){
	    if(this.value == "")
	        this.style.background = '#FFFFFF url(http:\x2F\x2Fwww.google.com\x2Fcoop\x2Fintl\x2Fen\x2Fimages\x2Fgoogle_custom_search_watermark.gif) left no-repeat';
	});
		
	// usage: add the class 'submit-on-enter' to any element
	$(".submit-on-enter input[type=text], .submit-on-enter textarea").keydown(function(ev){
        //$(".submit-on-enter").append(ev.keyCode);
        if(ev.keyCode == 13)
        {
            ev.preventDefault();
            ev.stopPropagation();
             //$(".submit-on-enter").append("==submitting");    
             $(this).parents(".submit-on-enter").children("input[type=image], input[type=button]").click();
             return false;
        }
    });
});

/* equal cols functions ================================================================================================= */

function colEq() {
	var highest = 0;
	if( $(".Homepage-Col1").height() > highest ){ highest = $(".Homepage-Col1").height() };
	if( $(".Homepage-Col2").height() > highest ){ highest = $(".Homepage-Col2").height() };
	if( $(".Homepage-Col3").height() > highest ){ highest = $(".Homepage-Col3").height() };
	for(i=1; i<4; i++){
		var targetCol = ".Homepage-Col"+i+" .padding";
		targetColHeight = $(targetCol).height(highest);
	}
}

