var stateObj = { };

function change_my_url(title, url) {
	history.pushState(stateObj, title, url);
}

var currentGal = 1;

var pe = new PeriodicalExecuter(function(pe) {
	num = currentGal + 1;
	if(num == 4) num = 1;
	galShow(num, false);
}, 5);

function galShow(num, buttonVar) {
	if(num == -1) {
		pe = new PeriodicalExecuter(function(pe) {
			num = currentGal + 1;
			if(num == 4) num = 1;
			galShow(num, false);
		}, 5);
	}
	else if(num != currentGal) {
		new Effect.Fade('object_'+currentGal);
		new Effect.Appear('object_'+num, { queue: 'end' });
		currentGal = num;
	}
	if(buttonVar && (num != -1)) pe.stop();
}

function titleFade() {
	new Effect.Morph('link', {style: 'color: #FFFFFF;', duration: 0.8});
	new Effect.Morph('navigation', {style: 'background-color: #1B344D', duration: 1.0});
}

function highlighter(node) {
	new Effect.Highlight(node, {endcolor: '#FFFFFF', restorecolor: '#1B344D'}); 
	new Effect.Highlight(node, {startcolor: '#FFFFFF', endcolor: '#1B344D', restorecolor: '#1B344D'});
	return false;
}

function goToPage(pageVar) {
	//titleFade();
	if(pageVar == "home") homePage();
	else if(pageVar == "aboutus") aboutUs();
	else if(pageVar == "contactus") contactUs();
	else if(pageVar == "services") servicesPage();
	else if(pageVar == "stream") streamFunction();
	else fourohfourPage();
}

function clearGal() {
	$('object_1').innerHTML = '';
	$('object_2').innerHTML = '';
	$('object_3').innerHTML = '';
}

function homePage() {

	$('object_1').innerHTML = '<img width="800" src="isimages/isgraphic.png">';
	$('object_2').innerHTML = '<img width="800" src="isimages/isgraphic2.png">';
	$('object_3').innerHTML = '<img width="800" src="isimages/isgraphic3.png">';
			
	//change_my_url('Ingenuity Systems - Home', '/');
	$('fourohfour').hide();
	$('contact').hide();
	$('about').hide();
	$('services').hide();
	$('stream').hide();
	$('home').appear();
}

function aboutUs() {
	clearGal();
	//change_my_url('Ingenuity Systems - About Us', '/aboutus/');
	$('fourohfour').hide();
	$('contact').hide();
	$('services').hide();
	$('stream').hide();
	$('home').hide();
	$('about').appear();
}

function contactUs() {
	clearGal();
	//change_my_url('Ingenuity Systems - Contact Us', '/contactus/');
	
	$('fourohfour').hide();
	$('about').hide();
	$('services').hide();
	$('stream').hide();
	$('home').hide();
	$('contact').appear();
	
	showVerify();
	
	$('name').value = '';
	$('email').value = '';
	$('verify').value = '';
	$('phone').value = '';
	$('subject').value = '';
	$('message').innerHTML = '';
	$('message').value = '';
	
	$('contact-form').show();
	$('contact-result').innerHTML = '';
}

function processContact() {	
	$('contact-result').innerHTML = '<div class="center" style="width: 450px;"><img src="http://www.is-pl.com/loading.gif"></div>';
	var pars = $('contactform').serialize(true);
	new Ajax.Updater({ success: 'contact-result' }, '../backend.php', { method: 'post', parameters: pars, evalScripts: true });
}

function showVerify() {
	new Ajax.Updater({ success: 'ver_drop' }, '../backend.php', { method: 'get', parameters: { act: 'verify' }, evalScripts: true });
}

function servicesPage() {
	clearGal();
	//change_my_url('Ingenuity Systems - Services', '/services/');
	$('fourohfour').hide();
	$('contact').hide();
	$('about').hide();
	$('stream').hide();
	$('home').hide();
	$('services').appear();
}

function streamFunction() {
	clearGal();
	//change_my_url('Ingenuity Systems - Stream', '/stream/');
	$('fourohfour').hide();
	$('contact').hide();
	$('about').hide();
	$('services').hide();
	$('home').hide();
	$('stream').appear();
}

function fourohfourPage() {
	clearGal();
	//change_my_url('Ingenuity Systems - 404', '');
	$('contact').hide();
	$('about').hide();
	$('services').hide();
	$('stream').hide();
	$('home').hide();
	$('fourohfour').appear();
}
