// Rotating background images
jQuery(function($){
  $.supersized({
    //Functionality
    slideshow               :   1,		//Slideshow on/off
    autoplay				:	1,		//Slideshow starts playing automatically
    start_slide             :   1,		//Start slide (0 is random)
    random					: 	0,		//Randomize slide order (Ignores start slide)
    slide_interval          :   20000,	//Length between transitions
    transition              :   1, 		//0-None, 1-Fade, 2-Slide Top, 3-Slide Right, 4-Slide Bottom, 5-Slide Left, 6-Carousel Right, 7-Carousel Left
    transition_speed		:	2500,	//Speed of transition
    new_window				:	1,		//Image links open in new window/tab
    pause_hover             :   0,		//Pause slideshow on hover
    keyboard_nav            :   0,		//Keyboard navigation on/off
    performance				:	1,		//0-Normal, 1-Hybrid speed/quality, 2-Optimizes image quality, 3-Optimizes transition speed // (Only works for Firefox/IE, not Webkit)
    image_protect			:	1,		//Disables image dragging and right click with Javascript
    image_path				:	'../img/bg/', //Default image path

//Size & Position
min_width		        :   0,		//Min width allowed (in pixels)
min_height		        :   0,		//Min height allowed (in pixels)
vertical_center         :   1,		//Vertically center background
horizontal_center       :   1,		//Horizontally center background
fit_portrait         	:   1,		//Portrait images will not exceed browser height
fit_landscape			:   0,		//Landscape images will not exceed browser width

//Components
navigation              :   0,		//Slideshow controls on/off
thumbnail_navigation    :   0,		//Thumbnail navigation
slide_counter           :   0,		//Display slide numbers
slide_captions          :   0,		//Slide caption (Pull from "title" in slides array)
slides 					:  	[		//Slideshow Images
                        {image : 'uploads/default/files/background1.jpg'},
                        {image : 'uploads/default/files/background2.jpg'},
                        {image : 'uploads/default/files/background3.jpg'}

]

  }); 
});
// End rotating background images

$(function() {


  // If refreshing the page, unset the window hash
  window.location.hash = "";
  
  // AJAX content grabbing and menu behaviors, 
  // we start by delegating a click event
  $("nav").delegate("a", "click", function(e) {
    
    // prevent default anchor behavior
    e.preventDefault();    

    // cache target href
    var target = $(this).attr("href");

    // target url parts
    var parts = target.split( '/' ),
        newHash = parts[parts.length -1];
    
    // test for target
    if(newHash !== window.location.hash.substring(1)){
    
      // modify window hash
      window.location.hash = newHash;

      // Paginate the menu items so the container maintains its shape
        $('.menuContainer').pajinate({
            items_per_page : 8,
            item_container_id : '.menuScroller',
            nav_panel_id : '.menuNav',
            nav_label_first : '<<',
            nav_label_last : '>>',
            nav_label_prev : ' ',
            nav_label_next : ' '
          });

          // animate out
          $('#content').fadeOut(200, function() {
          $('#mainContent').animate({ 
            width: '0',
            paddingLeft: '0',
            paddingRight: '0',
          
            duration: 800,
            easing: 'linear'
          });            
          /*
          // load content and animate in       
          $('#content').hide().load(target + " .content2", function() {
            $('#mainContent').animate({ width: '810px', paddingLeft: '65px', paddingRight: '25px'},{ duration: 800, easing: 'linear'});
            $('#content').delay(1500).fadeIn(200);
          });
          */
          
          var ajaxHref = '/' + newHash + '/';

          var request = $.ajax({
          	
          	url: ajaxHref,
          	dataType: 'html',
          	success: function (data) {

          		var gallery = $(data).find('.content2');

          		$('#content').html(gallery);
          		$('#mainContent').animate({ width: '810px', paddingLeft: '65px', paddingRight: '25px'},{ duration: 800, easing: 'linear'});     
          	},
          	complete: function () {
          		$('#content').delay(1500).fadeIn(200, function(){ 
					$('.ad-gallery').adGallery({
					loader_image: 'loader.gif'
				});          		
          		
          		
          		});       	
          	}
          	
          });
      });      
    }
	
  });

	// Interactive menu scrolling script	
	
	// Click handler
  $('div#menu-list ul li').live('click', function(){

		// Cache item id and description
		var item_id = $(this).attr('class');
		this.description = $('#' + item_id).html();

		// Inject HTML and fade in
		$('#item-description').html(this.description).fadeIn();
			
	});
	
	// Click handler for submenus
	$('ul.menu-links li a').live('click', function(e){
		
		// No navigation
		e.preventDefault();
		
		// Get the target href	
		var href = $(this).attr('href');
		href = href.substring(1);
		href = 'ul.' + href;

		// Actually scroll to the target href
		$('div#menu-list').scrollTo(href, 500, {margin:true});
	});
	
	// Standard scroll methods (up and down)
	// Up
	$('.scrollUp').live('click', function(e){
		
		// No navigation
		e.preventDefault();
		
		// Scroll by 150px
		$('div#menu-list').scrollTo('-=150px', 500);
	});
	
	// Down
	$('.scrollDown').live('click', function(e){
		
		// No navigation
		e.preventDefault();

		// Scroll by 150px
		$('div#menu-list').scrollTo('+=150px', 500);
	});

});

