var rotatingImages       = new Array();
var ndxCurrentBackground = -1;

function startFade()
{
  // store each image in the array
  rotatingImages[0] = '/images/gallery/gallery_Lipfinity3D_zoom.jpg';
  //rotatingImages[1] = '/images/gallery/gallery_colorGeniusBronzer_zoom.jpg';
  //rotatingImages[2] = '/images/gallery/gallery_colorGeniusBlush_zoom.jpg';
  //rotatingImages[3] = '/images/gallery/gallery-vividImpactLip_zoom.jpg';
  //rotatingImages[4] = '/images/gallery/';

  setTimeout("delayDisplay()", 8000); 
}


function delayDisplay()
{
  // fade current image out
  jQuery('#backgroundImage').fadeTo(2000,0,function()
                                           {
                                             // set new image in and fade it in
                                             ndxCurrentBackground++;
                                             if (ndxCurrentBackground == rotatingImages.length)
                                               ndxCurrentBackground = 0;

                                             jQuery('#backgroundImage').attr({src: rotatingImages[ndxCurrentBackground]});
                                             setTimeout("jQuery('#backgroundImage').fadeTo(2000, 0.3)", 100);

                                             // call delayDisplay every 20 seconds
                                             setTimeout("delayDisplay()", 20000);
                                           });
}


function goToGallery()
{
  if (ndxCurrentBackground == -1)
    jQuery('#backgroundImage').css({opacity:0.0}).attr({src: rotatingImages[0]});

  jQuery('#backgroundImage')  .fadeTo("normal", 1.0);
  jQuery("#header")           .fadeTo("fast", 0.0);
  jQuery("#carouselPanes")    .fadeTo("fast", 0.0);
  jQuery("#leftCallouts")     .fadeTo("fast", 0.0);
  jQuery("#rightCallouts")    .fadeTo("fast", 0.0);
  jQuery("#sliderPagination") .fadeTo("fast", 0.0);
  jQuery("#contentPanes")     .fadeTo("fast", 0.0);
  jQuery("#ratings")          .fadeTo("fast", 0.0);
  jQuery("#footer")           .fadeTo("fast", 0.0);

  setTimeout ("goToGalleryComplete()", 333);
}

function goToGalleryComplete()
{
  if (ndxCurrentBackground == -1)
    ndxCurrentBackground = 0;
  jQuery("#galleryField").val(ndxCurrentBackground);
  document.galleryForm.submit();
}
