$(function() {
    $('#slideshow').after('<div id="slidenav" class="slidenav">').cycle({
        fx:     'turnDown',
        speed:  'fast',
        timeout: 12000,
        pager:  '#slidenav',
        after: onAfter,
        before: function() { if (window.console) console.log(this.src); }
    });
});


function onAfter() {
	//var si = $(this).parent('slideshow'); 
	var sindex = $("#slideshow div").index(this);
   // alert(sindex);
    closeDivs(sindex);
		
}

$(function() { // selector for the accordion slide
	$("#slidenav a").click(function () { 
		 //alert( $(this).html() );
		 //alert( "acc" + $(this).html() );
	});
});
		
$(function() { 	// this function changes the slide, clicked by the h1
	$(".accslide h1 a").click(function () {
		//alert($(this).parent('h1').parent().attr('id'));
		var acc = $(this).parent('h1').parent(); // the h1
		var accindex = $("#accwrap div").index(acc) ;
		$('#slidenav a:eq('+accindex+')').click(); // selects the SECOND a because the index starts at 0

		closeDivs(accindex);
		
	});
});

function closeDivs(accindex) {
	$(".accslide").each(function(index) {
		
		//var myindex = $("#accwrap div").index(currentacc) ;
		//alert(index+'='+accindex);
		if(index==accindex){
			$(this).children('h1').addClass('active');
			$(this).children('p').show();
		}else{
			$(this).children('h1').removeClass('active');
			$(this).children('p').hide();
		}
	});
}


