jQuery(
	function( $ )
	{
		$.scrollTo.defaults.axis = 'x';

		//this one is important, many browsers don't reset scroll on refreshes
		$('.tab-container').scrollTo( 0 );//reset all scrollable panes to (0,0)
		$.scrollTo( 0 );//reset the screen to (0,0)

		//Target examples bindings
		var $group1 = $('#tab-group-1');
		var $group2 = $('#tab-group-2');

		$( '#home_tab_0' ).click( function(){ $group1.stop().scrollTo( 'li:eq(0)', 500 ); } );
		$( '#home_tab_1' ).click( function(){ $group1.stop().scrollTo( 'li:eq(1)', 500 ); } );
		$( '#home_tab_2' ).click( function(){ $group1.stop().scrollTo( 'li:eq(2)', 500 ); } );

		$( '#home_tab_3' ).click( function(){ $group2.stop().scrollTo( 'li:eq(0)', 500 ); } );
		$( '#home_tab_4' ).click( function(){ $group2.stop().scrollTo( 'li:eq(1)', 500 ); } );
		$( '#home_tab_5' ).click( function(){ $group2.stop().scrollTo( 'li:eq(2)', 500 ); } );

	}
);

$( document ).ready(
		function()
		{
			var myURL = document.location.toString();

			if( myURL.match( '#' ) )
			{
				var myAnchor 	= myURL.split( '#' )[ 1 ];
				var id 			= myAnchor.replace( 'tab_id_', '' );

				/* Remove all Classes */
				$( 'a.group-1' ).removeClass( 'tab-anchor-on' );
				$( 'a.group-1' ).removeClass( 'tab-anchor-off');
				$( 'a.group-2' ).removeClass( 'tab-anchor-on' );
				$( 'a.group-2' ).removeClass( 'tab-anchor-off');
				
				/* Default all tabs to off */
				$( 'a.group-1' ).addClass( 'tab-anchor-off'	);
				$( 'a.group-2' ).addClass( 'tab-anchor-off'	);

				/* Set Correct tab to on */
				$( 'a#home_tab_' + id ).removeClass( 'tab-anchor-off' );
				$( 'a#home_tab_' + id ).addClass( 'tab-anchor-on' );

				if( id < 3 )
				{
					/* Set Correct Current Tab Class */
					$( 'a#home_tab_3' ).removeClass( 'tab-anchor-off' );
					$( 'a#home_tab_3' ).addClass( 'tab-anchor-on' );

					/* Scroll to Default tabs */
					$( '#tab-group-1' ).stop().scrollTo( 'li:eq(' + id + ')', 400 );
					$( '#tab-group-2' ).stop().scrollTo( 'li:eq(0)', 400 );
				}
				else
				{
					/* Set Correct Current Tab Class */
					$( 'a#home_tab_0' ).removeClass( 'tab-anchor-off' );
					$( 'a#home_tab_0' ).addClass( 'tab-anchor-on' );

					/* Scroll to Default tabs */
					$( '#tab-group-1' ).stop().scrollTo( 'li:eq(0)', 400 );
					$( '#tab-group-2' ).stop().scrollTo( 'li:eq(' + (id - 3) + ')', 400 );
				}
			}

			// When a link is clicked
			$("a.group-1").click(
				function()
				{
					$( '.group-1' ).removeClass( 'tab-anchor-on' );
					$( '.group-1' ).removeClass( 'tab-anchor-off');

					$( this ).addClass( 'tab-anchor-on' );
					
					$( '.group-1' ).each(
						function()
						{
							if( !$( this ).is( '.tab-anchor-on' ) )
							{
								$( this ).addClass( 'tab-anchor-off');
							}
						}
					);

				}
			);

			// When a link is clicked
			$("a.group-2").click(
				function()
				{
					$( '.group-2' ).removeClass( 'tab-anchor-on' );
					$( '.group-2' ).removeClass( 'tab-anchor-off');

					$( this ).addClass( 'tab-anchor-on' );
					
					$( '.group-2' ).each(
						function()
						{
							if( !$( this ).is( '.tab-anchor-on' ) )
							{
								$( this ).addClass( 'tab-anchor-off');
							}
						}
					);

				}
			);

			$( '#img-logo' ).click(
				function()
				{
					window.location.href = '/';
				}
			);

			$( '#img-logo' ).mouseover(
				function()
				{
					$(this).css( 'cursor', 'pointer' );
				}
			);

			$( '#img-logo' ).mouseout(
				function()
				{
					$(this).css( 'cursor', 'default' );
				}
			);

		}
);