The SitePoint Forums have moved.

You can now find them here.
This forum is now closed to new posts, but you can browse existing content.
You can find out more information about the move and how to open a new account (if necessary) here.
If you get stuck you can get support by emailing forums@sitepoint.com

If this is your first visit, be sure to
check out the FAQ by clicking the
link above. You may have to register
before you can post: click the register link above to proceed. To start viewing messages,
select the forum that you want to visit from the selection below.

Need help calculating time

I'm trying to keep track of the time of a selected amount of videos. Here's my code:

(I used the php tag so for the color coding, but this is all javascript.

PHP Code:

//Get the current amount of seconds from what is already selected
var duration = document.getElementById('block_seconds').innerHTML;
//Now we add this to the passed seconds for the new video
duration = duration + add_duration;
//Calculate the minutes by dividing the seconds by 60
var minutes = duration / 60;
//Now change the division result to an integer
minutes = parseInt(minutes);
//Now set the seconds to what remains
var seconds = duration - (minutes * 60);
//Do the same thing for the hours using the minutes
var hours = minutes / 60;
//Adjust the hours to an integer
hours = parseInt(hours);
//set the minutes to whatever is left over
$minutes = minutes - (hours * 60);
//create our time variable
var time = "";
//If the seconds variable is only one digit we put a zero in front for formating
if(seconds.length == 1)
seconds = "0"+seconds;
//Do the same thing with the minutes
if(minutes.length == 1)
minutes = "0".minutes;
//If hours is not blank or zero set the time to the hours
if(hours != '' && hours > 0)
time = hours+":";
//Now add the minutes and seconds to the time to create a format of 0:00:00
time = time+minutes+":"+seconds;
//Display the duration and update the hidden value storing our total seconds.
document.getElementById('block_duration').innerHTML = time;
document.getElementById('block_seconds').innerHTML = duration;

Something must be wrong though as it works the first time, but when i add a second video the numbers increase an incredible amount, like it goes from 2 minutes to 234232 minutes.