if (typeof NCC == "undefined") NCC = new Object();
if (typeof NCC.home == "undefined") NCC.home = new Object();

var i;
var banner_img = new Array();
var banner_title = new Array();
var banner_desc = new Array();

var banner_path = "";

var banner_elements = new Array();
var banner_title_elements = new Array();
var banner_desc_elements = new Array();

var tid;
var fadeIn_speed;
var fadeOut_speed;

/*********************************************\
 To change the images (and related captions) 
 for the rotating banner on the homepage, use 
 the comments below as guidance. The section 
 of code requiring editing is delineated by
 comments just above and below that section.
\*********************************************/

NCC.init_home = function ()
{	
	console.log("NCC.init_home()");
	
	i = 0;
	
	// ***** Nothing above this point should be edited ***** //
	
	// This is a list of the image file names to be used in the rotating banner. They should be stored in the "images/" folder.
	banner_img = ["fea_01.jpg", 
					  "fea_02.jpg",
					  "fea_03.jpg",
					  "fea_04.jpg",
					  "fea_05.jpg"
					  ];
	
	// This is a list of the image caption titles for the rotating banner. 
	//   The order of these entries corresponds to the order of the files listed above.
	banner_title = ["Voting",
						  "Scanning the Ballot",
						  "Proud to Vote",
						  "A Woman Picks Her Candidate",
						  "Counting the Ballots"
						  ];
	
	// This is a list of the image caption descriptions for the rotating banner. 
	//   The order of these entries corresponds to the order of the files listed above.
	banner_desc = ["A woman&rsquo;s finger is marked with ink to ensure that she only votes once.  Photo Courtesy of the Marefat School.",
							  "A voter scans the ballot for the 2009 Afghanistan national election.  Photo courtesy of the Marefat School.",
							  "A woman proudly displays her voter identification and inked finger.  Photo courtesy of the Marefat School.",
							  "Voters wait in line to cast their vote.  Photo courtesy of the Marefat School.",
							  "Elections officials prepare to count the ballots. 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.
	banner_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.
	banner_elements = [$('<img />').attr('src', banner_path + banner_img[0]),
						   $('<img />').attr('src', banner_path + banner_img[1]),
						   $('<img />').attr('src', banner_path + banner_img[2]),
						   $('<img />').attr('src', banner_path + banner_img[3]),
						   $('<img />').attr('src', banner_path + banner_img[4])
						   ];
	
	banner_title_elements = [$('<div id="photo-title" />').html(banner_title[0]),
								   $('<div id="photo-title" />').html(banner_title[1]),
								   $('<div id="photo-title" />').html(banner_title[2]),
								   $('<div id="photo-title" />').html(banner_title[3]),
								   $('<div id="photo-title" />').html(banner_title[4])
								   ];
	
	banner_desc_elements = [$('<div id="photo-desc" />').html(banner_desc[0]),
								   $('<div id="photo-desc" />').html(banner_desc[1]),
								   $('<div id="photo-desc" />').html(banner_desc[2]),
								   $('<div id="photo-desc" />').html(banner_desc[3]),
								   $('<div id="photo-desc" />').html(banner_desc[4])
								   ];
	
	// ***** Nothing below this point should be edited ***** //
	
	tid = -1;
	fadeIn_speed = 700;
	fadeOut_speed = 700;
	
	NCC.home.banner_init();

}


NCC.home.banner_init = function ()
{
	tid = setInterval(NCC.home.cycle, 8000);
}

NCC.home.cycle = function ()
{
	if(i == banner_elements.length - 1)
	{
		i = 0;		
	} else
	{
		i++;
	}
	
	if ($.browser.msie && $.browser.version < 7) // fix for ie6
	{
	    $("#photo-carousel #photo-caption #photo-title").css("visibility", "hidden");
	    $("#photo-carousel #photo-caption #photo-desc").css("visibility", "hidden");
	    setTimeout(NCC.home.ie6_cycle, fadeOut_speed + fadeIn_speed);	    
	    
	    $("#photo-carousel #photo-holder img").fadeTo(fadeOut_speed, 0, function() {
		    $("#photo-carousel #photo-holder img").remove();
		    $("#photo-carousel #photo-holder").append(banner_elements[i]);
		    $("#photo-carousel #photo-holder img").css("opacity", 0);
		    $("#photo-carousel #photo-holder img").attr("alt", banner_title_elements[i]);
		    $("#photo-carousel #photo-holder img").fadeTo(fadeIn_speed, 1);							
	    });	
	    
	} else {
	
	    $("#photo-carousel #photo-caption #photo-title").fadeTo(fadeOut_speed, 0, function() {
		    $("#photo-carousel #photo-caption #photo-title").remove();	
		    $("#photo-carousel #photo-caption").append(banner_title_elements[i]);
		    $("#photo-carousel #photo-caption #photo-title").css("opacity", 0);
		    $("#photo-carousel #photo-caption #photo-title").fadeTo(fadeIn_speed, 1);
	    });
    	
	    $("#photo-carousel #photo-caption #photo-desc").fadeTo(fadeOut_speed, 0, function() {
		    $("#photo-carousel #photo-caption #photo-desc").remove();		
		    $("#photo-carousel #photo-caption").append(banner_desc_elements[i]);
		    $("#photo-carousel #photo-caption #photo-desc").css("opacity", 0);
		    $("#photo-carousel #photo-caption #photo-desc").fadeTo(fadeIn_speed, 1);	
	    });
    	
	    $("#photo-carousel #photo-holder img").fadeTo(fadeOut_speed, 0, function() {
		    $("#photo-carousel #photo-holder img").remove();
		    $("#photo-carousel #photo-holder").append(banner_elements[i]);
		    $("#photo-carousel #photo-holder img").css("opacity", 0);
		    $("#photo-carousel #photo-holder img").attr("alt", banner_title_elements[i]);
		    $("#photo-carousel #photo-holder img").fadeTo(fadeIn_speed, 1);							
	    });	
	}
}

NCC.home.ie6_cycle = function ()
{
    $("#photo-carousel #photo-caption #photo-title").remove();	
	$("#photo-carousel #photo-caption").append(banner_title_elements[i]);
    $("#photo-carousel #photo-caption #photo-title").css("visibility", "visible");

    $("#photo-carousel #photo-caption #photo-desc").remove();		
    $("#photo-carousel #photo-caption").append(banner_desc_elements[i]);
    $("#photo-carousel #photo-caption #photo-desc").css("visibility", "visible");
}