﻿/**
 * Effects
 */

RequestURI = location.href.substring(0,(location.href.indexOf('#') != -1)? location.href.indexOf('#'):location.href.length);

window.addEvent('domready', function() {	

/**
 * Flashing message
 */
$$('.Msg-Flash').each( function(el,i)
{
	el = el.getFirst();
	var F = new Fx.Tween(el,{duration: 300 });
	F.start('opacity',0).chain(function(){
		this.start('opacity',1);
	}).chain(function(){
		this.start('opacity',0);
	}).chain(function(){
		this.start('opacity',1);
	})
});

/**
 * Pop-up window links
 */
$$('.Link-Popup').each( function(el,i)
{
	el.addEvent('click',function(){
		this.Win = window.open(this.href,'PopupWindow','status=1,height=500,width=480,resizable=0,menubar=0,toolbar=0,scrollbars=1');
		this.Win.focus();
		return false;
	});
});

/**
 * Navigation highlights
 */
$(document.body).getElements('.Site-Nav a').each( function(el,i)
{
	if(el.href == RequestURI)
		el.addClass('on');
});
$(document.body).getElements('.Foot-Nav a').each( function(el,i)
{
	if(el.href == RequestURI)
		el.addClass('on');
});

/**
 * Scrollbar
 */
var ScrollBoxes = $(document.body).getElements('.Page-Scrollbox');
if(ScrollBoxes)
{
	ScrollBoxes.each(function(el,i) {
		var Bar = $(el.id+'-Bar');
		if(!Bar)
			return;
		var Knob = $(el.id+'-Knob');
		var ScrollParent = $(el.getOffsetParent());
		var Pad = 0;//Parent.getStyle('padding-top').toInt();

		var ContentHeight = el.getElement('.Page-Scrollbox-Content').getSize().y;
		var ContainerHeight = el.getSize().y;

		Bar.setStyle('height',el.getSize().y - Pad);
		Bar.setStyle('top',el.getPosition().y - ScrollParent.getPosition().y + Pad);

		if(ContentHeight > ContainerHeight)
		{
			KnobHeight = (ContainerHeight/ContentHeight) * ContainerHeight;
			if(KnobHeight < 12)
				KnobHeight = 12;
			Knob.setStyle('height',KnobHeight);

			el.Scroller = new ScrollBar(el.id,Bar,Knob, {
				slider: {
					mode: 'vertical',
					offset: 0
				}
			});
			
			Bar.setStyle('visibility','visible');
		}
	});
}

/**
 * Vertical center
 */

$(document.body).getElements('.vCenter').each(function(el,i) {

		var Height = el.getSize().y;
		var pHeight = el.getParent().getSize().y;

		if(pHeight > Height)
			el.setStyle('padding-top',Math.floor((pHeight - Height) / 2));

});


/**
 * Open external links in content body in new windows
 */
var Links = $(document.body).getElements('a');
if(Links)
	for(var i=0; i < Links.length;i++)
	{
		if(Links[i].href && Links[i].href.indexOf(document.domain) == -1 && Links[i].href.indexOf('javascript:') == -1)
			Links[i].target = '_blank';
	}
});

