/* Author: Jesse Overton

*/





$(function() {
    
        
    $('.zoom').zoomy('mouseover'); 
    
   $('#mudtrailer .pics img').eq(0).addClass('active');
    
    
    $('#mudtrailer .slider').slider({
       
       orientation: 'vertical',
       value:75,
            min: 0,
            max: 75,
         
        
        
    });
    
    
    
    
    $('#mudtrailer .slider').bind('slide', function(event, ui) {
    
        var $pics = $(this).parent().find('.pics img');
        
               
        $pics.removeClass('active');
        
        var val = ui.value;
        
        if ( val >= 0 && val < 25 )
        {
            $pics.eq(3).addClass('active');
            
        }
        
        if ( val >= 25 && val < 50 )
        {
            $pics.eq(2).addClass('active');
            
        }
        
        if ( val >= 50 && val < 75 )
        {
            $pics.eq(1).addClass('active');
            
        }
        
        if ( val === 75 )
        {
            $pics.eq(0).addClass('active');
            
        }

          
    });
    
    
    
    
    
});



    
    

function slideShow() {

    var current = $('#car-anim img.show') ? $('#car-anim img.show') : $('#car-anim img:first');
    var next = current.next().length ? current.next() : $('#car-anim img:first'); 
    next.fadeTo(3000,1).addClass('show');
    current.fadeTo(3000,0).removeClass('show');


}

$(document).ready(function() {


    

    $('.rotating-item').width($('#splash').width());
    
        $('.rotating-item').each(function(i) { 
 
    });
    
    //$('#content-scroll').height($('.items div:first').height());
    
    $('#content-scroll').height(800);
    
    var imgsLoaded = 0;
    var firstTabImgs = $('#content-scroll .items div:first img');
    var firstTabImgSize = firstTabImgs.size();
    
    
    firstTabImgs.each(function(i) {
    
        
    
        
    
        $(this).load(function() { 
            
            imgsLoaded++;
            
            if (imgsLoaded === firstTabImgSize)
            {        
             $('#content-scroll').height($('#content-scroll .items div:first').height());
    
            }            
        });
   
    
        //
    

    
    });
});

$(window).load(function() {

    function fileList() {      
      var frames = 119, fileNames = [];
      for (i=0; i <= frames; i++) {
        var name = 'car_' + i + '.jpg';
        fileNames.push(name);
      }
      return fileNames; 
    }

    $('.rotate img').reel({
    frames:     20,
    frame:      3,
    rows:       6,
    row:        1,
    speed:      0.3,
    delay:      0,
    wheelable:  false,
    cw:         true,
    suffix:     null,
    path:       '/sprites/car/',
    images:     fileList()
  });
/*


		

*/


    

        //$('#content-scroll').height($('.items div:first').height());



  



	


    //slideShow();
    //setInterval('slideShow()', 6000);




    $('.wpcf7-select').append('<option value="blah blah 1">blah blah 1</option><option value="blah blah 2">blah blah 2</option><option value="blah blah 3">blah blah 3</option>');


});







if (jQuery().scrollable) {

    
    $(function() {

        // initialize scrollable
        $(".front-scrollable").scrollable({
            onBeforeSeek: function() {
            
                var pos = this.getIndex();

                $('.rotating-item').eq(pos).children('.inner').children('.copy').animate({
                    left: '-' + $('#splash').width() + 'px'
                }, 800, 'easeInExpo', function() {
                    $(this).hide();
                });

            },
            onSeek: function() {
            
                $('.rotating-item .inner .copy').css('left', '0').show();

            },
            easing: 'easeInOutExpo',
            speed: 2000
        }).navigator({ navi: '#slide-tabs' });

        
        $(".front-scrollable .rotating-item").each(function(i) { 
            var bg = $(this).css('background-image');
            bg = bg.replace(/"/g,"").replace(/url\(|\)$/ig, "");
            var title = $(this).find('h2').text();
            
                        
    	   $("#slide-tabs a").eq(i).html('<img src="'+ bg + '"><span><strong>'+ title + '</strong></span>')
    	   
    	   
    	   
    	   
    	   
		}); 
		


		


        $('#slide-tabs a').each(function(i) {
        
            //console.log(i);

        /*

            $(this).click(function(e) {
            e.preventDefault();
            
                if ( $(".front-scrollable .items").is(':animated') )
                {
                
                
                }
                else
                {
                
                    $('#slide-tabs a').removeClass('selected');
                    $(this).addClass('selected');
                    var scrollIndex = i;
                        
                    
                    //var scrollIndex = parseInt($(this).attr('id').split('-')[1], 10) - 1;
                    
        
                    //console.log(scrollIndex);
                    if ((scrollIndex !== $(".front-scrollable").scrollable().getIndex()) /* && ($(".scrollable .items").is(':animated') === false) ) {
                        $(".front-scrollable").scrollable().seekTo(scrollIndex, 2000);
                    }
                }
        
    
                //$(this).trigger('click');
            });
*/
        
        });
        
        
               
      
        
     
        
    $("#content-scroll").scrollable({
        size:1,
        speed: 800,
        touch: false,
        onSeek: function(evt, index){
            
               
            $('#content-scroll').stop().animate({ height: $('.items > div').eq(index).height()+'px'}, 250);
                
        }
        
        
    }).navigator();
    
    /*
$('#content-scroll .items div:first').load(function() { 
    
        $('#content-scroll').height($('#content-scroll .items div:first').height());
    });
*/
    
        //$('#content-scroll').height($('.items div:first').height());
        //$('#content-scroll').stop().animate({ height: $('.items > div').eq(index).height()+'px'}, 250);
    
    
    
    
    
        $("#content-scroll .items div h2").each(function(i) { 
    	   $("#titlebar .navi a").eq(i).html('<span>' + $(this).text() + '</span>');
		});  
    
    
    });

        
        
        
        
        
  
       

/*

        $('.slide-tabs a').mouseenter(function(e) {
       
            var scrollIndex = parseInt($(this).attr('id').split('-')[1], 10) - 1;
            

            //console.log(scrollIndex);
            if ((scrollIndex !== $(".scrollable").scrollable().getIndex()) && ($(".scrollable .items").is(':animated') === false)) {
                $(".scrollable").scrollable().seekTo(scrollIndex, 2000);
            }


            //$(this).trigger('click');
        });

        
      
        $('.slide-tabs a').click(function(event) {

        });
        
        */

    

}


    
    /*
    $(window).smartresize(function() {

    var winWidth = $(window).width();
    
    if (jQuery().scrollable) {
    var visibleSlide = $('.scrollable').scrollable().getIndex();
    

    //alert(winWidth);
    //alert(winWidth);
    $('.rotating-item').eq(visibleSlide).css('width', winWidth + 'px');
    }

    //$('.rotating-item').css({'top':0,'left':0,'right':0,'bottom':0,'position':'absolute'});
    //$(".scrollable").scrollable().seekTo(1, 2000);
});

*/

