var PictureGal = {

	data: null,
	counter: 0,

	open: function(src, counter){
		var iframe = this.$('picture_win');
		var bgrd = this.$('picture_win_bgrd');

		if (typeof bgrd != 'undefined'){
			var wrapper = document.createElement('DIV');
			wrapper.id = 'wrap_picture_win_bgrd';
			wrapper.innerHTML = '<div id="picture_win_bgrd" onclick="PictureGal.close(this)"></div>';
			document.body.appendChild(wrapper);
			var bgrd = this.$('picture_win_bgrd');
		}

		if (typeof iframe != 'undefined'){
			var wrapper = document.createElement('DIV');
			wrapper.id = 'wrap_picture_win';
			wrapper.innerHTML = '<iframe src="" id="picture_win" scrolling="no" frameborder="0"></ifeame>';
			document.body.appendChild(wrapper);
			var iframe = this.$('picture_win');
		}

		iframe.src = src.href;
		iframe.style.top = (eval(document.body.scrollTop) + 40) + 'px';
		bgrd.style.display = 'block';

		iframe._counter = counter || 0;

		return false;
	},

//--------------------------------------------------------------------------------

	close: function(){

		var ob = this.$('wrap_picture_win_bgrd', true);
		ob.parentNode.removeChild(ob);
		var ob = this.$('wrap_picture_win',    true);
		ob.parentNode.removeChild(ob);

		this.data    = null;
		this.counter = 0;

		return false;
	},

//--------------------------------------------------------------------------------

	init: function(data){
		this.counter = parseInt(this.$('picture_win', true)._counter);
		this.data    = data;
		this.$('colpict').innerHTML = this.data.length;
	},

//--------------------------------------------------------------------------------

	first: function() {return this.img(0)},
	last:  function() {return this.img(this.data.length - 1)},
	next:  function() {return this.img(this.counter == this.data.length - 1 ? 0 : this.counter + 1)},
	prev:  function() {return this.img(this.counter == 0 ?  this.data.length - 1 : this.counter - 1)},

//--------------------------------------------------------------------------------

	img: function(index)
	{
		if (isNaN(index)) index = this.counter;
		if ( ! this.data[index]) return;

		this.counter = index;

		this.$('num').innerHTML  = this.counter + 1;

		if (this.data[index].flash == true){
			var html = "<object type='application/x-shockwave-flash' data='"
				+ this.data[index].i
				+ "' width='" + this.data[index].w
				+ "' height='" + this.data[index].h
				+ "'><param name='movie' value='" + this.data[index].i
				+ "' /><param name='quality' value='high' /></object>";
		}
		else{
			var html = '<img id="prew-picture" src="' + this.data[index].i + '">';
		}
		this.$('prew-picture-swf').innerHTML = html;

		t = this.data[index].t;
		this.$('prew-text-box').style.display = t ? 'block' : 'none';
		this.$('prew-text').innerHTML = t;

		this.resize(this.data[index].w, this.data[index].h, (t?30:0));

		return false;
	},

//--------------------------------------------------------------------------------

	resize: function(w, h, k)
	{
		w += 40;
		h += 100 + k;
		$(this.$('picture_win', true)).animate({
			width:      w,
			height:     h,
			marginLeft: - Math.abs(Math.ceil(w/2))
		}, 400);
	},

//--------------------------------------------------------------------------------

	$: function(id, prpt)
	{
		prpt = prpt ? parent.document : document;
		return prpt.getElementById(id)
	}

}