/************************/
/* Some of my functions */
/************************/
function showPrevious() {
	if (boxCurrent > 0) {
		$('#box'+boxCurrent).addClass('hidden');
		boxCurrent--;
		$('#box'+boxCurrent).removeClass('hidden');
	}
	else {
		$('#box0').addClass('hidden');
		boxCurrent = boxMax;
		$('#box'+boxCurrent).removeClass('hidden');
	}
}
function showNext() {
	if (boxCurrent < boxMax) { 
		$('#box'+boxCurrent).addClass('hidden');
		boxCurrent++;
		$('#box'+boxCurrent).removeClass('hidden');
	}
	else {
		$('#box'+boxMax).addClass('hidden');
		boxCurrent = 0;
		$('#box'+boxCurrent).removeClass('hidden');
	}
}
			
function showTooltip(id) {
	$('#'+id).fadeIn('fast');
}
function hideTooltip(id) {
	$('#'+id).fadeOut('fast');
}

/*****************************/
/* Content loading functions */
/*****************************/
$(document).ready(function () {
	generateProjects();
	$.history.init(pageload);
	$('a[href=' + window.location.hash + ']').addClass('selected');
	$('a[rel=ajax]').click(function () {
		var hash = this.href;
		hash = hash.replace(/^.*#/, '');
		$.history.load(hash);

		$('a[rel=ajax]').removeClass('selected');
		$(this).addClass('selected');
		$('#content').hide();
		getPage();

		return false;
	});
});
function pageload(hash) {
	if (hash) getPage();
}
function getPage() {
	var pageName = encodeURIComponent(document.location.hash);
	var cleanPageName = pageName.replace('%23', '');

	$.ajax({url: "loader.php", type: "GET", data: "page="+pageLanguage+pageName, cache: false,
		success: function (html) {
			setBookmark(cleanPageName);
			if (cleanPageName == "projects") {
				hideProjects();
			}
			$('#content').html(html);
			$('#content').fadeIn('slow');
		}
	});
}

/***********************/
/* phpjs.org functions */
/***********************/
function rand (min, max) {
	// Returns a random number  
	// 
	// version: 909.322
	// discuss at: http://phpjs.org/functions/rand
	// +   original by: Leslie Hoare
	// +   bugfixed by: Onno Marsman
	// %		  note 1: See the commented out code below for a version which will work with our experimental (though probably unnecessary) srand() function)
	// *	 example 1: rand(1, 1);
	// *	 returns 1: 1

	var argc = arguments.length;
	if (argc === 0) {
		min = 0;
		max = 2147483647;
	} else if (argc === 1) {
		throw new Error('Warning: rand() expects exactly 2 parameters, 1 given');
	}
	return Math.floor(Math.random() * (max - min + 1)) + min;
}
function in_array (needle, haystack, argStrict) {
	// Checks if the given value exists in the array  
	// 
	// version: 911.718
	// discuss at: http://phpjs.org/functions/in_array
	// +   original by: Kevin van Zonneveld (http://kevin.vanzonneveld.net)
	// +   improved by: vlado houba
	// +   input by: Billy
	// +   bugfixed by: Brett Zamir (http://brett-zamir.me)
	// *	 example 1: in_array('van', ['Kevin', 'van', 'Zonneveld']);
	// *	 returns 1: true
	// *	 example 2: in_array('vlado', {0: 'Kevin', vlado: 'van', 1: 'Zonneveld'});
	// *	 returns 2: false
	// *	 example 3: in_array(1, ['1', '2', '3']);
	// *	 returns 3: true
	// *	 example 3: in_array(1, ['1', '2', '3'], false);
	// *	 returns 3: true
	// *	 example 4: in_array(1, ['1', '2', '3'], true);
	// *	 returns 4: false
	var key = '', strict = !!argStrict;

	if (strict) {
		for (key in haystack) {
			if (haystack[key] === needle) {
				return true;
			}
		}
	} else {
		for (key in haystack) {
			if (haystack[key] == needle) {
				return true;
			}
		}
	}
	return false;
}