
window.addEvent('domready', function() {
	if(!window.ie6) {
		$('browser').setStyle('display', 'none');
		var active = 0;
		var navs = $$('#nav li');
		var pages = $$('.content');
		
		
		
		var path = 'images/';
		var images = [
			path + 'BodyBG.jpg',
			path + 'ButtonBG.png',
			path + 'ContactForm.png',
			path + 'ContentBG.png',
			path + 'MyPhoto1.png',
			path + 'MyPhoto2.jpg',
			path + 'NavAbout.png',
			path + 'NavContact.png',
			path + 'NavPortfolio.png',
			path + 'NavResources.png',
			path + 'NavBG.png',
			path + 'ProjectsThumbBG.png',
			path + 'TextAreaBG.png',
			path + 'TextBoxBG.png',
			path + 'Title.png',
			path + 'WrapperBG.png'
		];
		var loading = $('loading');
		//var progress = $('loadingBar').effect('width', {'duration': 500}).start(0);
		var progress = new Fx.Tween($('loadingBar'), {property: 'width', duration: 500}).start(0);
		var progressStatus = $('loadingStatus');
		var myFx = new Fx.Tween('wrapper', {property: 'opacity', duration: 2000, wait: false}).set(0);
		new Asset.images([path + 'LoadingBG.png', path + 'LoadingStatus.png'], {
			onComplete: function() {
				new Asset.images(images, {
					onProgress: function(i) {
						var percent = ((i + 1) * loading.getStyle('width').toInt()) / images.length;
						progress.start(percent);
						progressStatus.set('text', ((i + 1) / images.length * 100).toInt() + ' %');
						//alert((i + 1) / images.length * 100);
					},
					onComplete: function() {
						$('loading').setStyle('display', 'none');
						$('wrapper').setStyle('display', 'block');
						myFx.start(1);
					}
				});
			}
		});
		
		pages.each(function(page, j) {
			if (j != active) {
				page.setStyles({
					'left': '1010px'
				}); 
			}
		});
		navs.each(function(nav, i) {
			if (i != active) {
				nav.setOpacity(.7);
			}
			var navFx = new Fx.Tween(nav, {property: 'opacity', duration: 500});
			nav.addEvents({
				mouseenter: function() {
					navFx.start(1);
				},
				mouseout: function() {
					if (i != active) {
						navFx.start(.7);
					}
				},
				click: function() {
					pages.each(function(page, j) {
						if (j != active) {
							new Fx.Tween(pages[active], {property: 'left',duration: 1000}).start(1010);
							new Fx.Tween(pages[i], {property: 'left',duration: 1000}).start(171);
						}
					});			
					navFx.start(1);
					active = i;
					navs.each(function(nav, i) {
						if (i != active) {
							new Fx.Tween(nav, {property: 'opacity', duration: 500}).start(.7);
						}
					});
				}
			});
		});
		
	/*	
		var projectScroll = new Scroller('projectsDiv', {area: 100, velocity: .2});
		
		//$('projectsDiv').addEvent('mouseover', projectScroll.start.bind(projectScroll));
		//$('projectsDiv').addEvent('mouseout', projectScroll.stop.bind(projectScroll));		
		
		//var projectScroll = new Scroller('projectsDiv');
				
		$('projectsDiv').addEvent('mouseenter', projectScroll.start.bind(projectScroll));
		$('projectsDiv').addEvent('mouseleave', projectScroll.stop.bind(projectScroll));
	*/	
		$('formContact').getChildren().each(function(el, i) {
			el.setOpacity(.7);
			el.addEvent('click', function() {
				var formFx = new Fx.Tween(el, {property: 'opacity', duration: 500}).start(1);
				$('formContact').getChildren().each(function(els, other) {
					if (i != other) {
						formFx.start(.7);
					}
				});
			});
		});
		
		$$('#myPhoto img')[0].setOpacity(0);
		$('myPhoto').addEvent('mouseenter', function() {
			new Fx.Tween($$('#myPhoto img')[0], {property:'opacity', duration: 500}).start(1);
		});
		$$('#myPhoto img').addEvent('mouseout', function() {
			new Fx.Tween($$('#myPhoto img')[0], {property:'opacity', duration: 500}).start(0);
		});
		
		
		$('formContact').addEvent('submit', function(e) {
			new Event(e).stop();
	
			var status = 1, emailError = 0;
			
			$$('.required').each(function(el, i) {
				if (el.value == '' || el.value == 'Required') {	el.setProperty('value', 'Required').addClass('error'); status = 0; } else { el.removeClass('error');}
			});
			
			$$('.email').each(function(el, i) {
				if (el.value == '' || el.value == 'Required' || el.value == 'Must be Email') {	el.setProperty('value', 'Must be Email').addClass('error'); emailError = 1; } else { el.removeClass('error');}
			});
			
	
			if (status == 1 && emailError == 0) {
				var pleahForm = $('formContact').setStyle('display', 'none');
				var log = $('responseMessage').empty().addClass('ajaxLoading');
				log.setStyle('display', 'block');
			 
				var sender = new Request();
				sender.onSuccess=function(responseText, responseXML){log.set('html', responseText); log.removeClass('ajaxLoading');};
				sender.send({data: this, url: this.get('action')});
					
			}
		});
	}
	else {
		$('browser').setStyle('display', 'block');
		$('loading').setStyle('display', 'none');
	}


//moopan

	$("projectsDiv").moopan({fDeadZone: [0, 1],fStartProportion: [0.5, 0.5], iSecondsAtTopSpeed: [4, 4]});


});
