/* for layout */
function getWindowHeight() {
	var windowHeight = 0;
	if (typeof(window.innerHeight) == 'number') {
		windowHeight = window.innerHeight;
	}
	else {
		if (document.documentElement && document.documentElement.clientHeight) {
			windowHeight = document.documentElement.clientHeight;
		}
		else {
			if (document.body && document.body.clientHeight) {
				windowHeight = document.body.clientHeight;
			}
		}
	}
	return windowHeight;
}

function setFooter(layoutType, layoutStyle) {
	if (layoutType != 'fixed_size_center' && layoutType != 'fixed_size_top' && layoutType != 'auto') {
		var windowHeight = getWindowHeight();
		if (windowHeight > 0) {
			var contentHeight = document.getElementById('mainUpBox').offsetHeight;
			var footerElement = document.getElementById('mainDownBox');
			var footerHeight  = footerElement.offsetHeight;
			if (windowHeight - (contentHeight + footerHeight) >= 0) {
				footerElement.style.top = (windowHeight - (contentHeight + footerHeight)) + 'px';
			}
			else {
				footerElement.style.top = '0px';
			}
		}
	}
}

function trim(stringToTrim) {
	return stringToTrim.replace(/^\s+|\s+$/g,"");
}

function setHeaderImage(image) {
	if (trim(image) != '' ) {
		var headerElement = document.getElementById('head');
		headerElement.style.backgroundImage = 'url(../../cms_files/' + image + ')';
	}
}

