var photoExt = {

	data: null,
	current: 0,

	open: function(obj, current)
	{
		var iframe = this.$('photo_ext');
		var bg = this.$('photo_ext_bg');

		

		if (typeof bg != 'undefined')
		{
			var wrapper = document.createElement('DIV');
			wrapper.id = 'wrap_photo_ext_bg';
			wrapper.innerHTML = '<div id="photo_ext_bg" onclick="photoExt.close(this)"></div>';
			document.body.appendChild(wrapper);
			var bg = this.$('photo_ext_bg');
		}

		if (typeof iframe != 'undefined')
		{
			var wrapper = document.createElement('DIV');
			wrapper.id = 'wrap_photo_ext';
			wrapper.innerHTML = "<div id='wrap_photo_ext_box' class='photo_box2'><dl><dt></dt><dd></dd></dl>" +
					"<div class='r'><div class='l'><div id='photo_ext_box'></div></div></div>" +
				"<dl class='b'><dt></dt><dd></dd></dl></div>";
			document.body.appendChild(wrapper);
			
			this.$('photo_ext_box').innerHTML = "<iframe src='' id='photo_ext' scrolling='no' frameborder='0'></ifeame>";
			
			var iframe = this.$('photo_ext');
		}
		
		iframe.src = obj.href;
		iframe.style.top     = (eval(document.documentElement.scrollTop) + 40) + 'px';
		bg.style.display     = 'block';

		iframe._current = current || 0;
		
		//this.$('container').className = 'loginet';
		
		return false;
	},

	//--------------------------------------------------------------------------------

	close: function()
	{

		var ob = this.$('wrap_photo_ext_bg', true);
		ob.parentNode.removeChild(ob);
		var ob = this.$('wrap_photo_ext',    true);
		ob.parentNode.removeChild(ob);

		this.data    = null;
		this.current = 0;
		
		this.$('container').className = '';
		
		return false;
	},

	//--------------------------------------------------------------------------------

	init: function(data)
	{
		this.current = parseInt(this.$('photo_ext', true)._current);
		this.data    = data;
		this.$('colvo').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.current == this.data.length - 1 ? 0 : this.current + 1)},
	prev:  function() {return this.img(this.current == 0 ?  this.data.length - 1 : this.current - 1)},

	//--------------------------------------------------------------------------------

	img: function(index)
	{
		if (isNaN(index)) index = this.current;
		if ( ! this.data[index]) return;

		this.current = index;


		this.$('num').innerHTML  = this.current + 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-photo" src="' + this.data[index].i + '">';
		}
		this.$('prew-photo-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;
		var t = parseInt($(this.$('photo_ext', true)).css('top'));
		if (t+h+10 > parent.document.body.offsetHeight) t -= t+h+10 - parent.document.body.offsetHeight;
		
		$(this.$('photo_ext', true)).css({
			width:      w,
			height:     h
		});
		
		$(this.$('wrap_photo_ext_box', true)).animate({
			width:      w + 40,
			height:     h,
			top:        t - 20,
			marginLeft: -Math.abs(Math.ceil(w/2))
		}, 400);
		
		
	},

	//--------------------------------------------------------------------------------

	$: function(id, prnt)
	{
		prnt = prnt ? parent.document : document;
		return prnt.getElementById(id)
	}

}
