﻿/*
 * Wirepoint Media image slider
 *
 * Copyright (c) 2009 Wirepoint Media, LLC (www.wirepointmedia.com)
 *
 * @Author: Chris Cox <chris.cox@wirepointmedia.com> 
 * @Date: 06-23-09
 * @version: 1.2 REV. 08-05-09
 */

 
/*
 * This function will dynamically load the images from gallery. 
 */
 
 
$(function(){

	//Create description container and make ajax call
    $("#modulePage3804349 #content").prepend("<div id='desc' style='display:none'></div>");
	$("#modulePage3804349 #desc").load("/imagelibrary/rotator/ #content .description", function(data) {});

	//Create thumbnail container to load images into and make ajax call
	$("#modulePage3804349 #content").prepend("<div id='thumbs' style='display:none'></div>");
	$("#modulePage3804349 #thumbs").load("/imagelibrary/rotator/ #content img", function(data) {

		//Filter out gallery thumbnail images    
		$("#thumbs img").each(function(i){
          
			//Get attributes
			var desc = $("#content #desc .description:eq(" + i + ") p").html();
			var filename = $(this).attr("title");
			var id = $(this).attr("id").replace("picture", "").replace("-img", "");     
			var imgUrl = "/picture/" + filename + "?pictureId=" + id; 
			var thumbUrl = imgUrl + "&asThumbnail=true";   

			// add images to slider
			$('#slideshow').append("<img src='" + imgUrl + "' width='729' height='452' title='" + filename + "' alt='" + desc + "'/>");
            
		
		});

        //Add title & desc if only one image
        if ( $("#thumbs").length == 1 ){
            $('#textWrapper #slideShowHeader').html( $('#slideshow img').attr('title'));
            $('#textWrapper #slideShowText').html( $('#slideshow img').attr('alt'));
        }; 
        
        $('#slideshow').cycle({ 
			fx:     'fade',
			sync:    true,
			speed:   1500, 
			timeout: 7000, 
			pager:  '#nav',
			pagerAnchorBuilder: function(idx, slide) { 
                return '<li><a href="#"><img src="' + slide.src + '" width="80" height="50" /></a></li>';
            }
		}); 
        
		function onBefore() { 
			$('#textWrapper').fadeOut("fast"); 
		} 

		function onAfter() { 
			$('#textWrapper').fadeIn("slow");
			$('#textWrapper #slideShowHeader').html(this.title);
			$('#textWrapper #slideShowText').html(this.alt);
		}
		
	});
});