
var windowSlideshow;
var images = new Array();
var __preloadImgs = new Array();
var imageIndex = 0;
var slideshow = null;
var dictionary = [ "dummy",
					{ btnClose: "Schließen" },
					{ btnClose: "close" },
					{ btnClose: "close" },
					{ btnClose: "close" },
					{ btnClose: "close" },
					{ btnClose: "close" }];
			
function openSlideshow(id_node){
		
	this.images = new Array();
	this.__preloadImgs = new Array();
	
	showWindow();
	drawWindow(); 
	renderContent( id_node );
}

function closeWindow(){
	
	var overlay = $('container_overlay');
	var popup = $('popup_frame');
	overlay.hide();
	popup.hide();
}

function showWindow(){
	
	var overlay = $('container_overlay');
	var popup = $('popup_frame');
	overlay.show();
	popup.show();
}

function drawWindow() {
	
	var overlay = $('container_overlay');
	var popup = $('popup_frame');
	popup.style.width = "600px";
	popup.style.height = "400px";
	
	var content = 	'<div id="popup_head">'+
					'	<div id="popup_title">WIESNER HAGER - SLIDESHOW</div>'+
					'	<img id="icon_close" src="/_custom/gfx/common/btnClose.gif" alt="" onclick="closeWindow()" />'+
					'</div>'+						
					'<div id="popup_body">'+	
					'	<div id="slide_detail"></div>'+	
					'	<div id="slide_list" style="position: absolute;left: 430px;top: 25px;width: 168px;height: 326px;padding: 0;text-align:center;overflow:hidden;"></div>'+	
					'</div>'+					
					'<div id="popup_foot">'+
					'	<button id="btnClose" onclick="closeWindow()">'+ dictionary[curLang].btnClose +'</button>'+
					'</div>';
	
	popup.innerHTML = content;					
}

function renderContent( id_node ) {
						
	var body = $('popup_body');
	
	var srvfnc = "getSlideshowDetail";
	new Ajax.ServerCall("SlideshowModul", srvfnc, [id_node], { onSuccess: function(response) {
		
		var data = eval( response.responseText );
						
		$('slide_detail').innerHTML = '';
		$('slide_list').innerHTML = '';
		
		preload( data[0].files );
		preload( data[0].thumbs );
		
		//Build images-array and append thumbs
		for( var i=0; i<data[0].thumbs.length; i++ )  {
				
			var img = document.createElement("img");
			img.src = data[0].thumbs[i];
			images.push( data[0].files[i]);
			img.alt = "";
			img.id = 'img_'+i;
			Event.observe(img, 'click', replaceDetailImage); 			
			
			$('slide_list').appendChild( img );
		}
		
		pic = document.createElement("img");
		pic.src = images[0];
		pic.alt = "";
		
		$('slide_detail').appendChild( pic );				
						
	}});	
			
	var scrollbar1 = new UIScrollbar( $('slide_list'), {
		width: 14,
		marginHorizontal: 2,
		innerMargin: 3,
		areaActiveBorder: "1px solid #ccc",
		areaActiveBg: "#fff",
		areaDisabledBorder: "1px solid #fff",
		areaDisabledBg: "#fff",
		sliderActiveBorder: "",
		sliderActiveBg: "#ccc",
		sliderDisabledBorder: "#fff",
		sliderDisabledBg: "#fff",
		btnUpActive: "/_custom/gfx/common/scrollbar/scroll-up-active.gif",
		btnUpDisabled: "/_custom/gfx/common/scrollbar/scroll-up-disabled-white.gif",
		btnDownActive: "/_custom/gfx/common/scrollbar/scroll-down-active.gif",
		btnDownDisabled: "/_custom/gfx/common/scrollbar/scroll-down-disabled-white.gif"
	} );
	
}

function replaceDetailImage( img ){

	var img = Event.element(img);
	
	var index = img.id.substr(4);
	var d = $('slide_detail');
	d.innerHTML = '';
	pic = document.createElement("img");
	pic.src = images[index];
	pic.alt = "";
	
	d.appendChild( pic );
}

function preload(images){

	/*
	var temp = [];
	
	for (var i = 0; i < images.length; i++) {
		
		temp[i] = new Image();
		temp[i].src = images[i];
		__preloadImgs.push(temp);
	}	
	*/
}

