/*
 - Description
	jQuery Dynamic Slideshow Plugin
 - Author
	Yusuf Najmuddin (ynzi.com)
 - Licence
	GNU Lesser General Public License
 - Usage
	$("#slideshow").dynamicSlideshow();

	OR

	$("#slideshow").dynamicSlideshow({duration: 5000});

 - Date 6/30/2009
 - Version 1.0

*/


jQuery.fn.dynamicSlideshow = function(attr) {

	attr = attr || {};
	attr.duration = attr.duration || 3000;
	attr.intervalID;
	var i;
	function initSlider(container, img) {
		var curr = 1;
		clearInterval(attr.intervalID);
		attr.intervalID=setInterval( function(){
			if (curr == img.length) {
				curr = 0;
			}
			i = new Image();
			$(i).load(function(){
				$(container).append(this);
				$(container).find('img:first').css({'z-index': 1});
				//$(this).hide();	
				if(isIE){addIECorners(); }else {  addCorners();}	
				if(isIE){
								$(container).find('VAR:last').css({opacity: 0.0, 'z-index': 2}).animate({opacity: 1.0}, 1000, function() {
						$(container).find('VAR:first').remove();
						//$(container).html();
					});
				
		         }
				 else{
				 				$(container).find('canvas:last').css({opacity: 0.0, 'z-index': 2}).animate({opacity: 1.0}, 1000, function() {
						$(container).find('canvas:first').remove();
					});
				 }
			}).addClass('corner').addClass('iradius20').attr('src', img[curr++]).css({position:'absolute',top:0,left:0,'z-index':8});
		}, attr.duration );
	};

	$(this).each(function(){
		var img = [];
		$(this).find("a").each(function(){
			img.push($(this).attr("href"));		
		});
		var j = new Image();
		var container = this;
		$(this).empty();

		$(j).load(function(){
			$(container).append(this);if(isIE){addIECorners(); }else {addCorners();}initSlider(container, img);
		}).attr('src', img[0]).addClass('corner').addClass('iradius20').css({position:'absolute',top:0,left:0,'z-index':0});
	});
}


