	var secs=1;
	var timerID = null;
	var timerRunning = false;
	var currentBG= 0;
	var delay = 1000;
	var future=0;
$(document).ready(function() {

	$("#brands").hover(function(){
			$('#brands a').css('color','red') ;
			$('#brands ').css('background','#F6F6F6') ;
			$('#brandsCanvas').show();
		},function(){
			$('#brands a').css('color','#FFF') ;
			$('#brands ').css('background','transparent') ;
			$('#brandsCanvas').hide();
	});
	

	InitializeTimer();
});

function InitializeTimer()
{

   	// Set the length of the timer, in seconds
    secs = 5;

    StopTheClock();
    StartTheTimer();
}

function StopTheClock()
{
	
    if(timerRunning){
		
		clearTimeout(timerID);
	}
	
    timerRunning = false;
   
}
function StartTheTimer()
{
	
	
    if (secs==0)
    {
    	
       StopTheClock();
        // Here's where you put something useful that's
        // supposed to happen after the allotted time.
        // For example, you could display a message:
        swapBackgrounds();
        secs = 5;
        timerID = self.setTimeout("StartTheTimer()", delay);
    }
    else
    {
    	
        self.status = secs;
        secs = secs - 1;
        timerRunning = true;
        timerID = self.setTimeout("StartTheTimer()", delay);
    }
}

function swapBackgrounds(){
	$('#bg_'+currentBG).fadeOut('slow');

	 future = currentBG+1;
	 
	
	if(future >= total_number_bgs){
		future = 0;
	}
	$('#bg_'+future).fadeIn('slow', blah).addClass('activebg').removeClass('hiddenbg');
	
	
}

function blah(){
	currentBG = future ;
	$('#hid').html(total_number_bgs);
}


function popup() {
	window.open('http://mittens.mgpepe.com/home/home.php','mittens','width=550,height=400,toolbar=no,resizable=yes,status=no,menubar=no,copyhistory=no,directories=no,location=no,scrollbars=1');
}

function setstyle() {
	if(window.name == 'mittens') {
		document.getElementById('body').className = 'popup';
	}
}

function timeCountProjects(projects){
		for(var i in projects){
			time = projects[i]
			var h= Math.floor(time/3600)
			var m= Math.floor((time%3600)/60)
			var s= Math.floor(time%60)
			div = "project"+i
			document.getElementById(div).innerHTML=h+":"+m+":"+s
			projects[i]++
		}
			t=setTimeout('timeCountProjects(projects)',1000)
}

function timeCountClients(clients){
		for(var i in clients){
			time = clients[i]
			var h= Math.floor(time/3600)
			var m= Math.floor((time%3600)/60)
			var s= Math.floor(time%60)
			div = "client"+i
			document.getElementById(div).innerHTML=h+":"+m+":"+s
			clients[i]++
		}
			t=setTimeout('timeCountClients(clients)',1000)
}
function timeCount(){
	var o = $(".task");
	o.each(function(){
		var time =($(this).attr('currtime'));
		if($(this).hasClass('active'))
			time++;	
		$(this).attr('currtime',time);
		var h= Math.floor(time/3600);
		var m= Math.floor((time%3600)/60);
			if(m<10) m="0"+m;
		var s= Math.floor(time%60);
			if(s<10) s="0"+s;

		$(this).text(h+":"+m+":"+s);
	});
	timerId = setTimeout('timeCount()', 1000)
}

function startTask(task_id){
	var o = $('#click_'+task_id);
	$.post('/starttask', {tid: task_id}, function(data){
		//alert("Data Loaded: " + data);
		$('#time_'+task_id).addClass('active');
		$('#start_'+task_id).hide();
		$('#stop_'+task_id).show();
	});

}	

function stopTask(task_id){
	var o = $('#click_'+task_id);
	$.post('/stoptask', {tid: task_id}, function(data){
		//alert("Data Loaded: " + data);
		$('#time_'+task_id).attr('currtime',data);
		$('#time_'+task_id).removeClass('active');
		$('#start_'+task_id).show();
		$('#stop_'+task_id).hide();
	});

}	


function complete(task_id, status){
	if (status == 0 )status =1;
	else status =0;
	$.post('/complete', {tid: task_id, complete: status}, function(data){
		//alert("Data Loaded: " + data);
		$('#time_'+task_id).attr('currtime',data);
		$('#time_'+task_id).removeClass('active');
		$('#start_'+task_id).show();
		$('#stop_'+task_id).hide();
		$('#time_'+task_id).css('border','1px solid red');
	});
}
      
       
       
       
       