var fader;

$('contentBackground').show();

Event.observe(window, "load", function() {
	$('contentBackground').hide();
	$('contentBackground').className = styles[0];
	new Effect.Move($('contentText'), {x:260, y:0});
	$('contentBackground').appear({ duration: 1});
	fader = new Widget.Fader("contentBackground", styles);
});

if ($('homeLink') != null) {
	Event.observe($('homeLink'), "click", function(e) {
		changePage(e, fader, e.target);
	});
}

if ($('aboutLink') != null) {
	Event.observe($('aboutLink'), "click", function(e) {
		changePage(e, fader, e.target);
	});
}

if ($('eventsLink') != null) {
	Event.observe($('eventsLink'), "click", function(e) {
		changePage(e, fader, e.target);
	});
}

if ($('booksLink') != null) {
	Event.observe($('booksLink'), "click", function(e) {
		changePage(e, fader, e.target);
	});
}

if ($('jewishLink') != null) {
	Event.observe($('jewishLink'), "click", function(e) {
		changePage(e, fader, e.target);
	});
}

if ($('weddingsLink') != null) {
	Event.observe($('weddingsLink'), "click", function(e) {
		changePage(e, fader, e.target);
	});
}

if ($('bridalLink') != null) {
	Event.observe($('bridalLink'), "click", function(e) {
		changePage(e, fader, e.target);
	});
}

if ($('corporateLink') != null) {
	Event.observe($('corporateLink'), "click", function(e) {
		changePage(e, fader, e.target);
	});
}

Event.observe($('hideButton'), "click", function(e) {
	hideText();
});

Event.observe($('showButton'), "click", function(e) {
	showText();
});

Event.observe($('pauseButton'), "click", function(e) {
	fader.stop();
	$('playButton').setStyle({display: 'block'});
	$('pauseButton').setStyle({display: 'none'});
  	new Effect.Opacity($('contentBackground'), { duration: 0, to: 1 });
});

Event.observe($('playButton'), "click", function(e) {
	fader.start();
	$('playButton').setStyle({display: 'none'});
	$('pauseButton').setStyle({display: 'block'});
});

function changePage(event, fader, location) {
	Event.stop(event);
	fader.stop();
  	$('contentText').morph({left: '-260px' }, { duration: 1 });
  	new Effect.Opacity($('contentBackground'), { duration: 1, to: 0.0 });
  	setTimeout("window.location='" + location + "'", 1000);
}

function hideText() {
	$('contentText').morph({left: '-260px' }, { duration: 0.5 });
	$('showSpan').setStyle({display: 'block'});
	$('hideSpan').setStyle({display: 'none'});
}

function showText() {
	$('contentText').morph({left: '0px' }, { duration: 0.5 });
	$('showSpan').setStyle({display: 'none'});
	$('hideSpan').setStyle({display: 'block'});
}