$(document).ready(function() {

	var fxPhone  = 'fade';
	var fxImages = 'scrollHorz';
	var fxText 	 = 'fade';

	var previousDot = null;
	var dots = $('#content-dots');
	var currentPlatform;

	
	var $phoneSlide = $('#content-left').cycle({ 
	    fx:     fxPhone, 
	    speed:   300, 
	    timeout: 0 
	});
	
	var $textSlide = $('#content-text-slide').cycle({ 
	    fx:      fxText, 
	    speed:   300, 
	    timeout: 0 
	});
	
	var $iphoneScreenSlide = $('.screen-iphone').cycle({ 
	    fx:      fxImages, 
	    speed:   300, 
	    timeout: 0 
	});
	
	var $androidScreenSlide = $('.screen-android').cycle({ 
	    fx:      fxImages, 
	    speed:   300, 
	    timeout: 0 
	});	
	
	var $quotesSlide = $('#quotes-slide').cycle({ 
	    fx:      fxText, 
	    speed:   1000, 
	    timeout: 10000 
	});		
	
	var numberOfDots = $iphoneScreenSlide.children().length;

	$(dots).css("width", numberOfDots * 18);

	$iphoneScreenSlide.children().each(function(i) { 
		var dot = $('<div id="dot" class="dot-black"/>');
			
		if (i == 0) {
			dot.removeClass("dot-black");
            dot.addClass("dot-white");
			previousDot = dot;
		}
						     
        dot.appendTo(dots).click(function() {
        	if (previousDot != null) {
	            $(previousDot).removeClass("dot-white");
            	$(previousDot).addClass("dot-black");
            }
            
            $textSlide.cycle(i);
            $iphoneScreenSlide.cycle(i);
            $androidScreenSlide.cycle(i);
            
            $(this).removeClass("dot-black");
            $(this).addClass("dot-white");

            previousDot = this;
            
            return false; 
        });        
	});
	
	$('#platforms').children().each(function(i) {
					
		if ($(this).hasClass("platform-current")) {
			currentPlatform = this;
		}
		
		$(this).hover(function() {
						if (this != currentPlatform) {
							$(this).addClass("platform-hover");
							$(this).css("cursor", "pointer");
						}
					  },
					  function() {
					  	$(this).removeClass("platform-hover");
					  	$(this).css("cursor", "default");
					  });

		$(this).click(function() {
			if (this != currentPlatform) {
				
				$phoneSlide.cycle(i);
				
				$(currentPlatform).removeClass("platform-current");
				$(this).addClass("platform-current");
				
				currentPlatform = this;
			}	
		});
	});
});
