var windowHeight = null

function showGuide()
{
	window.scrollTo(0, 0);

	var sizes = getPageSize();

	var wrapperHeight = document.body.scrollHeight;
	if (wrapperHeight < sizes[3]) {
		wrapperHeight = sizes[3];
	}

	var containerWidth = (sizes[3] - 300)/2;
	if (containerWidth < 0) {
		containerWidth = 0;
	}

	var containerHeight = (sizes[2] - 600)/2;
	if (containerHeight < 0) {
		containerHeight = 0;
	}


	Element.removeClassName($('guide-wrapper'), 'block-hidden');
	Element.addClassName($('guide-wrapper'), 'block-visible');
	Element.setStyle($('guide-wrapper'), {'height': wrapperHeight + "px"});
	Element.setOpacity($('guide-wrapper'), 0.6);

	Element.removeClassName($('guide-container'), 'block-hidden');
	Element.addClassName($('guide-container'), 'block-visible');
	Element.setStyle($('guide-container'), {
		top: (containerWidth + 'px'),
		left: (containerHeight + 'px')
	});

	$j('#guide-container').bgiframe();
}

function hideGuide()
{
	$$('body')[0].undoClipping();
	$$('html')[0].undoClipping();

	Element.removeClassName($('guide-wrapper'), 'block-visible');
	Element.addClassName($('guide-wrapper'), 'block-hidden');
	Element.removeClassName($('guide-container'), 'block-visible');
	Element.addClassName($('guide-container'), 'block-hidden');

	pages = $$('.guide-page');
	for(i = 0; i < pages.length; i++) {
		Element.removeClassName(pages[i], 'block-visible');
		Element.addClassName(pages[i], 'block-hidden');
	}
}

function selectGuidePage(pageNumber)
{
	if (Element.hasClassName($('guide-wrapper'), 'block-hidden')) {
		showGuide();
	}
	pages = $$('.guide-page');
	for(i = 0; i < pages.length; i++) {
		Element.removeClassName(pages[i], 'block-visible');
		Element.addClassName(pages[i], 'block-hidden');
	}

	$('guide-number').innerHTML = pageNumber;
	Element.removeClassName($('guide-page-' + pageNumber), 'block-hidden');
	Element.addClassName($('guide-page-' + pageNumber), 'block-visible');
}

function  getPageSize()
{
	var xScroll, yScroll;

	if (window.innerHeight && window.scrollMaxY) {
		xScroll = document.body.scrollWidth;
		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 if (document.documentElement && document.documentElement.scrollHeight > document.documentElement.offsetHeight){ // Explorer 6 strict mode
		xScroll = document.documentElement.scrollWidth;
		yScroll = document.documentElement.scrollHeight;
	} else { // Explorer Mac...would also work in Mozilla and Safari
		xScroll = document.body.offsetWidth;
		yScroll = document.body.offsetHeight;
	}

	var windowWidth, windowHeight;
	if (self.innerHeight) { // all except Explorer
		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 = windowWidth;
	} else {
		pageWidth = xScroll;
	}

	return [pageWidth,pageHeight,windowWidth,windowHeight];
}

