jQuery.noConflict();
(function($) {
	
	// Show/Hide Filter Menu
	$('#filtering-nav ul').slideToggle();
	$('a.filter-btn').click(function(){
		$('#filtering-nav ul').slideToggle();
		return false;
	});
	
	// MouseOver Events
	$('.box').hover(function(){
			$('.img-container img', this).fadeTo("fast", 0.65).addClass('box-hover');
			$('.actions', this).fadeTo("fast", 1);
		},
		function(){
			$('img', this).fadeTo("fast", 1).removeClass('box-hover');
			$('.actions', this).fadeTo("fast", 0);
	});
	
	// Submenus
	$('.header-nav ul > li').not(".header-nav ul li li").hover(
	function(){
		$('ul', this).fadeIn(100);
	}, 
	function(){
		$('ul', this).delay(400).fadeOut(200);
	});
	
	// Sidebar Ads
	$('.shaken_sidebar_ads a:odd img').addClass('last-ad');
	
	// Share Icons
	$('.share-container').hide();
	
	$('.share').click(function(){
		var myParent =  $(this).parent();
		$('.share-container', myParent).slideToggle('fast');				   
	});
	
	// Find the spaces and replace with %20
	$(".share-icons a").each(function(){
	  $(this).attr( 'href', encodeURI( $(this).attr("href") ) );
	});
	
	// Colorbox Init
	$('.gallery-icon a').attr('rel', 'post-gallery');
	$("a[rel='gallery'], a[rel='lightbox'], .gallery-icon a, .colorbox").colorbox({
		maxWidth: '85%',
		maxHeight: '85%'	
	});
	
	// Remove margins
	$('.gallery-thumb:nth-child(3n)').addClass('last');
	
	// Slider Init
	$('.slider').slides({
		play: 4500,
		pause: 2500,
		hoverPause: true,
		effect: 'fade',
		generatePagination: false
	});
	
	// Vertically center all images in the slider
	$('.slides_container').each(function(){
		var $container = $(this).height();
		$('img', this).each(function(){
			var $img = $(this).height();	
			if($img != $('.slides_container').height()){
				var $margin = ($container - $img)/2; 
				$(this).css('margin-top', $margin);
			}
		});
	});
	
	// Isotope
	$(window).load(function(){
	
		// Init		
		$('.sort, #sort').isotope({
			itemSelector : '.box:not(.invis)',
			transformsEnabled: false,
			masonry: {
				columnWidth : 175 
			}
		});
		
		// Filtering
		$('#filtering-nav li a').click(function(){
		  var selector = $(this).attr('data-filter');
		  $('#sort, .sort').isotope({ filter: selector });
		  return false;
		});

	});
})(jQuery);

// Setup the function for the Tweet Button
function twitPop(myURL, myTitle, myRelated) {
	var width  = 650;
	var height = 500;
	var left   = (screen.width  - width)/2;
	var top    = (screen.height - height)/2;
	var params = 'width='+width+', height='+height;
	params += ', top='+top+', left='+left;
	params += ', directories=no';
	params += ', location=no';
	params += ', menubar=no';
	params += ', resizable=no';
	params += ', scrollbars=no';
	params += ', status=no';
	params += ', toolbar=no';
	newwin=window.open("http://twitter.com/share?url="+myURL+"&text="+myTitle+"&related="+myRelated,'Share via Twitter', params);
	if (window.focus) {newwin.focus();}
	return false;
}
