/*
 * ONLY USE AFTER THICKBOX
 */

if(!tb_image_onclick) alert('ONLY USE GALLERY AFTER THICKBOX');

//modify thickbox
thickbox_img_text ="ERROR";
tb_fixed_image_height = false; 
tb_image_onclick = function(){
	GAL.next();
}

GAL = {};

GAL.tb_info_html = new Array(
	"<div id='tb_image_text'>"+
		"<div id='tb_image_info'>"+
		"",
		"</div>"+
		"",
	"",
	"</div>"+
	""
); 
	
GAL.tb_navi_html = new Array(
	"<div id='tb_image_navi'>" +
		"<a href='#' class='thickbox' onclick='GAL.prev()' title='previous'>previous</a> | "+
		"<a href='#' class='thickbox' onclick='GAL.next()' title='next'>next</a> | "+
		"<a id='link_high_res' href='","' target='blank'class='thickbox' title='high res'>high res </a> | "+
		"<a href='#' id='TB_closeWindowButton' title='close'>close</a>"+
		"<br />© Berlinale Talent Campus"+
	"</div>" +
	""
);

GAL.current = 0;

/*
	text for first opening must be generated before opening thickbox...
*/
GAL.set_current = function(current){
	this.current = current;
	
	thickbox_img_text = 
	this.tb_navi_html[0] +
	this.current_high_res_url() +
		this.tb_navi_html[1] +
		this.tb_info_html[0] + 
		this.current_descr() +
		this.tb_info_html[1] +
		this.tb_info_html[2] +
		this.tb_info_html[3] +
		"";
	this.set_high_res();
}

/*
	called when clicking on a gallery image
*/
GAL.set_current_text = function(){
	$('#tb_image_info').html(this.current_descr());
}

GAL.set_high_res = function(){
	$('#link_high_res').attr('href',this.current_high_res_url());
}

GAL.current_descr = function(){
	var descr = this.images[this.current].descr;
	if(!descr)descr = '&nbsp;';
	return descr;
}

GAL.current_url = function(){
	return this.images[this.current].url_big;
}

GAL.current_high_res_url = function(){
	return this.images[this.current].url;
}

GAL.refresh_window_data = function(){
	$('#TB_Image').attr('src',GAL.current_url());
	this.set_current_text();
	this.set_high_res();
}

GAL.next = function(){
	this.current ++;
	this.current %= this.images.length;
	this.refresh_window_data();
	return false;
}

GAL.prev = function(){
	this.current = this.current + this.images.length - 1;//%2 on -1 = -1
	this.current %= this.images.length;
	this.refresh_window_data();
	return false;	
}

