var homepage = {


	start: function () {
		
		$('#flash_home').flash({
			src: '/assets/flash/home.swf',
			width: 960,
			height: 300,
			wmode: 'transparent'
		});
		
		if ( $('.nextButton').length ) {
			$('#carousel div').jCarouselLite({
				btnNext: ".nextButton",
				btnPrev: ".prevButton",
				easing: "jswing",
				speed: 800,
				beforeStart: homepage.beforeScroll,
				afterEnd: homepage.afterScroll
			});
			
		}
		
		$('#carousel li').hover( function() {
			
			var span = $(this).find('span');
			span.animate({ opacity: 1 }, 1000);
			
		}, function() {
			
			var span = $(this).find('span');
			span.animate({ opacity: .3 }, 1000);
			
		})
		
		$('#carousel a').click( function( e ) {
			
			var provider = ( $( this ).attr('href').indexOf('vimeo') != -1) ? 'vimeo' : 'youtube';
			
			e.preventDefault();
			var chunks = $(this).attr('id').split('-');
			if ( chunks.length > 1 ) homepage.showModal( chunks[1], provider );
			
			
		});

		
	},
	
	beforeScroll: function() {
		
		var links = $('#carousel ul a');
		links.animate({ opacity: 0 }, 200);
		
		var span = $('#carousel ul span');
		span.animate({ opacity: 0 }, 200);
		
	},
	
	afterScroll: function() {
		
		var links = $('#carousel ul a');
		links.animate({ opacity: 1 }, 200);
		
		var span = $('#carousel ul span');
		span.animate({ opacity: .3 }, 200);		
		
	},
	
	showModal: function( idString, provider  ) {
		
		var urlStub;
		
		if ( provider == 'vimeo' ) {
			urlStub = 'http://player.vimeo.com/video/' + idString + '?color=ffffff';			
		} else {
			urlStub = 'http://www.youtube.com/embed/' + idString + '';			
			
		}

		$("#modalWindow").modal({
			opacity:80,
			overlayCss: {backgroundColor:"#000"},
			overlayClose: true
			
		});
		
		$("#modalWindow iframe").attr( 'src', urlStub );
		
	}
	
	
	
	
	
};

$(homepage.start);