function setLayout(layoutType, layoutStyle, layoutMainWidth, layoutHeaderHeight, layoutMenuItemHeight, layoutMenuItemWidth, layoutFooterHeight, layoutMenuHeight, layoutContentMarginTop, layoutContentMarginLeft, layoutContentMarginBottom, layoutContentMarginRight, layoutContentHeight, layoutMenuPaddingTop, layoutMenuPaddingLeft, layoutMenuPaddingBottom, layoutMenuPaddingRight) {
	
	var windowHeight = getWindowHeight();
	
	// calculate content height, width
	if (layoutType == 'fixed_auto') {
		if (layoutStyle == 'left') {
			var contentHeight = windowHeight - layoutHeaderHeight - layoutFooterHeight;
		}
		else {
			var contentHeight = windowHeight - layoutHeaderHeight - layoutFooterHeight - layoutMenuItemHeight;
		}
	}
	else if (layoutType == 'fixed_size_top' || layoutType == 'fixed_size_center') {
		var contentHeight = layoutContentHeight;
	}
	
	if (layoutStyle == 'left') {
		var contentWidth = layoutMainWidth - layoutMenuItemWidth;
	}
	else {
		var contentWidth = layoutMainWidth;
	}
	
	
	var contentElement = document.getElementById('contentBox');
	var sectionElement = document.getElementById('sectionBox');	
	
	
	if (layoutType == 'fixed_auto' || layoutType == 'fixed_size_center' || layoutType == 'fixed_size_top') {
		if (Math.ceil(layoutMenuHeight) > Math.ceil(contentHeight)) {
			contentHeight = layoutMenuHeight;
		}
		contentElement.style.height = contentHeight + 'px';
		contentElement.style.width = contentWidth + 'px';
		var sectionHeight = contentHeight - layoutContentMarginTop - layoutContentMarginBottom;
		var sectionWidth = contentWidth - layoutContentMarginLeft - layoutContentMarginRight;
		sectionElement.style.height = sectionHeight + 'px';	
		sectionElement.style.width = sectionWidth + 'px';	
		sectionElement.style.overflow = 'auto';
		sectionElement.style.overflowX = 'hidden';
	}


	//header
	var headerBoxElement = document.getElementById('headerBox');
	headerBoxElement.style.height = layoutHeaderHeight + 'px';

	//footer
	var footerBoxElement = document.getElementById('footerBox');
	footerBoxElement.style.height = layoutFooterHeight + 'px';

	var mainUpElement = document.getElementById('mainUpBox');
	mainUpElement.style.width = layoutMainWidth + 'px';
	var mainDownElement = document.getElementById('mainDownBox');
	mainDownElement.style.width = layoutMainWidth + 'px';

	if (layoutStyle == 'below' || layoutStyle == 'above') {
		var menuElement = document.getElementById('menuBox');
		menuElement.style.width = layoutMainWidth + 'px';
		menuElement.style.height = layoutMenuItemHeight + 'px';
		
		menuElement.style.paddingLeft = layoutMenuPaddingLeft + 'px';
		menuElement.style.paddingBottom = layoutMenuPaddingBottom + 'px'; 
		
		var menuListElement = document.getElementById('menuList');
		menuListElement.style.height = layoutMenuItemHeight + 'px';
		var listItems = $('menuList').getElementsByTagName('LI');
		for (var i = 0; i < listItems.length; i++){
			listItems[i].style.display = 'block';
			if(listItems[i].style.cssFloat == '') {
				listItems[i].style.cssFloat = 'left';
			}
			if(listItems[i].style.styleFloat == '') {
				listItems[i].style.styleFloat = 'left';
			}
			listItems[i].style.height = layoutMenuItemHeight + 'px';
			listItems[i].style.width = layoutMenuItemWidth + 'px';
			
			listItems[i].style.paddingTop = layoutMenuPaddingTop + 'px';
			//listItems[i].style.paddingLeft = layoutMenuPaddingLeft + 'px';
			//listItems[i].style.paddingBottom = layoutMenuPaddingBottom + 'px';
			listItems[i].style.paddingRight = layoutMenuPaddingRight + 'px';
		}
		var listLinks = $('menuList').getElementsByTagName('A');
		for (var i = 0; i < listLinks.length; i++){
			//listLinks[i].style.display = 'block';
			//listLinks[i].style.float = 'left';
			//listLinks[i].style.height = layoutMenuItemHeight + 'px';
			//listLinks[i].style.width = layoutMenuItemWidth + 'px';
		}
	}
	else {
		var menuElement = document.getElementById('menuBox');
		menuElement.style.width = layoutMenuItemWidth + 'px';
		//menuElement.style.border = '1px solid red';
		menuElement.style.paddingTop = layoutMenuPaddingTop + 'px';
		menuElement.style.paddingRight = layoutMenuPaddingRight + 'px'; 
		var listItems = $('menuList').getElementsByTagName('LI');
		for (var i = 0; i < listItems.length; i++){
			
			listItems[i].style.height = layoutMenuItemHeight + 'px';
			listItems[i].style.display = 'block';			
			//listItems[i].style.paddingTop = layoutMenuPaddingTop + 'px';
			listItems[i].style.paddingLeft = layoutMenuPaddingLeft + 'px';
			listItems[i].style.paddingBottom = layoutMenuPaddingBottom + 'px';
			//listItems[i].style.paddingRight = layoutMenuPaddingRight + 'px';
		}
	}
	
	if (layoutType == 'fixed_size_center') {
		if (layoutStyle == 'left') {
			var topMargin = windowHeight - contentHeight - layoutHeaderHeight - layoutFooterHeight;
		}
		else {
			var topMargin = windowHeight - contentHeight - layoutHeaderHeight - layoutFooterHeight - layoutMenuItemHeight;
		}
		topMargin = Math.round(topMargin / 2);
		if (topMargin > 0) {
			mainUpElement.style.marginTop = topMargin + 'px';
		}
	}
	
}


/* roll over images */

function MM_swapImgRestore() { //v3.0
  var i,x,a=document.MM_sr; for(i=0;a&&i<a.length&&(x=a[i])&&x.oSrc;i++) x.src=x.oSrc;
}

function MM_preloadImages() { //v3.0
  var d=document; if(d.images){ if(!d.MM_p) d.MM_p=new Array();
    var i,j=d.MM_p.length,a=MM_preloadImages.arguments; for(i=0; i<a.length; i++)
    if (a[i].indexOf("#")!=0){ d.MM_p[j]=new Image; d.MM_p[j++].src=a[i];}}
}

