// Slideshow for Miksang.com
// by Todd Roseman luky.com, unrestricted use by Miksang.com and Michael Wood
// All other rights reserved.
// Generate random selection from image array included separately (images.js)
 
var nslides = 20;
// get random images and insert into DOM to make slideshow
var images_show_list = Array();
// fill with random images from big list
var show_index = Array();
var ishow = 0;		// index of shown images
var itt=0;			// iterations
var i;
var ntotal;

if (typeof(window.images_list) === "undefined") {
} else {
	ntotal = images_list.length;
	// build list of slides
	while (ishow<nslides && itt<nslides*3) {
		i = Math.floor(Math.random()*ntotal);
		// see if exists
		if (jQuery.inArray(i,show_index) == -1) {
			images_show_list[ishow] = images_list[i];
			show_index[ishow] = i;
			ishow++;
		}	
		itt++;
	}
}


$(document).ready(function(){   

	// check if slideshow exists and has images on this page
	if ($(".slideimages").length && images_show_list.length) {
		
		o='';
		t='';
		n = images_show_list.length;
		for (i=0;i<n;i++) {
			o += '<div><img src="'+images_show_list[i]+'" ></div>';
			t += '<a href="#"></a>';
		}

		$(".slideimages").append(o);
		$(".slidetabs").append(t);

		$(".slidetabs").tabs(".slideimages > div", {
			// enable "cross-fading" effect
			effect: 'fade',
			fadeInSpeed: 1000,
			fadeOutSpeed: 1000,
			rotate: true
		}).slideshow({ autoplay: true, interval: 6000 });
	}	

});

