if (typeof NCC == "undefined") NCC = new Object();
if (typeof NCC.recording_democracy == "undefined") NCC.recording_democracy = new Object();

var i;
var gallery_img = new Array();
var gallery_title = new Array();
var gallery_desc = new Array();

var gallery_path = "";

var gallery_elements = new Array();
var gallery_title_elements = new Array();
var gallery_desc_elements = new Array();

var fadeIn_speed;
var fadeOut_speed;

/*********************************************\
 To change the images (and related captions) 
 for the gallery on the Recording Democracy 
 page, use the comments below as guidance. 
 The section  of code requiring editing is 
 delineated by comments just above and below 
 that section.
\*********************************************/

NCC.init_recording_democracy = function ()
{	
	console.log("NCC.init_recording_democracy()");
	
	i = 0;
	
	// ***** Nothing above this point should be edited ***** //
	
	// This is a list of the image file names to be used in the gallery. They should be stored in the "images/" folder.
	gallery_img = [ "rd_01.jpg", 
					  "rd_02.jpg",
					  "rd_03.jpg",
					  "rd_04.jpg"
					  ];
	
	// This is a list of the image caption titles for the gallery. 
	//   The order of these entries corresponds to the order of the files listed above.
	gallery_title = [ "Picture in Picture",
						  "School Colors",
						  "Tea in Kabul",
						  "Afghan Girl"
						  ];
	
	// This is a list of the image caption descriptions for the gallery. 
	//   The order of these entries corresponds to the order of the files listed above.
	gallery_desc = [ "Students at the Marefat School are instructed in Photography as part of the Being We, the People Project funded by the American Association of Museums. Photo Courtesy of the Marefat School.",
							  "Constitution High School is the Philadelphia partner in the Being We, the People Project. Photo Courtesy of Constitution High School.",
							  "Women prepare tea and <em>naan</em> bread on the side of a street in Kabul. Photo courtesy of the Marefat School.",
							  "Child poses for one of the photographers-in-training.  Photo Courtesy of the Marefat School."
							  ];
	
	// This is the path to the directory where the images can be found. This should not need to be changed.
	gallery_path = "./images/";
	
	// The number of entries in the following three lists should match the number of images being used.
	//   Each entry should have an incrementally higher number between the brackets ("[]"), starting at zero.
	gallery_elements = [$('<img />').attr('src', gallery_path + gallery_img[0]),
						   $('<img />').attr('src', gallery_path + gallery_img[1]),
						   $('<img />').attr('src', gallery_path + gallery_img[2]),
						   $('<img />').attr('src', gallery_path + gallery_img[3])
						   ];
	
	gallery_title_elements = [$('<div id="photo-title" />').html(gallery_title[0]),
								   $('<div id="photo-title" />').html(gallery_title[1]),
								   $('<div id="photo-title" />').html(gallery_title[2]),
								   $('<div id="photo-title" />').html(gallery_title[3])
								   ];
	
	gallery_desc_elements = [$('<div id="photo-desc" />').html(gallery_desc[0]),
								   $('<div id="photo-desc" />').html(gallery_desc[1]),
								   $('<div id="photo-desc" />').html(gallery_desc[2]),
								   $('<div id="photo-desc" />').html(gallery_desc[3])
								   ];
	
	// ***** Nothing below this point should be edited ***** //

	fadeIn_speed = 300;
	fadeOut_speed = 300;
	
	NCC.recording_democracy.bind_next();
	NCC.recording_democracy.bind_prev();

}

NCC.recording_democracy.bind_next = function ()
{
	$("span#next-photo a").bind("click", function () {
		NCC.recording_democracy.next();		
		return false;
	});
												   
}

NCC.recording_democracy.bind_prev = function ()
{
	$("span#prev-photo a").bind("click", function () {
		NCC.recording_democracy.prev();		
		return false;
	});
												   
}

NCC.recording_democracy.next = function ()
{
	if(i == gallery_elements.length - 1)
	{
		i = 0;		
	} else
	{
		i++;
	}
	
	NCC.recording_democracy.transition();
}

NCC.recording_democracy.prev = function ()
{
	if(i == 0)
	{
		i = gallery_elements.length - 1;		
	} else
	{
		i--;
	}
	
	NCC.recording_democracy.transition();
}

NCC.recording_democracy.transition = function ()
{	
	if ($.browser.msie && $.browser.version < 7) // fix for ie6
	{
	    $("#gallery #photo-caption #photo-title").css("visibility", "hidden");
	    $("#gallery #photo-caption #photo-desc").css("visibility", "hidden");
	    setTimeout(NCC.recording_democracy.ie6_cycle, fadeOut_speed + fadeIn_speed);	    
	    
	    $("#gallery #photo-holder img").fadeTo(fadeOut_speed, 0, function() {
		    $("#gallery #photo-holder img").remove();
		    $("#gallery #photo-holder").append(gallery_elements[i]);
		    $("#gallery #photo-holder img").css("opacity", 0);
		    $("#gallery #photo-holder img").attr("alt", gallery_title_elements[i]);
		    $("#gallery #photo-holder img").fadeTo(fadeIn_speed, 1);							
	    });	
	    
	} else {
	
	    $("#gallery #photo-caption #photo-title").fadeTo(fadeOut_speed, 0, function() {
		    $("#gallery #photo-caption #photo-title").remove();	
		    $("#gallery #photo-caption").append(gallery_title_elements[i]);
		    $("#gallery #photo-caption #photo-title").css("opacity", 0);
		    $("#gallery #photo-caption #photo-title").fadeTo(fadeIn_speed, 1);
	    });
    	
	    $("#gallery #photo-caption #photo-desc").fadeTo(fadeOut_speed, 0, function() {
		    $("#gallery #photo-caption #photo-desc").remove();		
		    $("#gallery #photo-caption").append(gallery_desc_elements[i]);
		    $("#gallery #photo-caption #photo-desc").css("opacity", 0);
		    $("#gallery #photo-caption #photo-desc").fadeTo(fadeIn_speed, 1);	
	    });
    	
	    $("#gallery #photo-holder img").fadeTo(fadeOut_speed, 0, function() {
		    $("#gallery #photo-holder img").remove();
		    $("#gallery #photo-holder").append(gallery_elements[i]);
		    $("#gallery #photo-holder img").css("opacity", 0);
		    $("#gallery #photo-holder img").attr("alt", gallery_title_elements[i]);
		    $("#gallery #photo-holder img").fadeTo(fadeIn_speed, 1);							
	    });	
	}
}

NCC.recording_democracy.ie6_cycle = function ()
{
    $("#gallery #photo-caption #photo-title").remove();	
	$("#gallery #photo-caption").append(gallery_title_elements[i]);
    $("#gallery #photo-caption #photo-title").css("visibility", "visible");

    $("#gallery #photo-caption #photo-desc").remove();		
    $("#gallery #photo-caption").append(gallery_desc_elements[i]);
    $("#gallery #photo-caption #photo-desc").css("visibility", "visible");
}
