/// <summary>
/// The GalleryCollection class adds the javascript logic for the processing images within the new cars section.
/// </summary>
/******************************************************************************/
$(document).ready(function() {
    bindThumbnailEvents($("div.scrollableArea"));
});
/******************************************************************************/

/******************************************************************************/
function bindThumbnailEvents(thumbs)
{
    //Used to bind the click event of a given thumbnail image.
    thumbs.find("img").click(
        function() {
            var ctrl = $(this);
            thumbs.find("img").removeClass();
            ctrl.addClass("active");
            ajaxGetMediaImage("clickedId" + "=" + ctrl.attr("id"));
        }
    );
    
    //Used to renable hotspots as they both disappear if inactive.
    thumbs.parent("div.scrollWrapper").hover(
        function() {
            var scrollingHotSpotLeft = $("div.scrollingHotSpotLeft:visible").length > 0;
            var scrollingHotSpotRight = $("div.scrollingHotSpotRight:visible").length > 0;
            
            if ((scrollingHotSpotLeft == false) && (scrollingHotSpotRight == false))
            {
                $("div.scrollingHotSpotLeft").show();
                $("div.scrollingHotSpotRight").show();
            }
        },
        function() {            
        }
    );
}
/******************************************************************************/

/******************************************************************************/
function ajaxGetMediaImage(args)
{
    //Used to render the required media selection.
	$.ajax({
		 type: "GET",
		 url: "/Arbury/layouts/pages/GetNewCarMedia.ashx",
		 data: ((args) ? args + "&" : "") + "rngItem=" + $("input#rangeItem").val(),
		 dataType: "json",
		 success: function(newCarMedia) {
			$("div#main_image").html(newCarMedia.NewCarMediaMain);
		 },
		 error: function(e) {
			 alert("New Car Media Library : There was a problem with your request.");
		 }
	 });
}
/******************************************************************************/
