$(function(){
	// Fetch the elements
	var	$content = $('.tabs'),
		$default = $('#home');
	// Fetch specific list
	var tabNames = ['home', 'virus', 'webdesign', 'software', 'hardware', 'spam', 'netwerk', 'randapparatuur', 'prijzen'];
	// Get the tabs
	var $tabs = $content.children();
	// Hide all our tabs initially
	$tabs.hide();
	// Define our update menu function - as this is used a lot
	var updateMenu = function(state){
		// Update out tab menu
		$('.tabNavigation li').removeClass('sel');
		$('a[href=#'+state+']').parent().addClass('sel');
	};
	// Show the default tab
	$default.show();
	updateMenu('/home'); 
	// Bind a handler for ALL hash/state changes
	$.History.bind(function(state){
		// Update the current element to indicate which state we are now on
		//$current.text('Our current state is: ['+state+']');
		if(state == ''){
			$default.show();
			updateMenu('/home');
		}
		if(state != '/vragen'){
			$('#contact').show();	
		}
		if(state != '/error'){
			$('#error').empty();
		}
	});
	// Only react on hashchanges where hash = tabNames[x]
	$.each(tabNames, function(index, value){
		$.History.bind('/'+value, function(state){
			// Update Menu
			updateMenu(state);
			// Show apricots tab, hide the other tabs
			$tabs.hide();
			$('#'+value).stop(true,true).fadeIn(200);	
		});	
	});
	// `vragen` 
	$.History.bind('/vragen', function(state){
		// Update Menu
		updateMenu(state);
		// Show apricots tab, hide the other tabs
		$tabs.hide();
		$('#vragen').stop(true,true).fadeIn(200);	
		$('#contact').hide();
	});
	$.History.bind('/error', function(state){
		$('#container').prepend('<div id="error"><p>Sorry, deze pagina is niet meer beschikbaar. Dit kan komen doordat de gehele website net vernieuwd is.</p></div>');
	});
	// fix internet explorer because it doesn't cares about the w3c standards...
	if($.browser.msie && $.browser.version < 8){
		$('#left ul').css({'list-style-image' : 'none', 'list-style-position' : 'outside', 'list-style-type' : 'none', 'text-indent' : '20px'});
		if($.browser.version.substr(0,1) == 7){
			$('#left li').prepend('<img src="http://localhost/gooisev2/img/icons/vink.png" />');
			$('.tabNavigation img').css('margin-right', '5px');
		}
	}
});
