function lightBoxMain() {
  mainImage = $($(".gallery-nav:visible .main_image img")[0]);
  exploded_image_path = mainImage.attr('src').split('images/');
  exploded_src = mainImage.attr('src').split('.');
  exploded_src[exploded_src.length-2] = exploded_src[exploded_src.length-2] + '_big';
  target = exploded_src.join('.');
  //bigImage = $("<img src='"+target+"' />")
  //alert(target);
  $.facebox({image: target});
}

function videoFor(name) {
  return "" +
  "<object classid=\"clsid:D27CDB6E-AE6D-11cf-96B8-444553540000\" codebase=\"http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=7,0,19,0\" width=\"437\" height=\"366\">" +
  "  <param name=\"movie\" value=\"swf/"+name+".swf\" />" +
  "  <param name=\"quality\" value=\"high\" />" +
  "  <param name=\"allowFullScreen\" value=\"true\" />" +
  "  <embed src=\"swf/"+name+".swf\" width=\"437\" height=\"366\" quality=\"high\" pluginspage=\"http://www.macromedia.com/go/getflashplayer\" type=\"application/x-shockwave-flash\" allowfullscreen=\"true\"></embed>" +
  "</object>";
}

function optionsForGallery(number){  
  return {
		history   : false, // activates the history object for bookmarking, back-button etc.
		clickNext : false, // helper for making the image clickable
		insert    : ('#detail'+number+' .main_image'), // the containing selector for our main image
		onImage   : function(image,caption,thumb) { // let's add some image effects for demonstration purposes
			
			// fetch the thumbnail container
			var _li = thumb.parents('li');
			
			// fade out inactive thumbnail
			_li.siblings().children('img.selected').fadeTo(500,0.3);
			
			// fade in active thumbnail
			thumb.fadeTo('fast',1).addClass('selected');
			
			// add a title for the clickable image
			image.attr('title',"+enlarge");
			
			exploded_src = image.attr('src').split('.')
			target = exploded_src[0] + '_big.' + exploded_src[1];
			
			$(".lb_button").unbind('click');
			$(".lb_button").click(function(){ 
			  lightBoxMain(); 
			});
			
			$(".main_image .caption").prepend("<strong>Client</strong> ");
		},
		onThumb : function(thumb) { // thumbnail effects goes here
			
			// fetch the thumbnail container
			var _li = thumb.parents('li');
			
			// if thumbnail is active, fade all the way.
			var _fadeTo = _li.is('.active') ? '1' : '0.3';
			
			// fade in the thumbnail when finnished loading
			thumb.css({display:'none',opacity:_fadeTo}).fadeIn(1500);
			
			// hover effects
			thumb.hover(
				function() { thumb.fadeTo('fast',1); },
				function() { _li.not('.active').children('img').fadeTo('fast',0.3); } // don't fade out if the parent is active
			)
		}
	}
}

jQuery(function($) {

		$('#detail18 ul.gallery').galleria(optionsForGallery('21'));
		$('#detail18 ul.gallery').galleria(optionsForGallery('20'));
		$('#detail18 ul.gallery').galleria(optionsForGallery('19'));
		$('#detail18 ul.gallery').galleria(optionsForGallery('18'));
		$('#detail17 ul.gallery').galleria(optionsForGallery('17'));
		$('#detail16 ul.gallery').galleria(optionsForGallery('16'));
		$('#detail15 ul.gallery').galleria(optionsForGallery('15'));
		$('#detail14 ul.gallery').galleria(optionsForGallery('14'));
		$('#detail13 ul.gallery').galleria(optionsForGallery('13'));
		$('#detail12 ul.gallery').galleria(optionsForGallery('12'));
		$('#detail11 ul.gallery').galleria(optionsForGallery('11'));
		$('#detail10 ul.gallery').galleria(optionsForGallery('10'));
		$('#detail9 ul.gallery').galleria(optionsForGallery('9'));
		$('#detail8 ul.gallery').galleria(optionsForGallery('8'));
		$('#detail7 ul.gallery').galleria(optionsForGallery('7'));
		$('#detail6 ul.gallery').galleria(optionsForGallery('6'));
		$('#detail5 ul.gallery').galleria(optionsForGallery('5'));
		$('#detail4 ul.gallery').galleria(optionsForGallery('4'));
		$('#detail3 ul.gallery').galleria(optionsForGallery('3'));
		$('#detail2 ul.gallery').galleria(optionsForGallery('2'));
		$('#detail1 ul.gallery').galleria(optionsForGallery('1'));
		
		// Hide other galleries for now
		$('#detail2').hide();
		$('#detail3').hide();
		$('#detail4').hide();
		$('#detail5').hide();
		$('#detail6').hide();
		$('#detail7').hide();
		$('#detail8').hide();
		$('#detail9').hide();
		$('#detail10').hide();
		$('#detail11').hide();
		$('#detail12').hide();
		$('#detail13').hide();
		$('#detail14').hide();
		$('#detail15').hide();
		$('#detail16').hide();
		$('#detail17').hide();
		$('#detail18').hide();
		$('#detail19').hide();
		$('#detail20').hide();
		$('#detail21').hide();
		
		// initialize scrollable 
  	$("div.scrollable").scrollable({vertical:true, size: 5, hoverClass: 'hover'});
  	
  	if($("body").hasClass('video-gallery')) {
  	  
  	  // Setup up your vids here
  	  $("div.items .detail1").click(function(){ $("#flash-video").html($(videoFor('clearChoice'))); });
  	  $("div.items .detail2").click(function(){ $("#flash-video").html($(videoFor('greenville'))); });
  	  $("div.items .detail3").click(function(){ $("#flash-video").html($(videoFor('stJosephs'))); });
  	  $("div.items .detail4").click(function(){ $("#flash-video").html($(videoFor('clearChoice2'))); });
  	  $("div.items .detail5").click(function(){ $("#flash-video").html($(videoFor('felt'))); });
  	  $("div.items .detail6").click(function(){ $("#flash-video").html($(videoFor('providence'))); });
  	  $("div.items .detail7").click(function(){ $("#flash-video").html($(videoFor('colonial'))); });
  	  
  	  
  	}else {
  	  
  	  $("div.scrollable div.items div").click(function(){
    		target = $($(this).children('img')[0]).attr('class');
    		$("div.gallery-nav").hide();
    		$("#"+target).show();
    		$("#"+target+" ul.gallery li:last-child img").click();
    	});
    	
  	}
  	
  	// Enable lightbox for focused image
  	$(".main_image").click(function(){ lightBoxMain(); });
  	
});

