// SLIDESHOW
$.fn.cycle.updateActivePagerLink = function(pager, currSlideIndex) {
    $(pager).find('li').removeClass('activeLI')
        .filter('li:eq('+currSlideIndex+')').addClass('activeLI');
};

$(document).ready(function() {
    $('.slideshow').cycle({
        fx: 'fade',
		prev:   '.prev', 
		next:   '.next', 
		timeout: 5000,
        pager:  '.logos-bg ul',
        
        pagerAnchorBuilder: function(id, slide) { 
		var new_src = slide.src.substring(0,slide.src.length-4);
        new_src += "-thumb.png";
		return '<li><a href="#"><img src="' + new_src + '" /></a></li>';
		}
    });
});


/**
 * Parallax Scrolling Tutorial
 * For Smashing Magazine
 * July 2011
 *   
 * Author: Richard Shepherd
 * 		   www.richardshepherd.com
 * 		   @richardshepherd   
 */

function isPhone(){
    return (
        (navigator.platform.indexOf("iPhone") != -1) ||
        (navigator.platform.indexOf("iPod") != -1) ||
        (navigator.platform.indexOf("iPad") != -1) ||
        (navigator.platform.indexOf("Android") != -1)
    );
}

if(isPhone()){
    var sections = ["about", "facility", "staff", "customers", "getstarted", "productdev"];
	jQuery.each(sections, function() {
	      $("#" + this).css({backgroundAttachment:'scroll'});
	});
} else {




	// On your marks, get set...
	$(document).ready(function(){
							
		// Cache the Window object
		$window = $(window);
		
		// Cache the Y offset and the speed of each sprite
		$('[data-type]').each(function() {	
			$(this).data('offsetY', parseInt($(this).attr('data-offsetY')));
			$(this).data('Xposition', $(this).attr('data-Xposition'));
			$(this).data('speed', $(this).attr('data-speed'));
		});
		
		// For each element that has a data-type attribute
		$('div[data-type="background"]').each(function(){
		
		
			// Store some variables based on where we are
			var $self = $(this),
				offsetCoords = $self.offset(),
				topOffset = offsetCoords.top;
			
			// When the window is scrolled...
		    $(window).scroll(function() {
		
				// If this section is in view
				if ( ($window.scrollTop() + $window.height()) > (topOffset) &&
					 ( (topOffset + $self.height()) > $window.scrollTop() ) ) {
		
					// Scroll the background at var speed
					// the yPos is a negative value because we're scrolling it UP!								
					var yPos = -($window.scrollTop() / $self.data('speed')); 
					
					// If this element has a Y offset then add it on
					if ($self.data('offsetY')) {
						yPos += $self.data('offsetY');
					}
					
					// Put together our final background position
					var coords = '50% '+ yPos + 'px';
	
					// Move the background
					$self.css({ backgroundPosition: coords });
					
					// Check for other sprites in this section	
					$('[data-type="sprite"]', $self).each(function() {
						
						// Cache the sprite
						var $sprite = $(this);
						
						// Use the same calculation to work out how far to scroll the sprite
						var yPos = -($window.scrollTop() / $sprite.data('speed'));					
						var coords = $sprite.data('Xposition') + ' ' + (yPos + $sprite.data('offsetY')) + 'px';
						
						$sprite.css({ backgroundPosition: coords });													
						
					}); // sprites
				
					// Check for any Videos that need scrolling
					$('[data-type="video"]', $self).each(function() {
						
						// Cache the video
						var $video = $(this);
						
						// There's some repetition going on here, so 
						// feel free to tidy this section up. 
						var yPos = -($window.scrollTop() / $video.data('speed'));					
						var coords = (yPos + $video.data('offsetY')) + 'px';
		
						$video.css({ top: coords });													
						
					}); // video
				
					// Check for any text blurb that needs scrolling to the left
					$('[data-type="blurbleft"]', $self).each(function() {
						
						// Cache the blurb
						var $blurbleft = $(this);
						
						// There's some repetition going on here, so 
						// feel free to tidy this section up. 
						var yPos = -($window.scrollTop() / $blurbleft.data('speed'));					
						var coords = (yPos + $blurbleft.data('offsetY')) + 'px';
		
						$blurbleft.css({ left: coords });													
						
					}); // text blurbs
				
					// Check for any text blurb that needs scrolling to the right
					$('[data-type="blurbright"]', $self).each(function() {
						
						// Cache the blurb
						var $blurbright = $(this);
						
						// There's some repetition going on here, so 
						// feel free to tidy this section up. 
						var yPos = -($window.scrollTop() / $blurbright.data('speed'));					
						var coords = (yPos + $blurbright.data('offsetY')) + 'px';
		
						$blurbright.css({ right: coords });													
						
					}); // text blurbs
				
					// Check for any text blurb that needs scrolling up
					$('[data-type="blurbup"]', $self).each(function() {
						
						// Cache the blurb
						var $blurbup = $(this);
						
						// There's some repetition going on here, so 
						// feel free to tidy this section up. 
						var yPos = -($window.scrollTop() / $blurbup.data('speed'));					
						var coords = (yPos + $blurbup.data('offsetY')) + 'px';
		
						$blurbup.css({ top: coords });													
						
					}); // text blurbs
				
					// Check for any text blurb that needs scrolling down
					$('[data-type="blurbdown"]', $self).each(function() {
						
						// Cache the blurb
						var $blurbdown = $(this);
						
						// There's some repetition going on here, so 
						// feel free to tidy this section up. 
						var yPos = -($window.scrollTop() / $blurbdown.data('speed'));					
						var coords = (yPos + $blurbdown.data('offsetY')) + 'px';
		
						$blurbdown.css({ bottom: coords });													
						
					}); // text blurbs
				
				}; // in view
		
			}); // window scroll
				
		});	// each data-type
	
	}); // document ready

};

