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

window.onload = function()
{	

	var url = window.location.toString();
	url = url.split('#')[1];
	if ((!url) || (url == "home")){	
	// Slideshow
	$('#slideshow').animate({
		opacity: 1,
		filter: '',
		}, 700);
	

  	}else{
  		$('#slideshow').animate({
		opacity: 1,
		filter: '',
		}, 10, function(){
			gotoLocation(url);		
  		});
  	}
  	
	function gotoLocation(url)
	{
		if (url == 'home'){
			slideshow.setStep(1);
		}else if (url == 'marketing'){
			slideshow.setStep(2);
		}else if (url == 'development'){
			slideshow.setStep(3);
		}else if (url == 'media'){
			slideshow.setStep(4);
		}else if (url == 'trade'){
			slideshow.setStep(5);
		} else if (url == 'about') {
			slideshow.setStep(6);
		} else if (url == 'stats') {
			slideshow.setStep(7);
		}
		
	}
	function arrow(dir){
		currenturl = window.location.toString();
		var newSlideStr = currenturl.split('#')[1];
		var newSlide = 1;
		if (newSlideStr == 'home'){
			newSlide = 1;
		}else if (newSlideStr == 'marketing'){
			newSlide = 2;
		}else if (newSlideStr == 'development'){
			newSlide = 3;
		}else if (newSlideStr == 'media'){
			newSlide = 4;
		}else if (newSlideStr == 'trade'){
			newSlide = 5;
		}else if (newSlideStr == 'about'){
			newSlide = 6;
		}else if (newSlideStr == 'stats'){
			newSlide = 7;
		}
		if (dir == 'right'){
			newSlide+=1;
			if (newSlide > 7){
				newSlide = 1;
			}
		}else if (dir = 'left'){
			newSlide-=1;
			if (newSlide <= 0){
				newSlide = 7;
			}
		}		
		slideshow.setStep(newSlide);
		var anch= 'home';
		if (newSlide == 1){
			anch = 'home';
		}else if (newSlide == 2){
			anch = 'marketing';
		}else if (newSlide == 3){
			anch = 'development';
		}else if (newSlide == 4){
			anch = 'media';
		}else if (newSlide == 5){
			anch = 'trade';
		}else if (newSlide == 6){
			anch = 'about';
		}else if (newSlide == 7){
			anch = 'stats';
		}

		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;
    	}
	});

	function getStep(){
		currenturl = window.location.toString();
		var curSlideStr = currenturl.split('#')[1];
		var curSlide = 1;
		if (curSlideStr == 'home'){
			curSlide = 1;
		}else if (curSlideStr == 'marketing'){
			curSlide = 2;
		}else if (curSlideStr == 'development'){
			curSlide = 3;
		}else if (curSlideStr == 'media'){
			curSlide = 4;
		}else if (curSlideStr == 'trade'){
			curSlide = 5;
		}else if (curSlideStr == 'about'){
			curSlide = 6;
		}else if (curSlideStr == 'stats'){
			curSlide = 7;
		}
		return curSlide;
	}
	
	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: 7,
		animationCallback: function(x, y)
		{
			//var top = x * (menuWrapper.offsetWidth - cursor.offsetWidth);
		
			var stepNum = getStep();
			
				if( (navigator.userAgent.match(/iPad/i)) || (navigator.userAgent.match(/iPhone/i)) || (navigator.userAgent.match(/iPod/i) ) ) {
					var top = x * (menuWrapper.offsetWidth - 120);
					if ( stepNum == 1 ) { top = top; } //home	
					if ( stepNum == 2 ) { top = top - 40; } //marketing	
					if ( stepNum == 3 ) { top = top - 25;} //development	
					if ( stepNum == 4 ) { top = top - 30;} //media	
					if ( stepNum == 5 ) { top = top - 70;} //trade
					if ( stepNum == 6 ) { top = top - 100;} //about
					if ( stepNum == 7 ) { top = top - 120;} //stats
					
				} else  {
					var top = x * (menuWrapper.offsetWidth - 150);	
					
				}
			//if ( stepNum == 3 ) { top = top + 30;} //develoopment
			//if ( stepNum == 4 ) { top = top + 40;} 	//media
			//if ( stepNum == 5 ) { top = top + 30;} //trade
			
			
			cursor.style.left = String(top) + 'px';
		}
	});
	
	document.getElementById('slideshow-slide-1').onclick = function()
	{
		slideshow.setStep(1);
		return false;
	}		
	document.getElementById('slideshow-slide-2').onclick = function()
	{
		slideshow.setStep(2);
		return false;
	}
	document.getElementById('slideshow-slide-3').onclick = function()
	{
		slideshow.setStep(3);
		return false;
	}
	document.getElementById('slideshow-slide-4').onclick = function()
	{
	
		slideshow.setStep(4);
		return false;
	}
	document.getElementById('slideshow-slide-5').onclick = function()
	{
		slideshow.setStep(5);
		return false;
	}
	document.getElementById('slideshow-slide-6').onclick = function()
	{
		slideshow.setStep(6);
		return false;
	}
	document.getElementById('slideshow-slide-7').onclick = function()
	{
		slideshow.setStep(7);
		return false;
	}

	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';

		}		
		
	});
	*/


}




