var global_transitions=[ //array of IE transition strings
	"progid:DXImageTransform.Microsoft.Barn()",
	"progid:DXImageTransform.Microsoft.Blinds()",
	"progid:DXImageTransform.Microsoft.CheckerBoard()",
	"progid:DXImageTransform.Microsoft.Fade()",
	"progid:DXImageTransform.Microsoft.GradientWipe()",
	"progid:DXImageTransform.Microsoft.Inset()",
	"progid:DXImageTransform.Microsoft.Iris()",
	"progid:DXImageTransform.Microsoft.Pixelate()",
	"progid:DXImageTransform.Microsoft.RadialWipe()",
	"progid:DXImageTransform.Microsoft.RandomBars()",
	"progid:DXImageTransform.Microsoft.RandomDissolve()",
	"progid:DXImageTransform.Microsoft.Slide()",
	"progid:DXImageTransform.Microsoft.Spiral()",
	"progid:DXImageTransform.Microsoft.Stretch()",
	"progid:DXImageTransform.Microsoft.Strips()",
	"progid:DXImageTransform.Microsoft.Wheel()",
	"progid:DXImageTransform.Microsoft.Zigzag()"
]

function flashyslideshow(setting){
	this.wrapperid=setting.wrapperid
	this.imagearray=setting.imagearray
	this.pause=setting.pause
	this.transduration=setting.transduration/1000 //convert from miliseconds to seconds unit to pass into el.filters.play()
	this.currentimg=setting.currentimg 
	var preloadimages=[] //temp array to preload images
	for (var i=0; i<this.imagearray.length; i++){
		preloadimages[i]=new Image()
		preloadimages[i].src=this.imagearray[i][0]
	}
	document.write('<div id="'+this.wrapperid+'" class="'+setting.wrapperclass+'">'+this.getSlideHTML(this.currentimg)+'</div>')
	this.rotate()
}

var pause;
var interval;

function pauseResume() {
  if(pause) {
    clearInterval(interval);
    pause = false;
  } else {
    interval = setInterval(function(){flashyshow.rotate()},flashyshow.pause)
    pause = true;
  }
}



flashyslideshow.prototype.getSlideHTML=function(index){
	var slideHTML=(this.imagearray[index][1])? '<a href="'+this.imagearray[index][1]+'" target="'+this.imagearray[index][1]+'">\n' : '' //hyperlink slide?
	slideHTML+='<img src="'+this.imagearray[index][0]+'" alt='+this.imagearray[index][3]+' />'
	slideHTML+=(this.imagearray[index][1])? '</a>' : ''
	return slideHTML //return HTML for the slide at the specified index
}

flashyslideshow.prototype.rotate=function(){
	var wrapperdiv=document.getElementById(this.wrapperid)
	this.currentimg=(this.currentimg<this.imagearray.length-1)? this.currentimg+1 : 0
    this.filters = scegliFiltro(wrapperdiv, this.transduration);  
	this.pause+=this.transduration; //add transition time to pause
	this.filtersupport=(wrapperdiv.filters && wrapperdiv.filters.length>0)? true : false //test if element supports transitions and has one defined
		 
	if (this.filtersupport)
    	wrapperdiv.filters[0].apply()
		
	wrapperdiv.innerHTML=this.getSlideHTML(this.currentimg)
	
	if (this.filtersupport)
		wrapperdiv.filters[0].play(this.transduration)	
}

function scegliFiltro(wpId,transduration){
	var effectindex=Math.floor(Math.random()*global_transitions.length) //randomly pick a transition to utilize
	if (wpId.filters){ //if the filters[] collection is defined on element (only in IE)
		wpId.style.filter=global_transitions[effectindex] //define transition on element
	}
	return wpId.style.filter;
}

///Sample call on your page
/*
var flashyshow=new flashyslideshow({ //create instance of slideshow
	wrapperid: "myslideshow", //unique ID for this slideshow
	wrapperclass: "flashclass", //desired CSS class for this slideshow
	imagearray: [
		["summer.jpg", "http://en.wikipedia.org/wiki/Summer", "_new", "Such a nice Summer getaway."],
		["winter.jpg", "http://en.wikipedia.org/wiki/Winter", "", "Winter is nice, as long as there's snow right?"],
		["spring.jpg", "", "", "Flowers spring back to life in Spring."],
		["autumn.jpg", "", "", "Ah the cool breeze of autumn."]
	],
	pause: 2000, //pause between slides (milliseconds)
	transduration: 1000 //transition duration (milliseconds)
})
*/