$(document).ready(function() {
    $(".inline").fancybox({
        'titlePosition'	: 'inside',
        'transitionIn'	: 'none',
        'transitionOut'	: 'none',
        'overlayOpacity': '0.4',
        'scrolling'     : 'no',
        'onComplete'    : function(){
            $('#school').autocomplete({
                source: "school_search.php",
                minLength: 2,
                select: function(event, ui) {
                    $('#school').val(ui.item.value);
                    $('#findSchool').submit();
                }
            });
            setTimeout(function() {
                $('#school').focus();
            }, 50);
        }
    });
    $("ul.tabs li:first").addClass("on").show();
    $(".on").find("img").hide();
    //$(".on").find("a").css('backgroundImage', 'url(/images/buttonA2.png)');
    $(".tab:first").addClass("active").show();
    function changeSlide( newSlide ) {
        // cancel any timeout
        clearTimeout( slideTimeout );
        // change the currSlide value
        currSlide = newSlide;
        // make sure the currSlide value is not too low or high
        if ( currSlide > maxSlide ) currSlide = 0;
        else if ( currSlide < 0 ) currSlide = maxSlide;
        currTab = "#"+tabs[currSlide];
        currNav = "#tab-"+tabs[currSlide];
        //$(currNav).find("a").css('backgroundImage', 'url(/images/'+$(currNav).find("a").attr("class")+'2.png)');
        $(".active").removeClass("active").hide();
        $(currTab).addClass("active").show();
        $(".on").find("img").show();
        $(".on").removeClass("on");
        $(currNav).addClass("on");
        $(currNav).find("img").hide();
        if ( activeSlideshow ) slideTimeout = setTimeout(nextSlide, slideInterval);
    }
    
    function nextSlide() {
        changeSlide( currSlide + 1 );
    }
    
    var activeSlideshow = true,
    tabs = ["selection","approved","quality","term","stepup","accessory"],
    currSlide = 0,
    slideTimeout,
    $slideshow = $('#top_content'),
    maxSlide = $slideshow.children().length - 1,
    slideInterval = 3500;
    
    $("ul#navigation li").click(function (ev) {
        ev.preventDefault();
	activeSlideshow = false;
        changeSlide($(this).index());
    });
    
    // start the animation
    //slideTimeout = setTimeout(nextSlide, slideInterval);
});

function setSchool ( selected )
{
    $('#school').val(selected);
    $('#findSchool').submit();
}
