var $j = jQuery.noConflict();
var counter = 1;
var timer;

function changeEntry(n) {
	var duration = 600;
	
	$j('#titleClone').html($j('#titleBanHome').html());
	$j('#titleBanHome').html(data[n]['title']);
	if (!$j.browser.msie) {
		$j('#titleClone').hide('drop', {direction: 'right'}, duration);
		$j('#titleBanHome').show('drop', {direction: 'right'}, duration);
	}
	
	$j('#subTitleBanHome').hide('fade', {}, (duration / 2), function() {
		$j('#subTitleBanHome').html(data[n]['subtitle']).show('fade', {}, (duration / 2));
	});
	$j('#txtBanHome').hide('fade', {}, (duration / 2), function() {
		$j('#txtBanHome').html(data[n]['text']).show('fade', {}, (duration / 2));
	});

	$j('#imgBanHome').html('<img src="/_includes/framer.php?base=' + data[n]['image'] + '&mask=225x155" width="225" height="155">').effect('slide', {direction: 'left'}, duration);
	
	$j('#bannerInner').attr('href', data[n]['link']);
	
	selectedPage(n);
}

function selectedPage(n) {
	$j('#m1,#m2,#m3,#m4').removeClass('selected');
	$j('#m' + n).addClass('selected');
}

function autoChange() {
	counter++;
	if (counter > 4) counter = 1;
	changeEntry(counter);
}

$j(function() {
	timer = setInterval('autoChange()', 5000);
	$j('#m1,#m2,#m3,#m4').click(function() {
		changeEntry($j(this).html());
		clearTimeout(timer);
	});
	$j('#mPrev').click(function() {
		counter--;
		if (counter < 1) counter = 4;
		changeEntry(counter);
		clearTimeout(timer);
	});
	$j('#mNext').click(function() {
		counter++;
		if (counter > 4) counter = 1;
		changeEntry(counter);
		clearTimeout(timer);
	});
});

