﻿function toggleMenu(el, over)
{
    if (Element.childElements(el)) {
    var uL = Element.childElements(el)[1];
    var iS = true;
    }
    if (over) {
        Element.addClassName(el, 'over');
        
        if(iS){ uL.addClassName('shown-sub')};
    }
    else {
        Element.removeClassName(el, 'over');
        if(iS){ uL.removeClassName('shown-sub')};
    }
}

function getCookie(name) {
		var nameEQ = name + "=";
		var ca = document.cookie.split(';');
		for(var i=0;i < ca.length;i++) {
			var c = ca[i];
			while (c.charAt(0)==' ') c = c.substring(1,c.length);
			if (c.indexOf(nameEQ) == 0) return c.substring(nameEQ.length,c.length);
		}
		return null;
	}
	
function setCookie(name,value,days){
	if (days) {
			var date = new Date();
			date.setTime(date.getTime()+(days*24*60*60*1000));
			var expires = "; expires="+date.toGMTString();
		}
		else {var expires = "";
		}
		document.cookie = name+"="+value+expires+"; path=/";
}


function loadVerification(){
	 	var v = "";
	 	v += '<div id="ver_back">';
		v += '</div>';
		v += '<div id="ver_outer" align="center">';
		v += '<div id="ver_content">';
		v += '<div id="btn_enter"  onClick="clickEnter()"/></div>'
		v += '<div id="btn_exit"  onClick="clickExit()"/></div>'
		v += '</div>';		
		v += '</div>';

		document.writeln(v)
	}
	
function showVerification(){

		if(getCookie('verified') == null){
			loadVerification();
			document.getElementById('ver_back').style.display = 'block';
			document.getElementById('ver_outer').style.display = 'block';
			}
	}
	
function hideVerification(){
		document.getElementById('ver_back').style.display = 'none';
		document.getElementById('ver_outer').style.display = 'none';	
	}

function clickExit(){
		if (history.length==0){window.location.href='http://www.google.com'}
		else{history.go(-1)}
		//location.href='http://www.google.com'
}

function clickEnter(){
	setCookie('verified','true', 365);
	hideVerification();
}



//SCROLLER
var scrollTimeout;
var maskId 		= "dmask";		// ---	id of the <div> container that masks the scroll content
var scrollId 	= "dscroll";		// ---	id of the <div> containing the content to be scrolled
var btnId 		= "scroll_btn";			// ---	id of the <div> that has the buttons used to call scrollDiv function


function scrollDiv ( dir, incr ) {
	clearTimeout ( scrollTimeout );
	scrollTimeout 	= null;
	if ( dir != "stop" ) {
		// ---	get the mask height... the window that the content scrolls in
		var oMask 	= document.getElementById ( maskId );
		var maskH 	= oMask.clientHeight;
		// ---	get the content height and y position of the scrolling layer
		var oScroll 	= document.getElementById ( scrollId );
		var scrollY 	= Number ( oScroll.style.top.replace ( "px", "" ) );
		var scrollH 	= oScroll.clientHeight;
		// ---	buttons
		var oBtns 	= document.getElementById ( "news_btns" );
		switch ( dir ) {
			case "init" :
				// ---	if there isn't anything to scroll, hide the buttons
				if ( maskH > scrollH ) 	oBtns.style.display 	= "none";
				break;
			case "up" :
				if ( scrollY < 0 ) 	oScroll.style.top = ( scrollY + incr ) + "px";
				else 				oScroll.style.top = "0px";
				break;
			case "down" :
				if ( scrollY > ( maskH - scrollH ) ) 	oScroll.style.top = ( scrollY - incr ) + "px";
				else 									oScroll.style.top = ( maskH - scrollH ) + "px";
				break;
		}
		if ( dir != "init" ) {
			// ---	keep the scroll going until dir = "stop"
			funct 			= "scrollDiv('" + dir + "'," + incr + ");";
			scrollTimeout 	= setTimeout ( funct, 10 );
		}
	}
}


