$(document).ready(function(){

	/*---------------------------------------------------

	Nav

	---------------------------------------------------*/
	
	$("#xmasOverlay").css("height",$(document).height() + "px");
	$("#xmasOverlay").css("width",$(document).width() + "px");
	$("#xmasLetter").click(function(){ $("#xmasOverlay").hide(); });

	/*---------------------------------------------------

	Nav

	---------------------------------------------------*/

	

	$("#nav a.current-cat, #nav a.current_page_ancestor").each(function (i) {



		var bradar = $(this).siblings();

		bradar.show();

		

		var rand = Math.ceil(3*Math.random());

		bradar.parent().addClass('expand' + rand);

	

	});

	



	

	

	$("#nav .open > a").each(function (i) {



		var bradar = $(this).parent().parent();

		

		var rand = Math.ceil(3*Math.random());

		$(this).parent().addClass('expand' + rand);

	

	});

	

	

	/*$("#nav a.last-cat, #nav a.current_page_item").each(function (i) {



		var bradar = $(this).parent().siblings();

		

		if ($(this).parent().parent().is('ul'))

			bradar.hide();

		

	});*/

	

	

	$('#nav > li > a').not('.intact a').each(function() {

		

		$(this).click( function(event) {

			event.preventDefault();

		});

	

		$(this).addClass('weak');

		

	});



	$("#nav a").hover(

	function(){

		

		var unkles = $(this).parent().siblings();

		

		$(this).siblings('ul').show();

		$(this).siblings('ul').children('li').show();

		

		unkles.find('ul').hide();	

		

		unkles.removeClass('expand1 expand2 expand3');

		unkles.find('li').removeClass('expand1 expand2 expand3');

		

	},

	function(){ 

	});

	

	

	$("#header li:has(ul)").children('a').hover(

	function(){

		

		var dad = $(this).parent();

		

		var rand = Math.ceil(3*Math.random());

		var has = dad.attr("class");

				

		if ( has.indexOf('expand') < 0 ) dad.addClass('expand' + rand);

		

	},

	function(){ 

		

		//$(this).parent().removeClass('expand1 expand2 expand3');

	

	});

	

	/*

	$("#nav").hover(

	function(){

			

	},

	function(){ 

		

		$(this).find("ul").hide();

		$(this).find("li").removeClass('expand1 expand2 expand3');

	

	});*/

	

	

	

	/*---------------------------------------------------

	Wheel

	---------------------------------------------------*/

	leadingZeros = function(num, totalChars, padWith) {

		num = num + "";

		padWith = (padWith) ? padWith : "0";

		if (num.length < totalChars) {

			while (num.length < totalChars) {

				num = padWith + num;

			}

		} 



		return num;

	}

	

	

	shuffle = function(o){ //v1.0

		for(var j, x, i = o.length; i; j = parseInt(Math.random() * i), x = o[--i], o[i] = o[j], o[j] = x);

		return o;

	};

	

	WheelSpin = function() {

		var src = $("#more img").attr("src");

		var temp = new Array();	temp = src.split('wheel-')



		var rand_no = Math.random();

		rand_no = rand_no * 13;

		rand_no = Math.ceil(rand_no);



		$("#more img").attr("src",temp[0] + 'wheel-'  + leadingZeros(rand_no,2) + '.png');



	}

	

	var refreshId = 0;

	if ( !$.cookie('wheel') ) { refreshId = setInterval("WheelSpin()", 4000); }

	

	

	

	var images = shuffle([ 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13 ]);

	

	$("#more img").click( function(event) {

		event.preventDefault();



		if ($('#selector').length == 0) {



			$("#header").append('<ul id="selector"></ul>');

		

			for (var i=0; i<13; i++) {

				$("#selector").append('<li><a href="#"><img src="' + templatedir + '/i/wheel-s-' + leadingZeros(images[i],2)  + '.png"  alt="" /></a></li>');

			}

			$("#selector").append('<li><a class="shuffle" href="#"><img src="' + templatedir + '/i/wheel-s.png"  alt="" /></a></li>');

			$("#selector").append('<li><a class="about" href="' + homedir + '/' + wheellink + '"><img src="' + templatedir + '/i/wheel-a.png"  alt="" /></a></li>');

		

					

			$('#selector a').click( function(event) {

				if (!$(this).hasClass('about')) event.preventDefault();



				if ($(this).hasClass('shuffle')) { 

					$.cookie('wheel', null, { path: '/' });

					refreshId = setInterval("WheelSpin()", 4000);

				}

				else {

					var src = $(this).children('img').attr("src");

					var key = src.substring(src.length-6, src.length-4);

					var temp = new Array();	temp = src.split('wheel-s-')

					

					clearInterval ( refreshId );

					

					$.cookie('wheel', key, { path: '/' });	

					$("#more img").attr("src",temp[0] + 'wheel-'  + key + '.png');

				}



				$('#selector').remove();

			});

			

		}

		else $('#selector').remove();

		

	});





	

	

	

	

	

	$("#more img").hover(

	function(){

		$(this).css("background-position","left -113px");

	},

	function(){ 

		$(this).css("background-position","top left");

	});







	/*---------------------------------------------------

	Home

	---------------------------------------------------*/

	var gotime = new Array(1,1);



		$("#content.home .safe .holder").hover(

		function(){ 



				$(this).animate({marginLeft: 0}, "medium");



		},

		function(){ 



				$(this).animate({marginLeft: "-260px"}, "medium");



		});	



		





	

});









function opentab(id) {

	if(document.getElementById("ul" + id).style.display == "block") {

		document.getElementById("ul" + id).style.display="none";

		document.getElementById("img" + id).src="/wp-content/themes/_basic/i/expand.jpg";

	} else {

		document.getElementById("ul" + id).style.display="block";

		document.getElementById("img" + id).src="/wp-content/themes/_basic/i/collapse.jpg";

	}

	

}