//uses jQuery cycle plugin 

//this function runs when slide changes
$.fn.cycle.updateActivePagerLink = function(pager, currSlideIndex) { 

    var c = $(pager).find('li:eq('+currSlideIndex+') div'); //current slide
    var e = $(pager).find('li:not(:eq('+currSlideIndex+')) div'); //non-current slides
	var ctx = $("#intro-text");//context, for performance
        
	e.parent().removeClass('on').removeClass('next');
	e.children('p', ctx).hide();//hide detailed desc
	e.children('a', ctx).show();//show link txt
		
	c.parent().addClass('on');
	$("#slide" + (currSlideIndex+1)).addClass('next'); //to remove dots .next works incorrectly in ie
	c.children('a', ctx).hide();//hide link txt
	c.children('p', ctx).slideDown('fast');//show details	

};
 
$slideshow = {
    context: false,
    tabs: false,
    timeout: 7000,      // time before next slide appears (in ms)
    slideSpeed: 600,   // time it takes to slide in each slide (in ms)
    tabSpeed: 600,      // time it takes to slide in each slide (in ms) when clicking through tabs
    fx: 'scrollDown',   // the slide effect to use
    
    init: function() {
        this.context = $('#intro');//context, for performance
        this.tabs = $('ul#pager').find('li'); // set tabs to current hard coded navigation items - use "find" 'cuz of ie6
        //this.tabs.remove();// remove hard coded navigation items from DOM broken in IE
        this.prepareSlideshow();// prepare slideshow and jQuery nav
    },
    
    prepareSlideshow: function() {
        $('div#slides > ul', $slideshow.context).cycle({
            fx: $slideshow.fx,
            timeout: $slideshow.timeout,
            speed: $slideshow.slideSpeed,
            fastOnEvent: $slideshow.tabSpeed,
            pager: $('ul#pager', $slideshow.context),
            pagerAnchorBuilder: $slideshow.prepareTabs,
//            pauseOnPagerHover: true,
            pause: true,
            autostop: 1,
            autostopCount: 6 //stop after 6 slides on Family
        });            
    },

    prepareTabs: function(i, slide) {
        // return markup from hardcoded tabs for use as jQuery cycle tabs
        return $slideshow.tabs.eq(i);
    }
};

$(function() {	
	/*
	 * HOMEPAGE
	 */
	    $slideshow.init(); // initialize slideshow 
		$("#pager li").click(function() {$("#slides").cycle('pause');});//pause slideshow after clicking slide nav
		
		//make sure links click through
		$(".intro-text-link").click(function() {
                    window.location.href = $(this).attr('href');
                });
				
		$(".home-col").hover(function() {
			$(this).children('h3').addClass('hover');
		}, function() {
			$(this).children('h3').removeClass('hover');
		});
			
});  