$(document).ready(function(){
	$('img.background').maxImage({
		isBackground: true
	});
	
	
	//MAIN NAV TOGGLING
	$('#menu-toggle').click(function(){
		$('.menu-custom_menu-container').toggle();
	});
	
	
	//VIDEO INFORMATION TOGGLING
	
	
	$('.info').click(function(){
		$('#video-content .sidebar').css({opacity: 1.0});
	});
	
	$('#video-info-close').click(function(){
		$('#video-content .sidebar').css({opacity: 0.0});
	});
	
	//newsletter
	$('#newsletter #one').click(function(){
		$(this).toggle();
		$('#newsletter #two').toggle();
	});
	
	
	// VIDEO SHOW ICONS
	$(".no-touch #video-icons").delay(5000).fadeOut(500);
	
	var s_saver;
	$('body').mousemove(function() {
	clearTimeout(s_saver);
    
	s_saver = setTimeout(function(){
        $('.no-touch #video-icons').fadeOut(100);
	 }, 2000);
    
	 $('.no-touch #video-icons').fadeIn(500);
	});
	
	$('.slideshow').delay(500).show();
	
	$("img[src='']").addClass("hide");


	//quotes slide show
	 $('.quotes-slideshow').cycle({
		fx: 'fade' 
	});
	 
	
	//SIDEBAR FUNCTIONS
	$('.sidebar ul li a').click(function(){
		$('.sidebar ul li a').removeClass("current");
		$(this).addClass("current");
	});
	
	$('.menu-custom_menu-container ul li').click(function(){
		$('.menu-custom_menu-container ul li').removeClass("home-current-menu-item");
		$(this).addClass("home-current-menu-item");
	});
	
	
	//ABOUT PAGE SCROLLING
	$('#about .content').scrollTo( 0 );
	// Reset the screen to (0,0)
	$.scrollTo( 0 );
	
	var $paneTargetAbout = $('#about .content');
	$('a.scroll').click(function(){
		$paneTargetAbout.stop().scrollTo( this.hash, 800, 'easeInOutExpo');
		return false;
	});
	
	
	//CATEGORY THUMB PAGE SCROLLING
	$('div#category-content').scrollTo( 0,0 );
	// Reset the screen to (0,0)
	$.scrollTo( 0,0 );
	
	var $paneTargetThumb = $('#category-content');
	$('#arrow-right').click(function(){
		$paneTargetThumb.stop().scrollTo( {top:'10px',left:'+=276'}, 500 );
		
	});
	
	$('#arrow-left').click(function(){
		$paneTargetThumb.stop().scrollTo( {top:'10px',left:'-=276'}, 500 );
		
	});
	
	$('.scroll-text-right').click(function(){
		$('#panel').scrollTo( {top:'-=100px', left:'+=100'}, 800 );
		
	});


	
	$('ul#filters li a').click(function(){
		$paneTargetThumb.stop().scrollTo( 0 );
		return false;	
	});
	
	if((navigator.userAgent.match(/iPhone/i)) || (navigator.userAgent.match(/iPod/i)) || (navigator.userAgent.match(/iPad/i))) {
	$('a').removeClass('fancybox');
	$('#close').click(function(){
		history.back();
		return false;
	});
	};
	
				     
	//CATEGORY FILTERING
	var $container = $('#category-content');

      $container.isotope({
        itemSelector : '.post',
	layoutMode : 'cellsByColumn',
	cellsByColumn : {
          columnWidth : 276,
          rowHeight : 178
        }
      });
      
        // change layout
      var isHorizontal = false;
      function changeLayoutMode( $link, options ) {
        var wasHorizontal = isHorizontal;
        isHorizontal = $link.hasClass('horizontal');

        if ( wasHorizontal !== isHorizontal ) {
          // orientation change
          // need to do some clean up for transitions and sizes
          var style = isHorizontal ? 
            { height: '80%', width: $container.width() } : 
            { width: 'auto' };
          // stop any animation on container height / width
          $container.filter(':animated').stop();
          // disable transition, apply revised style
          $container.addClass('no-transition').css( style );
          setTimeout(function(){
            $container.removeClass('no-transition').isotope( options );
          }, 100 )
        } else {
          $container.isotope( options );
        }
      }
      
      
      var $optionSets = $('#options .option-set'),
          $optionLinks = $optionSets.find('a');

      $optionLinks.click(function(){
        var $this = $(this);
        // don't proceed if already selected
        if ( $this.hasClass('selected') ) {
          return false;
        }
        var $optionSet = $this.parents('.option-set');
        $optionSet.find('.selected').removeClass('selected');
        $this.addClass('selected');
  
        // make option object dynamically, i.e. { filter: '.my-filter-class' }
        var options = {},
            key = $optionSet.attr('data-option-key'),
            value = $this.attr('data-option-value');
        // parse 'false' as false boolean
        value = value === 'false' ? false : value;
        options[ key ] = value;
        if ( key === 'layoutMode' && typeof changeLayoutMode === 'function' ) {
          // changes in layout modes need extra logic
          changeLayoutMode( $this, options )
        } else {
          // otherwise, apply new options
          $container.isotope( options );
        }
        
        return false;
      });


$(".fancybox-embed").fancybox({
		'modal' : true,
		'hideOnOverlayClick': true,
		'showCloseButton' : false
	});


$("a.fancybox").fancybox({
	'width' : 783,
	'height' : 520,
	'type' : 'iframe',
	'titleShow' : false,
	'overlayShow': false,
	'showCloseButton' : false,
	'cyclic' : false,
	'showNavArrows' : false,
	'onStart' : function(){
		$('#category-content .post img').fadeTo("fast", 0.5);
	},
	'onClosed' :function(){
		$('#category-content .post img').fadeTo("fast", 1);
	}
	});

	
	$('#close').click(function(){
		parent.$.fancybox.close();
	});
	
	
	
	


	 
  // get current slide's number
	function currentSlide() {
		var hash = window.location.hash || '#1';
		return parseInt(hash.replace(/[A-Za-z#\-\/!]/g, '') - 1); 
	}
	// global vars	
	var	cycleSelector = $('.slideshow'),
			startSlide = currentSlide(),
			hasSlid = 0;
	
	// append some markup for the controls		
	cycleSelector.before('<div id="nav"></div>') 
	// start jQuery Cycle	
	.cycle({ 
		 startingSlide: startSlide,
		 // when using the next/prev links
   	 onPrevNextEvent: function(isNext, idx, slide) { 
   	 	hasSlid = 1;
   	 	window.location.hash = (parseInt(idx) + 1) + ""; 
   	 	return false;
   	 },
   	 // when using the pager thumbnails
   	 onPagerEvent: function(idx, slide) { 
   	 	hasSlid = 1;
   	 	window.location.hash = (parseInt(idx) + 1) + ""; 
   	 	
   	 	return false;
   	 },
   	 timeout: 0, 
   	 speed: 5,
   	 // build the thumbnails
   	 pagerAnchorBuilder: function(idx, slide) { 
       return '<li><a href="#photo-'+ (idx+1) +'"><img src="' + slide.src + '" width="50" height="50" /></a></li>'; 
    } 
	});
	
	// bind to the hashchange event
	$(window).bind('hashchange', function () {
			var slideNo = currentSlide();
			// we only want to fire the slide change if the next button or the pager hasn't done it for us
			if (hasSlid === 0) { cycleSelector.cycle(slideNo); }
			// return it back to zero
			hasSlid = 0;
	}); 
	
	// when the page loads, we need to trigger a hashchange
	$(window).trigger( "hashchange" );
	
});


