// EDIT NUMBER FOR CORRECT AMOUNT OF IMAGES
var slideshownum = 32;

// DO NOT EDIT BELOW THIS LINE

$(document).ready(function() {
	
	/* Margin fixes and menu styling
    -------------------------------------------------------------- */
    
	$('section#header nav#mainmenu ul li, section#header nav#sitemapmenu ul li').last().css('margin-right',"0");
	$('section#header #headerimg nav#sitemapmenu ul li a').not('nav#sitemapmenu ul li:last-child a').after(' | ');
	$('section#header nav#mainmenu ul li a').not('section#header nav#mainmenu ul li:last-child a').after('|');
	
	
	/* Handle input placeholder if not HTML5 compatible
    -------------------------------------------------------------- */

    if (!Modernizr.input.placeholder) {

        $("input").each(

        function() {
            if ($(this).val() === "" && $(this).attr("placeholder") !== "") {
                $(this).val($(this).attr("placeholder"));
                $(this).focus(function() {
                    if ($(this).val() === $(this).attr("placeholder")) {
                        $(this).val("");
                    }
                });
                $(this).blur(function() {
                    if ($(this).val() === "") {
                        $(this).val($(this).attr("placeholder"));
                    }
                });
            }

        });

    }
    
    
    /* Infinte Scroll
    -------------------------------------------------------------- */
    
    var newArticles,articlesLeft;
    
    $('#archiveexpand').click(function(e) {
    	e.preventDefault();
    	
    	insertArticles();
    	insertCallback();
    	
    });
    
    function insertArticles() {
    	findNewArticles();
    	if (articlesLeft >= 5) {
    		newArticles = $('#archived article').slice(0,4);
    	} else {
    		newArticles = $('#archived article').slice(0,(articlesLeft-1));
    		$('#archiveexpand').remove();
    	};
    	
    	newArticles.insertAfter('#archivedcontainer #visiblenews article:last-child');
	};
	
	function insertCallback() {
		findNewArticles();
		if (articlesLeft === 0) {
			$(this).remove();
		};
	};
    
    function findNewArticles() {
    	articlesLeft = $('#archived article').length;
    	return articlesLeft;
    };
    
    
    /* Slideshow
    -------------------------------------------------------------- */
    
    var i = 0;
    for (i = 0; i < slideshownum; i++) {
    	$('#racer-slideshow').append('<img src="/v/vspfiles/assets/images/impactracers/impactracer_' + (i+1) + '.jpg" alt="' + (i+1) + '" />');
    };
    
    $('#racer-slideshow').cycle({
        fx: 'fade',
        timeout: 3000,
        speed: 400,
        easing: 'easeInOutQuad',
        startingSlide: 0 //(currentslide - 1)
    });



});
