var xmlhttp = initXMLHttpRequest();

function initXMLHttpRequest(){
	var tmp = null;
	if (window.XMLHttpRequest)
	  {
	  // code for IE7+, Firefox, Chrome, Opera, Safari
	  tmp = new XMLHttpRequest();
	  }
	else if (window.ActiveXObject)
	  {
	  // code for IE6, IE5
	  tmp = new ActiveXObject("Microsoft.XMLHTTP");
	  }
	else
	  {
	  alert("Your browser does not support XMLHTTP!");
	  }
	return tmp;
}

	  
var elementNews =  "restaurantNews";
var elementEvents = "restaurantEvents";
var elementMenus = "restaurantMenus";

function hideNews(){
	document.getElementById(elementNews).style.visibility="hidden";
}

function showNews(){
	document.getElementById(elementNews).style.visibility="visible";
}

function hideEvents(){
	document.getElementById( restaurantEvents ).style.visibility="hidden";
}

function hideMenus(){
	document.getElementById( restaurantMenus ).style.visibility="hidden";
}

function hideNewsEventsMenus(){
	hideNews();
	hideMenus();
	hideEvents();
}

function parseBaseURL(){
	
	return location.href.indexOf( ".fi" )!=-1?location.href.substr( 0, location.href.indexOf( ".fi" )+3 ) + "/":null;
	
}

/**
 * Function performs http request to show all news based on restaurant id
 *
 * @param int rid restaurant id
 */
function showAllNews( rid ){
	
	var url = parseBaseURL();
	
	if( url != null ){
		url += "showAllNews.php?ravintola="+rid;
		var popup = window.open( url, "", "toolbar=yes,location=yes,directories=yes,status=yes,menubar=yes,width=800px,height=600px,resizable=yes,scrollbars=yes" );
	}
	
	/*
	xmlhttp.onreadystatechange=function()
	{
	if(xmlhttp.readyState==4)
	  {
	  var resp = xmlhttp.responseText;
	  alert( resp );
		if( resp != "error" ){
		
			showNews();
			document.getElementById(elementNews).innerHTML = resp;
			
		}
		else{
			hideNewsEventsMenus();
		}
	  }
	}
	
	xmlhttp.open("GET","showAllNews.php?ravintola="+rid,true);
	xmlhttp.send(null); */
	
}
function array_search( array, key, func ){
	
	for( i = 0;  i < array.length; i++ ){
		if( func( array[i], key ) )
			return array[i];		
	}
	
	return null;
	
}
function search_news( news, key ){
	if( news[0] == key )
		return true;
	return false;	
}

/**
 * Function performs http request to show a single news
 *
 * @param int nid is news id
 */
function showNews( nid ){

	var url = parseBaseURL();
	
	if( url != null ){
		url += "showAllNews.php?news="+nid;
		var popup = window.open( url, "", "toolbar=yes,location=yes,directories=yes,status=yes,menubar=yes,width=800px,height=600px,resizable=yes,scrollbars=yes" );	
	}
/*
	xmlhttp.onreadystatechange=function(){
		if(xmlhttp.readyState==4){
			if( xmlhttp.responseText != "error" ){
				document.getElementById( elementNews ).innerHTML = xmlhttp.responseText;
			}
			else{
				hideNewsEventsMenus();
			}
		}
	}

	xmlhttp.open("GET","showAllNews.php?news=" + nid,true);
	xmlhttp.send(null);
*/

}


/**
 * Function performs http request to show all events based on restaurant id
 *
 * @param int rid is restaurant id
 */
