
// globals -- sort of.
var $body;

// colour variations 
var colours = ['option1', 'option2', 'option3', 'option4'];
var currentChoice;
var randomChoice;
function chooseColour(){

	do {
		randomChoice = Math.floor(Math.random()*colours.length);
		
	} while(currentChoice && currentChoice === randomChoice);
	currentChoice = randomChoice;
	return colours[currentChoice];
}




function paging() {
	$('.slides article:first-child, .product:first-child').siblings().hide();
	$(window).on('hashchange', function(e){
		e.preventDefault();
		var h = window.location.hash;
		var p = $(h);

		if(p.is(':visible') || h.length < 2) { return false; }
		var s = h.replace("#", "/"),
			n = $('a[href$='+h+']').parents().hasClass('sub-menu'),
			g = h.replace("#", "").charAt(0).toUpperCase() + h.substr(2).toLowerCase();

		_gaq.push(['_trackPageview', s]);
		document.title = g + (n?' - Packages': "") + " - RightClick";

		pageTransition(p);



		$('nav.small').hide();
		if (h === '#home') {
			$('nav.small').hide();
		} else {
			$('nav.small').show();
		}

		if(n || h === '#packages') {
			$('.sub-menu').show();
		} else {
			$('.sub-menu').hide();
		}
		$('html, body').animate({scrollTop:0}, 300);
		return false;		
	});
	$(window).trigger('hashchange');
}

function pageTransition(element) {
	var callback = callback || function(){};
	element.css({top:200}).siblings(':visible').animate({top:-200,opacity:0}, 300, function(){
		element.show().css({opacity:0}).siblings().hide().end().animate({top:0,opacity:1}, 300);
		
		var h =  window.location.hash;
		var t = ["#analyst","#webmaster","#megaphone", "#publisher", "#radar" ]
		if($.inArray(window.location.hash, t) == -1){
			$body.removeClass().addClass(chooseColour());
		}
		
		switch (h) {
		    case "#analyst":
				$body.removeClass().addClass("option5");
				break
		    ;
		    		
		    case "#webmaster": 
				$body.removeClass().addClass("option6");
				break
		    ; 
		
		    case "#megaphone": 
				$body.removeClass().addClass("option7");
				break
		    ;
		
		    case "#publisher": 
				$body.removeClass().addClass("option8");
				break
		    ; 
		    
		    case "#radar": 
				$body.removeClass().addClass("option9");
				break
		    ;
		
		   }
		
	});
}

function equalizeProductDetails() {
	$('.product').each(function(){
		var t = $(this);
		t.find('.package-details, .package-overview').equal();
	});
}

function construct() {
	// assignments
	$body = $('body');
	$body.addClass(chooseColour());
	// do things
	$("#branding a").lettering();
	equalizeProductDetails();
	paging();
}




$(document).ready(construct)







