﻿/* theChrisxox 2011 - Scripts */

var top = 0;
$(document).ready(function() {	
			
	$('#intro-logo').fadeIn(2000, function(){ });
	
	
		//horizontal CD-Position
			
	/* -------------- tooltips dot-navigation ---------------- */	
	
	$('#intro-dot').tipsy({html: true, gravity: 'e'});
	$('#two-door-dot').tipsy({html: true, gravity: 'e'});
	$('#hoepstein-dot').tipsy({html: true, gravity: 'e'});
	$('#termite-book-dot').tipsy({html: true, gravity: 'e'});
	$('#termite-drills-dot').tipsy({html: true, gravity: 'e'});
	$('#come-hell-dot').tipsy({html: true, gravity: 'e'});
	$('#tracy-dot').tipsy({html: true, gravity: 'e'});
	$('#intern-dot').tipsy({html: true, gravity: 'e'});
	
	/* -------------- scrollTo dot-navigation ---------------- */
	
	$('#nav-section').localScroll({hash : 'true'});
	//$('#dot-nav').localScroll({hash : 'true'});
	
	
	
	/* -------------- keyboard navigation ---------------- */
	
	function scrollToNew () {
	  var scroll_position = $(window).scrollTop();
	  
	  $('.text-container').each(function(i, div){ 
		div_top = $(div).offset().top; 
		if (scroll_position < div_top) { 
		  
		  anchor_hash = $(this).attr("id")
		  
		  $.scrollTo(div, 800, {onAfter:function(){ 
		  
		  	document.location.hash = anchor_hash;
			
		  } }); 
		 
		  
		  return false; 
		}
	  });
	}
	
	
	function scrollToLast () {
		
	  var scroll_position = $(window).scrollTop();
	
	  var scrollToThis = null;
	  
	  $('.text-container').each(function(i, div) {
		div_top = $(div).offset().top;
		if (scroll_position > div_top) {
		  
		  scrollToThis = div;
		  
		  anchor_hash = $(this).attr("id");
		  		  
		} else {
		  
		  return false;
		}
	  });
	
	  if(scrollToThis != null) {
		$.scrollTo(scrollToThis, 800, {onAfter:function(){ 
		  
		  	document.location.hash = anchor_hash;
			
		  } }); 
	  }
	}
	
	$(document).keydown(function (evt) {
	  if (evt.keyCode == 40) { 
		evt.preventDefault();
		scrollToNew(); 
	  } else if (evt.keyCode == 38) {
		evt.preventDefault();
		scrollToLast();
	  }
	});
	
	$('#Menu li a,,#dot-nav li a').click(function()
	{
		href = $(this).attr('href');
		id = $(this).attr('rel');
		var target_offset = $(id).offset();
		var target_top = target_offset.top;
		$(this).attr('href','javascript:;');
		
		$('html, body').animate({scrollTop:target_top}, 800);

		if(id=="#hoepstein-redesign"){
			$('html, body').animate({scrollTop:target_top+400}, 800);
		}	
		$(this).attr('href',href);
	});
	
	$('#homeBT').click(function()
	{
		href = $(this).attr('href');
		id = $(this).attr('rel');
		var target_offset = $(id).offset();
		var target_top = target_offset.top;
		$(this).attr('href','javascript:;');
		$('html, body').animate({scrollTop:target_top}, 800);
		$(this).attr('href',href);
	});

	
});//end document.ready

var window_width = $(window).width();
var window_height = $(window).height();

var new_position;
$(window).mousemove(function(e) {
		
	var position = e.pageX;
	margin = $("#intro-logo").css("margin-left").replace("px","");
	
	if(position > window_width){
		if(top < 1000){
			new_top = (e.pageY < window_height/2) ? top+e.pageY/70 : top-e.pageY/70;
			new_position = -990 + (parseInt(e.pageX)/50);
		}
	}else{
		if(top<1000){
			new_top = (e.pageY < $("#intro-logo").css("top")) ? top+e.pageY/70 : top-e.pageY/70;
			new_position = -990 - (parseInt(e.pageX)/50);
		}
	}	
	$("#intro-logo").css({"margin-left":new_position+"px","top":new_top+"px"});
 

		/*(mouse_position >= 11700 && mouse_position <= 12270) {				
			$("#smoke-and-mirrors-plx-1").stop().animate({ right: 5320 - (mouse_position * bg_speed * 0.5)}, delay);
		}*/

});

