$(document).ready(function() {

	// About section
	$(".expertise").click(function(type) {
			$("#uniqueExpertise").fadeIn('slow');
			$("#uniqueBackground").hide();	
			$(".expertise").toggleClass("active");
			$(".background").removeClass('active');
	 });
	
	$(".background").click(function(type) {
			$("#uniqueExpertise").hide();
			$("#uniqueBackground").fadeIn('slow');
			$(".background").toggleClass("active");
			$(".expertise").removeClass('active');
	 });
	
	
	// Fade in gallery images
	$(".image").fadeTo(1, .5);
	$("#image").fadeIn(500);
	
	// Check to see if case study contains muliple case styudy videos
	var firstThumb = $(".thumbs li:first-child > .image");
	if(firstThumb.attr('title')==0){
		firstThumb.toggleClass("active");
		firstThumb.append('<span></span>');
		firstThumb.fadeTo(0, 1);
	} 
	
	
	// Image gallery
	    	$(".image").hover(function() {
			if (!$(this).hasClass('active')){
				$(this).fadeTo("fast", 1);
			}
	        	}, function () {
			if (!$(this).hasClass('active')){
	       			$(this).fadeTo("fast", .5);
			}
	 });
	
	
	$(".image").click(function(type) {
	
		// Check to see it's not current thumb
		if (!$(this).hasClass('active')){
		
			// Set current state
			$(".active").fadeTo("fast", .5);
			$('.active > span').remove();
			$(".active").removeClass('active');
			$(this).toggleClass("active");
			$('.image.active').append('<span></span>');
			
	
		
			// Grab image details
			var src = $(this).attr("rel");
			var title = $(this).attr("title");
			var desc = $(this).attr("desc");
			var type = $(this).attr("type");
			var display = $(this).attr("display");
		
			// If image or video has information provided
			if(title.length != 0){
				$('#intro').hide();
				$('#intro').fadeIn('slow');
				$('#intro > h2').html(title);
				$('#intro > p').html(desc);
			}
		
			// Change main gallery image
			$('#image').hide();
			if(type=="img"){
				$('#image').html('<img src="' + src + '" width="545" height="306"/>');
				$('#image').css('background', 'url(images/img_loading.gif) center center');
				$('#image img').hide();
				$('#image').show();
				$('#image img').load(function() {
					$('#image img').fadeIn('slow');
					$('#image').css('background', 'none');
				});
			}
			if(type=="vid"){
				$('#image').fadeIn('slow');
				$('#image').html('<iframe src="http://player.vimeo.com/video/' + src + '?title=0&amp;byline=0&amp;portrait=0&amp;color=d60076" width="545" height="306" frameborder="0"></iframe>');
				//flashMovie = $('#image');
				//flashMovie.flash(
					//{
						//swf: 'flash/flash_player.swf',
						//width: 545,
						//height: 306,
						//play: true,
						//autostart: true,
						//flashvars: {
							//sFLV: src
						//}
					//}
				//);
			}
		}
		return false;
	});
});
