$(document).ready(function() {
	
	$('#small_pictures_before li img, #small_pictures_after li img').hover(
		function(){
			$lgPicture = $('#large_picture img');
			$beforePicLg = "images/pictures/large/before/";
			$afterPicLg = "images/pictures/large/after/";			
			$thisEl = $(this);
			$thisElScr = $thisEl.attr('src');
			$thisElScrArr = $thisElScr.split('/');
			$arrLength = $thisElScrArr.length;
			$thisElScrBaseName = $thisElScrArr[$arrLength-1];
			
			if($thisElScr.lastIndexOf('/before/') > -1){
				$lgImgSrc = $beforePicLg + $thisElScrBaseName;
			}else if($thisElScr.lastIndexOf('/after/') > -1){
				$lgImgSrc = $afterPicLg + $thisElScrBaseName;			
			}
			$lgPicture.attr({src:$lgImgSrc});
		},
		function(){
			//alert('off');
		}
	);
	
	$('#main_navigation li').each(function(){
		$(this).click(function(){
			$thisAnchor = $(this).find('a');
			$thisHref = $thisAnchor.attr('href');
			window.location = $thisHref;
			
//			alert($thisHref);
		}).hover(
			function(){
				$thisNav = $(this);
				$classOrig = $thisNav.attr("class");
				$classOn = $classOrig + "_on";
				if($classOrig.indexOf("_on") < 0){
					$thisNav.attr({"class":$classOn});
				}
			},
			function(){
				$thisNav = $(this);
				if($classOrig){
					$thisNav.attr({"class":$classOrig});
				}
			});
	});
	
});




function checkPattern(aStr,aPattern){
	var aPat = '~NA~';
	switch(aPattern){
		case 'aFullName': aPat =  /^([1-zA-Z0-1@.\s]{1,255})$/; break;
		case 'aContactNumber': aPat =  /^(\(?\d\d\d\)?)?( |-|\.)?\d\d\d( |-|\.)?\d{4,4}(( |-|\.)?[ext\.]+ ?\d+)?$/; break;
		case 'anEmailAddress': aPat =   /(\w[-._\w]*\w@\w[-._\w]*\w\.\w{2,3})/; break;
		default: 'NULL';
	}

	if (aStr.match(aPat)) {
   		return true;
 	} else {
 		return false;
 	}

}



function mkRandNumArr(pgPicCount,dirImgCount){
	randNumArr = new Array();
	do {
		randNum = Math.floor(Math.random() * dirImgCount);
		if (randNumArr.indexOf(randNum) == -1){
			randNumArr.push(randNum);
		}
	}
	while (randNumArr.length < pgPicCount);
	return randNumArr;
}

/*---------------------------------------------------------------------------
WORK AROUND IE non support of indexOf method
*/
Array.prototype.find = function(searchStr) {
  var returnArray = false;
  for (i=0; i<this.length; i++) {
    if (typeof(searchStr) == 'function') {
      if (searchStr.test(this[i])) {
        if (!returnArray) { returnArray = [] }
        returnArray.push(i);
      }
    } else {
      if (this[i]===searchStr) {
        if (!returnArray) { returnArray = [] }
        returnArray.push(i);
      }
    }
  }
  return returnArray;
}

//This prototype is provided by the Mozilla foundation and
//is distributed under the MIT license.
//http://www.ibiblio.org/pub/Linux/LICENSES/mit.license

if (!Array.prototype.indexOf)
{
  Array.prototype.indexOf = function(elt /*, from*/)
  {
    var len = this.length;

    var from = Number(arguments[1]) || 0;
    from = (from < 0)
         ? Math.ceil(from)
         : Math.floor(from);
    if (from < 0)
      from += len;

    for (; from < len; from++)
    {
      if (from in this &&
          this[from] === elt)
        return from;
    }
    return -1;
  };
}


