$(document).ready(function(){
  
  setup_slider();
  setup_fancybox();
  setup_ecommerce();
  slideSwitch();

});


function setup_ecommerce(){
 
  $('#roadrunner-details').hide();
  $('#ereport-details').hide();
  $('#hide-roadrunner').hide();
  $('#hide-ereport').hide();
  
  $('#expand-roadrunner').click(function(){
	$('#expand-roadrunner').toggle();
	$('#roadrunner-details').toggle();
    $('#hide-roadrunner').toggle();
	return false;
  });

  $('#expand-ereport').click(function(){
	$('#expand-ereport').toggle();
	$('#ereport-details').toggle();
    $('#hide-ereport').toggle();
	return false;
  });

  $('#hide-ereport').click(function(){
	$('#expand-ereport').toggle();
	$('#ereport-details').toggle();
    $('#hide-ereport').toggle();
	return false;
  });

  $('#hide-roadrunner').click(function(){
	$('#expand-roadrunner').toggle();
	$('#roadrunner-details').toggle();
    $('#hide-roadrunner').toggle();
	return false;
  });

}

function setup_fancybox(){

  $(document).ready(function() {
    //This is basic - uses default settings */
    $("a.single_image").fancybox();

    //Using custom settings
	$("a.inline").fancybox({
		'hideOnContentClick': true
	});

    $("a.group").fancybox({
	  'speedIn'		:	600, 
	  'speedOut'		:	200, 
	  'overlayShow'	:	false
    });
  });
}

function formatText(index, panel) {
  return index + "";
}


function setup_slider(){


	$('.anythingSlider').anythingSlider({
		easing: "easeInOutExpo",        // Anything other than "linear" or "swing" requires the easing plugin
		autoPlay: true,                 // This turns off the entire FUNCTIONALY, not just if it starts running or not.
		delay: 8000,                    // How long between slide transitions in AutoPlay mode
		startStopped: false,            // If autoPlay is on, this can force it to start stopped
		animationTime: 600,             // How long the slide transition takes
		hashTags: true,                 // Should links change the hashtag in the URL?
		buildNavigation: true,          // If true, builds and list of anchor links to link to each slide
		pauseOnHover: true,             // If true, and autoPlay is enabled, the show will pause on hover
		startText: "Go",             // Start text
		stopText: "Stop",               // Stop text
		navigationFormatter: formatText       // Details at the top of the file on this use (advanced use)
	});

	$("#slide-jump").click(function(){
		$('.anythingSlider').anythingSlider(6);
	});            

}


function slideSwitch() {
    var $active = $('#slideshow IMG.active');

    if ( $active.length == 0 ) $active = $('#slideshow IMG:last');

    // use this to pull the images in the order they appear in the markup
    var $next =  $active.next().length ? $active.next()
        : $('#slideshow IMG: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})
        .addClass('active')
        .animate({opacity: 1.0}, 1000, function() {
            $active.removeClass('active last-active');
        });
}

$(function() {
    setInterval( "slideSwitch()", 7000 );
	setInterval( "slideSwitch2()", 5000 );
});


function slideSwitch2() {
    var $active = $('#slideshow2 IMG.active2');

    if ( $active.length == 0 ) $active = $('#slideshow2 IMG:last');

    // use this to pull the images in the order they appear in the markup
    var $next =  $active.next().length ? $active.next()
        : $('#slideshow2 IMG: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-active2');

    $next.css({opacity: 0.0})
        .addClass('active2')
        .animate({opacity: 1.0}, 1000, function() {
            $active.removeClass('active2 last-active2');
        });
}
