var slideshow_lasttime=new Date().getTime();
var gallerycounter = 0;
var stopslideshow = false;
function moveGallery(counter){
	slideshow_lasttime=new Date().getTime();
	x = jQuery("#gallery .active");
	if (jQuery(x).get(0)!==jQuery("#gallery-"+counter).get(0)){
		jQuery(x).removeClass("active");
		jQuery("#gallery-"+counter).addClass("active");
	}
}
function gallerySlideshow(){
	if (stopslideshow)
		return;
	if (slideshow_lasttime<new Date().getTime()-1000*10){
		gallerycounter++;
		if (gallerycounter > 3){
			gallerycounter = 1;
		}
		moveGallery(gallerycounter);
	}
	setTimeout('gallerySlideshow()',1000);
}

jQuery(function(){
	jQuery("#activedescription").empty().append(jQuery(".active .entry").clone());
	jQuery(".thumbnail-image a").click(function(){
		x = jQuery("#campaign-gallery .active");
		currentpost = jQuery(this).parent().parent();
		if (jQuery(x).get(0)!==jQuery(currentpost).get(0)){
			jQuery(currentpost).addClass("active").find(".fullimage").show();
			jQuery("#activedescription").empty().append(jQuery(currentpost).find(".entry").clone());
//			jQuery(x).find(".fullimage").fadeOut();
			jQuery(x).removeClass("active");
		}
		return false;
	});
	
	jQuery("#gallery .gallery-nav a").click(function(){
		moveGallery(jQuery(this).attr("counter"));
		return false;
	});
	jQuery("#gallery .fullimage").click(function(){
		stopslideshow = true;
		if (jQuery(this).find("object").size()>0)
			jQuery(this).find("img").hide();
		if (jQuery(this).is("object"))
			return true;
		return false;
		
	});
	setTimeout('gallerySlideshow()',1000);
	
});

