        (function ($) {
            var imgcache = [];
          //parameters
          //arg: (req) array of images or an image (DOM image/s)
          //srcattr: (opt) the attribute name of the img element to be used as the source of the image. Default = src if none specified (string)
          //pre: (opt) a string to prepend to the source if any (string)
            $.simpleImgPreload = function (arg, srcattr, pre) {
                var p = (pre) ? pre : "";
                if ($.isArray(arg)) {
                    $($(arg).get().reverse()).each(function () {
                        if ($(this).is("img"))
                         (srcattr) ? pushimg($(this), srcattr, p) : pushimg($(this), null, p);
                    });
                }
                if ($(arg).is("img")) {
                    (srcattr) ? pushimg(arg, srcattr, p) : pushimg(arg, null, p);
                }
            }
            function pushimg(_img, _src, _pre) {
                var s = (_src) ? _src : "src";
                var nimg = new Image();
                nimg.src = _pre + $(_img).attr(s);
                imgcache.push(nimg);
            }
        })(jQuery)

$(function () {
    
    var rpath = "";
    var adomain = "http://"+location.host+"/";
    var depth = location.href.replace(adomain,"").split("/").length;
    depth = (depth <= 2 )? 0:depth-2;
    for (var i=0;i<depth;i++){
       rpath += "../";
    }
          
    $("ul.subnav").parent().append("<span></span>"); //Only shows drop down trigger when js is enabled (Adds empty span tag after ul.subnav*)
    $("ul.subnav").wrap("<div  class=\"shdw\"></div>");
    $("ul.fyitopnav li span, ul.fyitopnav li a").mouseover(function () { //When trigger is clicked...
        $(this).addClass("subhover");
        //Following events are applied to the subnav itself (moving subnav up and down)
        //$(this).parent().find("ul.subnav").slideDown('fast').show(); //Drop down the subnav on click
        $(this).parent().find("div.shdw").slideDown('fast').show();
        $(this).parent().find("span").css({ "background": "url("+rpath+"../img/arrows_down_15px.png) no-repeat 0 -13px" });
        
          $(this).parent().hover(function () {
          }, function () {
              //$(this).parent().find("ul.subnav").slideUp('slow'); //When the mouse hovers out of the subnav, move it back up
              $(this).parent().find("div.shdw").slideUp('slow');
              $(this).parent().find("span").css({ "background-position": "0 0" });
          });

        //Following events are applied to the trigger (Hover events for the trigger)
    }).hover(function () {
        $(this).addClass("subhover"); //On hover over, add class "subhover"
    }, function () {    //On Hover Out
        $(this).removeClass("subhover"); //On hover out, remove class "subhover"
    });
  
   $("#easyslides").css("display","block");  
  
  $("ul#tileset li").hover(function(){
    $(this).css({"background-position":"0 0"});
    var mt = parseInt($(this).find(".tiletitle").css("margin-top"));
    $(this).find(".tile").css("width","98%");
    $(this).find(".tiletitle").css("margin-top",(mt-2)+"px");
  }, function(){
    $(this).css({"background-position":"0 -175px"});
    var mt = parseInt($(this).find(".tiletitle").css("margin-top"));
    $(this).find(".tile").css("width","100%");
    $(this).find(".tiletitle").css("margin-top",(mt+2)+"px");
  });
  
  $("ul#tileset li div.tile").click(function(){
    $(this).parent("li").css({"background-position":"0 -175px"});
    location.href = "http://"+document.domain+$(this).attr("alt");
  });
  
  $("dd div.imagemap").each(function(i){
    var url = $(this).children("span:first-child").text();
    var mainimg = $(this).siblings("img")[0];
    var map= $(this).find("map")[0];
    $(map).attr("name","slidemap"+i);
    $(map).children("area:first-child").attr("href",url);
    $(mainimg).attr("usemap","#slidemap"+i);
  });
  
  $("img.thumbnailpop").each(function(){
    //note: thumbnailpop_slidespeed is defined in FYIStandardPage and overridden in FYITextPage 
    $(this).parent("a").attr("rel","poppreview").colorbox({current:"", slideshow:true, slideshowSpeed:thumbnailpop_slidespeed});
  });

});

