var xmlHttp;
var xmlHttp2;
var currentPage;
var x=1;

currentPage = "door";

setTimeout("loadProductAd()", 8000);

function loadPage(page, fetch)
{
	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 Kuching Herbal please email us at info@kuchingherbal.com");
		return;
	} 
	var url="pages/"+fetch+".html";
	url=url+"?sid="+Math.random();
	
	if (fetch=="interact"){
		xmlHttp.onreadystatechange=stateChangedInteract;
	}else{
		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;
	url=url+"&message="+document.getElementById('message').value;
	
	xmlHttp.onreadystatechange=stateChanged;
	xmlHttp.open("GET",url,true);
	xmlHttp.send(null);
}  

function stateChanged() 
{ 
	if (xmlHttp.readyState==4)
	{ 
		document.getElementById('content').innerHTML=xmlHttp.responseText;
	}
	else {
     	document.getElementById('content').innerHTML="<div id='waiting' style='padding: 20px; background-color: black; position: relative; top: 10%; visibility: visible; margin: auto; text-align: -moz-center; height:1000px;'><img src='res/loading3.gif' alt='loading...' /></div>";
  	}
}

function stateChangedInteract() 
{ 
	if (xmlHttp.readyState==4)
	{ 
		document.getElementById('content').innerHTML=xmlHttp.responseText;
		FB.init("7944c450583cff43b77ca3190c73c56b");
	}
	else {
     	document.getElementById('content').innerHTML="<div id='waiting' style='padding: 20px; background-color: black; position: relative; top: 10%; visibility: visible; margin: auto; text-align: -moz-center; height:1000px;'><img src='res/loading3.gif' alt='loading...' /></div>";
  	}
}


function loadProductAd()
{

	xmlHttp2=GetXmlHttpObject();
	if (xmlHttp2==null)
	{
		alert ("Sorry, your browser is too old to view our site. We apologise for this. For information about Kuching Herbal please email us at info@kuchingherbal.com");
		return;
	}
	
	var url="pages/productbanner.php";
	url=url+"?sid="+Math.random();
	url=url+"&adnum="+(x%2);
	
	xmlHttp2.onreadystatechange=stateChangedProductBanner;
	xmlHttp2.open("GET",url,true);
	xmlHttp2.send(null);
}


function stateChangedProductBanner() 
{ 
	if (xmlHttp2.readyState==4)
	{
		document.getElementById('productbanner').innerHTML=xmlHttp2.responseText;
		x=x+1;
		setTimeout("loadProductAd()", 8000);
	}
	else {
     	//document.getElementById('content').innerHTML="<div id='waiting' style='padding: 20px; background-color: black; position: relative; top: 10%; visibility: visible; margin: auto; text-align: -moz-center; height:1000px;'><img src='res/loading3.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 fadein(e){
	document.getElementById(e).style.display="none";
	$('#'+e).fadeIn(4000);
	//alert("called");
}

/*$(document).ready(function(){

	$("ul.subnav").parent().append("<span></span>"); //Only shows drop down trigger when js is enabled (Adds empty span tag after ul.subnav*)

	$("ul.topnav li").hover(function() { //When trigger is clicked...

		//Following events are applied to the subnav itself (moving subnav up and down)
		document.getElementById('connect').src = "res/connect-lit.gif";
		$(this).parent().find("ul.subnav").slideDown('fast').show(); //Drop down the subnav on click

		$(this).parent().find("ul.subnav").hover(function() {
		}, function(){
			unlight('connect');
			$(this).parent().find("ul.subnav").slideUp('slow'); //When the mouse hovers out of the subnav, move it back up
		});
		

		//Following events are applied to the trigger (Hover events for the trigger)
		}).hover(function() {
			$(this).addClass("subhover"); //On hover over, add class "subhover"
		}, function(){	//On Hover Out
			$(this).removeClass("subhover"); //On hover out, remove class "subhover"
		
	});
	
	$("td.menubutt").hover(function() {
		unlight('connect');
		$(this).parent().find("td ul.topnav ul.subnav").slideUp('slow'); //When the mouse hovers out of the subnav, move it back up
	});
	
	
});*/

$(document).ready(function(){

	$("ul.subnav").parent().append("<span></span>"); //Only shows drop down trigger when js is enabled (Adds empty span tag after ul.subnav*)

	$("ul.topnav li span").hover(function() { //When trigger is clicked...

		//Following events are applied to the subnav itself (moving subnav up and down)
		$(this).parent().find("ul.subnav").slideDown('fast').show(); //Drop down the subnav on click

		$(this).parent().hover(function() {
		}, function(){
			$(this).parent().find("ul.subnav").slideUp('slow'); //When the mouse hovers out of the subnav, move it back up
		});

		//Following events are applied to the trigger (Hover events for the trigger)
		}).hover(function() {
			$(this).addClass("subhover"); //On hover over, add class "subhover"
		}, function(){	//On Hover Out
			$(this).removeClass("subhover"); //On hover out, remove class "subhover"
	});

});

