function formatText(index, panel) {
  return index + "";
}

$(document).ready(function() {
    $("ul.sf-menu").superfish({
        pathClass:  'current'
    });
        
    var swapValue = [];
    $(".swap-value").each(function(i){
       swapValue[i] = $(this).val();
       $(this).focus(function(){
          if ($(this).val() == swapValue[i]) {
             $(this).val("");
          }
          $(this).addClass("focus");
       }).blur(function(){
          if ($.trim($(this).val()) == "") {
             $(this).val(swapValue[i]);
      $(this).removeClass("focus");
          }
       });
    });
    $('#pics').after('<div id="ss-nav">').cycle({ 
        fx:     'fade', 
        speed:  'slow', 
        timeout: 5000, 
        pager:  '#ss-nav' 
    });
    $("area").cluetip({
			"local": true,
			"cursor": "pointer",
            // "positionBy": "mouse",
            "positionBy": "auto",
			"showTitle": false,
			"fx": {open:"fadeIn"},
			"dropShadow": false,
			"width": 339
	});
	$('#egreen').click(function() {
		var eimg = $('#emap');
		eimg.fadeOut('fast');
		eimg.attr('src', '/themes/elliptigo/images/elliptigo_interactive_green.jpg');
		eimg.fadeIn('slow');
		$('#cup_adjust').attr('src', '/themes/elliptigo/images/adjustability_green.jpg')
		$('#cup_speed').attr('src', '/themes/elliptigo/images/8_spd_hub_green.jpg')
		$('#cup_pedal').attr('src', '/themes/elliptigo/images/pedaling_motion_green.jpg')
		$('#cup_portability').attr('src', '/themes/elliptigo/images/portability_green.jpg')
		return false;
	});
	$('#eblack').click(function() {
		var eimg = $('#emap');
		eimg.fadeOut('fast');
		eimg.attr('src', '/themes/elliptigo/images/elliptigo_interactive_black.jpg');
		eimg.fadeIn('slow');
		$('#cup_adjust').attr('src', '/themes/elliptigo/images/adjustability_black.jpg')
		$('#cup_speed').attr('src', '/themes/elliptigo/images/8_spd_hub_black.jpg')
		$('#cup_pedal').attr('src', '/themes/elliptigo/images/pedaling_motion_black.jpg')
		$('#cup_portability').attr('src', '/themes/elliptigo/images/portability_black.jpg')
		return false;
	});
	$('#eblue').click(function() {
		var eimg = $('#emap');
		eimg.fadeOut('fast');
		eimg.attr('src', '/themes/elliptigo/images/elliptigo_interactive_blue.jpg');
		eimg.fadeIn('slow');
		$('#cup_adjust').attr('src', '/themes/elliptigo/images/adjustability_blue.jpg')
		$('#cup_speed').attr('src', '/themes/elliptigo/images/8_spd_hub_blue.jpg')
		$('#cup_pedal').attr('src', '/themes/elliptigo/images/pedaling_motion_blue.jpg')
		$('#cup_portability').attr('src', '/themes/elliptigo/images/portability_blue.jpg')
		return false;
	});
	$('.anythingSlider').anythingSlider({
        easing: "easeInOutExpo",        // Anything other than "linear" or "swing" requires the easing plugin
        autoPlay: false,                 // This turns off the entire FUNCTIONALY, not just if it starts running or not.
        delay: 3000,                    // 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: false,          // 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)
    });
    
    $("#slider-nav a").click(function(){
		var item = $('#'+$(this).attr('id'));
		var indx = $('#slider-nav li a').index(item);
        $('.anythingSlider').anythingSlider(indx+1);
    });
    $("img.rollover").click(function() {
		$("img.rollover").each(function() {
			this.src = this.src.replace("_on", "_off");
			$(this).removeClass('current');
		});
		this.src = this.src.replace("_off", "_on");
		$(this).addClass('current');
	});
	$("img.rollover").hover(
		function () {
			$(this).attr("src", $(this).attr("src").replace("_off", "_on"));
		},
		function () {
			if (!$(this).hasClass('current')) {
				$(this).attr("src", $(this).attr("src").replace("_on", "_off"));
			}
		}
	);
    // $('#reviews-holder').hide();
    // $('#show-reviews').click( function() {
    //     $('#reviews-holder').slideDown();
    // });
	$('span.stars').stars();
	$.nyroModalSettings({
      processHandler: function(settings) {
        var from = settings.from;
        if (from && from.href && from.href.indexOf('http://www.youtube.com/watch?v=') == 0) {
          $.nyroModalSettings({
            type: 'swf',
            height: 355,
            width: 425,
            url: from.href.replace(new RegExp("watch\\?v=", "i"), 'v/')+'&autoplay=1'
          });
        }
      }
    });
    $('a.nyroModal').nyroModal();
    $('a.nyroModalText').nyroModal({
        type: 'div',
        height: 300,
        width: 400
    });
});