$(document).ready(function(){
	var 
	speed = 1000,   // animation speed
	$wall = $('#linky').find('.demo'),
	
	masonryOptions = {         // initial masonry options
		columnWidth: 150, 
		itemSelector: '.boxy:not(.invis)',
		animate: true,
		animationOptions: {
		  duration: speed,
		  queue: false
		}
	};
	$(window).load(function(){
		$wall.masonry(masonryOptions);
	});
					   
	var 
	speed = 1000,   // animation speed
	$wall2 = $('#linky').find('.demo'),
	
	masonryOptions_ok = {         // initial masonry options
		columnWidth: 110, 
		itemSelector: '.boxy_small:not(.invis)',
		animate: true,
		animationOptions: {
		  duration: speed,
		  queue: false
		}
	};
	$(window).load(function(){
		$wall2.masonry(masonryOptions_ok);
	});

	var 
	speed = 1000,   // animation speed
	$wall3 = $('#sideb').find('.related_img'),
	
	masonryOptions_ok2 = {         // initial masonry options
		columnWidth: 60, 
		itemSelector: '.boxy_rel:not(.invis)',
		animate: true,
		animationOptions: {
		  duration: speed,
		  queue: false
		}
	};
	$(window).load(function buildWall(){
		$wall3.masonry(masonryOptions_ok2);
	});


	$('#slider').nivoSlider({
        effect:'fade', // Specify sets like: 'fold,fade,sliceDown'
        slices:15, // For slice animations
        boxCols: 8, // For box animations
        boxRows: 4, // For box animations
        animSpeed:500, // Slide transition speed
        pauseTime:3000, // How long each slide will show
        startSlide:1, // Set starting Slide (0 index)
        directionNav:false, // Next & Prev navigation
        directionNavHide:true, // Only show on hover
        controlNav:false, // 1,2,3... navigation
        controlNavThumbs:false, // Use thumbnails for Control Nav
        controlNavThumbsFromRel:false, // Use image rel for thumbs
        controlNavThumbsSearch: '.jpg', // Replace this with...
        controlNavThumbsReplace: '_thumb.jpg', // ...this in thumb Image src
        keyboardNav:true, // Use left & right arrows
        pauseOnHover:true, // Stop animation while hovering
        manualAdvance:false, // Force manual transitions
        captionOpacity:0.8 // Universal caption opacity
});


	$('.menu li').not('.children li').mouseover(function() {
		$(this).children('.children').css("visibility", "visible");
		$('.children').not(this.children).css("visibility", "hidden");
		$('ul.children:has(.current_page_item)').css("visibility", "visible");
	});
	
	$('.menu li').not('.children li').mouseout(function() {
		$('.children').css("visibility", "hidden");
		$('ul.children:has(.current_page_item)').css("visibility", "visible");
	});
	
	$('ul.children:has(.current_page_item)').css("visibility", "visible");
	
	/*$('#linky').masonry({
	 columnWidth: 150,
	 itemSelector: '.boxy' 
	
	});*/
	
	$('a img').hover(
		function () {
			$("a img").not(this).stop().animate({'opacity': .3});
		},
		function () {
			$("a img").not(this).stop().animate({'opacity': 1});
		}
	);

			$('.related_img').RegisterAjaxer($('#wrapper'),[changeHash = true]);
			
			
			//$('#AjaxerContainer').InitAjaxer();
			
			// Bind to the AjaxerBeforeReload and animate collapsing
			$('#wrapper').bind('AjaxerBeforeReload', function(){
				// Collapse the container
				$('#wrapper').animate({opacity: 'toggle'}, 400);
				
				// Show the loading bar
				//$('#loading').show();
			});
			
			// Bind to the AjaxerReload and animate expanding
			$('#wrapper').bind("AjaxerReload", function(){
				// Expand the container
				$('#wrapper').animate({opacity: 'toggle'}, 400);
				//buildWall();
				$('#sideb').masonry({
				columnWidth: 60, 
				itemSelector: '.boxy_rel:visible',
				animate: true,
				animationOptions: {
					duration: speed,
					queue: false
				}

				});

				
				// Hide the loading bar
				//$('#loading').hide();
			});
			
			// We tell Ajaxer to reload every container with ID matching a container from the response
			//$('.boxy_rel').RegisterContainer();
			//$('h3').RegisterContainer();
			
	//$('p:first').css('padding-top','0');

});
