 /** 
* @projectDescription L'Evenement VIP
* @author	Guyllaume Doyer
*/


// ---------------------------------------------------------------------------------------------- \\
// Jquery init event
// ---------------------------------------------------------------------------------------------- \\
$(document).ready(function()
{
	handleLocationMaterielProducts();
});


function handleLocationMaterielProducts()
{
	
	
	var ttprod = {
		
		context: $("#LocationMaterielProductsBlock"),
		
		init: function()
		{
			// Show Pics Diaporama Block (hidden by default for accessibility issue)
			$(".diaporamaBlk", ttprod.context).show();
			
			// Hide pics (displayed by default for accessibility issue)
			$("dd .itemPics", ttprod.context).hide();
			
			this.listeners()
			
			$("dt:first", ttprod.context).click();
			
			return this;
		},
		
		
		listeners: function()
		{
			$("dt.itemTitle", ttprod.context).css("cursor", "pointer").click( function() { ttprod.showItemPics($(this)); } );
			
			//$(".diaporamaBlk span.goNextLnk", ttprod.context).click( function(){ ttprod.next(); } );
			
			//$(".diaporamaBlk span.goPreviousLnk", ttprod.context).click( function(){ ttprod.previous(); } );
			
			return this;
		},
		
		
		showItemPics: function(clickedItem)
		{
				// Remove "current" class of every DT and DD (quicklier than finding the current ones and the remove class)
				$("dt, dd", ttprod.context).removeClass("current");
				
				// Add "current" class on clicked item DT
				clickedItem.addClass("current");
			
				// Get clicked item related pics attributes (and add "current" class on clicked item DD)
				var itemPics = clickedItem.next("dd").addClass("current").find("img.itemPics");
				var itemPicsSRC = itemPics.attr("src");
				var itemPicsAlt = itemPics.attr("alt");
				var itemPicsTitle = itemPics.attr("title");
				
				// Set Diaporama Pics new attributes
				$("#diaporamaPics", ttprod.context).attr({src:itemPicsSRC, alt:itemPicsAlt, title:itemPicsTitle});
				
			
			return this;
		},
		
		
		getCurrent: function()
		{
			return $("dt.current" ,ttprod.context);
		},
		
		
		next: function()
		{
			var current = ttprod.getCurrent();
			
			// If The current is the last item, the next item has to be the first
			if ( $("dt", ttprod.context).index(current[0]) == $("dt", ttprod.context).length - 1 )
			{
					$("dt:first", ttprod.context).click();
			}
			else
			{
				ttprod.getCurrent().prev("dd").prev("dt").click();
			}
			
			current.next("dd").next("dt").click();
			
			return this;
		},
		
		
		previous: function()
		{
			var current = ttprod.getCurrent();
			
			// If The current is the first item, the previous item has to be the last
			if ( $("dt", ttprod.context).index(current[0]) == 0 )
			{
					$("dt:last", ttprod.context).click();
			}
			else
			{
				ttprod.getCurrent().prev("dd").prev("dt").click();
			}
			
			return this;
		}
		
	}
	
	// Initialise function
	ttprod.init();
	
}