// JavaScript Document
function fixImages(){
	$("#pageContent img").each(function(){
		var img = $(this),
	    src = img.attr("src");
		if(src.indexOf("/thumbs/") == -1){
			img.attr("src",src + "?width=" + img.width() + "&height=" + img.height());
		}

	});
}

(function ($) {
	$.fn.gwpImageFade = function(options){
		var opts = $.extend({}, $.fn.gwpImageFade.defaults, options);
		
		return this.each(function(){
			$this = $(this);
			$image = $this.find("img:last");
			$clone = $image.clone();
			pauseInt = parseInt(opts.pause) * 1000;
			durationInt = parseInt(opts.duration) * 1000;
			var rotate = function rotateImage(){
				$image.stop().fadeTo(pauseInt,1).fadeTo(durationInt,0,function(){
					$image.remove();
					$this.prepend($clone);
					$.fn.gwpImageFade.rotate();
				});
			}
			rotate();
		});
	};
	$.fn.gwpImageFade.defaults = {
		pause:5,
		duration:5
	};
})(jQuery);


function rotateImage()
{
	var $carousel = $("#imageCarouselWrap"),
		$image = $("#imageCarouselWrap > img:last"),
		$clone = $image.clone();
	$image.stop().fadeTo(5000,1).fadeTo(5000,0,function(){
		$image.remove();
		$carousel.prepend($clone);
		rotateImage();
	});
	
	return false;
}

function startRotation()
{
	$("#imageCarouselWrap").fadeIn();
	rotateImage();
}

$(document).ready(function(){
	var $carousel = $("#imageCarousel");	
	if($carousel.length > 0){
		window.setTimeout(startRotation, 4000);
		//$("#imageCarouselWrap").gwpImageFade({duration:2});
	}
    
        
});