$(window).scroll(function(e) {
	
	/* -------------- parallax scroll ---------------- */	
	
	
	
	var delay = 0;
	var bg_speed = 0.8;
	var object_speed = 0.5; 			 		
	var container_offset = 0;
	
	var scroll_position = $(window).scrollTop();
	var top = $(window).scrollTop();
	$("#main-content").stop().animate({ top : 0 - scroll_position}, delay);
	
	
	if (scroll_position >= 0 && scroll_position <= 900) {
		$("#intro-logo").stop().animate({ top : (0 * object_speed * 1.2) + (scroll_position * object_speed * 1.2)}, delay);	
		$("#intro-bg").stop().animate({ top: container_offset - (0 * bg_speed) + (scroll_position * bg_speed)}, delay);
		$("#intro-plx").stop().animate({ top : (0 * object_speed * 2) + (scroll_position * object_speed * 1.2)}, delay);	
	}
	
	// #design
	
	if (scroll_position >= 1000 && scroll_position <= 1900) {
		$("#two-door-cinema-bg").stop().animate({ top: container_offset - (1100 * bg_speed) + (scroll_position * bg_speed)}, delay);
	}
	
	
	if (scroll_position >= 2000 && scroll_position <= 3369) {
		$("#hoepstein-redesign-bg").stop().animate({ top: container_offset - (2100 * bg_speed) + (scroll_position * bg_speed)}, delay);
		$("#hoepstein-redesign-botte2").stop().animate({ top : (1 * object_speed * 1.1) + ((scroll_position-800) * object_speed * 1.1)}, delay);
	}
	//HISTORY
	
	if (scroll_position >= 3469 && scroll_position <= 4568) {
		$("#termite-book-bg").stop().animate({ top: container_offset - (3659 * bg_speed) + (scroll_position * bg_speed)}, delay);
		$("#termite-3").stop().animate({ top: container_offset - (3459 * bg_speed) + ((scroll_position+250) * bg_speed)}, delay);
	
	}
	
	
	if (scroll_position >= 4568 && scroll_position <= 5568) {	
		$("#termite-drills-bg").stop().animate({ top: container_offset - (4768 * bg_speed) + (scroll_position * bg_speed)}, delay);
	}
	
	
	if (scroll_position >= 5668 && scroll_position <= 6568) {
		$("#come-hell-or-high-water-bg").stop().animate({ top: container_offset - (5768 * bg_speed) + (scroll_position * bg_speed)}, delay);
	}
	
	
	if (scroll_position >= 6668 && scroll_position <= 7568) {
		$("#tracys-waters-bg").stop().animate({ top: container_offset - (6768 * bg_speed) + (scroll_position * bg_speed)}, delay);
	}
	
	
	if (scroll_position >= 7668 && scroll_position <= 8568) {
		$("#internship-journal-bg").stop().animate({ top: container_offset - (7728 * bg_speed) + (scroll_position * bg_speed)}, delay);	
	}
		
	
	
	
	
			/* -------------- dot navigation position ---------------- */	
						
			
			
			/* -------------- active position in dot navigation ---------------- */			
			
			
			var active_position = scroll_position + 100;			
			
			$("#Menu li").removeClass("active");
			$("#dot-nav li a.dot-turquoise-active").removeClass("dot-turquoise-active");	
			$("#dot-nav li a.dot-orange-active").removeClass("dot-orange-active");	
			$("#dot-nav li a.dot-green-active").removeClass("dot-green-active");
			
			
			if (active_position <= 1000 ) {
				$("#intro-dot").addClass("dot-turquoise-active");
			}
			
			else if (active_position <= 2000) {
				$("#two-door-dot").addClass("dot-turquoise-active");
				$("#calendar").parent().addClass("active");
			}
			
			else if (active_position <= 3469) {
				$("#hoepstein-dot").addClass("dot-turquoise-active");
				$("#collection").parent().addClass("active");
			}
			
			else if (active_position <= 4668) {
				$("#termite-book-dot").addClass("dot-turquoise-active");
				$("#spirit").parent().addClass("active");
			}
			
			else if (active_position <= 5668) {
				$("#termite-drills-dot").addClass("dot-turquoise-active");
				$("#ambiant").parent().addClass("active");
			}
			
			else if (active_position <= 6668) {
				$("#come-hell-dot").addClass("dot-turquoise-active");
				$("#factory").parent().addClass("active");
			}
			
			else if (active_position <= 7668) {
				$("#tracy-dot").addClass("dot-turquoise-active");
				$("#press").parent().addClass("active");
			}
			
			else {
				$("#intern-dot").addClass("dot-turquoise-active");
				$("#contact").parent().addClass("active");
			}
			
	
});// end window.scroll


				
/* -------------- input placeholder fix ---------------- */


/*$(function(){   

	if (!(Modernizr.input.placeholder)) {  
		
		$('[placeholder]').focus(function() {
		  var input = $(this);
		  if (input.val() == input.attr('placeholder')) {
			input.val('');
			input.removeClass('placeholder');
		  }
		}).blur(function() {
		  var input = $(this);
		  if (input.val() == '' || input.val() == input.attr('placeholder')) {
			input.addClass('placeholder');
			input.val(input.attr('placeholder'));
		  }
		}).blur();
		
		$('[placeholder]').parents('form').submit(function() {
		  $(this).find('[placeholder]').each(function() {
			var input = $(this);
			if (input.val() == input.attr('placeholder')) {
			  input.val('');
			}
		  })
		});
	}

});*/
		


	


