////////////////////////////////////////////////////////////
//                                                        //
//                 Jquery Plugins                         //
//                                                        //
////////////////////////////////////////////////////////////

// Image Preload

(function($) {
  var cache = [];
  // Arguments are image paths relative to the current page.
  $.preLoadImages = function() {
    var args_len = arguments.length;
    for (var i = args_len; i--;) {
      var cacheImage = document.createElement('img');
      cacheImage.src = arguments[i];
      cache.push(cacheImage);
    }
  }
})(jQuery)

/*
 * jQuery Slideshow Plugin v1.3
 * Made by Matt Oakes (http://www.matto1990.com)
 * Changes by Meinhard Benn (http://benn.org/)
 */
eval(function(p,a,c,k,e,r){e=function(c){return(c<a?'':e(parseInt(c/a)))+((c=c%a)>35?String.fromCharCode(c+29):c.toString(36))};if(!''.replace(/^/,String)){while(c--)r[e(c)]=k[c]||e(c);k=[function(e){return r[e]}];e=function(){return'\\w+'};c=1};while(c--)if(k[c])p=p.replace(new RegExp('\\b'+e(c)+'\\b','g'),k[c]);return p}('4.I.U=p(a){j b={y:\'Q\',n:\'10\',6:\'l\',m:8,o:8,u:8};3(a){4.Y(b,a)}j c=0,2=1,9=0,k=\'\';j d=p(){3(c==0){O(j i=0;i<f.g;i++){4(f[i]).5(\'F\',\'G\')}4(f[9]).5(\'F\',\'H\').5(\'r\',\'0\');4(f[2]).5(\'r\',\'1\').J(b.y);3(b.6==\'l\'){3((2+1)<f.g){2=2+1;9=2-1}h{2=0;9=f.g-1}}h 3(b.6==\'7\'){9=2;z(2==9){2=q.D(q.7()*(f.g))}}h{E(\'6 x B C \\\'l\\\' A \\\'7\\\'\')}k=s(d,b.n)}};j e=p(){3(c==0){c=1;S(k);3(b.o!=8){b.u(4(\'#\'+b.m))}}h{c=0;d();3(b.o!=8){b.o(4(\'#\'+b.m))}}v W};t.5(\'w\',\'M\');j f=t.R(\'K\').T();4.N(f,p(i){4(f[i]).5(\'r\',f.g-i).5(\'w\',\'V\').5(\'L\',\'0\').5(\'X\',\'0\')});3(b.6==\'l\'){k=s(d,b.n)}h 3(b.6==\'7\'){P{2=q.D(q.7()*(f.g))}z(2==0);k=s(d,b.n)}h{E(\'6 x B C \\\'l\\\' A \\\'7\\\'\')}3(b.m!=8){4(\'#\'+b.m).Z(e)}v t};',62,63,'||current|if|jQuery|css|type|random|null|last|||||||length|else||var|timer|sequence|pauselink|timeout|playcallback|function|Math|zIndex|setTimeout|this|pausecallback|return|position|must|fadetime|while|or|either|be|floor|alert|display|none|block|fn|fadeIn|img|top|relative|each|for|do|slow|find|clearTimeout|get|slideshow|absolute|false|left|extend|click|2000'.split('|'),0,{}))



/*
 * searchField - jQuery plugin to display and remove
 * a default value in a searchvalue on blur/focus
 *
 * Copyright (c) 2008 Jï¿½Ã¶rn Zaefferer
 * 
 * $Id: jquery.searchField.js 6233 2009-02-17 18:38:23Z joern.zaefferer $
 *
 * Dual licensed under the MIT and GPL licenses:
 *   http://www.opensource.org/licenses/mit-license.php
 *   http://www.gnu.org/licenses/gpl.html
 *
 */

/**
 * Clear the help text in a search field (either in the value or title attribute)
 * when focused, and restore it on blur if nothing was entered. If the value is
 * blank but there is a title attribute, the title will be moved to the initial value.
 *
 * @example $('#quicksearch').searchField();
 * @before <input id="quicksearch" title="Enter search here" name="quicksearch" />
 * @result <input id="quicksearch" value="Enter search here" name="quicksearch" />
 *
 * @name searchField
 * @type jQuery
 * @cat Plugins/SearchField
 */

jQuery.fn.searchField=function(mark){return this.each(function(){var mark=mark||this.title;if(!mark)
return;var target=this;var original=$(this);if(this.type=="password"){target=$("<input />").insertBefore(this).css("display",$(this).css("display")).attr("size",this.size).attr("title",this.title).attr("class",this.className).addClass("watermark")[0];if(!this.value){$(this).hide();}else{$(target).hide();}}
if(!target.value||mark==this.value){$(target).addClass("watermark");}
if(!this.value||target!=this){target.value=mark;}
$(target).focus(function(){if(target!=original[0]){$(this).hide();original.show().focus();}else if(this.value==mark){this.value='';$(this).removeClass("watermark");}});$(this).blur(function(){if(!this.value.length){if(target!=original[0]){$(target).show();original.hide();}else{this.value=mark;$(this).addClass("watermark")}}});$(this).parents("form:first").submit(function(){if($(target).hasClass("watermark")){$(target).attr("value","");$(target).removeClass("watermark");}});});};

////////////////////////////////////////////////////////////
//                                                        //
//                 Site Specific Code                     //
//                                                        //
////////////////////////////////////////////////////////////

function trim(s) {
  return s.replace(/^\s+|\s+$/, '');
}

function validatePhone(fld) {
    var error=false;
    var stripped = fld.value.replace(/[\(\)\.\-\ ]/g, '');
   if (fld.value == "") {
        error = "You didn't enter a phone number.";
    } else if (isNaN(parseInt(stripped))) {
        error = "The phone number contains illegal characters.";
    } else if (!(stripped.length < 6)) {
        error = "The phone number is the wrong length.";
    }
    return error;
}

function validateEmail(fld) {
    var error=false;
    var tfld = trim(fld.value);                        // value of field with whitespace trimmed off
    var emailFilter = /^[^@]+@[^@.]+\.[^@]*\w\w$/ ;
    var illegalChars= /[\(\)\<\>\,\;\:\\\"\[\]]/ ;
    if (fld.value == "") {
        error = "You didn't enter an email address.";
    } else if (!emailFilter.test(tfld)) {              //test email for illegal characters
        error = "Please enter a valid email address.";
    } else if (fld.value.match(illegalChars)) {
        error = "The email address contains illegal characters.";
    } else {
    }
    return error;
}

function init() {
    if ($('#slideshow img').length>1) {
        $('#slideshow').slideshow({
            timeout: 3000
        });
    } else {
        $('#slideshow img').show();
    }
    if (typeof site_init === 'function') { //Run site specific global code
        site_init();
    }
    if (typeof page_init === 'function') { //Run page specific global code
        page_init();
    }
}

$(document).ready(init);
