// JavaScript Document
var slideWidth = 768;
var mastHeight = 88;
var scrollElement;

$(document).ready(function() {
		 
	// SMOKE URL HASH
	$(window).bind('hashchange', function() {
		hashChange();
	});
	
	function hashChange() {
		var st = 0;
		if(window.location.hash != '') st = $("div[id='" + window.location.hash.replace('#', '') + "']").offset().top - mastHeight;
		
		$('html, body').attr('scrollTop', st);
	}
	
	
	//  MAKE THEM SHITS SLIDE
	
	
	$('.section').each(function() {
		
		var leftNav = $('.left_arrow', this);
		var rightNav = $('.right_arrow', this);
		var gallery = $('.slider', this);
		var position = 0;
		var imgNum = $('li', gallery).size();
		var slidePos = 1;
		var imgNum = $('li', gallery).size();
		var ulWidth = ( imgNum + 2 ) * slideWidth; // extra 2 to show slide bg behind when scrolling
		var div = $('.sliderWrapper')
		var divWidth = $(div).width();
		
		// LET OUT THE HEMS
		$(gallery).css('width', ulWidth);
		
		// TO THE LEFT (TO THE LEFT)
		$(leftNav).click(function() {
			if ( (slidePos > 1) ) {
				position = position + slideWidth;
				$(gallery).animate({
					'left' : position
				});
				slidePos--;
			}
		});
		
		// TO THE RIGHT (TO THE RIGHT)
		$(rightNav).click(function() {
			if ( (slidePos < imgNum) ) {
				position = position - slideWidth;
				$(gallery).animate({
					'left' : position
				});
				slidePos++;
			}
		});
		
	});
	
	
	// PRICK EARS FOR MAIN NAV
	if($.browser.webkit) scrollElement = 'body';
	if($.browser.msie) scrollElement = 'html';
	if($.browser.mozilla) scrollElement = 'html';

	$('.lutionMedia_nav').click(function() {
		getGoing('lutionMedia');
	});
	
	$('.p3_exp_nav').click(function() {
		getGoing('p3-experience-site');
	});
	
	$('.impavid').click(function() {
		getGoing('impavid');
	});
	
	$('.embrace_nav').click(function() {
		getGoing('embrace-the-culture');
	});
	
	$('.moana_nav').click(function() {
		getGoing('moana');
	});
	
	$('.etc_nav').click(function() {
		getGoing('etc');
	});
	
	$('.inConcertApp').click(function() {
		getGoing('in-concert-app');
	});
	
	$('.space_nav').click(function() {
		getGoing('a-space-addysy');
	});
	
	$('.haunted_nav').click(function() {
		getGoing('haunted-queens-club');
	});
	
	$('.horrorscopes_nav').click(function() {
		getGoing('horrorscopes');
	});
	
	$('.p3_site_nav').click(function() {
		getGoing('p3-site');
	});
	
	$('.blacktop_nav').click(function() {
		getGoing('blacktop');
	});
	
	$('.queensClub_nav').click(function() {
		getGoing('queensClub');
	});
	
	$('.sprint_nav').click(function() {
		getGoing('sprint');
	});
	
	$('.2_minuteDrill_nav').click(function() {
		getGoing('2_minuteDrill');
	});
	
	$('.ip3apps_nav').click(function() {
		getGoing('ip3apps');
	});
	
	$('.raven_watches_nav').click(function() {
		getGoing('raven_watches');
	});
	
	$('.10_years_nav').click(function() {
		getGoing('10_years');
	});
	
	$('.random_nav').click(function() {
		getGoing('random');
	});	
	
	$('.about_nav').click(function() {
		getGoing('about');
	});
		
	
	// MAKE CONTENT DANCE
	function getGoing(source) {
		
		switch(source) {
			case 'lutionMedia':
			$('html, body').animate({
				'scrollTop' : $('#lutionMedia').offset().top - mastHeight
			}, 600);
			break;
			
			case 'p3-experience-site':
			$('html, body').animate({
				'scrollTop' : $('#p3_experience_site').offset().top - mastHeight
			}, 600);
			break;
			
			case 'impavid':
			$('html, body').animate({
				'scrollTop' : $('#impavid').offset().top - mastHeight
			}, 600);
			break;
						
			case 'embrace-the-culture':
			$('html, body').animate({
				'scrollTop' : $('#embrace').offset().top - mastHeight
			}, 600);
			break;
			
			case 'moana':
			$('html, body').animate({
				'scrollTop' : $('#moana').offset().top - mastHeight
			}, 600);
			break;
			
			case 'etc':
			$('html, body').animate({
				'scrollTop' : $('#etc').offset().top - mastHeight
			}, 600);
			break;
			
			case 'in-concert-app':
			$('html, body').animate({
				'scrollTop' : $('#inConcertApp').offset().top - mastHeight
			}, 600);
			break;
			
			case 'a-space-addysy':
			$('html, body').animate({
				'scrollTop' : $('#space_addysy').offset().top - mastHeight
			}, 600);
			break;
			
			case 'haunted-queens-club':
			$('html, body').animate({
				'scrollTop' : $('#haunted_queens_club').offset().top - mastHeight
			}, 600);
			break;
			
			case 'horrorscopes':
			$('html, body').animate({
				'scrollTop' : $('#horrorscopes').offset().top - mastHeight
			}, 600);
			break;
			
			case 'p3-site':
			$('html, body').animate({
				'scrollTop' : $('#p3_site').offset().top - mastHeight
			}, 600);
			break;
			
			case 'blacktop':
			$('html, body').animate({
				'scrollTop' : $('#blacktop').offset().top - mastHeight
			}, 600);
			break;
			
			case 'queensClub':
			$('html, body').animate({
				'scrollTop' : $('#queens_club').offset().top - mastHeight
			}, 600);
			break;
			
			case 'sprint':
			$('html, body').animate({
				'scrollTop' : $('#sprint').offset().top - mastHeight
			}, 600);
			break;
			
			case '2_minuteDrill':
			$('html, body').animate({
				'scrollTop' : $('#2_minuteDrill').offset().top - mastHeight
			}, 600);
			break;
			
			case 'ip3apps':
			$('html, body').animate({
				'scrollTop' : $('#ip3_apps').offset().top - mastHeight
			}, 600);
			break;
			
			case 'raven_watches':
			$('html, body').animate({
				'scrollTop' : $('#raven_watches').offset().top - mastHeight
			}, 600);
			break;
			
			case '10_years':
			$('html, body').animate({
				'scrollTop' : $('#10_years').offset().top - mastHeight
			}, 600);
			break;
			
			case 'random':
			$('html, body').animate({
				'scrollTop' : $('#random').offset().top - mastHeight
			}, 600);
			break;
									
			case 'about':
			$('html, body').animate({
				'scrollTop' : $('#about').offset().top - mastHeight
			}, 600);
			break;
		}
	}

});
