var at = 1;
var newTab = 0;
var slidingTimer = null; 
var click = false;

function init()
{
	$('a.mlnk').each( function( idx, curr )
		{
		p = $(curr).parent().parent().parent().parent().parent();
		p.click( function() { window.location = curr.href; } );
		p.addClass( 'pntr' );
		}
	);
	h1 = $('#tlp').height();
	h2 = $('#trp').height();
	if( h1 > h2 )
		$('#trp .ls').css('height', (h1-10) );
	else
		$('#tlp .cp').css('height', (h2-20) );
	$('.tbs').click( function()
		{
		if( slidingTimer )
			{
			clearTimeout( slidingTimer );
			slidingTimer = null;
			}
		id = $(this).attr('id').substr(1);
		newTab = id;
		cs = $('#slide_'+id);
		ts = $('#sl_txt_'+id);
		cs.parent().prepend( '<div class="slide ac">'+cs.html()+'</div>' );
		ts.parent().prepend( '<div class="sl_txt ac">'+ts.html()+'</div>' );
		$('#slides_txt .ac').fadeIn();
		$('#slides_img .ac').fadeIn('normal', function() 
			{
			for( i=1; i<=4; i++ )
				if( newTab != i )
					{
					$('#slide_'+i).addClass('nd');
					$('#sl_txt_'+i).addClass('nd');
					}
				else
					{
					$('#sl_txt_'+i).removeClass('nd');
					$('#slide_'+i).removeClass('nd');
					}
			$('#slides_img .ac').remove();
			$('#slides_txt .ac').remove();
			}
		);
		$('.tbs').removeClass('a');
		$(this).addClass('a');
		click = true;
		}
	);

	slidingTimer = setTimeout( 'slideIt()', 5000 );
}

function slideIt()
{
	if( click )
		return;
	tgt = newTab?Math.floor(newTab)+1:2;
	if( tgt > 4 )
		tgt = 1;


		id = tgt;
		newTab = id;
		cs = $('#slide_'+id);
		ts = $('#sl_txt_'+id);
		cs.parent().prepend( '<div class="slide ac">'+cs.html()+'</div>' );
		$('#slides_img .ac').fadeIn('normal', function() 
			{
			for( i=1; i<=4; i++ )
				if( newTab != i )
					$('#slide_'+i).addClass('nd');
				else
					$('#slide_'+i).removeClass('nd');
			$('#slides_img .ac').remove();
			}
		);


	setTimeout( 'slideIt()', 5000 );
}

