Make a random number, and then address a list item with li:eq(X) as seen here:
$('ul.slideshow li:eq('+randNum+')').addClass('show');
By the way, that line also fixes a bug if you don't start with a li that has class="show" (which you wouldn't if you are randomly starting). If that class isn't added to the one that you randomly start with, it will keep "popping up" between fades on the other list items, until the slide show gets around to the second display of the image when it applies
current.animate({opacity: 0.0}, 500).removeClass('show');
//Generate a random number
var randNum = Math.floor(Math.random() * $('ul.slideshow li').length);
//Randomly pick up a slide
$('ul.slideshow li:eq('+randNum+')').addClass('show');
Did you try removing the class="show" from the HTML code on the first item...? Because at this point it has two show classes, doesn't it?
Make sure to call gallery(); after you addClass('show') at the end of your first function. Otherwise it won't take the show class into account, I suppose...
<script type="text/javascript">
$(document).ready(function() {
$('#slider').s3Slider({
timeOut: 6000
});
$('#slider1').s3Slider({
timeOut: 4000
});
$('#slider2').s3Slider({
timeOut: 4000
});
});
</script><div id="slider">
<ul id="sliderContent">
<?php
$header = array(
array('http://virgilio.lorenzoraffio.com/wp-content/themes/virgilio/images/header/aula_magna.jpg', 'CAPTION AULA MAGNA', 'right'),
array('http://virgilio.lorenzoraffio.com/wp-content/themes/virgilio/images/header/portone.jpg', 'CAPTION PORTONE', 'bottom'),
array('http://virgilio.lorenzoraffio.com/wp-content/themes/virgilio/images/labchimica.jpg', 'CAPTION LAB CHIMICA', 'top'),
array('http://virgilio.lorenzoraffio.com/wp-content/themes/virgilio/images/header/aula_informatica.jpg', 'CAPTION INFORMATICA', 'bottom'),
array('http://virgilio.lorenzoraffio.com/wp-content/themes/virgilio/images/header/atrio.jpg', 'CAPTION ATRIO', 'top'),
);
$rand = rand(0, count($header) - 1);
echo '<li class="sliderImage"><img src="', $header[$rand][0], '" width="', HEADER_IMAGE_WIDTH, '" height="', HEADER_IMAGE_HEIGHT, '" alt="" /><span class="', $header[$rand][2], '">', $header[$rand][1], '</span></li>';
$header2 = array(
array('http://virgilio.lorenzoraffio.com/wp-content/themes/virgilio/images/header/aula_magna.jpg', 'CAPTION AULA MAGNA', 'right'),
array('http://virgilio.lorenzoraffio.com/wp-content/themes/virgilio/images/header/portone.jpg', 'CAPTION PORTONE', 'bottom'),
array('http://virgilio.lorenzoraffio.com/wp-content/themes/virgilio/images/labchimica.jpg', 'CAPTION LAB CHIMICA', 'top'),
array('http://virgilio.lorenzoraffio.com/wp-content/themes/virgilio/images/header/aula_informatica.jpg', 'CAPTION INFORMATICA', 'bottom'),
array('http://virgilio.lorenzoraffio.com/wp-content/themes/virgilio/images/header/atrio.jpg', 'CAPTION ATRIO', 'top'),
);
$rand = rand(0, count($header2) - 1);
echo '<li class="sliderImage"><img src="', $header2[$rand][0], '" width="', HEADER_IMAGE_WIDTH, '" height="', HEADER_IMAGE_HEIGHT, '" alt="" /><span class="', $header2[$rand][2], '">', $header2[$rand][1], '</span></li>';
$header3 = array(
array('http://virgilio.lorenzoraffio.com/wp-content/themes/virgilio/images/header/aula_magna.jpg', 'CAPTION AULA MAGNA', 'right'),
array('http://virgilio.lorenzoraffio.com/wp-content/themes/virgilio/images/header/portone.jpg', 'CAPTION PORTONE', 'bottom'),
array('http://virgilio.lorenzoraffio.com/wp-content/themes/virgilio/images/labchimica.jpg', 'CAPTION LAB CHIMICA', 'top'),
array('http://virgilio.lorenzoraffio.com/wp-content/themes/virgilio/images/header/aula_informatica.jpg', 'CAPTION INFORMATICA', 'bottom'),
array('http://virgilio.lorenzoraffio.com/wp-content/themes/virgilio/images/header/atrio.jpg', 'CAPTION ATRIO', 'top'),
);
$rand = rand(0, count($header3) - 1);
echo '<li class="sliderImage"><img src="', $header3[$rand][0], '" width="', HEADER_IMAGE_WIDTH, '" height="', HEADER_IMAGE_HEIGHT, '" alt="" /><span class="', $header3[$rand][2], '">', $header3[$rand][1], '</span></li>';
$header4 = array(
array('http://virgilio.lorenzoraffio.com/wp-content/themes/virgilio/images/header/aula_magna.jpg', 'CAPTION AULA MAGNA', 'right'),
array('http://virgilio.lorenzoraffio.com/wp-content/themes/virgilio/images/header/portone.jpg', 'CAPTION PORTONE', 'bottom'),
array('http://virgilio.lorenzoraffio.com/wp-content/themes/virgilio/images/labchimica.jpg', 'CAPTION LAB CHIMICA', 'top'),
array('http://virgilio.lorenzoraffio.com/wp-content/themes/virgilio/images/header/aula_informatica.jpg', 'CAPTION INFORMATICA', 'bottom'),
array('http://virgilio.lorenzoraffio.com/wp-content/themes/virgilio/images/header/atrio.jpg', 'CAPTION ATRIO', 'top'),
);
$rand = rand(0, count($header4) - 1);
echo '<li class="sliderImage"><img src="', $header4[$rand][0], '" width="', HEADER_IMAGE_WIDTH, '" height="', HEADER_IMAGE_HEIGHT, '" alt="" /><span class="', $header4[$rand][2], '">', $header4[$rand][1], '</span></li>';
$header5 = array(
array('http://virgilio.lorenzoraffio.com/wp-content/themes/virgilio/images/header/aula_magna.jpg', 'CAPTION AULA MAGNA', 'right'),
array('http://virgilio.lorenzoraffio.com/wp-content/themes/virgilio/images/header/portone.jpg', 'CAPTION PORTONE', 'bottom'),
array('http://virgilio.lorenzoraffio.com/wp-content/themes/virgilio/images/labchimica.jpg', 'CAPTION LAB CHIMICA', 'top'),
array('http://virgilio.lorenzoraffio.com/wp-content/themes/virgilio/images/header/aula_informatica.jpg', 'CAPTION INFORMATICA', 'bottom'),
array('http://virgilio.lorenzoraffio.com/wp-content/themes/virgilio/images/header/atrio.jpg', 'CAPTION ATRIO', 'top'),
);
$rand = rand(0, count($header5) - 1);
echo '<li class="sliderImage"><img src="', $header5[$rand][0], '" width="', HEADER_IMAGE_WIDTH, '" height="', HEADER_IMAGE_HEIGHT, '" alt="" /><span class="', $header5[$rand][2], '">', $header5[$rand][1], '</span></li>';
$header6 = array(
array('http://virgilio.lorenzoraffio.com/wp-content/themes/virgilio/images/header/aula_magna.jpg', 'CAPTION AULA MAGNA', 'right'),
array('http://virgilio.lorenzoraffio.com/wp-content/themes/virgilio/images/header/portone.jpg', 'CAPTION PORTONE', 'bottom'),
array('http://virgilio.lorenzoraffio.com/wp-content/themes/virgilio/images/labchimica.jpg', 'CAPTION LAB CHIMICA', 'top'),
array('http://virgilio.lorenzoraffio.com/wp-content/themes/virgilio/images/header/aula_informatica.jpg', 'CAPTION INFORMATICA', 'bottom'),
array('http://virgilio.lorenzoraffio.com/wp-content/themes/virgilio/images/header/atrio.jpg', 'CAPTION ATRIO', 'top'),
);
$rand = rand(0, count($header5) - 1);
echo '<li class="sliderImage"><img src="', $header6[$rand][0], '" width="', HEADER_IMAGE_WIDTH, '" height="', HEADER_IMAGE_HEIGHT, '" alt="" /><span class="', $header6[$rand][2], '">', $header6[$rand][1], '</span></li>';
?>
<li class="sliderImage">
</li>
</ul>
</div>
You should be showing your pics in order after the first randomization. I noticed several pics being faded out only to show up again next...
<div id="slider">
<ul id="sliderContent">
<?php
$header = array(
array('http://virgilio.lorenzoraffio.com/wp-content/themes/virgilio/images/header/aula_magna.jpg', 'CAPTION AULA MAGNA', 'right'),
array('http://virgilio.lorenzoraffio.com/wp-content/themes/virgilio/images/header/portone.jpg', 'CAPTION PORTONE', 'bottom'),
array('http://virgilio.lorenzoraffio.com/wp-content/themes/virgilio/images/labchimica.jpg', 'CAPTION LAB CHIMICA', 'top'),
array('http://virgilio.lorenzoraffio.com/wp-content/themes/virgilio/images/header/aula_informatica.jpg', 'CAPTION INFORMATICA', 'bottom'),
array('http://virgilio.lorenzoraffio.com/wp-content/themes/virgilio/images/header/atrio.jpg', 'CAPTION ATRIO', 'top'),
);
$rand = rand(0, count($header) - 1);
echo '<li class="sliderImage"><img src="', $header[$rand][0], '" width="', HEADER_IMAGE_WIDTH, '" height="', HEADER_IMAGE_HEIGHT, '" alt="" /><span class="', $header[$rand][2], '">', $header[$rand][1], '</span></li>'; ?>
<li class="sliderImage">
<img src="<?php echo get_stylesheet_directory_uri(); ?>/images/header/aula_magna.jpg" width="<?php echo HEADER_IMAGE_WIDTH; ?>" height="<?php echo HEADER_IMAGE_HEIGHT; ?>" alt="" />
<span class="right"><strong>L'aula magna</strong><br />CAPTION AULA MAGNA</span>
</li>
<li class="sliderImage">
<img src="<?php echo get_stylesheet_directory_uri(); ?>/images/header/portone.jpg" width="<?php echo HEADER_IMAGE_WIDTH; ?>" height="<?php echo HEADER_IMAGE_HEIGHT; ?>" alt="" />
<span class="bottom"><strong>Il portone</strong><br />CAPTION PORTONE</span>
</li>
<li class="sliderImage">
<img src="<?php echo get_stylesheet_directory_uri(); ?>/images/header/aula_informatica.jpg" width="<?php echo HEADER_IMAGE_WIDTH; ?>" height="<?php echo HEADER_IMAGE_HEIGHT; ?>" alt="" />
<span class="top"><strong>Laboratorio di Chimica</strong><br />CAPTION LAB CHIMICA</span>
</li>
<li class="sliderImage">
<img src="<?php echo get_stylesheet_directory_uri(); ?>/images/labfisica.jpg" width="<?php echo HEADER_IMAGE_WIDTH; ?>" height="<?php echo HEADER_IMAGE_HEIGHT; ?>" alt="" />
<span class="top"><strong>Laboratorio di Fisica</strong><br />CAPTION INFORMATICA</span>
</li>
<li class="sliderImage">
<img src="<?php echo get_stylesheet_directory_uri(); ?>/images/header/atrio.jpg" width="<?php echo HEADER_IMAGE_WIDTH; ?>" height="<?php echo HEADER_IMAGE_HEIGHT; ?>" alt="" />
<span class="top"><strong>Atrio</strong><br />CAPTION ATRIO</span>
</li>
<li class="sliderImage">
</li>
</ul>
</div>