var isBackend = false;

function switchPanel(obj, panel)
{
	if (obj.checked)
	{
		$(panel).show();
	}
	else
	{
		$(panel).hide();
	}
}

var slideFinished = true;
var slideSize = 93;
var viewSize = 276;

function clickSlideLeft()
{
	var object = $('slideContent');
	var offset = Position.positionedOffset(object);
	
	if (slideFinished && offset[0]<0)
	{
		slideFinished = false;
		new Effect.Move(object, { x: slideSize, y: 0, fps:100, duration:0.3, transition:Effect.Transitions.linear, afterFinish: setSlideFinished});
	}
}

function clickSlideRight()
{
	var object = $('slideContent');
	var offset = Position.positionedOffset(object);
	var width = object.getWidth();
	
	if (slideFinished && width+offset[0]>viewSize)
	{
		slideFinished = false;
		new Effect.Move(object, { x: -slideSize, y: 0, fps:100, duration:0.3, transition:Effect.Transitions.linear, afterFinish: setSlideFinished});
	}
}

function setSlideFinished()
{
	slideFinished = true;
}

//Functions for modal window
function showPopup(popupName)
{
	var arrayPageSize = getPageSize();
	var overlay = $('popup-overlay');
	var popup = $(popupName);
	var popupDimensions = popup.getDimensions();
	
	overlay.setStyle({width: arrayPageSize[0] + 'px', height: arrayPageSize[1] + 'px'});
	popup.setStyle({left: (arrayPageSize[0] - popupDimensions.width)/2 + 'px', top: overlay.cumulativeScrollOffset().top + 40 + 'px'});
	
	new Effect.Appear('popup-overlay', { duration: 0.5, from: 0.0, to: 0.8 });
	new Effect.Appear(popupName, { duration: 0.5 });
	
	$$('object', 'embed').each(function(node){ node.style.visibility = 'hidden' });
}

function hidePopup(popupName)
{
	Effect.Fade('popup-overlay', { duration: 0.5, from: 0.8, to: 0.0 });
	Effect.Fade(popupName, { duration: 0.5 });
	
	$$('object', 'embed').each(function(node){ node.style.visibility = 'visible' });
}

function getPageSize()
{
    var xScroll, yScroll;
	
	if (window.innerHeight && window.scrollMaxY) {	
		xScroll = window.innerWidth + window.scrollMaxX;
		yScroll = window.innerHeight + window.scrollMaxY;
	} else if (document.body.scrollHeight > document.body.offsetHeight){ // all but Explorer Mac
		xScroll = document.body.scrollWidth;
		yScroll = document.body.scrollHeight;
	} else { // Explorer Mac...would also work in Explorer 6 Strict, Mozilla and Safari
		xScroll = document.body.offsetWidth;
		yScroll = document.body.offsetHeight;
	}
	
	if (self.innerHeight) {	// all except Explorer
		if(document.documentElement.clientWidth){
			windowWidth = document.documentElement.clientWidth; 
		} else {
			windowWidth = self.innerWidth;
		}
		windowHeight = self.innerHeight;
	} else if (document.documentElement && document.documentElement.clientHeight) { // Explorer 6 Strict Mode
		windowWidth = document.documentElement.clientWidth;
		windowHeight = document.documentElement.clientHeight;
	} else if (document.body) { // other Explorers
		windowWidth = document.body.clientWidth;
		windowHeight = document.body.clientHeight;
	}	
	
	// for small pages with total height less then height of the viewport
	if(yScroll < windowHeight){
		pageHeight = windowHeight;
	} else { 
		pageHeight = yScroll;
	}

	// for small pages with total width less then width of the viewport
	if(xScroll < windowWidth){	
		pageWidth = xScroll;		
	} else {
		pageWidth = windowWidth;
	}
	
	return [pageWidth,pageHeight];
}