/* 
*	Our custom jquery area on the home page.
*	
*	Written by Mindutopia
*
*/
var c = 0; // start at 0
var t;
var timer_is_on = 0;

/*
 *	
 *	
 *
 */

function slideTimer(){
	//set the time out variable
	t = setTimeout("slideTimer()", 6000);
	
	if(c == 4){
		c = 0;
	}
	$('.ui-accordion').accordion('activate', c);
	
	c = c + 1;  //position
	temp = '#'+String(c);
	activateImage($(temp).attr('title'));
}


function startTimer(){
	if(!timer_is_on){
		timer_is_on = 1;
		slideTimer();
	}
}

function resetCount(){
	clearTimeout(t);
	timer_is_on=0;
	
}

function activateImage( imageId ){
	$('.active-img').addClass('hidden-img').removeClass('active-img');
	$(imageId).removeClass('hidden-img').fadeIn(800).addClass('active-img');
	$('.hidden-img').fadeOut();
}

$(document).ready(function(){
	$('.hidden-img').hide();
	$('#accord').accordion({
		selectedClass: 'heavy',
		autoHeight: false
	}).bind("change.ui-accordion", function(event, ui) {
		Cufon.refresh();
	});
	
	
	$('div#accord a.section').click(function(){
		
		//change the image in here.
		img = $(this).attr('title');
		activateImage(img);
		c = parseInt($(this).attr('id')) - 1;
		resetCount(c);
		startTimer();

	});
	
	startTimer();
	
});
