jQuery(document).ready(function()
{
	SetRollOvers();
	SetEnterSubmit();
	SetExternalLinks();
	//SetBiggerClick();
	Equalise($("#page, #side-bar"));
	RandomLoginPics();
	$.preloadCssImages();
});

function SetRollOvers(){
	// usage: add the class 'rollover' to image elements
	jQuery("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'));
	});
}

function SetBiggerClick(){
	// make a '.clickable' element activate the first link it contains (when clicking anywhere on it)
	$(".clickable").biggerlink(); // requires: jquery.biggerlink.pack.js
}

function SetEnterSubmit(){
	// 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;
        }
    });
}

function SetExternalLinks(){
	/*
	Purpose: checks all <a>'s in the doc, if it has a rel attribute of 'external', sets to open in new window
	usage: <a href="http://www.google.com" rel="external">Google</a>
	*/
	
	$('a[rel=external]').click(function(){ window.open(this.href); return false; });
	
}

function Equalise(elms){
	// usage:
	// Equalise($(".list li"));
	// Equalise($("#nav, #content"));
	var highest = 0;
	for(i=0; i < elms.length; i++){ if($(elms[i]).height() > highest) highest = $(elms[i]).height(); }
	for(i=0; i < elms.length; i++){ if($(elms[i]).height() < highest) $(elms[i]).height(highest); }
}
function RandomLoginPics(){
	//generate random number between 1-5
	var rndNum = Math.ceil(Math.random() * 5);
	//set the icon and text image source
	$("#login-box .login-text").attr("src","/images/homepage/copy_"+rndNum+".png");
	$("#login-box .login-icon").attr("src","/images/homepage/img_"+rndNum+".png");
}
