window.addEvent('domready', function () {
	var id = $(document.body).get('id');
	
	// Cufon text replacment
	// Select string containing all elements to replace
	var cufonReplace = '#header ul li a'+
	', #header h2'+
	', #home .col1 h2'+
	', #home #welcome h2'+
	', .workList h2, .workList h3'+
	', table th'+
	', #caseStudies form label'+
	', #caseStudies .col4 h2'+
	', #caseStudies .col4 h3'+
	', #caseStudies .images h3'+
	', #contact #contact_send_text'+
	', .flash.promo a.cta';

	Cufon.replace($$(cufonReplace), {
		hover: true
	});

	if(id === 'home') {
		var flash = $$('.flash');
		var imgs = flash.getElements('img');
		
		new SlideShow($$('.promo.flash .item'), {cont: flash[0]});
	} else if (id === 'contact') {
		$$('form')[0].addEvent('submit', function (e) {
			var vals = ['Your message', 'Your email', 'Your name'];
			var fields = [$('contact_message'), $('contact_email'), $('contact_name')];

			fields.each(function (field, i) {
				if (field.get('value') === vals[i]) {
					field.set('value', '');
				}
			});
		});


		$('contact_message').addEvents({
			'focus': function() {
				if(this.get('value') === 'Your message')
					this.set('value', '');
			},
			'blur': function() {
				if(!this.get('value'))
					this.set('value', 'Your message');
			}
		});

		$('contact_email').addEvents({
			'focus': function() {
				if(this.get('value') === 'Your email')
					this.set('value', '');
			},
			'blur': function() {
				if(!this.get('value'))
					this.set('value', 'Your email');
			}
		});

		$('contact_name').addEvents({
			'focus': function() {
				if(this.get('value') === 'Your name')
					this.set('value', '');
			},
			'blur': function() {
				if(!this.get('value'))
					this.set('value', 'Your name');
			}
		});
	} else if (id === 'showReel') {
		var embedSwf = function (vid) {
			var swiff = new Swiff(BASE_URL+'assets/swf/video_app.swf', {
				width: 647,
				height: 364,
				vars: {
					_vidURL: BASE_URL+'assets/flv/'+vid+'.flv',
					_autoPlay: 0
				}
			});

			swiff.inject($$('.video_player')[0].empty());
		};

		embedSwf('content_reel');

		var reel1 = $('reel1').addEvent('click', embedSwf.pass('content_reel'));
		var reel2 = $('reel2').addEvent('click', embedSwf.pass('studio_reel'));
	}


	$('footer').getElements('li').each(function (li) {
		var img = li.getElement('img');
		var imgOver = li.getElement('img.over');

		if (imgOver) {
			li.addEvents({
				mouseover: function () {
					img.setStyle('display', 'none');
					imgOver.setStyle('display', 'block');
				},
				mouseout: function () {
					img.setStyle('display', 'block');
					imgOver.setStyle('display', 'none');
				}
			});
		}
	});
});
