/* ls.js
 *
 * Custom controls for Mike Alsup's jQuery Cycle Plugin
 *
 * Written by Jeff Parker - jeffreyp(at)codero.com
 *
 * Props to the jQuery community for guidance and support
 *
 * $Id: ls.js 2706 2010-02-03 14:05:01Z codero $
 */
    
$(document).ready(function()
{
     startCycle();

    //initial state of cycle
    function startCycle()
    {
        $('#loopedSlider .container').cycle(
            {
                fx:          'fade',
                easing:      'easeInOutQuad',
                timeout:      8000,
                speed:        800,
                next:         '#n',
                prev:         '#p',
                before:        getID,
                cleartypeNoBg: true
            }
            );
    }

    //to be executed after each slide transitions during normal cycle
    function getID()
    {
        var k = $(this).attr('id');
        paginate(k);
    }

    //sets buttons to different states to indicate active slide
    function paginate(l)
    {
        $('.pagination > li').children('a').removeClass('active');
        $('li.'+l).children('a').addClass('active');
    }

    //when pagination item is clicked, pause cycle and activate correct tab
    function switchAndPause(k, m)
    {
        //k = class of clicked item
        //m = id of clicked item

         //whoa there, buddy
         $('#loopedSlider .container').cycle('pause');
         //switch classes for the clicked button
         paginate(k);
         m = parseInt(m);
         //Cycle resumes at the next slide, so we'll just go back one
         $('#loopedSlider .container').cycle(m-1);
         //and pause so it stops there
         $('#loopedSlider .container').cycle('pause');
         //wait and then keep on truckin'
         wait4it();
    }

    //sets a timeout to wait before beginning cycle again
    function wait4it()
    {
        setTimeout
        (
            function()
            {
                $('#loopedSlider .container').cycle('resume');
            },
            90000
        );
    }

//*************PAGINATION CONTROLS*************//
    $('.pagination > li').children('a').click(function(){
      
       var k = $(this).parent('li').attr("class");
       var m = this.id;
       switchAndPause(k, m);
       
    });

//*************NEXT AND PREV CONTROLS*************//
    $('#n').click(function(){

        $('#loopedSlider .container').cycle('pause');

        wait4it();

    });

    $('#p').click(function(){

        $('#loopedSlider .container').cycle('pause');

        wait4it();

    });

//preloader for active states of pagination
    jQuery.preloadImages = function()
    {
      for(var i = 0; i<arguments.length; i++)
      {
        jQuery("<img>").attr("src", arguments[i]);
      }
    }
    $.preloadImages("../images/design/banner-btn01-active.gif", "../images/design/banner-btn02-active.gif", "../images/design/banner-btn03-active.gif", "../images/design/banner-btn04-active.gif", "../images/design/banner-btn05-active.gif");
        });
