/* JS stuff for home page */

var loadedID = 0;
var introDone = false;
var loaderInterval;
//var timeout = false;

function startIntro() {
	//setTimeout("timeout = true", 10000); 
	//loaderInterval = setInterval("checkFlashLoaded()", 100)
	$('introwrap').setStyle({'visibility': 'visible'});
	$('logoline').setStyle({'top': (parseInt($('logoline').getStyle('top')) + 22) + 'px', backgroundColor: '#B0963F'});
		new Effect.Morph('logoline', {style: 'top:' + (parseInt($('logoline').getStyle('top')) - 22) + 'px; height:45px', delay: 1.0, duration: 0.5, afterFinish: function() {
		new Effect.Morph('logo1mask', {style: 'left: -300px', duration: 2.0});
		new Effect.Morph('logo2mask', {style: 'left: 400px', duration: 2.0, afterFinish: function() {
			//new Effect.Appear('loadbarwrap', {duration: 0.5});
			new Effect.Appear('introload', {duration: 0.5, afterFinish: function() {
				loadedID = setInterval("checkLoaded()", 500);
			}});
		}});
	}});
}

function galleryPreloadDone() {
	if (!GALLERIES) return true;
	else {
		var done = true;
		$H(GALLERIES).each(function(o) {
			if (!o.value.isDoneLoading()) return false;
		});
		return true;
	}
}

function checkLoaded() {
	var done = galleryPreloadDone();
	if (flashMovie)
		done = done && flashMovie.PercentLoaded() == 100;
	if (done) {
		var logolineheight = document.body.clientHeight - 11;
		var menudelay = .5;
	
		clearInterval(loadedID);
		clearInterval(loaderInterval);
		
		//new Effect.Fade('loadbarwrap', {duration: 0.5});
		new Effect.Fade('introload', {duration: 0.5, afterFinish: function() {
			new Effect.Fade('logo1', {duration: 1.0});
			new Effect.Fade('logo2', {duration: 1.0, afterFinish: function() {
				$('mainpicwrap').setStyle({width: ((document.body.clientWidth / 2) - 23) + 'px'});
				new Effect.Morph('tlcol', {style: 'background-color: #eee'});
				new Effect.Morph('blcol', {style: 'background-color: #eee'});
				new Effect.Morph('logoline', {style: 'top: 11px; height:' + logolineheight + 'px', duration: 1.0});
				new Effect.Fade('logoline', {delay: 0.5, duration: 0.5, afterFinish: function() {
					new Effect.Appear('copyrightwrap', {duration: 0.5});
					if (f_clientHeight() < 750) {
						$('bglogo').setStyle({left: '37px', width: '37px', height: '209px', background: 'url(/images/logo_domokur_sml.gif) no-repeat bottom right'});
						$('bglogowrap').setStyle({width: '37px', height: '209px'});
					}
					new Effect.Morph('bglogo', {style: 'left: 0px', duration: 0.75, afterFinish: function() {
						if (f_clientHeight() < 750) {
							$('body').setStyle({background: 'url(/images/logo_domokur_sml.gif) no-repeat bottom right'});
							$('bglogo').setStyle({left: '37px', display: 'none'});
						} else {
							$('body').setStyle({background: 'url(/images/logo_domokur.gif) no-repeat bottom right'});
							$('bglogo').setStyle({left: '42px', display: 'none'});
						}
						$('introwrap').setStyle({display: 'none'});
					}});
					new Effect.Morph('home_off', {style: 'left: 0px', delay: menudelay, duration: 0.8});
					new Effect.Morph('contact_off', {style: 'left: 0px', delay: menudelay + .4, duration: 0.8});
					new Effect.Morph('people_off', {style: 'left: 0px', delay: menudelay + .8, duration: 0.8});
					new Effect.Morph('approach_off', {style: 'left: 0px', delay: menudelay + 1.2, duration: 0.8});
					new Effect.Morph('services_off', {style: 'left: 0px', delay: menudelay + 1.6, duration: 0.8});
					new Effect.Morph('portfolio_off', {style: 'left: 0px', delay: menudelay + 2.0, duration: 0.8, afterFinish: function() {
						if (flashMovie)
							playFlash(0.5);
					}});
				}});
			}});
		}});
	}
}

function checkFlashLoaded() {
	$('loadbar').setStyle({width: (flashMovie.PercentLoaded() * 2) + 'px'});
}