// JavaScript Document

$(function(){
	
	Main = new Main;
	var $has = {
		touch: "ontouchstart" in document	
	}
	var touchEvent;
	
	$has.touch ? touchEvent = "touchend" : touchEvent = "click";
	
	var thumbnailHoverSpeed = 200;
	
	$('#sliderThumbs ul li').bind(touchEvent, function(){
		var self = this;
		var thumbIndex = $(self).index();
		Main.moveToImage(self, thumbIndex);
	});
	
	if(!$has.touch){
		$('#sliderThumbs ul li').hover(function(){
			$(this).siblings('li').stop().animate({ 'opacity' : '0.6' }, thumbnailHoverSpeed);
			$(this).css({ 'border' : '3px solid #fff' });
		}, function(){
			$(this).siblings('li').stop().animate({ 'opacity' : '1' }, thumbnailHoverSpeed);
			$(this).css({ 'border' : '3px solid #eaeaea' });
		});
		
		$('#imageSliderContainer').bind({
			mouseenter: function(){
				Main.stopSlideShow();
			},
			mouseleave: function(){
				Main.resumeSlideShow();
			}
		});
	}
	
	$('.free_download').click(function(e){
		e.preventDefault();
		$(this).fadeOut(function(){
			$('#freeDownload').fadeIn();	
		});
	});
	
	$('#freeEmail').bind( 'focus', function(){
		clearTimeout(Main.timeOut); // stop rotation timer
		Main.timeOut = null;
		Main.slideShowIsActive = false;
		console.log(Main.slideShowIsActive);
		if($(this).val() == "email address"){
			$(this).val("");	
		}
	});
	
	$('#freeEmail').bind('blur', function(){
		if($(this).val() == ""){
			$(this).val("email address");	
		}
	});
	
	$('input#getDownload').click(function(){
		Main.timeOut = setTimeout(Main.nextImage, Main.rotationSpeed);
		Main.slideShowIsActive = true;
		getDownload();
	});
	
	
});
