var tabs;
var selected = 0;
/*
Copyright (c) 2009 Michal Charemza
Released under MIT License http://www.opensource.org/licenses/mit-license.php
*/

var SlidingTabs = new Class({

Implements: [Options],

options: {
	high: {top: 0, left: 0},
	low: {top: 0, left: 0},
	show: {},
	hideInitial: {height: 0},
	hide: {height: 0, opacity: 0},
	endShow: {'z-index': 10},
	endShowHidden: {opacity:1, 'z-index': 30},
	titleSelector: 'h3',
	contentSelector: '.section'
},

initialize: function(container, options) {
	this.setOptions(options);
	var titles = container.getElements(this.options.titleSelector);
	this.contents = container.getElements(this.options.contentSelector);
	
	var originalHeight = titles[0].getStyle('height').toInt();
	var heights = this.contents.getSize().map(function(size) {return {height:originalHeight + size.y}});
	var contentsHeightsShow = heights.map(function(h) {return $merge(this.options.show,{height:(h.height-originalHeight)})},this);
		
	var highlightOne = new Fx.Preset(Fx.Presets.Unique, [this.options.high, this.options.low]);
	var lowlightAll = new Fx.Preset(Fx.Presets.All, this.options.low);

	var toContentSize = new Fx.Preset(Fx.Presets.Arbitrary, [heights]);		
	var showOne = new Fx.Preset(Fx.Presets.ArbitraryUnique, [contentsHeightsShow, this.options.hide]);

	var hideAll = new Fx.Preset(Fx.Presets.All, this.options.hide);
	var toOriginalSize = new Fx.Preset(Fx.Presets.All, {height: originalHeight});

	this.showTab = [highlightOne, showOne, toContentSize];
	this.hideTabs = [lowlightAll, hideAll, toOriginalSize];

	this.fx = new Fx.Elements.Preset([titles, this.contents, [container]], {link:'chain', duration:'long'})
	this.fx.addEvent('complete', this.onEnd.bind(this));

	this.contents.setStyles(this.options.hideInitial);

	titles.each(function(box, i) {
		box.addEvent('click', function() {
			tabs.buttonevent(box, i)
		});
	}, this);
//	titles.each(function(box, i) {
//		box.addEvent('click', this.highlight.bind(this, i));
//	}, this);	
//	$(document.body).addEvent('click', function(ev) {
//		container.hasChild(ev.target) || this.reset();
//	}.bind(this));
},
buttonevent: function(box, i) {

	this.highlight(i);
	var sel = $$('.selected');
	sel.each(function(item, index) {
		item.removeClass('selected');
	});		
	box.addClass('selected');	
},
onEnd: function(i) {
	this.contents.filter(function(el, j) {return (j != i);}).setStyles(this.options.endShowHidden);
	!$defined(i) || this.contents[i].setStyles(this.options.endShow);
},

highlight: function(i) {
	this.isReset = !this.fx.start(this.showTab, i);
},

reset: function() {
	this.isReset = this.isReset || this.fx.start(this.hideTabs);
}

});

window.addEvent('domready', function() {
	var hidden = $$('div.hidden')
	hidden.each(function(item, index) {
		item.removeClass('hidden');
	});	
	tabs = new SlidingTabs($('tabs'));
	if(selected.toInt() > 0)
		tabs.highlight(selected-1);
});

function show(images, w, h) 
{
    MyImg = new Image();
    MyImg.src = images;
	var i = w + 30;
    var j = h + 60;
    config = 'scrollbars,resizable,width='+i+', height='+j+', left=50, top=10'; 
    var okno = window.open("/image.php?img="+images,"img",config);
    okno.resizeTo(i,j);
    okno.focus();
}
/****************************************
Copyright (c) 2004 Tomasz Elendt- Elu
****************************************/
function t(v,e,t)
{
if(!v.title||!document.createElement)return
t=document.createElement("div")
t.move=function(e)
{
  e=e||event
  t.style.left=e.clientX+15+(document.documentElement.scrollLeft||document.body.scrollLeft)+"px"
  t.style.top=e.clientY+22+(document.documentElement.scrollTop||document.body.scrollTop)+"px"
}
t.hide=function(x)
{
  v.title=t.innerHTML
  if(x=document.getElementById("tooltip")) document.body.removeChild(x)
}
t.move(e);
t.id="tooltip"
t.innerHTML=v.title;v.title=""
document.body.appendChild(t)
v.onmouseout=t.hide
v.onmousemove=t.move
}