function showEvents( rid ){
	
	var url = parseBaseURL();
	
	if( url != null ){
		
		url += "showAllEvents.php?ravintola="+rid;
		var popup = window.open( url, "", "toolbar=yes,location=yes,directories=yes,status=yes,menubar=yes,width=800px,height=600px,resizable=yes,scrollbars=yes" );
	
	}
	/*
	xmlhttp.onreadystatechange=function()
	{
	if(xmlhttp.readyState==4)
	  {
		if( xmlhttp.responseText != "error" ){
			//document.myForm.time.value=xmlhttp.responseText;
		}
		else{
			hideNewsEventsMenus();
		}
	  }
	}

	xmlhttp.open("GET","showEvents.php",true);
	xmlhttp.send(null);
*/	
	
}


/**
 * Function performs http request to show a single event based on event id
 *
 * @param int eid is event id
 */
function showEvent( eid ){

	var url = parseBaseURL();
	
	if( url != null ){
		
		url += "showAllEvents.php?event="+eid;
		var popup = window.open( url, "", "toolbar=yes,location=yes,directories=yes,status=yes,menubar=yes,width=800px,height=600px,resizable=yes,scrollbars=yes" );
	
	}
	/*
	xmlhttp.onreadystatechange=function()
	{
	if(xmlhttp.readyState==4)
	  {
		if( xmlhttp.responseText != "error" ){
			//document.myForm.time.value=xmlhttp.responseText;
		}
		else{
			hideNewsEventsMenus();
		}
	  }
	}

	xmlhttp.open("GET","showEvent.php",true);
	xmlhttp.send(null);
*/
	
}






















	/************************************************************************************************************
	(C) www.dhtmlgoodies.com, November 2005
	
	This is a script from www.dhtmlgoodies.com. You will find this and a lot of other scripts at our website.	
	
	Terms of use:
	You are free to use this script as long as the copyright message is kept intact. However, you may not
	redistribute, sell or repost it without our permission.
	
	Thank you!
	
	www.dhtmlgoodies.com
	Alf Magne Kalleland
	
	************************************************************************************************************/
		
	var slideSpeed = 5;
	var slideTimeBetweenSteps = 40;
	
	
	var scrollingContainer = false;
	var scrollingContent = false;
	var containerHeight;
	var contentHeight;	
	
	var contentObjects = new Array();
	var originalslideSpeed = false;
	function slideContent(containerId)
	{
		var topPos = contentObjects[containerId]['objRef'].style.top.replace(/[^\-0-9]/g,'');
		topPos = topPos - contentObjects[containerId]['slideSpeed'];
		if(topPos/1 + contentObjects[containerId]['contentHeight']/1<0)topPos = contentObjects[containerId]['containerHeight'];
		contentObjects[containerId]['objRef'].style.top = topPos + 'px';
		setTimeout('slideContent("' + containerId + '")',slideTimeBetweenSteps);
		
	}
	
	function stopSliding()
	{
		var containerId = this.id;
		contentObjects[containerId]['slideSpeed'] = 0;	
	}
	
	function restartSliding()
	{
		var containerId = this.id;
		contentObjects[containerId]['slideSpeed'] = contentObjects[containerId]['originalSpeed'];
		
	}
	function initSlidingContent(containerId,slideSpeed)
	{
		scrollingContainer = document.getElementById(containerId);
		scrollingContent = scrollingContainer.getElementsByTagName('DIV')[0];
		
		scrollingContainer.style.position = 'relative';
		scrollingContainer.style.overflow = 'hidden';
		scrollingContent.style.position = 'relative';
		
		scrollingContainer.onmouseover = stopSliding;
		scrollingContainer.onmouseout = restartSliding;
		
		originalslideSpeed = slideSpeed;
		
		scrollingContent.style.top = '0px';
		
		contentObjects[containerId] = new Array();
		contentObjects[containerId]['objRef'] = scrollingContent;
		contentObjects[containerId]['contentHeight'] = scrollingContent.offsetHeight;
		contentObjects[containerId]['containerHeight'] = scrollingContainer.clientHeight;
		contentObjects[containerId]['slideSpeed'] = slideSpeed;
		contentObjects[containerId]['originalSpeed'] = slideSpeed;
		
		slideContent(containerId);
		
	}