// Homepage slider function. Leave outside of jQuery function.
  function slideSwitch() {
      var $active = $('#home-gallery img.active');

      if ( $active.length == 0 ) $active = $('#home-gallery img:last');

      var $next =  $active.next().length ? $active.next() : $('#home-gallery img:first');

      $active.addClass('last-active');

      $next.css({opacity: 0.0})
          .addClass('active')
          .animate({opacity: 1.0}, 1000, function() {
              $active.removeClass('active last-active');
          });
  };


  $(document).ready(function(){
    
    // Accordion - Secondary Nav
    var $nav = $('#navigation>ul');
    
    $nav.accordion({
      active: ".current",
      header: 'a.more',
      autoHeight: false,
      //fillSpace: true, // Use this OR change autoHeight to false
      animated: 'slide' // Or some other easing equation
    });
    

    var $show = $('#slider ul');
    $show.find('li:last-child').css('margin', '0');
    $show.css({overflow: 'hidden', width:'182px'});
    $show.before('<div id="previous"><a href="#"><span>Previous</span></a></div>');
    $show.after('<div id="next"><a href="#"><span>Next</span></a></div>');

    $show.serialScroll({
		items:'li',
		axis: 'y',
		prev:'#previous a',
		next:'#next a',
		duration: 1500,
		step: 3, // How many at a time?
		//easing:'easeOutQuart', // Which easing equation to use? default: linear
        force:true,
        stop:true,
        lock:false,
	    cycle:false
	});
    	
    // Inner Drawers (Using h6 and divs)
      var $drawerhead = $("h6");
      
      $drawerhead.next().wrap('<div class="drawerwrap"></div>').wrapInner('<div></div>');
      
      $drawerhead.hover(function() {
        //over
        $(this).addClass('over');
      }, function() {
        //out
        $(this).removeClass('over');
      });
      
      $drawerhead.toggle(function() {
      		$(this).addClass('active')
      		.next().slideToggle(500);
      }, function(){
          $(this).removeClass('active')
          .next().slideToggle(500);
      }).next().hide();
      
      $('a[rel="external"]').click( function() {
          window.open( $(this).attr('href'), 'external', 'location=no,toolbar=nostatus=no,scrollbars=no,width=400,height=343' );
          return false;
      });
      
    	
    // Home Gallery setup
    $(window).load(function () {
        
      $('#home-gallery.refresh-2009')
        .find('img')
          .addClass('active')
        .end()
        .prepend('<img src="/_images/home2.jpg" alt=""/><img src="/_images/home3.jpg" alt=""/><img src="/_images/home4.jpg" alt=""/>');
    	
   // $('#home-gallery.refresh-2010')
   //  .find('img')
   //  .addClass('active')
   //  .end()
   //  .prepend('<img src="/refresh/home-refresh2.jpg" alt=""/><img src="/refresh/home-refresh3.jpg" alt=""/><img src="/refresh/home-refresh4.jpg" alt=""/>');
   //  setInterval( "slideSwitch()", 5000 );
       
    });
    
    if ($('#map').length > 0)
    {
     mapLoad(); // Google Maps
    }
      
    
  });
  
  
  $(document).ready(function(){
    $gallery = $('#gallery ul');
    $li_first = $gallery.find('li:first-child').addClass('active');
    $items = $gallery.find('li');
    wid = $li_first.find('img:first-child').width();
      if (wid == 0){ wid = 40 }
      
    sliding_width = ((wid + 8) * $items.size()) + 8;
    $gallery.width( sliding_width ); 
    
    $gallery.before('<div class="galleria_container"/>').wrap('<div class="galleria_nav_wrapper" />');
    

    $gallery.galleria({
      history: false,
      onImage: function(image,caption,thumb) {
             // fade in the image & caption
             image.css('display','none').fadeIn(1000);
    
             // add a title for the clickable image
             image.attr('title','Next image >>');
           }
    });
    
    $('.galleria_nav_wrapper')
    .before('<a class="iprev" href="#">Previous</a>')
    .after('<a class="inext" href="#">Next</a>');
    
    var number_shown = 8;
    
    $gallery.parent().serialScroll({
  		items:'li',
  		axis: 'x',
  		prev:'a.iprev',
  		next:'a.inext',
  		duration: 1500,
  		//easing:'easeOutQuart', // Which easing equation to use? default: linear
      force:true, // Slide to the first element
      stop:true,
      exclude: (number_shown-1),
      //lock:false,
      //cycle:true,
  		step: number_shown // How many at a time?
     });
     
     $gallery.find('li:first-child').css('margin-left','0');
  });

	var cssLink = document.createElement("link") 
	cssLink.href = "style.css"; 
	cssLink .rel = "stylesheet"; 
	cssLink .type = "text/css"; 
	frames['frame1'].document.body.appendChild(cssLink);
