/*
Standards Compliant Rollover Script
Author : Daniel Nolan
http://www.bleedingego.co.uk/webdev.php
	
Add the attribute class="imgover" to any image in your document that requires a mouseover effect to be trigger
Hover image is named exactly the same as the original image plus _o at the end of name
*/

function initRollovers() {
	if (!document.getElementById) return
	
	var aPreLoad = new Array();
	var sTempSrc;
	var aImages = document.getElementsByTagName('img');

	for (var i = 0; i < aImages.length; i++) {		
	
		//there may be multiple class assignments
		//separates the img class into an array
		classes = aImages[i].className.split(" ");
				
		//checks if img has a class of menu
		//if so, set up rollover
		if ( inArray('imgover', classes) ) {

			var src = aImages[i].getAttribute('src');
			var ftype = src.substring(src.lastIndexOf('.'), src.length);
			var hsrc = src.replace(ftype, '_on'+ftype);

			aImages[i].setAttribute('hsrc', hsrc);
			
			aPreLoad[i] = new Image();
			aPreLoad[i].src = hsrc;
			
			aImages[i].onmouseover = function() {
				sTempSrc = this.getAttribute('src');
				this.setAttribute('src', this.getAttribute('hsrc'));
			}	
			
			aImages[i].onmouseout = function() {
				if (!sTempSrc) sTempSrc = this.getAttribute('src').replace('_on'+ftype, ftype);
				this.setAttribute('src', sTempSrc);
			}
		}
	}
}

function inArray( value, array ) {
//passed a value and an array, this function returns true
//if the value is contained with in the array,
//false if it is not
	for ( var i = 0; i < array.length; i++ )
		if ( array[i] == value )
			return true;
	return false;
} 

//------------------- for clearing and replacing text in form input fields and textareas -------------------//

function clearText(thefield) {
    if (thefield.defaultValue==thefield.value) { thefield.value = "" }
} 

function replaceText(thefield) {
    if (thefield.value=="") { thefield.value = thefield.defaultValue }
}


//------------------- swap banner images when page is refreshed -------------------//
var imgPath = "http://thecatterycc.org/images/site/"  //path to where swapped images are stored
var imgArray_cats_tl = new Array("cats_tl_1.png", "cats_tl_2.png", "cats_tl_3.png"); //array of image file names
var imgArray_cats_tr = new Array("cats_tr_1.png", "cats_tr_2.png", "cats_tr_3.png"); //array of image file names
var imgCount = 3;
var randomNumber = Math.floor((Math.random() * imgCount));
var nbrImgsLoaded = 0;

function imageFadeIn() {
    nbrImgsLoaded += 1;
    if (nbrImgsLoaded == 2) {
        $('img#cats_tl, img#cats_tr').fadeIn(400);
    }
}

function insertPic() {
    $('<img id="cats_tl" alt="" width="320" height="223" />').appendTo('div#banner_images');
    $('<img id="cats_tr" alt="" width="153" height="145" />').appendTo('div#banner_images');
    //$('img#cats_tl, img#cats_tr').hide();
    //$('img#cats_tl, img#cats_tr').load(imageFadeIn);
    $('img#cats_tl').attr('src',imgPath  + imgArray_cats_tl[randomNumber]);
    $('img#cats_tr').attr('src',imgPath  + imgArray_cats_tr[randomNumber]);
}

$(document).ready(function() {
    // Handler for .ready() called.
    initRollovers();
    insertPic();

    $('#donate').hover(function() {
    $(this).attr('src', imgPath  + 'btn_donate_on.png');
    }, function() {
    $(this).attr('src',imgPath  + 'btn_donate.png');
    });

//ipad and iphone fix
if((navigator.userAgent.match(/iPhone/i)) || (navigator.userAgent.match(/iPod/i)) || (navigator.userAgent.match(/iPad/i))) {
    $("#main_navigation li a").click(function(){});}
});








