(function($) {
   $.fn.foxoRotate = function(options) {
      var Me = $(this);
      var Timer;
      
      var defaults = {
         currentIndex : 0,
         interval : 5000
      };
      
      var Settings = $.extend({}, options, defaults);
      
      var I = {
         rotateImage : function() {
            var img = new Image();
            img.src = Settings.images[Settings.currentIndex];

            $(img).load(function() {
               Me.fadeOut(400, function() {
                  I.updateIndex();
                  Me.css({'background-image' : "url('"+img.src+"')" }).fadeIn(400);
                  clearTimeout(Timer);
                  Timer = setTimeout(I.rotateImage, Settings.interval);
               }).each(function() {
						if(this.complete) {
							$(this).load();	
						}
					});
            });		
         },
         updateIndex : function() {
            Settings.currentIndex = Settings.currentIndex + 1;
            
            if(Settings.currentIndex > (Settings.images.length - 1)) {	
               Settings.currentIndex = 0;	
            }
         }
      }
      
      I.rotateImage();
   };
   
   $(function () {
      var timeout = 500;
      var closetimer	= 0;
      var ddmenuitem = 0;
      
      function jsddm_open() {	
         jsddm_canceltimer();
         jsddm_close();
         ddmenuitem = $(this).find('ul').eq(0).css('visibility', 'visible');
      }
      
      function jsddm_close() {
         if(ddmenuitem) {
				ddmenuitem.css('visibility', 'hidden');
			}
      }
      
      function jsddm_timer() {
         closetimer = window.setTimeout(jsddm_close, timeout);
      }
      
      function jsddm_canceltimer() {
         if(closetimer) {	
            window.clearTimeout(closetimer);
            closetimer = null;
         }
      }
      
      $('#nav > ul > li').bind('mouseover', jsddm_open);
      $('#nav > ul > li').bind('mouseout',  jsddm_timer);
      
      $(document).bind('click', jsddm_close());
      
		
      var searchForm = $("#searchForm");
      
      if(searchForm.length > 0) {
         $("#startSearchBtn").bind('click', function() {
            searchForm.submit();	
         });
      }
   });
})(jQuery);
