var current_slide = -1;
var num_reviews = 10;

// jQuery after document is ready (HTML DOM is all downloaded & parsed)
// I put the testimonial slideshow stuff here too
$(function() {
	$('#shopping-cart, .purch_01').cornerz({radius:7});
	$('#shopping-cart-central-area').cornerz({radius:7, background:'#E7E7E7'});
	$('.desc_06').cornerz({radius:10});
	
	$('a[rel^=lightbox]').lightBox({
		imageLoading: '/images/waveriderdesign/lightboxes/loading.gif',
		imageBtnClose: '/images/waveriderdesign/lightboxes/closelabel.gif',
		imageBtnPrev: '/images/waveriderdesign/lightboxes/prevlabel.gif',
		imageBtnNext: '/images/waveriderdesign/lightboxes/nextlabel.gif',
		containerResizeSpeed: 250
	});

  change_slide();
  var interval = window.setInterval(change_slide, 7000),
  		$slideBody = $('.slide-accordion .slide-body'),
  		realHeight = $slideBody.show().height();
  $slideBody.hide().css('height', '0');

  // I'm also going to put the product info page "more images" slider in here
	$('.slide-accordion').mouseenter(function() {
		$(this).find('.slide-body').animate({height: realHeight + 'px'}, {
			duration: 750,
			easing: 'swing',
			queue: false
		});
		return false;
	}).mouseleave(function() {
		$(this).find('.slide-body').animate({height: 0}, {
			duration: 500,
			easing: 'linear',
			complete: function() { $(this).hide(); },
			queue: false
		});
		return false;
	});
	
	// image handler additional images hover effect
	$('.add_02 img').each(function() {
		var $this = $(this);
		$this.qtip({
			content: {text: '<img src="' + $this.attr('rel') + '" />', title: {text: $this.attr('alt')}},
			position: {target: 'mouse', corner: {tooltip: 'bottomLeft'}, adjust: {screen: true}},
			show: {delay: 0, effect: {length: 0}},
			style: {tip: true, width: {max: 500}, border: {width: 0}, title: {'background-color': '#FFF'}}
		});
	});

	// video lightbox home page video-swapping effect
	$('.video-thumbs a').click(function() {
		var $this = $(this),
				$large = $('#large-video'),
				$img = $this.find('img'),
				largeSrc = $this.find('img').attr('src').replace(/thumb/, 'large'),
				smallHref = $this.attr('href'),
				smallSrc = $large.find('img').attr('src').replace(/large/, 'thumb'),
				largeHref = $large.attr('href');
		$large.effect('transfer', { to: $img }, 400, function() {
			$large.attr('href', smallHref);
			$large.find('img').attr('src', largeSrc);
		});
		$img.effect('transfer', { to: $large }, 500, function() {
			$this.attr('href', largeHref);
			$this.find('img').attr('src', smallSrc);
		});
		return false;
	});
/*	$('#home-page-slider').cycle({ 
    fx:      'custom', 
    sync: 0, 
    cssBefore: {  
        top:  0, 
        left: 232, 
        display: 'block' 
    }, 
    animIn:  { 
        left: 0 
    }, 
    animOut: {  
        top: 232 
    }, 
    delay: -1000 
});*/
	
	$('#home-page-slider')
	.before('<ul id="slider-nav-wrap">')
	.cycle({
	  fx: ('scrollVert'),
      speed: (1000) ,
	  pause: (1) ,
	  timeout: (9000) , 
      delay: (500) ,
	  pager: '#slider-nav-wrap',
	  	pagerAnchorBuilder: function(index, el) {
        return '<a href="#"></a>'; // whatever markup you want
		},
      next: ('#slider-down') ,
      prev: ('#slider-up') ,
      easing: ('easeInOutSine')});

/*
  var $slideWrapper = $('.slide-display-wrapper');
  if ($slideWrapper.length > 0 && $slideWrapper.find('.slide-display').length > 1) {
  	var $slidePane = $slideWrapper.closest('.slide-pane'),
  			$slideContainer = $slidePane.parent(),
  			$slideBack = $('<a href="#" class="slide-back back"></a>').css('opacity', '0.5'),
  			$slideForward = $('<a href="#" class="slide-forward forward"></a>');
  	$slideWrapper.find('.slide-display:first').addClass('current-slide');
  	
  	$slideForward.click(function() {
  		var $current = $slideWrapper.find('.current-slide');
  		if ($current.is('.slide-display:last-child')) return false;

  		$current.removeClass('current-slide');
  		var $next = $current.next('.slide-display').addClass('current-slide');

  		$slideBack.css('opacity', '1');  		
  		if ($next.is('.slide-display:last-child')) $slideForward.css('opacity', '0.5');
  		else $slideForward.css('opacity', '1');
  		
  		$slidePane.stop(true).scrollTo($next, 250);
  		return false;
  	});
  	
  	$slideBack.click(function() {  	
  		var $current = $slideWrapper.find('.current-slide');
  		if ($current.is('.slide-display:first-child')) return false;
  		
  		$current.removeClass('current-slide');
  		var $prev = $current.prev('.slide-display').addClass('current-slide');
  		
  		$slideForward.css('opacity', '1');
  		if ($prev.is('.slide-display:first-child')) $slideBack.css('opacity', '0.5');
  		else $slideBack.css('opacity', '1');
  		
  		$slidePane.stop(true).scrollTo($prev, 250);
  		return false;
  	});
  			
  	$slideBack.appendTo($slideContainer);
  	$slideForward.appendTo($slideContainer);
  }
*/
});


// jQuery after page is loaded (all images downloaded too)
$(window).load(function() { 
	//$('.main_bg').css('background', 'url(/images/waveriderdesign/people-bg.png) center top no-repeat');
});

// this is the heart of the rotating testimonials in the header
function change_slide() {
  if (current_slide >= 0) {
    $('#testimonial-' + current_slide).fadeOut(500);
    $('#testimonial-author-' + current_slide).fadeOut(500);
  }
  /* current_slide = Math.floor(Math.random() * num_reviews); */
	current_slide = (current_slide + 1) % 10;
  $('#testimonial-' + current_slide + ', #testimonial-author-' + current_slide).fadeIn(500);
}