function MM_findObj(n, d) { //v4.01
  var p,i,x;  if(!d) d=document; if((p=n.indexOf("?"))>0&&parent.frames.length) {
    d=parent.frames[n.substring(p+1)].document; n=n.substring(0,p);}
  if(!(x=d[n])&&d.all) x=d.all[n]; for (i=0;!x&&i<d.forms.length;i++) x=d.forms[i][n];
  for(i=0;!x&&d.layers&&i<d.layers.length;i++) x=MM_findObj(n,d.layers[i].document);
  if(!x && d.getElementById) x=d.getElementById(n); return x;
}

function MM_swapImage() { //v3.0
  var i,j=0,x,a=MM_swapImage.arguments; document.MM_sr=new Array; for(i=0;i<(a.length-2);i+=3)
   if ((x=MM_findObj(a[i]))!=null){document.MM_sr[j++]=x; if(!x.oSrc) x.oSrc=x.src; x.src=a[i+2];}
}



function popUp(url) {
	day = new Date();
	id = day.getTime();
	eval("page" + id + " = window.open(url, '" + id + "', 'toolbar=0,scrollbars=1,location=0,statusbar=1,menubar=0,resizable=0,width=610,height=501');");
}

function popUpWithParams(url, height, width, top, left, location, menubar, resizable, scrollbars, status, titlebar, toolbar, fullscreen) {
	day = new Date();
	id = day.getTime();
	eval("page" + id + " = window.open(url, '" + id + "', 'height=" + height + ",width=" + width+ ",top=" + top + ",left=" + left +  ",location=" + location  + ",menubar=" + menubar + ",resizable=" + resizable + ",scrollbars=" + scrollbars + ",status=" + status + ",titlebar=" + titlebar + ",toolbar=" + toolbar + ",fullscreen=" + fullscreen + "');");
}

/*Login */
// -----------------------------------------------------------------------------------

//
//  Configurationl
//
LoginboxOptions = Object.extend({
   

    overlayOpacity: 0.5   // controls transparency of shadow overlay

}, window.LoginboxOptions || {});

// -----------------------------------------------------------------------------------
	
var Loginbox = Class.create();	

Loginbox.prototype = {
	
	initialize: function() { 
	
		var objBody = $$('body')[0];
		objBody.appendChild(Builder.node('div',{id:'overlaylogin'}));
		$('overlaylogin').setStyle ({display: 'none'})
		this.overlaylogin = $('overlaylogin');
			
		//$('overlaylogin').hide().observe('click', (function() { this.end(); }).bind(this));
		
		this.overlayDuration = 0.2;  // shadow fade in/out duration (0)
		//this.overlayDuration = 0;  // shadow fade in/out duration (0)
		
	},
	
	start: function() {
	
		// stretch overlay to fill page and fade in
        var arrayPageSize = this.getPageSize();
        
        
        
        $('overlaylogin').setStyle({ width: arrayPageSize[0] + 'px', height: arrayPageSize[1] + 'px' });
        
        
        
        new Effect.Appear(this.overlaylogin, { duration: this.overlayDuration, from: 0.0, to: LightboxOptions.overlayOpacity });
	},
	
    //
    //  end()
    //
    end: function() {
        //this.loginbox.hide();
        new Effect.Fade(this.overlaylogin, { duration: this.overlayDuration });
    },
    
	//
    //  getPageSize()
    //
    getPageSize: function() {
	        
	     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;
		}
		
		var windowWidth, windowHeight;
		
		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];
	}    
	
}

var loginbox;

//document.observe('dom:loaded', function () { loginbox = new Loginbox(); });


function toggleMemberMenu(flag){
	var menuContainer = document.getElementById("mMenu");
	var titleBg = document.getElementById("member-title-bg");
	var bgStart = document.getElementById("member-title-bg-st");

	if(menuContainer.style.display == "none") {
		
		menuContainer.style.display = "block";
		titleBg.className = "member-title-bg" + flag + "-hov";
		bgStart.className = "member-title-bg-st-hov";
		
		if(loginbox) 
			loginbox.start();
		
	}else{
		
		menuContainer.style.display = "none";
		titleBg.className = "member-title-bg";
		bgStart.className = "";
		
		if(loginbox) 
			loginbox.end();
		
	}
}

/* end Login */
