jQuery(function(){
});

var j 			= 0;
var currentPict	= 0;


// checks, if the first image of the large gallery is loaded and calls itself as long as the first image is not loaded
function checkFirstImage(){
	if(document.getElementById("0").complete ){
		setLargeGallery();
	}else{
		setTimeout(checkFirstImage, 100);
	}
};

// activates the div containers called 'largeimg' for animated gallery actions
function setLargeGallery(){
		
		$('#largeimg').slideViewLarge();
};

// function for the large image gallery
jQuery.fn.slideViewLarge = function(settings) {
	  settings = jQuery.extend({
     easeFunc: "expoinout",
     easeTime: 750,
     toolTip: false
  }, settings);
	return this.each(function(){
		var container = jQuery(this);
		container.find("img.ldrgif").remove(); // removes the preloader gif
		container.removeClass("svw").addClass("stripViewerLarge");		
		var pictWidth = container.find("li").find("img").width() ;
		var pictHeight = container.find("li").find("img").height();
		var pictEls = container.find("li").size();
		var stripViewerWidth = (pictWidth+1)*pictEls;
		var currentPict=0;
		var counter=0;
		container.find("ul").css("width" , stripViewerWidth); //total size of the ul list
		container.css("width" , pictWidth);
		container.css("height" , pictHeight);
		container.each(function(i) {
			
			// writes the div-boxes staight to html dom
			jQuery(this).after("<div class='stripTransmitter' id='stripTransmitter" + j + "'><div id='img_menu'></div><\/div>");
			
			// writes a numerouse anchor for each picture of the gallery into the image-navigation-menu
			jQuery(this).find("li").each(function(n) {
						counter++;
						jQuery("div#stripTransmitter" + j + " #img_menu").append(" <a title='" + jQuery(this).find("img").attr("alt") + "' href='#'>"+(n+1)+"<\/a> ");												
				});
			
			// handle the click-event for each anchor of the image-navigation-menu
			jQuery("div#stripTransmitter" + j + " a").each(function(z) {
				jQuery(this).bind("click", function(){
				if (z==currentPict) return;
				jQuery(this).addClass("current").parent().parent().find("a").not(jQuery(this)).removeClass("current"); //removes the current class and sets it to the current active anchor
				currentPict = z; //updates the current picture
				var cnt = - ( (pictWidth + 1) * z); //calculates the length in pixels for animation
				jQuery(this).parent().parent().prev().find("ul").animate({ left: cnt}, settings.easeTime, settings.easeFunc); //animates the ul list with the images inside				
				return false;
				   });
				});
			
			// handle the click event vor the prev button
			jQuery("#nav_left").each(function(){
				jQuery(this).bind("click", function(){
				var i = currentPict-1;
				jQuery("#slide #img_menu").find('a').eq(i).click();
				return false;
				});
			});		
			
			// handle the click event vor the next button
			jQuery("#nav_right").each(function(){
				jQuery(this).bind("click", function(){
				var i = currentPict+1;
				jQuery("#slide #img_menu").find('a').eq(i).click();
				return false;
				});				
			});
			
			//hides the image-navigation-menu
			jQuery('#slide #img_menu').hide();			
				
			jQuery("div#stripTransmitter" + j).css("width" , pictWidth);
			jQuery("div#stripTransmitter" + j + " a:eq(0)").addClass("current");
			
			});
		j++;
  });	
};
