/* anaframe.net gallery javascript */
/* design and development by David Hilgier - http://theviale.net */



/* javascript controlling image swap on gallery pages
/* based off of http://www.sohtanaka.com/web-design/examples/image-rotator/ */
/* using elements from http://www.twospy.com/galleriffic */
$(document).ready(function() {	
	//Show Banner
	$(".galleryleft").show(); //Show Banner
	//$(".galleryleft .block").show();
	//Show Description if it has content
  	// detect if div has content within it
  	var content = $.trim($(".galleryleft .block").html()).length;
  	//hides if not, otherwise reveal
  	if(content == 0) {
    	$(".galleryleft .block").hide();
    	$(".galleryleft .galleryinfo").hide();
  	}else {
  		$(".galleryleft .block").show();
  		$(".galleryleft .galleryinfo").show();
  	}
	//Rollover for thumbnails
	$(".galleryright ul li").opacityrollover({
		mouseOutOpacity:   1.0,
		mouseOverOpacity:  .8,
		fadeSpeed:'fast',
		exemptionSelector: '.active'
	});
	//Click events for thumbnail list
	$(".galleryright ul li:first").addClass('active');
	$(".galleryright ul li:first").fadeTo('fast', .5); 
	$(".galleryright ul li").click(function(){ 
		//Set Variables
		var imgAlt = $(this).find('img').attr("alt"); //Get Alt Tag of Image
		var imgTitle = $(this).find('a').attr("href"); //Get Main Image URL
		var imgDesc = $(this).find('.block').html(); 	//Get HTML of block
		var imgDescHeight = $(".galleryleft").find('.block').height();	//Calculate height of block	
		if ($(this).is(".active")) {  //If it's already active, then...
			return false; // Don't click through
		} else {
			// $(".galleryleft .block").html(imgDesc).show();//show info ORIGINAL
			//detects if new image needs description
			var imgDescTrim = $.trim(imgDesc).length;
			if (imgDescTrim == 0) {
				$(".galleryleft .galleryinfo").hide();
				$(".galleryleft .block").html(imgDesc).hide();//hide new description
			} else {
				$(".galleryleft .galleryinfo").show();
				$(".galleryleft .block").html(imgDesc).show();//show new description
			}
			$(".galleryleft img").attr({ src: imgTitle , alt: imgAlt});//show image
		}
		$(".galleryright ul li").removeClass('active'); //Remove class of 'active' on all lists
		$(this).addClass('active');  //add class of 'active' on this list only //
		jQuery(".galleryright ul li").css('opacity', 1.0);//Sets opacity of inactive thumbs
		jQuery(this).css('opacity', .5);//Sets opacity of active thumb
		return false;
	});	
});
