$(document).ready(
	function(){
		
			$.fn.search = function() {
				return this.focus(function() {
					if( this.value == this.defaultValue ) {
						this.value = "";
					}
				}).blur(function() {
					if( !this.value.length ) {
						this.value = this.defaultValue;
					}
				});
			};
			// newsletter IDs
			$("#s").search();
			
			jQuery("#mySlider").royalSlider({
		        captionShowEffects:["moveleft", "fade"],
		        directionNavAutoHide: true,
				blockLinksOnDrag: true, 
				slideshowEnabled: true,
		 		slideshowAutoStart:true,   
		    	imageScaleMode:"fill",          // Scale mode of all images. Can be "fill", "fit" or "none"
		    	imageAlignCenter:false		    // Aligns all images to slide center
		        /* other options go here, view javascript options to learn more */			
		    });
			
		  // Reset Font Size
		  var originalFontSize = $('html').css('font-size');
		    $(".resetFont").click(function(){
		    $('html').css('font-size', originalFontSize);
		  });
		  // Increase Font Size
		  $(".increaseFont").click(function(){
		    var currentFontSize = $('html').css('font-size');
		    var currentFontSizeNum = parseFloat(currentFontSize, 10);
		    var newFontSize = currentFontSizeNum*1.2;
		    $('html').css('font-size', newFontSize);
		    return false;
		  });
		  // Decrease Font Size
		  $(".decreaseFont").click(function(){
		    var currentFontSize = $('html').css('font-size');
		    var currentFontSizeNum = parseFloat(currentFontSize, 10);
		    var newFontSize = currentFontSizeNum*0.8;
		    $('html').css('font-size', newFontSize);
		    return false;
		  });
		
		

			
			
			
			$("a#inline").fancybox({
				'overlayColor': '#000'
			});
		
		
});


$(function() {
	
	
var $container = $('#posts');
	
$container.imagesLoaded( function(){
  	$container.isotope({
  		// options
  		itemSelector : 'div.box',
  		layoutMode : 'masonry'
	});
});

    /* Initiate masonry
    -------------------------------------------------------------- */



    $('#posts').infinitescroll({
        navSelector: '.wp-pagenavi',
        // selector for the paged navigation AA
        nextSelector: '.nextpostslink',
        // selector for the NEXT link (to page 2)
        itemSelector: 'div.box',
        // selector for all items you'll retrieve
        loadingText: 'Loading the next page',
        donetext: 'No more pages to load',
        debug: false,
        loadingImg: '/css/images/ajax-loader.gif'
    },
    // call masonry as a callback
    function(newElements) {
          $container.isotope( 'appended', $( newElements ) ); 
    });

    /* Scroll the page up if clicked
    -------------------------------------------------------------- */

    $('a.top').click(function() {
        $.scrollTo('0px', 700);
    });




    /* Collapse the navigation as the page scrolls
    -------------------------------------------------------------- */

    var header = $('#header');
    var headerHeight = header.height();
    var expandBar = $('#expand', header);
    var expandBarHeight = expandBar.height();
    var showNavLink = $('a', expandBar);
    var heightCache;

    var searchcheck = $('#searchterms').length;
    if (searchcheck != 0) {
        var searchtop = $('#searchterms').offset().top - parseFloat($('#searchterms').css('marginTop').replace(/auto/, 0));
    }


    $(window).scroll(function() {
        var scrollDistance = $(this).scrollTop();
        var isExpanded = $('#header').hasClass('navfixed');
        if (headerHeight < scrollDistance) {
            $('#expand').fadeIn(400);
        }

        if (headerHeight > scrollDistance) {
            $('#expand').fadeOut(400);
        }

        if (isExpanded == 1) {
            $('#header').removeClass('navfixed');
            $('#header').fadeOut(300, function() {
                $(this).show();
            });
        }

        if (searchcheck != 0) {
            if (scrollDistance >= searchtop) { $('#searchterms').addClass('fixed'); }
            else { $('#searchterms').removeClass('fixed'); }
        }
    });

    $('#expand').hover(function(e) {
        e.preventDefault();
        $(this).fadeOut(400);
        $('#header').addClass('navfixed');
        $('#header').fadeIn(400);
    });

    $('#expand a').click(function(e) {
        e.preventDefault();
    });



});

