//window.resizeTo(screen.width,screen.height);

window.onload = function()
{	

	var url = window.location.toString();
	url = url.split('#')[1];
	if ((!url) || (url == "the-beginning")){	
	// Slideshow
	$('#slideshow').animate({
		opacity: 1,
		filter: '',
		}, 500);
	
	$('#top-1 .slide-front').animate({
    	left: '-=150',
   		top: '-=100',
   		opacity: 0,
		filter: '',
  		}, 1);
  		
	$('#top-1 .slide-front').animate({
		opacity: 1,
		filter: '',
    	left: '+=150',
   		top: '+=100'
  		}, 1000, function(){
  			$('#top-1 #slide-content').animate({
				opacity: 1,
				filter: '',
			}, 200);		
  		});
  	}else{
  		$('#slideshow').animate({
		opacity: 1,
		filter: '',
		}, 10, function(){
			$('#top-1 .slide-front').css('opacity', '1');
			$('#top-1 #slide-content').css('opacity', '1');
			gotoLocation(url);		
  		});
  	}
  	
	function gotoLocation(url)
	{
		if (url == 'the-beginning'){
			_gaq.push(['_trackEvent', 'the-beginning', 'click']);
			slideshow.setStep(1);
		}else if (url == 'the-legend'){
			_gaq.push(['_trackEvent', 'the-legend', 'click']);
			slideshow.setStep(2);
		}else if (url == 'the-frame'){
			_gaq.push(['_trackEvent', 'the-frame', 'click']);
			slideshow.setStep(3);
		}else if (url == 'the-builder'){
			_gaq.push(['_trackEvent', 'the-builder', 'click']);
			slideshow.setStep(4);
		}else if (url == 'buy-the-frame'){
			_gaq.push(['_trackEvent', 'buy-the-frame', 'click']);
			slideshow.setStep(5);
		}
	}
	function arrow(dir){
		currenturl = window.location.toString();
		var newSlideStr =currenturl.split('#')[1];
		var newSlide = 1;
		if (newSlideStr == 'the-beginning'){
			_gaq.push(['_trackEvent', 'the-beginning', 'click']);
			newSlide = 1;
		}else if (newSlideStr == 'the-legend'){
			_gaq.push(['_trackEvent', 'the-legend', 'click']);
			newSlide = 2;
		}else if (newSlideStr == 'the-frame'){
			_gaq.push(['_trackEvent', 'the-frame', 'click']);
			newSlide = 3;
		}else if (newSlideStr == 'the-builder'){
			_gaq.push(['_trackEvent', 'the-builder', 'click']);
			newSlide = 4;
		}else if (newSlideStr == 'buy-the-frame'){
			_gaq.push(['_trackEvent', 'buy-the-frame', 'click']);
			newSlide = 5;
		}
		if (dir == 'right'){
			newSlide+=1;
			if (newSlide > 5){
				newSlide = 1;
			}
		}else if (dir = 'left'){
			newSlide-=1;
			if (newSlide <= 0){
				newSlide = 5;
			}
		}		
		slideshow.setStep(newSlide);
		var anch= 'the-beginning';
		if (newSlide == 1){
			anch = 'the-beginning';
		}else if (newSlide == 2){
			anch = 'the-legend';
		}else if (newSlide == 3){
			anch = 'the-frame';
		}else if (newSlide == 4){
			anch = 'the-builder';
		}else if (newSlide == 5){
			anch = 'buy-the-frame';
		}

		slideshow.goToMyHref('#', anch);
	}
	
	$('#right-nav a').click(function() {
		arrow('right');
	});
	
	$('#left-nav a').click(function() {
		arrow('left');
	});
	
	$(document).keydown(function(e){
   		if ((e.keyCode == 38)||(e.keyCode == 39)) { 
       		arrow('right');
       		return false;
    	}else if ((e.keyCode == 37)||(e.keyCode == 40)) { 
       		arrow('left');
       		return false;
    	}
	});

	
	
	$('#nav-white').css('opacity', '0.3');
	
	var menuWrapper = document.getElementById('slideshow-menu-wrapper');
	var cursor = document.getElementById('slideshow-menu-cursor');
	var slideshowWrapper = document.getElementById('slideshow');
	var cursor2 = document.getElementById('slideshow-inner');
	
	var cursorwrapper = document.getElementById('slideshow-cursor');

	var slideshow = new Dragdealer('slideshow',
	{		
		steps: 5,
		animationCallback: function(x, y)
		{
			var top = x * (menuWrapper.offsetWidth - cursor.offsetWidth);
			cursor.style.left = String(top) + 'px';
		}
	});
	
	document.getElementById('slideshow-slide-0').onclick = function()
	{
		_gaq.push(['_trackEvent', 'the-beginning', 'click']);
		slideshow.setStep(1);
		return true;
	}		
	document.getElementById('slideshow-slide-1').onclick = function()
	{
		_gaq.push(['_trackEvent', 'the-beginning', 'click']);
		slideshow.setStep(1);
		return true;
	}
	document.getElementById('slideshow-slide-2').onclick = function()
	{
		_gaq.push(['_trackEvent', 'the-legend', 'click']);
		slideshow.setStep(2);
		return true;
	}
	document.getElementById('slideshow-slide-3').onclick = function()
	{
		_gaq.push(['_trackEvent', 'the-frame', 'click']);
		slideshow.setStep(3);
		return true;
	}
	document.getElementById('slideshow-slide-4').onclick = function()
	{
		_gaq.push(['_trackEvent', 'the-builder', 'click']);
		slideshow.setStep(4);
		return true;
	}
	document.getElementById('slideshow-slide-5').onclick = function()
	{
		_gaq.push(['_trackEvent', 'buy-the-frame', 'click']);
		slideshow.setStep(5);
		return true;
	}
	slideshow.enable();
	/*
	var dragger = new Dragdealer('slideshow-cursor',
	{
		steps: 5,
		animationCallback: function(x, y)
		{
					
			var top = x * (cursorwrapper.offsetWidth - cursor.offsetWidth);
			cursor.style.left = String(top) + 'px';
			
			var topx = x * (slideshowWrapper.offsetWidth - cursor2.offsetWidth);
			cursor2.style.left = String(topx) + 'px';

		}		
		
	});
	*/


}




