var eBody, eContent, eHeader, eHeader_illustration, iContent_top;
function main(){
	eBody = document.getElementsByTagName( 'body' )[0];
	eBody.className += '';
	if( eBody.id != 'home_page' && eBody.id != 'popup_page' ){
		eContent = document.getElementById( 'content' );
		setTimeout( 'init_FAQ()', 0 );
		eHeader = document.getElementById( 'header' );
		if( eContent && eHeader ){
			eHeader_illustration = eHeader.getElementsByTagName( 'div' );
			if( eHeader_illustration && eHeader_illustration.length ){
				eHeader_illustration = eHeader_illustration[0];
				iContent_top = eContent.offsetTop// - ( eContent.currentStyle ? eContent.currentStyle.marginTop.replace( /(\d+).*/, '$1' ) : eContent.style.marginTop.replace( /(\d+).*/, '$1' ) );
				Common.Event.add( window, 'resize', hide_header );
				hide_header();
			}
		}
	}
	var aeInput = document.getElementsByTagName( 'input' );
	for( var i = 0 ; i < aeInput.length ; i++ ){
		if( aeInput[i].getAttribute( 'placeholder' ) ){
			placeholder( aeInput[i], aeInput[i].getAttribute( 'placeholder' ), 'empty' );
		}
	}
}

function hide_header(){
	if( eBody.clientHeight ){
		var iDY = eBody.clientHeight - iContent_top - 500;
		if( iDY < 0 ){
			if( -iDY > iContent_top - 180 ){
				iDY = -iContent_top + 180;
			}
			eHeader_illustration.style.top = iDY + 'px';
			eContent.style.marginTop = iContent_top + iDY - 120 + 'px';
			eBody.className += '';
		}else if( eContent.offsetTop ){
			eHeader_illustration.style.top = 0 + 'px';
			eContent.style.marginTop = iContent_top - 120 + 'px';
			eBody.className += '';
		}
	}
}

function placeholder( eThis, sText, sClass_on_empty ){
	eThis.onfocus = function(){ if( eThis.value.length && eThis.value == sText ){ eThis.value = ''; } Common.Class.remove( this, sClass_on_empty ); eThis.select(); document.getElementsByTagName( 'body' )[0].className += ''; }
	eThis.onblur = function(){ if( !this.value.length ){ Common.Class.add( this, sClass_on_empty ); this.value = sText; document.getElementsByTagName( 'body' )[0].className += ''; } }
	if( !eThis.value.length ){ eThis.onblur(); }
	if( !eThis.getAttribute( 'placeholder' ) ){ eThis.setAttribute( 'placeholder', sText ); }
}

function UnHide_depended( oEvent ){
	oEvent = Common.Event.normalize( oEvent );
	if( Common.Class.match( oEvent.target.eDepended, 'hidden' ) ){
		Common.Class.add( oEvent.target, 'active' );
		Common.Class.remove( oEvent.target.eDepended, 'hidden' );
	}else{
		Common.Class.remove( oEvent.target, 'active' );
		Common.Class.add( oEvent.target.eDepended, 'hidden' );
	}
}

function init_FAQ(){
	var aeQuestion = Common.Dom.getElementsByClassName( eContent, 'question' );
	if( aeQuestion.length ){
		var aeAnswer = Common.Dom.getElementsByClassName( eContent, 'answer' );
		for( var i = 0, eINS, j ; i < aeQuestion.length ; i++ ){
			if( aeAnswer[i] ){
				eINS = document.createElement( 'ins' );
				eINS.className = 'pseudo-link question';
				aeQuestion[i].appendChild( eINS );
				for( j = 0 ; j < aeQuestion[i].childNodes.length - 1 ; j++ ){
					eINS.appendChild( aeQuestion[i].childNodes[j] );
				}
				Common.Event.add( eINS, 'click', UnHide_depended );
				eINS.eDepended = aeAnswer[i];
				Common.Class.add( aeAnswer[i], 'hidden' );
			}
		}
	}
}


$(function(){
	
		$('.foldable').each(function(){
			var defenition = $(this);
			//defenition.hide();
			defenition.prev().wrapInner('<span class="pseudo-href"></span>').find('.pseudo-href').first().click(function(){
				if($.browser.msie){
					defenition.toggle();
				} else {
					defenition.slideToggle();
				}
			});
		});
	
})
