// Global Variables
var supportsTouch;

// Initialize on load
$(function() {
	// Check touch support
	supportsTouch = false;
	
	try {
		// document.createEvent("TouchEvent");
		// supportsTouch = true;
		supportsTouch = navigator.userAgent.match(/iPad/i) != null;
	}
	catch (e) {}
	
	if (!supportsTouch) {
		// Add extra divs for parallax
		$('#container').wrap('<div class="wrap_extra_1" />').wrap('<div class="wrap_extra_2" />').wrap('<div class="wrap_extra_3" />');
		
		// Parallax Background
		$(window).bind('scroll',function(e){
			parallaxScroll();
		})

		function parallaxScroll() {
			var scrolled = $(window).scrollTop();
			
			var newPos = '0 ';
			var ringPos = '0 ';
			var trianglePos1 = '0 ';
			var trianglePos2 = '0 ';
			newPos += -scrolled/25 + 'px';
			ringPos += -scrolled/20 + 'px';
			trianglePos1 += -scrolled/10 + 'px';
			trianglePos2 += -scrolled/7 + 'px';
			$('#wrap').css({'backgroundPosition':newPos});
			$('.wrap_extra_1').css({'backgroundPosition':ringPos})
			$('.wrap_extra_2').css({'backgroundPosition':trianglePos1})
			$('.wrap_extra_3').css({'backgroundPosition':trianglePos2})
		}
	}
	
	$('a.fb_share').click( function( e ) {
		e.preventDefault( );
		var url = "https://www.facebook.com/sharer.php?u=" + encodeURIComponent( window.location.href ) + "&t=" + encodeURIComponent( $(this).attr('data-title') );
		window.open( url, "fb_share", "width=640,height=480,location=no,resizable=no,scrollbars=no,toolbar=no" );
		return false;
	});

	$('a.twitter_share').click( function( e ) {
		e.preventDefault( );
		var anchor;
		if ( !( anchor = $(this).attr('data-anchor') ) )
			anchor = "";
		var url = "https://twitter.com/share?url=" + encodeURIComponent( window.location.href + anchor ) + "&text=" + encodeURIComponent( $(this).attr('data-text') ) + "&related=juxtinteractive";
		window.open( url, "twitter_share", "width=640,height=360,location=no,resizable=no,scrollbars=no,toolbar=no" );
		return false;
	});
	
	if ($('body').hasClass('clients')) {
		$('.primary_content').isotope({
		  // options
		  itemSelector : 'img'
		});

		$('.secondary_content ul a').click(function(e){
			var selector = $(this).attr('data-filter');
			$('.primary_content').isotope({filter: selector});
			e.preventDefault();
		})
	}
});
