/// <summary>The Locator class adds generic javascript logic used throughout the UVL.
$(document).ready(function() { 
	/******* START - Compact Compare/Favourites Script *******/
	
	/******* START - Initalisation *******/
	
	//Calculate compare div height based on no. of images.
	var compareCount = $("ul.menu.related > li.parent.compare > div.compareCompactPanel > div.list > div.item > a > img").length;
	var compareImageHeight = $("ul.menu.related > li.parent.compare > div.compareCompactPanel > div.list > div.item > a > img").attr("height");
	var compareRows = compareCount;
	var compareGap = (compareRows * 3) + 60;
	$("ul.menu.related > li.parent.compare > div.compareCompactPanel").attr({
		style : "height : " + ((compareImageHeight * compareRows) + compareGap) + "px"
	});

	//Calculate favourites div height based on no. of images.
	var favouritesCount = $("ul.menu.related > li.parent.favourites > div.favouritesCompactPanel > div.list > div.item > a > img").length;
	var favouritesImageHeight = $("ul.menu.related > li.parent.favourites > div.favouritesCompactPanel > div.list > div.item > a > img").attr("height");
	var favouritesRows = favouritesCount;
	var favouritesGap = (favouritesRows * 3) + 60;
	$("ul.menu.related > li.parent.favourites > div.favouritesCompactPanel").attr({
		style : "height : " + ((favouritesImageHeight * favouritesRows) + favouritesGap) + "px"
	});

	//Close all compact panels.
	$("ul.menu.related > li.parent > div").hide();
	
	/******* END - Initalisation *******/		
	
	//Handle the click event on a given panel.
    $("ul.menu.related > li.parent").click(
      function () {
		if ($(this).hasClass("greyArrowDown"))
		{		
			$(this).removeClass("greyArrowDown");
			$(this).addClass("greyArrowUp");
			$(this).children("div").slideDown("slow");
		}
		else
		{
			$(this).removeClass("greyArrowUp");
			$(this).addClass("greyArrowDown");
			$(this).children("div").slideUp("slow");
		}
      }      
    ); 
    
    /******* END - Compact Compare/Favourites Script *******/
    
    /******* START - Compare Script *******/
	//Handle the click event on a collapseable section.
    $("tr.sectionCollapse").click(
      function () {
		var sectionToCollapse = "";
		if ($(this).hasClass("greyArrowUp"))
		{		
			$(this).removeClass("greyArrowUp");
			$(this).addClass("greyArrowDown");			 			
			sectionToCollapse = "#" + $(this).children("th").children("input").attr("value");
			$(sectionToCollapse).slideUp("slow");
			//$(sectionToCollapse).hide();
		}
		else
		{
			$(this).removeClass("greyArrowDown");
			$(this).addClass("greyArrowUp");
			sectionToCollapse = "#" + $(this).children("th").children("input").attr("value");
			$(sectionToCollapse).slideDown("slow");	
			//$(sectionToCollapse).show();
		}
      }      
    );     
    /******* END - Compare Script *******/
    
    /******* START - Show/Hide FieldSet Script *******/
	//Handle the click event on a collapseable fieldset.
    $("div.fldSetDivider").click(
      function () {
		var fldSetRequired = $("fieldset.panel." + $(this).attr("id"));
		var anchSymbol = $("#" + $(this).attr("id") + "> a.symbol");
		
		if (anchSymbol.html() == "-")
		{
			anchSymbol.html("+")
			fldSetRequired.hide();
		}
		else
		{
			anchSymbol.html("-")
			fldSetRequired.show();
		}
      }      
    );     
    /******* END - Show/Hide FieldSet Script *******/
});