var xmlHttp
var currentPage

currentPage = "door";

function loadPage(page)
{
	currentPage = page;
	unlightAll();
	light(page);
	
	xmlHttp=GetXmlHttpObject();
	if (xmlHttp==null)
	{
		alert ("Sorry, your browser is too old to view our site. We apologise for this. For information about Indubitably please email us at eldoradonuts@gmail.com");
		return;
	} 
	//var url="pages/"+page+".php";
	var url="pages/"+page+".php";
	url=url+"?sid="+Math.random();

	xmlHttp.onreadystatechange=stateChanged;
	xmlHttp.open("GET",url,true);
	xmlHttp.send(null);
}

function submitContact()
{

	xmlHttp=GetXmlHttpObject();
	if (xmlHttp==null)
	{
		alert ("Sorry, your browser is too old to view our site.");
		return;
	} 
	var url="pages/submit.php";
	url=url+"?sid="+Math.random();
	url=url+"&name="+document.getElementById('name').value;
	url=url+"&email="+document.getElementById('email').value;
	var msg=document.getElementById('message').value;
	msg=escape(msg);
	url=url+"&message="+msg;
	
	xmlHttp.onreadystatechange=stateChanged;
	xmlHttp.open("GET",url,true);
	xmlHttp.send(null);
}  

function stateChanged() 
{ 
	if (xmlHttp.readyState==4)
	{ 
		document.getElementById('content').innerHTML=xmlHttp.responseText;
		//playSound("beepdble.wav");
		checkGallery();
	}
	else {
     	document.getElementById('content').innerHTML="<div id='waiting' style='width:100%; position: relative; top: 54px; left: -10px; visibility: visible; margin: auto; text-align: center;'><img src='res/loading.gif' alt='loading...' /></div>";
  	}
}

function GetXmlHttpObject()
{
	var xmlHttp=null;
	try
	{
		// Firefox, Opera 8.0+, Safari
		xmlHttp=new XMLHttpRequest();
	}
	catch (e)
	{
		// Internet Explorer
		try
	{
		xmlHttp=new ActiveXObject("Msxml2.XMLHTTP");
	}
	catch (e)
	{
		xmlHttp=new ActiveXObject("Microsoft.XMLHTTP");
	}
	}
	return xmlHttp;
}

function playSound(x) {
	var soundurl = "res/" + x;
	document.getElementById("soundspan").innerHTML = '<embed id="wav" src="' + soundurl + '" hidden="true" autostart="true" loop="false" />';
}

function changelg(lg){
	var url="pages/change_lg.php?lg="+lg+"&pg="+currentPage;
	location.href=url;
}

function fadein(e){
	document.getElementById(e).style.display="none";
	$('#'+e).fadeIn(3000);
	//alert("called");
}

function checkGallery(){
	if (currentPage == "gallery"){
		// We only want these styles applied when javascript is enabled
		$('div.navigation').css({'width' : '300px', 'float' : 'left'});
		$('div.content').css('display', 'block');
		// Initially set opacity on thumbs and add
		// additional styling for hover effect on thumbs
		var onMouseOutOpacity = 0.45;
		$('#thumbs ul.thumbs li').css('opacity', onMouseOutOpacity).hover(
		function () {
		$(this).not('.selected').fadeTo('fast', 1.0);
		},
		function () {
		$(this).not('.selected').fadeTo('fast', onMouseOutOpacity);
		}
		);

		$(document).ready(function() {
		// Initialize Advanced Galleriffic Gallery
		var galleryAdv = $('#gallery').galleriffic('#thumbs', {
		delay: 4500,
		numThumbs: 6,
		preloadAhead: 3,
		enableTopPager: true,
		enableBottomPager: false,
		imageContainerSel: '#slideshow',
		controlsContainerSel: '#controls',
		captionContainerSel: '#caption',
		loadingContainerSel: '#loading',
		renderSSControls: true,
		renderNavControls: true,
		playLinkText: '<img src=\'res/play.gif\'/>',
		pauseLinkText: '<img src=\'res/pause.gif\'/>',
		prevLinkText: '<img src=\'res/rev.gif\'/>',
		nextLinkText: '<img src=\'res/ff.gif\'/>',
		nextPageLinkText: '<img src=\'res/next.gif\'/>',
		prevPageLinkText: '<img src=\'res/previous.gif\'/>',
		enableHistory: true,
		autoStart: false,
		onChange: function(prevIndex, nextIndex) {
		$('#thumbs ul.thumbs').children()
		.eq(prevIndex).fadeTo('fast', onMouseOutOpacity).end()
		.eq(nextIndex).fadeTo('fast', 1.0);
		},
		onTransitionOut: function(callback) {
		$('#caption').fadeTo('fast', 0.0);
		$('#slideshow').fadeTo('fast', 0.0, callback); }, 
		onTransitionIn: function() {
		$('#slideshow').fadeTo('fast', 1.0);
		$('#caption').fadeTo('fast', 1.0);
		},
		onPageTransitionOut: function(callback) {
		$('#thumbs ul.thumbs').fadeTo('fast', 0.0, callback);
		},
		onPageTransitionIn: function() {
		$('#thumbs ul.thumbs').fadeTo('fast', 1.0);
		}
		});
		});
	}
}

function light(e){
	if (document.getElementById(e)==null || document.getElementById(e)===null){
		
	}else{
		document.getElementById(e).src = "res/" + e + "-lit.gif";
	}
}

function unlight(e){
	if (currentPage == e){
	}
	else{
		document.getElementById(e).src = "res/" + e + "-unlit.gif";
	}
}

function lightsend(){
	document.getElementById('send').src = "res/send-lit.png";
}

function unlightsend(){
		document.getElementById('send').src = "res/send-unlit.gif";
}

function unlightAll(){
	unlight('home');
	unlight('news')
	unlight('gallery')
	unlight('shop')
	unlight('links')
	unlight('contact')	
}


var setsumei_disp = false;

function toggledisp(){
	if (!setsumei_disp){
		document.getElementById('instructions').innerHTML='To zoom in, press the left mouse button and drag upwards. To zoom out, press the left mouse button and drag downwards.<br/>To change the size of the zoom window, press the left mouse button and drag sideways.<br/>Enjoy!';
		document.getElementById('zoomshow').innerHTML="Hide zoom instructions";
		setsumei_disp = true;
	} else {
		document.getElementById('instructions').innerHTML='';
		document.getElementById('zoomshow').innerHTML="Show zoom instructions";
		setsumei_disp = true;
	}
}

function toggledisp2(){
	if (!setsumei_disp){
		document.getElementById('instructions').innerHTML="ズームインすると、ズームの窓を上の方向へドラッグしてください。　ズームアウトの時、下の方向へ。<br/>ズーム窓のサイズの変更の際、左右にドラッグしてください。<br/>では、楽しんで下さい！";
		document.getElementById('zoomshow').innerHTML="ズームの説明を表示しない";
		setsumei_disp=true;
	} else {
		document.getElementById('instructions').innerHTML='';
		document.getElementById('zoomshow').innerHTML="ズームの説明を表示する";
		setsumei_disp=false;
	}
}


