As2 Horizontal Gallery - Headache

Hi all I’m developing a horizontal scrolling loop gallery which currently works using button controls.

However what i’m stuck on is i would like it to scroll through the images with a delay by its self. i can’t find any help for this on the net and it’s driving me mad.

I also would like to keep the current controls as its good for usability and looks cool.

heres the code:


[LEFT][COLOR=#0066cc]import[/COLOR] mx.[COLOR=#006600]transitions[/COLOR].[COLOR=#006600]Tween[/COLOR];
[COLOR=#0066cc]import[/COLOR] mx.[COLOR=#006600]transitions[/COLOR].[COLOR=#006600]easing[/COLOR].[COLOR=#006600]Strong[/COLOR];
[COLOR=#808080]*// index in theItems of the currently viewed image *[/COLOR]
[COLOR=#000000]**var**[/COLOR] curIndex = [COLOR=#cc66cc]0[/COLOR];
[COLOR=#808080]*// boolean to track if the container is moving forward (left) or backward (right) *[/COLOR]
[COLOR=#000000]**var**[/COLOR] movingForward:[COLOR=#0066cc]Boolean[/COLOR] = [COLOR=#000000]**false**[/COLOR];[COLOR=#808080]*// an array of the itmes (images) in the container *[/COLOR]
[COLOR=#000000]**var**[/COLOR] theItems = [COLOR=#66cc66][[/COLOR]container.[COLOR=#006600]item1[/COLOR], container.[COLOR=#006600]item2[/COLOR], container.[COLOR=#006600]item3[/COLOR], container.[COLOR=#006600]item4[/COLOR], container.[COLOR=#006600]item5[/COLOR], container.[COLOR=#006600]item6[/COLOR][COLOR=#66cc66]][/COLOR];
[COLOR=#808080]*// add listeners to the next/prev buttons  *[/COLOR]
nextBtn.[COLOR=#0066cc]onRelease[/COLOR] = showNext;
prevBtn.[COLOR=#0066cc]onRelease[/COLOR] = showPrev;
[COLOR=#808080]*// stores direction, replaces items, updates current index and tells the container where to move *[/COLOR]
[COLOR=#000000]**function**[/COLOR] showNext[COLOR=#66cc66]([/COLOR][COLOR=#66cc66])[/COLOR]:[COLOR=#0066cc]Void[/COLOR] [COLOR=#66cc66]{[/COLOR]
   movingForward = [COLOR=#000000]**true**[/COLOR];
   placeItemsForLooping[COLOR=#66cc66]([/COLOR]getNextIndex[COLOR=#66cc66]([/COLOR][COLOR=#66cc66])[/COLOR][COLOR=#66cc66])[/COLOR];
   [COLOR=#808080]*// look an item ahead and make sure its in the right position     *[/COLOR]
   curIndex = getNextIndex[COLOR=#66cc66]([/COLOR][COLOR=#66cc66])[/COLOR];
   showItem[COLOR=#66cc66]([/COLOR]curIndex[COLOR=#66cc66])[/COLOR];
[COLOR=#66cc66]}[/COLOR]
[COLOR=#808080]*// stores direction, replaces items, updates current index and tells the container where to move *[/COLOR]
[COLOR=#000000]**function**[/COLOR] showPrev[COLOR=#66cc66]([/COLOR][COLOR=#66cc66])[/COLOR]:[COLOR=#0066cc]Void[/COLOR] [COLOR=#66cc66]{[/COLOR]
   movingForward = [COLOR=#000000]**false**[/COLOR];
   placeItemsForLooping[COLOR=#66cc66]([/COLOR]getPrevIndex[COLOR=#66cc66]([/COLOR][COLOR=#66cc66])[/COLOR][COLOR=#66cc66])[/COLOR];[COLOR=#808080]*// look an item ahead and make sure its in the right position     *[/COLOR]
   curIndex = getPrevIndex[COLOR=#66cc66]([/COLOR][COLOR=#66cc66])[/COLOR];
   showItem[COLOR=#66cc66]([/COLOR]curIndex[COLOR=#66cc66])[/COLOR];
[COLOR=#66cc66]}[/COLOR]
[COLOR=#808080]*// figures out the distance that the container needs to move to align the desired item under the mask and tweens it *[/COLOR]
[COLOR=#000000]**function**[/COLOR] showItem[COLOR=#66cc66]([/COLOR]itemIndex:[COLOR=#0066cc]Number[/COLOR][COLOR=#66cc66])[/COLOR]:[COLOR=#0066cc]Void[/COLOR] [COLOR=#66cc66]{[/COLOR]
   [COLOR=#000000]**var**[/COLOR] showMe:[COLOR=#0066cc]MovieClip[/COLOR] = theItems[COLOR=#66cc66][[/COLOR]itemIndex[COLOR=#66cc66]][/COLOR];
   [COLOR=#000000]**var**[/COLOR] showMeBounds:[COLOR=#0066cc]Object[/COLOR] = showMe.[COLOR=#0066cc]getBounds[/COLOR][COLOR=#66cc66]([/COLOR][COLOR=#0066cc]_root[/COLOR][COLOR=#66cc66])[/COLOR];
   [COLOR=#000000]**var**[/COLOR] maskBounds:[COLOR=#0066cc]Object[/COLOR] = theMask.[COLOR=#0066cc]getBounds[/COLOR][COLOR=#66cc66]([/COLOR][COLOR=#0066cc]_root[/COLOR][COLOR=#66cc66])[/COLOR];
   [COLOR=#000000]**var**[/COLOR] xDiff:[COLOR=#0066cc]Number[/COLOR] = showMeBounds.[COLOR=#006600]xMin[/COLOR] - maskBounds.[COLOR=#006600]xMin[/COLOR] - [COLOR=#66cc66]([/COLOR]theMask.[COLOR=#0066cc]_width[/COLOR] - showMe.[COLOR=#0066cc]_width[/COLOR][COLOR=#66cc66])[/COLOR] / [COLOR=#cc66cc]536[/COLOR];
   [COLOR=#000000]**new**[/COLOR] Tween[COLOR=#66cc66]([/COLOR]container, [COLOR=#ff0000]'_x'[/COLOR], Strong.[COLOR=#006600]easeOut[/COLOR], container.[COLOR=#0066cc]_x[/COLOR], container.[COLOR=#0066cc]_x[/COLOR] - xDiff, [COLOR=#cc66cc]2[/COLOR], [COLOR=#000000]**true**[/COLOR][COLOR=#66cc66])[/COLOR];
[COLOR=#66cc66]}[/COLOR]
[COLOR=#808080]*// inspects position of desired item, and determines if it should be moved based on the current direction *[/COLOR]
[COLOR=#000000]**function**[/COLOR] placeItemsForLooping[COLOR=#66cc66]([/COLOR]itemIndex:[COLOR=#0066cc]Number[/COLOR][COLOR=#66cc66])[/COLOR]:[COLOR=#0066cc]Void[/COLOR] [COLOR=#66cc66]{[/COLOR]
   [COLOR=#000000]**var**[/COLOR] nextItem:[COLOR=#0066cc]MovieClip[/COLOR] = theItems[COLOR=#66cc66][[/COLOR]itemIndex[COLOR=#66cc66]][/COLOR];
   [COLOR=#000000]**var**[/COLOR] nextBounds:[COLOR=#0066cc]Object[/COLOR] = nextItem.[COLOR=#0066cc]getBounds[/COLOR][COLOR=#66cc66]([/COLOR]theMask[COLOR=#66cc66])[/COLOR];
   [COLOR=#000000]**var**[/COLOR] containerBounds:[COLOR=#0066cc]Object[/COLOR] = container.[COLOR=#0066cc]getBounds[/COLOR][COLOR=#66cc66]([/COLOR]container[COLOR=#66cc66])[/COLOR];
   [COLOR=#b1b100]if[/COLOR] [COLOR=#66cc66]([/COLOR]movingForward[COLOR=#66cc66])[/COLOR] [COLOR=#66cc66]{[/COLOR]
       [COLOR=#b1b100]if[/COLOR] [COLOR=#66cc66]([/COLOR]nextBounds.[COLOR=#006600]xMin[/COLOR] < [COLOR=#cc66cc]0[/COLOR][COLOR=#66cc66])[/COLOR] [COLOR=#66cc66]{[/COLOR]
           nextItem.[COLOR=#0066cc]_x[/COLOR] = containerBounds.[COLOR=#006600]xMax[/COLOR];
       [COLOR=#66cc66]}[/COLOR]
   [COLOR=#66cc66]}[/COLOR] [COLOR=#b1b100]else[/COLOR] [COLOR=#66cc66]{[/COLOR]
       [COLOR=#b1b100]if[/COLOR] [COLOR=#66cc66]([/COLOR]nextBounds.[COLOR=#006600]xMin[/COLOR] > [COLOR=#cc66cc]0[/COLOR][COLOR=#66cc66])[/COLOR] [COLOR=#66cc66]{[/COLOR]
           nextItem.[COLOR=#0066cc]_x[/COLOR] = containerBounds.[COLOR=#006600]xMin[/COLOR] - nextItem.[COLOR=#0066cc]_width[/COLOR];
       [COLOR=#66cc66]}[/COLOR]
   [COLOR=#66cc66]}[/COLOR]
[COLOR=#66cc66]}[/COLOR]
[COLOR=#808080]*// the index of the item ahead of the currently viewed item *[/COLOR]
[COLOR=#000000]**function**[/COLOR] getNextIndex[COLOR=#66cc66]([/COLOR][COLOR=#66cc66])[/COLOR]:[COLOR=#0066cc]Number[/COLOR] [COLOR=#66cc66]{[/COLOR]
   [COLOR=#b1b100]return[/COLOR] [COLOR=#66cc66]([/COLOR]curIndex < theItems.[COLOR=#0066cc]length[/COLOR] - [COLOR=#cc66cc]1[/COLOR][COLOR=#66cc66])[/COLOR] ? curIndex + [COLOR=#cc66cc]1[/COLOR] : [COLOR=#cc66cc]0[/COLOR];
[COLOR=#66cc66]}[/COLOR]
[COLOR=#808080]*// the index of the item behind of the currently viewed item *[/COLOR]
[COLOR=#000000]**function**[/COLOR] getPrevIndex[COLOR=#66cc66]([/COLOR][COLOR=#66cc66])[/COLOR]:[COLOR=#0066cc]Number[/COLOR] [COLOR=#66cc66]{[/COLOR]
   [COLOR=#b1b100]return[/COLOR] [COLOR=#66cc66]([/COLOR]curIndex > [COLOR=#cc66cc]0[/COLOR][COLOR=#66cc66])[/COLOR] ? curIndex - [COLOR=#cc66cc]1[/COLOR] : theItems.[COLOR=#0066cc]length[/COLOR] - [COLOR=#cc66cc]1[/COLOR];
[COLOR=#66cc66]}[/COLOR][/LEFT]
 

I anyone can help with this i will be eternally grateful.