function open_img_big(img, pic_width, pic_height, pic_path){
	//var pic_id = $(img).getProperty('id');	
	//var pic_height = parseInt($(pic_id+'_height').getProperty('value')) + 0;
	//var pic_width = parseInt($(pic_id+'_width').getProperty('value')) + 0;
//	var pic_path = $(pic_id+'_path').getProperty('value'); 
	//alert(pic_path);
	var wraper = new Element('div', {id:'img_wraper', styles:{width:pic_width+'px', 'overflow':'hidden'}});
	var bilde = new Element('img', {src: pic_path, styles: {width:pic_width+"px"}});	
	//var text_dic = new Element('div', {html:$(img).get('bilde_text'), styles:{height:'20px', 'overflow':'hidden'}});
	bilde.inject(wraper);	
	//text_dic.inject(wraper);	
	SqueezeBox.fromParams({handler:'div', size:{x:pic_width+0,y:pic_height}, div_cont:wraper, divOptions:{styles:{overflow:'hidden'}}, onClose:function(){
		var bilde_f = bilde;
		var wraper_f = wraper;
		delete bilde_f;
		delete wraper_f;		
	}});	
}
function flash_img_clicked(img_ind){
	var img_flash = $('flash_holder');
	var pic_width = parseInt(img_flash.get_tag_property(img_ind, 'big_img_src', 'width'));	
	var pic_height = parseInt(img_flash.get_tag_property(img_ind, 'big_img_src', 'height'));	
	var pic_src = img_flash.get_tag_value(img_ind, 'big_img_src');
	var wraper = new Element('div', {id:'img_wraper', styles:{width:pic_width+'px', 'overflow':'hidden'}});
	var bilde = new Element('img', {src: pic_src, styles: {width:pic_width+"px"}});	
	//var text_dic = new Element('div', {html:$(img).get('bilde_text'), styles:{height:'20px', 'overflow':'hidden'}});
	bilde.inject(wraper);	
	//text_dic.inject(wraper);	
	SqueezeBox.fromParams({handler:'div', size:{x:pic_width+0,y:pic_height}, div_cont:wraper, divOptions:{styles:{overflow:'hidden'}}, onClose:function(){
		var bilde_f = bilde;
		var wraper_f = wraper;
		delete bilde_f;
		delete wraper_f;		
	}});
}

var FlashFadeSetup = new Class({
	Implements: [Options, Events],
	options : {
		toc_id: '.toc_item',
		toc_rel: 'toc_',
		active_toc_postfix: 'item_selected',
		next_id: 'media-next',
		prev_id: 'media-prev',
		transitionIn: 'fadeOutFadeIn',
		transitionOut: 'fadeOutFadeIn',
		flash_text_id: 'flash_text'
	},
	
	flash_dom: null,
	active_toc: null,
	curr_pic: null,
	curr_ind: 0,
	prev_ind: -1,
	flash_id: '',
	flash_json: null,
	num_pics: 0,
	initialize : function(options){
		this.setOptions(options);
	},

	init: function(flash_dom, options){
		this.setOptions(options);
		this.flash_id = flash_dom;
	},
	
	xml_parsed: function(json){
		var doc = this;
		if(typeof(json) != 'undefined'){
			this.flash_dom = $(this.flash_id);
			this.flash_json = json;
			this.num_pics = json.totalImg;
	
			$(this.options.next_id).addEvent('click', function(){
				doc.flash_dom.next_image(doc.options.transitionIn);
			});

			$(this.options.prev_id).addEvent('click', function(){
				doc.flash_dom.pr_image(doc.options.transitionOut);
			});

			this.set_flash_text(0);
			this.setupToc();
		}
	},

	switch_pic: function(ind){
		var doc = this;
		var selected = $(this.options.toc_rel+ind);
		var active_toc_class = this.options.toc_rel+this.options.active_toc_postfix;
		
		if(this.active_toc != null){
			this.active_toc.removeClass(active_toc_class);
		}

//		if (locked_pic[ind] == true) return;
//		locked_pic[this.curr_ind] = false;
//		locked_pic[ind] = true;
		this.curr_ind = ind;
		
		selected.addClass(active_toc_class);
		this.active_toc = selected;
		this.prev_ind = this.curr_ind;
		this.set_flash_text(this.curr_ind);
	},

	goto_pic: function(ind){
		var doc = this;
		this.curr_ind = ind;
		var transition = this.options.transitionOut;
		if(this.prev_ind < this.curr_ind){
			transition = this.options.transitionIn;
		}

		this.flash_dom.goto_image(this.curr_ind, transition);
		this.switch_pic(this.curr_ind);
	},

	set_flash_text: function(ind){
		var doc = this;
		var flash_title = this.flash_dom.get_tag_value(ind, 'img_title');
		var flash_text = this.flash_dom.get_tag_value(ind, 'img_text');

		var flash_text_div = $(this.options.flash_text_id);
		flash_text_div.set('html', flash_text);
		flash_text_div.addClass(this.options.flash_text_id);

		if(flash_text == ""){
			flash_text_div.removeClass(this.options.flash_text_id);
		}
	},
	
	setupToc : function(){
		var doc = this;
		var tocs = $$('.toc_item');
		var toc = $('toc');

		this.active_toc = toc.getElement("span");
		this.active_toc.addClass(doc.options.toc_rel+doc.options.active_toc_postfix);

		tocs.addEvents({
			'click': function(e){
				var rel = this.get('id').replace(doc.options.toc_rel,'');
				doc.goto_pic(rel);
				e.stop();
			}
		});
	}

});

var flash_fade_setup = new FlashFadeSetup();
