//// JavaScript Document


//Simple jQuery Slideshow Script

//Released by Jon Raasch (jonraasch.com) under FreeBSD license: free to use or modify, not responsible for anything, etc. Please link out to me if you like it :)

var slideInterval = 0;
var running = false

//function slideSwitch(slideShowID) {
//    
//    var $active = $('#'+slideShowID+' DIV.active');
//    if ($active.length == 0) $active = $('#' + slideShowID + ' DIV:last');
//    // use this to pull the images in the order they appear in the markup
//    var $next = $active.next().length ? $active.next()
//             : $('#' + slideShowID + ' DIV:first');
//    // uncomment the 3 lines below to pull the images in random order
//    // var $sibs = $active.siblings();
//    // var rndNum = Math.floor(Math.random() * $sibs.length );
//    // var $next = $( $sibs[ rndNum ] );
//    $active.addClass('last-active');
//    $next.css({ opacity: 0.0, display: 'block' })
//             .addClass('active')
//             
//    //  .focusout(function () { $next.css({ opacity: 1.0 }); })
//    // .mouseleave({ $next.cssopacity: 1.0 })
//             .animate({ opacity: 1.0 }, 1000, function () {
//                 $active.removeClass('active last-active').css({ display: 'none' });
//             });
//             $next.hover(function () {
//                 $next.css({ opacity: 0.8 });
//                 // clearInterval(slideInterval);
//             }, function () {
//                 $next.css({ opacity: 1.0 });
//                 // slideInterval = setInterval("slideSwitch('" + slideShowID + "')", 4000);
//             })
//}


function slideSwitch(slideShowID, mouseOver) {

    var $active = $('#' + slideShowID + ' DIV.active');
    if ($active.length == 0) $active = $('#' + slideShowID + ' DIV:last');
    // use this to pull the images in the order they appear in the markup
    var $next = $active.next().length ? $active.next()
             : $('#' + slideShowID + ' DIV:first');
    // uncomment the 3 lines below to pull the images in random order
    // var $sibs = $active.siblings();
    // var rndNum = Math.floor(Math.random() * $sibs.length );
    // var $next = $( $sibs[ rndNum ] );
   
     if (mouseOver){
    
        $active.unbind('hover');
        $active.unbind('mouseover');
        $active.unbind('mouseout');
        $active.unbind('mouseenter');
        $active.unbind('mouseleave');

    }
   
    $active.addClass('last-active');
    $next.addClass('active');
    $next.css({ opacity: 0.0, display: 'block' });
             

    //  .focusout(function () { $next.css({ opacity: 1.0 }); })
    // .mouseleave({ $next.cssopacity: 1.0 })
    $next.animate({ opacity: 1.0 }, 1000, function () {
        $active.css({ display: 'none' });
        $active.removeClass('active last-active').css({ display: 'none' });
        if (mouseOver) {
            $next.hover(function () {
                $next.css({ opacity: 0.9 });
                // clearInterval(slideInterval);
            }, function () {
                $next.css({ opacity: 1.0 });
            });
        }

        // slideInterval = setInterval("slideSwitch('" + slideShowID + "')", 4000);
    })
}



//function loadSlideShow(slideShowID) {

//    $(function () {
//        setInterval("slideSwitch('"+slideShowID+"')", 5000);
//    });

function loadSlideShow(slideShowID, mouseOver) {

    slideInterval = setInterval("slideSwitch('" + slideShowID + "'," + mouseOver + ")", 4000);


   }


   function basicSlideShow(slideShowID, transitionTime) {

       var $active = $('#' + slideShowID + ' DIV.active');
       if ($active.length == 0) $active = $('#' + slideShowID + ' DIV:last');
       // use this to pull the images in the order they appear in the markup
       var $next = $active.next().length ? $active.next()
             : $('#' + slideShowID + ' DIV:first');
       // uncomment the 3 lines below to pull the images in random order
       // var $sibs = $active.siblings();
       // var rndNum = Math.floor(Math.random() * $sibs.length );
       // var $next = $( $sibs[ rndNum ] );
//       $active.unbind('hover');
//       $active.unbind('mouseover');
//       $active.unbind('mouseout');
//       $active.unbind('mouseenter');
//       $active.unbind('mouseleave');
//       //  $active.hover(function () { }, function () { })
       $active.addClass('last-active');
       $next.addClass('active');
       $next.css({ opacity: 0.0, display: 'block' });


       //  .focusout(function () { $next.css({ opacity: 1.0 }); })
       // .mouseleave({ $next.cssopacity: 1.0 })
       $next.animate({ opacity: 1.0 }, transitionTime * 1000, function () {
           $active.css({ display: 'none' });
           $active.removeClass('active last-active').css({ display: 'none' });
//           $next.hover(function () {
//               $next.css({ opacity: 0.9 });
//               // clearInterval(slideInterval);
//           }, function () {
//               $next.css({ opacity: 1.0 });
//           });

           // slideInterval = setInterval("slideSwitch('" + slideShowID + "')", 4000);
       })
   }



   //function loadSlideShow(slideShowID) {

   //    $(function () {
   //        setInterval("slideSwitch('"+slideShowID+"')", 5000);
   //    });

   function LoadBasicSlideShow(slideShowID, transitionTime) {

       slideInterval = setInterval("basicSlideShow('" + slideShowID + "','" + transitionTime + "')", 4000);


   }


   function randomImage(imgClassName, imgArray) {


       //get size of array, randomize a number from this
       // use this number as the array index

       var imageNamesSize = imgArray.length;

       var lotteryNumber = Math.floor(Math.random() * imageNamesSize);

       var winnerImage = imgArray[lotteryNumber];

       //document.getElementById('mens').src = winnerImage
//       $('#mens').attr({
//           src: winnerImage
//       });

       //     alert(winnerImage);	

       $('.' + imgClassName).attr({
           src: winnerImage,
           alt: winnerImage
       });


   }
