function Get(el) { return document.getElementById(el); }
function GetCSSProperty(el, prop)
{
 if(typeof(el.currentStyle) == 'undefined') return window.getComputedStyle(el, '').getPropertyValue(prop)
 else
  {
	var index = prop.indexOf('-');
	if(index != -1) prop = prop.replace(prop.substr(index, 2), prop.substr(index + 1, 1).toUpperCase());
	return el.currentStyle[prop];
  }
}
function SetOpacity(el, val)
{
 if(typeof(el.filters) == 'undefined') el.style.opacity = val;
 else
  {
	val *= 100;
    var oAlpha = el.filters['DXImageTransform.Microsoft.alpha'] || el.filters.alpha;
    if(oAlpha) oAlpha.opacity = val;
    else el.style.filter += "progid:DXImageTransform.Microsoft.Alpha(opacity=" + val + ")";
  }
}
function GetOpacity(el)
{
 if(typeof(el.filters) == 'undefined') return parseFloat(GetCSSProperty(el, 'opacity'));
 else
  {
	var oAlpha = el.filters['DXImageTransform.Microsoft.alpha'] || el.filters.alpha;
    return (typeof(oAlpha) == 'undefined') ? 1.0 : oAlpha.opacity / 100;
  }
}
function Animate(el, speed, inc)
{
 var func = function(sender)
  {
	var opacity = GetOpacity(sender);
	if(inc ? opacity < 0.999 : opacity > 0.001) SetOpacity(el, (inc ? opacity += speed : opacity -= speed).toFixed(2));
	else clearInterval(sender.interval);
  };
 clearInterval(el.interval);
 el.interval = setInterval(function(){func(el);}, 50);
}
function ClickNext(ctr){/*TurnOffContainer();*/Next(ctr);}
function ClickPrevious(ctr){/*TurnOffContainer();*/Previous(ctr);}
function EnableBtns(ctr)
{
 ctr.nextSibling.onclick = function(){ClickNext(this.previousSibling);};
 ctr.previousSibling.onclick = function(){ClickPrevious(this.nextSibling);};
}
function DisableBtns(ctr)
{
 ctr.nextSibling.onclick = function(){};
 ctr.previousSibling.onclick = function(){};
}
function Activate(el, ctr)
{
 ctr[(el == 'next' ? 'next' : 'previous') + 'Sibling'].className = 'btn ' + (el == 'next' ? 'down' : 'up');
}
function Deactivate(el, ctr)
{
 ctr[(el == 'next' ? 'next' : 'previous') + 'Sibling'].className = 'btn ' + (el == 'next' ? 'down' : 'up') + '_disabled';
}
function Next(ctr)
{
 var first = GetFirstVisible(ctr);
 var last = GetLastHidden(ctr);
 if(first && last)
  {
	DisableBtns(ctr);
	Hide(first);
	Show(last);
	Activate('prev', ctr);
  }
// if(!GetLastHidden(ctr)) Deactivate('next', ctr);
 if(!GetLastHidden(ctr))
  {
	var node = GetItems(ctr)[0];
	node.parentNode.appendChild(node);
  }
}
function Previous(ctr)
{
 var first = GetFirstHidden(ctr);
 var last = GetLastVisible(ctr);
 if(first && last)
  {
	DisableBtns(ctr);
	Hide(last);
	Show(first);
	Activate('next', ctr);
  }
// if(!GetFirstHidden(ctr)) Deactivate('prev', ctr);
 if(!GetFirstHidden(ctr))
  {
	var items = GetItems(ctr);
	var node = items[items.length - 1];
	var parent = node.parentNode;
	if(parent.childNodes.length == 1) parent.appendChild(node);
	else parent.insertBefore(node, parent.firstChild);
  }
}
function Hide(el)
{
 var prev_h = GetCSSProperty(el, 'height');
 var h = parseInt(prev_h);
 var p_h = h;
 var i = setInterval(function()
  {
	if((h -= 5) > 0)
	 {
		el.style.height = h + 'px';
		SetOpacity(el, h / p_h);
	 }
	else
	 {
		el.style.height = prev_h;
		el.style.display = 'none';
		EnableBtns(el.parentNode);
		SetOpacity(el, 1);
		clearInterval(i);
	 }
  }, 10);
}
function Show(el)
{
 var prev_h = GetCSSProperty(el, 'height');
 var h = 1;
 var p_h = parseInt(prev_h);
 el.style.height = '0px';
 el.style.display = 'block';
 var i = setInterval(function()
  {
	if((h += 5) < parseInt(prev_h))
	 {
		el.style.height = h + 'px';
		SetOpacity(el, h / p_h);
	 }
	else
	 {
		el.style.height = prev_h;
		EnableBtns(el.parentNode);
		SetOpacity(el, 1);
		clearInterval(i);
	 }
  }, 10);
}
function GetFirstVisible(ctr)
{
 var els = GetItems(ctr);
 if(!els.length) return null;
 for(var i = 0; i < els.length; ++i) if(els[i].style.display != 'none') return els[i];
 return null;
}
function GetLastVisible(ctr)
{
 var els = GetItems(ctr);
 if(!els.length) return null;
 for(var i = els.length - 1; i >= 0; --i) if(els[i].style.display != 'none') return els[i];
 return null;
}
function GetFirstHidden(ctr)
{
 var els = GetItems(ctr);
 if(!els.length || els[0].style.display != 'none') return null;
 for(var i = 1; i < els.length; ++i) if(els[i - 1].style.display == 'none' && els[i].style.display != 'none') return els[i - 1];
 return null;
}
function GetLastHidden(ctr)
{
 var els = GetItems(ctr);
 if(!els.length || els[els.length - 1].style.display != 'none') return null;
 for(var i = els.length - 1; i > 0; --i) if(els[i].style.display == 'none' && els[i - 1].style.display != 'none') return els[i];
 return null;
}
function GetItems(ctr){return ctr.getElementsByTagName('div');}
function Timer()
{
 var interval = null;
 var _function = null;
 var _interval = null;
 this.SetFunction = function(func){_function = func;};
 this.SetInterval = function(intv){_interval = intv;};
 this.Start = function(){interval = setInterval(_function, _interval);};
 this.Stop = function(){clearInterval(interval);};
}
function TurnOffContainer()
{
 var container = document.getElementById('container');
 container.timer.Stop();
 container.onmouseover = function(){};
 container.onmouseout = function(){};
}
/*AddWndOnLoadHdlr(function(){
var container = document.getElementById('container');
container.timer = new Timer();
container.timer.SetFunction(function(){Next(container);});
container.timer.SetInterval(4000);
container.timer.Start();
container.onmouseover = function(){container.timer.Stop();};
container.onmouseout = function(){container.timer.Start();};
});*/
