$(function() {
	 $("html").removeClass("no-js");


	// enable circular scrollables with a click handler
	$(".scroll").scrollable({ circular: false }).click(function() {

	});

		    var 
		      speed = 1000,   // animation speed
		      $wall = $('#wrapper').find('.wrap')
		    ;

		    $wall.masonry({
		      columnWidth: 49, 
		      // only apply masonry layout to visible elements
		      filter: '.filter1',
		      itemSelector: '.box:not(.invis)',
		      animate: true,
		      animationOptions: {
			    duration: 750,			
			    easing: 'linear',
			    queue: false
			  }
		    });
		    
		    // $('.filtering-nav a').click(function(){
		      // var colorClass = '.' + $(this).attr('class');
		      	// moveElements(colorClass);
				// return false;
		    // });
		    
		    function moveElements(colorClass){
		    	//changeTitles(colorClass);
		    	
		    	if(colorClass=='.all') {
		        // show all hidden boxes
		        $wall.children('.invis')
		          .toggleClass('invis').fadeIn(speed);
		      } else {  
		        // hide visible boxes 
		        $wall.children().not(colorClass).not('.invis')
		          .toggleClass('invis').fadeOut(speed);
		        // show hidden boxes
		        $wall.children(colorClass+'.invis')
		          .toggleClass('invis').fadeIn(speed);
		        $wall.children(colorClass).fadeIn(speed);
		      }
		      $wall.masonry();
		    }

				// hides the slickbox as soon as the DOM is ready
				 // (a little sooner than page load)
				  $('#contact_pop').hide();
				 // shows the slickbox on clicking the noted link  
				

				 // toggles the slickbox on clicking the noted link  
				  $('.email').click(function() {
				    $('#contact_pop').slideToggle(400);
				    return false;
				  });
				
			
				var $elem = $('.home');


				    $('#none-filtering').click(
				        function (e) {
				            $('html, body').animate({scrollTop: $elem.height()}, 800);
				        }
				    );

			

					// $("#twitter").getTwitter({
						// userName: "mashable",
						// numTweets: 2,
						// loaderText: "Loading tweets...",
						// slideIn: true,
						// showHeading: true,
						// headingText: "Latest Tweets",
						// showProfileLink: true
					// });

			// if(typeof currentFilter !== 'undefined'){
			// var colorClass = '.filter'+currentFilter;
		    	// moveElements(colorClass);
		    // }

//Jquery BBQ
  
  // Keep a mapping of url-to-container for caching purposes.
  var cache = {
    // If url is '' (no fragment), display this div's content.
    '': $('#header_information')
  };
  
  var states = [];
  states[0] = '/What-eNox-Media-Does-to-Help-Improve-Your-Business';
  states[1] = '/Fresh-Creative-Web-Graphic-Marketing-Solutions-by-eNox-Media';
  states[2] = '/About-eNox-Media-Awsome-Since-2001';
  states[3] = '/eNox-Media-Blog';
  states[4] = '/Everything';
  states[5] = '';
  
  if(currentFilter > 0 && pushState)
	$.bbq.pushState(states[currentFilter-1],2);
  // Bind an event to window.onhashchange that, when the history state changes,
  // gets the url from the hash and displays either our cached content or fetches
  // new content to be displayed.
  
  if(typeof doHashChange === 'undefined')
    	doHashChange = true;
   if(doHashChange)
  $(window).bind( 'hashchange', function(e) {
    
    // Get the hash (fragment) as a string, with any leading # removed. Note that
    // in jQuery 1.4, you should use e.fragment instead of $.param.fragment().
    var url = $.param.fragment();
    
	if(url == states[5])
		url = states[0];
	if(url == states[0])
		moveElements('.filter1');
	if(url == states[1])
		moveElements('.filter2');
	if(url == states[2])
		moveElements('.filter3');
	if(url == states[3])
		moveElements('.filter4');
	if(url == states[4])
		moveElements('.all');
	
		    
	var currentNavItem = 'bbq-current';
    //alert(url);
    
    if(typeof removeClass === 'undefined')
    	removeClass = true;
    if(removeClass)
		$( 'a.current-item' ).removeClass( 'current-item' );
    
    // Hide any visible ajax content.
    $( '.bbq-content' ).children( ':visible' ).hide();
    
    url && $( 'a[href="#' + url + '"]' ).addClass( 'current-item' );
    
    if ( cache[ url ] ) {
      renameHeaderTags(cache[url]);
    } else {
    	
    	$.get(url, function(newPage){
    		$newPage = $(newPage).find('#header_information');
    		renameHeaderTags($newPage);
    		cache [url] = $newPage
    	}, 'html');
    	
    }
    });
    
    function renameHeaderTags($dataElement)
    {
		document.title = $dataElement.find('#title').eq(0).text();
    	$("meta[property=og:title]").attr("content", $dataElement.find('#title').html());
		$("meta[property=og:url]").attr("content", $dataElement.find('#og-url').html());
		$("meta[property=og:image]").attr("content", $dataElement.find('#og-image').html());
		$("meta[property=og:description]").attr("content", $dataElement.find('#og-description').html());
		$("meta[name=description]").attr("content", $dataElement.find('#og-description').html());
		$("meta[name=keywords]").attr("content", $dataElement.find('#og-keywords').html());
    }
  
  // Since the event is only triggered when the hash changes, we need to trigger
  // the event now, to handle the hash the page may have loaded with.
  $(window).trigger( 'hashchange' );
  
});


