$(document).ready(function() {
    $('.racetile,.partstile,.sterndrive,.tdi,.mercracing,.mercruiser,.mercury,.verado').append('<span class="hover"></span>').each(function () {
        var $span = $('> span.hover', this).css('opacity', 0);
        $(this).hover(function () {
            $span.stop().fadeTo(500, 1);
        }, function () {
            $span.stop().fadeTo(500, 0);
        });
    });
    
    
    $('#splash').nivoSlider({
        effect:'fade', // Specify sets like: 'fold,fade,sliceDown'
        slices:15, // For slice animations
        boxCols: 8, // For box animations
        boxRows: 4, // For box animations
        animSpeed:700, // Slide transition speed
        pauseTime:6000, // How long each slide will show
        startSlide:0, // Set starting Slide (0 index)
        directionNav:false, // Next & Prev navigation
        directionNavHide:true, // Only show on hover
        controlNav:false, // 1,2,3... navigation
        controlNavThumbs:false, // Use thumbnails for Control Nav
        controlNavThumbsFromRel:false, // Use image rel for thumbs
        controlNavThumbsSearch: '.jpg', // Replace this with...
        controlNavThumbsReplace: '_thumb.jpg', // ...this in thumb Image src
        keyboardNav:true, // Use left & right arrows
        pauseOnHover:false, // Stop animation while hovering
        manualAdvance:false, // Force manual transitions
        captionOpacity:0.8, // Universal caption opacity
        prevText: '', // Prev directionNav text
        nextText: '' // Next directionNav text

    });     
                
                
                
                
                
    function goToByScroll(id){
        $('html,body,.showphotos').animate({
            scrollTop: $("#"+id).offset().top
            },'slow');
    }
						   

    $(".showphotos").click(function(e){
        e.preventDefault();							
        $(this).parents(".beforeafter").slideToggle("slow", function(){
            $(this).parent().find(".repowerphotodiv").slideToggle("slow");
            goToByScroll("photodiv-footer");										
        });
        $(this).parent().parent().parent().find(".techspec-container").hide("slow");
    });
	
    $(".closephotos").click(function(){
        $(this).parent().parent().parent().find(".beforeafter").slideToggle("fast");							 
        $(this).parent().parent().parent().find(".repowerphotodiv").slideToggle("fast");	  
    });
	
    /*$(".closephotos").click(function(){
		$(this).parent().parent().parent().find(".beforeafter").show("slow");							 
	  	$(this).parent().parent().parent().find(".repowerphotodiv").slideToggle("slow");	  
	  	$(this).toggleClass("active");
	});*/
	
    $(".showspecs").click(function(e){
        e.preventDefault();
        $(this).parent().parent().parent().find(".techspec-container").fadeToggle("slow");
		
    });
	
    /* Image Swap */
	
    $("h2").append('<em></em>')

    $(".thumbs a").click(function(){
								  
        var li = $(this).parent().parent();
        var largePath = $(this).attr("href");
        var largeAlt = $(this).attr("title");
		
        $(".largeImg", li).attr({
            src: largePath, 
            alt: largeAlt
        });
		
        $("h2 em", li).html(" (" + largeAlt + ")");
        return false;
    });                
    
    
	$("a.group").fancybox({
		'transitionIn'	:	'elastic',
		'transitionOut'	:	'elastic',
		'speedIn'		:	200, 
		'speedOut'		:	200, 
		'overlayShow'	:	true
	});
	
	$("a.video").click(function(e) {$.fancybox({
		'padding'             : 0,
		'autoScale'   		: false,
		'transitionIn'        : 'none',
		'transitionOut'       : 'none',
		'title'               : this.title,
		'width'               : 680,
		'height'              : 495,
		//'href'                : this.href.replace(new RegExp("watch\\?v=", "i"), 'v/'),
		'href'				  : this.href = this.href.replace(new RegExp("watch\\?v=", "i"), 'v/') + '&autoplay=1',
		'type'                : 'swf',    // <--add a comma here
		'swf'                 : {'allowfullscreen':'true', 'wmode':'transparent'}
		});
		//return false;
		e.preventDefault();
	});     
});

