$('document').ready(function(){

	/**
	* Start xb-tabs
	* 18.1.2010 PV
	*/


	// Hide all tabs by default and remove all active-classes
	$('div.xb-tabs').hide();
	$('a.xb-tabs-a').removeClass('active');


	// When xb-tab link is clicked
	$('a.xb-tabs-a').click(function(){
		href = $(this).attr('href');
		if ($(this).hasClass('active'))
			return false;
		// Hide all tabs
		$('div.xb-tabs').each(function(){
			if ($(this).css('display') != 'none') {
				$(this).fadeOut('fast', function(){
					// Show selected tab
					$('div#'+href).fadeIn('fast');
				});
			}
		});

		// Change active-class
		$('a.xb-tabs-a').removeClass('active');
		$(this).addClass('active');



		var location = window.location.toString();
		if (window.location.toString().indexOf("#")>-1) {
			location = window.location.toString().substr(0,window.location.toString().indexOf("#"));
		}

		var stateObj = { foo: "bar" };
		if (typeof(window.history.pushState) == 'function') {
	    	window.history.pushState(stateObj, "", location+"#"+$(this).attr('href'));

		} else {
	    	window.location = location+"#"+$(this).attr('href');

		}

	    return false;
	});


	// If hash is set during pageload
	if(window.location.hash!='') {
		tabSelect = document.location.hash.substr(1,document.location.hash.length);
		$('div#'+tabSelect).show();
		$('a.xb-tabs-a[href="'+tabSelect+'"]').addClass('active');
		window.scroll(0,0);
	}
	else {
		// If hash is not set, load the first xb-tab 
		$('div.xb-tabs:first').show();
		$('a.xb-tabs-a_first').addClass('active');
		$('a.xb-tabs-a:first').trigger('click');
	}

	/**
	* end xb-tabs
	*/



});
