// <summary>
// Global function calls
// </summary>
function ExecuteHandler(){
	AssignCSSSelectors();
	AssignLinks();
 RolloverEffect("Navigation1","IMG");
 $("#FeaturedProducts").corner("10px");
 $(".Comparator").corner("10px");
 toggleListItem();
}

// <summary>
//  Dropdown Navigation initialize function
// </summary>

function Rollover(ImageObject)
{
	try
	{
		var RolloverImage = ImageObject.src;
		RolloverImage = RolloverImage.replace(".gif","Active.gif")
		ImageObject.src = RolloverImage;
	}
	catch (ExceptionObject)
	{
	}
}

function Rollout(ImageObject)
{
	try
	{
		var RolloutImage = ImageObject.src;
		RolloutImage = RolloutImage.replace("Active.gif",".gif")
 	ImageObject.src = RolloutImage;
	}
	catch (ExceptionObject)
	{
	}
}

function RolloverEffect (MenuRootNodeGroupTagId,TagType)
{
	try
	{
 
		if (document.getElementById(MenuRootNodeGroupTagId))
		{
			var MenuRootNodeGroupTag = document.getElementById(MenuRootNodeGroupTagId);
			var MenuNodeTag = MenuRootNodeGroupTag.getElementsByTagName("LI");
			for (var i = 0; i < MenuNodeTag.length; i++)
			{
				var MenuChildNodeGroupTag = MenuNodeTag[i].getElementsByTagName(TagType);
				if (MenuChildNodeGroupTag.length > 0)
				{
					if(MenuChildNodeGroupTag[0].src.indexOf("Active.gif")<0)
					{					
						MenuChildNodeGroupTag[0].onmouseover = new Function("Rollover(this);");
						MenuChildNodeGroupTag[0].onmouseout = new Function("Rollout(this);");
					}
				}
			}
		}
  
  $("#Navigation1").children().hover(
  function(){
   $(this).addClass("Active");
  },
  function(){
   $(this).removeClass("Active");
  });  
	}
	catch (ExceptionObject)
	{
	}
}

// <summary>
//  Function to attach css class to dropdown element on hover
// </summary>
$.fn.hoverClass = function(c) {
 return this.each(function(){
  $(this).hover( 
   function() { $(this).addClass(c);  },
   function() { $(this).removeClass(c); }
  );
 });
};    

// <summary>
//  This function to assign target blank to the external link. html target blank is not a standard w3c validated code. insted of using target="_blank" we use rel="external" and replace the rel with javascript.
// </summary>
function AssignLinks() 
{
	$("a[rel='external']").attr("target","_blank");
	$("a[href='#']").click(function(){
		return false;
	});
}

// <summary>
//  This function to attach non-ie css selectors to the html elements
// </summary>
function AssignCSSSelectors()
{
	if(jQuery.browser.msie)
	{
		$("li:first-child").addClass("FirstChild");
		$("li:last-child").addClass("LastChild");
		$("td:last").addClass("LastChild");
  $("tr:first").addClass("FirstChild");
	}
}

/// <summary>
///  These functions handle events generated by an Input Text box
/// </summary>

function InputTextOnFocusHandler (InputTag, DefaultText,TextType)
{
	try
	{  		
		if (InputTag.value == DefaultText)
		{
			InputTag.value = "";
			if (TextType=="Password")
			{
				//changeInputType(InputTag, "password",DefaultText,TextType);
			}
		}
		
	}
	catch (ExceptionObject)
	{

	}
}

function InputTextOnBlurHandler (InputTag, DefaultText,TextType)
{
	try
	{
		if (InputTag.value == "")
		{
			InputTag.value = DefaultText;	
			if (TextType=="Password")
			{
				//changeInputType(InputTag, "text",DefaultText,TextType);
			}
		}
	}
	catch (ExceptionObject)
	{
		//alert();
	}
}

/// <summary>
///  Reading XML for the homepage featured product list items
/// </summary>
function LoadFeautredProductsList()
{
var NavigationMarkup = "";
 $.ajax({
   type: "Get",
   url: "/system/includes/xml/FeaturedList.xml",
   cache: false,
   dataType: "xml",
   success: function(xml){
    $(xml).find("FeaturedProduct").each(function(){
     NavigationMarkup = NavigationMarkup +  "<li><a href=" + $(this).find("link").text() + " title=" + $(this).find("id").text() +">"+ $(this).find("linkText").text()+"</a></li>"
    });
    $(".RightPane ul").html("");
    $(".RightPane ul").html(NavigationMarkup);
    $(".RightPane ul li").css({borderBottom: "1px solid #fff"});
    $(".RightPane ul li:last-child").css({borderBottom: "0px solid #fff"});
    LoadFeaturedProduct();
   }
 });
 
}

/// <summary>
///  Loading the data on hover
/// </summary>
function LoadFeaturedProduct()
{
var ProductId = "";
 $(".RightPane ul").children().hover(function(){
 $("#Arrow").show();
 $("#Arrow").css({top: $(this).offset().top-210 + "px" });
  ProductId = $(this).find("a").attr("title");
  $.ajax({
    type: "Get",
    url: "/system/includes/xml/FeaturedList.xml",
    dataType: "xml",
    success: function(xml){
     $(xml).find("FeaturedProduct").each(function(){
     if ($(this).find("id").text() == ProductId)
     {
      $(".FeatureImage").find("img").hide();
      $(".FeatureImage").find("img").attr("src",$(this).find("image").text());
      $(".FeatureImage").find("img").show();
      $(".Description").find("p:first").html($(this).find("description").text());
      $(".Description").find("a").attr("href",$(this).find("link").text());

     }
      //NavigationMarkup = NavigationMarkup +  "<li><a href=" + $(this).find("link").text() + " title=" + $(this).find("id").text() +">"+ $(this).find("linkText").text()+"</a></li>"
     });
    }
    
  });
  
 },
 function(){
 $("#Arrow").hide();
 }
 );
}


// <summary>
// this function toggles the list item being used for faqs
// </summary>
function toggleListItem()
{
 $(".Accordion").find("div").hide();
 $(".Accordion").children().each(function(){
  $(this).find("a").click(function(){
  if ($(this).parent().hasClass("Selected"))
  {
   $(this).parent().find("div").slideUp(500);
  }
  else
  {
   $(this).parent().find("div").slideDown(500);
  }
  $(this).parent().toggleClass("Selected");
 });
 });
}

// <summary>
// this function Handling the glossary section
// </summary>
function HandleGlossary()
{
	  
$(".GlossaryHolder").find("div").hide();
$(".GlossaryHolder").find("div:first").show();
$(".Glossary").children().each(function(){
 $(this).find("a").click(function(){
 $(".GlossaryHolder").find("div").hide();
  $($(this).attr("href")).show();
  $(".Glossary li").removeClass("Active");
  $(this).parent().addClass("Active");

 });
});
}