// <summary>
// Global function calls
// </summary>

var AppPath="/";
function ExecuteHandler(){
 $(document).ready(function(){
	AssignCSSSelectors();
	AssignLinks();
	FixFonts();
	//RolloverEffect("SerchNext","IMG");
	ToggleListItem();
	InitializeMenu();
	RoundCorners();
	if (location.href.indexOf("/news/") != -1){
		AddPdfClass();
	}
 });
}

// <summary>
//  Setting the dropdown Navigation
// </summary>

function InitializeMenu()
{
$("#Navigation li ul").css({display: "none"});
	$("#Navigation").children().each(function()
	{
		$(this).hover(
		function(){
		 if (!$(this).hasClass("Highlight"))
		 {
		  $(this).addClass("Active");
          $(this).find("img").attr("src",$(this).find("img").attr("src").replace(".gif","Active.gif"));    
         }
		 if ($(this).children("ul").length > 0 )
		 {
          $(this).children("ul").css({display:"block"});
       	 }},
		function(){
		 if (!$(this).hasClass("Highlight")){
		  $(this).removeClass("Active");
          $(this).find("img").attr("src",$(this).find("img").attr("src").replace("Active.gif",".gif"));
         }
        if ($(this).children("ul").length > 0 ){
         $(this).children("ul").css({display:"none"});
        }
  }
	);
 }); 
}

// <summary>
// this function toggles the content. Used in FAQ module
// </summary>
function ToggleListItem()
{
 $(".Toggle").find("div").hide();
 $(".Toggle").children().each(function(){
  $(this).find("a").click(function(){
  if ($(this).parent().hasClass("Clicked"))
  {
   $(this).parent().find("div").slideUp(500);
  }
  else
  {
   $(this).parent().find("div").slideDown(500);
  }
  $(this).parent().toggleClass("Clicked");
 });
 });
}

// <summary>
// Add rounded corners to all div elements with class="round"
// <summary>
function RoundCorners(){
try
{
 var str = '<b class="cn tl"></b><b class="cn tr"></b><b class="cn bl"></b><b class="cn br"></b>';
 // Three lines below handle images
  $('img.round').wrap('<div class="round"></div>');//returns img element
 // var floating = $('img.round').css("float");
 // $('img.round').removeClass('round').css("float", "none").parent().css("float", floating);
 $('.round').addClass("boxc").append(str);
}
catch(obj)
{
}
};


// <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);");
					}
				}
			}
		}
 
  $("#Navigation").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>
//  sifr replacement script.
// </summary>
function FixFonts()
{
  $("h2").sifr({
	  font: AppPath + 'Fonts/MyriadPro', 
   color: '#abe9ff'
  });
  
    $("#InnerPage h2").sifr({
	  font: AppPath + 'Fonts/MyriadPro', 
   color: '#00b0ef'
  });
	
	$("#htmlContent #LeftCol h3").sifr({
	  font: AppPath + 'Fonts/MyriadPro', 
   color: '#abe9ff'
  });

$(".contentBox h4").sifr({
	  font: AppPath + 'Fonts/MyriadPro', 
   color: '#abe9ff'
  });


   }

// <summary>
//  window resize call
// </summary>
function winResize(){
 $(window).resize(function(){
  fixScreen();
 });
}

/// <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();
	}
}

function HandleMediaSpace(){
 $("#MediaSpace ul").css({height:"40px", overflow: "hidden",opacity: 0});
 $("#Canvas img").css({opacity:0});
 $("#MediaSpace ul").animate({opacity: 1},{queue:false,duration:1000,easing: "easeInQuad",complete:function(){
  $("#Canvas img").animate({opacity: 1},{queue:false,duration:1200,easing: "easeInQuad"}); 
  if(jQuery.browser.msie){
   $("#MediaSpace ul").css({opacity: 0.8});
  }
 }
});

$("#MediaSpace ul li:first").addClass("Active");
$("#MediaSpace ul").children().each(function(){
 $(this).hover(
  function(){
   var ImgName = $(this).find("a").attr("rel");
   if ($(this).hasClass("Active")){
    return false;
   }
   $("#MediaSpace ul li").removeClass("Active");
   $(this).addClass("Active");
   $(this).css({opacity:0.2});
   $(this).animate({opacity: 1},{queue:false,duration:600,easing: "easeInQuad"});
   $("#Canvas img").stop().animate({opacity: 0},{queue:false,duration:600,easing: "easeInQuad",complete:function(){
    $("#Canvas img").attr("src", AppPath + "Images/Content/" + ImgName + ".jpg");
    $("#Canvas img").animate({opacity: 1},{queue:false,duration:600,easing: "easeInQuad"});
   }});
  },
  function(){
  
  });
 });
}

function onUpdatingForm(elementId)
{
  $.extend($.blockUI.defaults.overlayCSS, { backgroundColor: '#ffffff' });
  $('#'+elementId).block('<img src="/Images/Generic/Bigrotation.gif" border="0" style="margin:auto;" />',{ background: 'transparent', border: '0' });
}

function onUpdatedForm(elementId)
{
$('#'+elementId).unblock();
}

function AddPdfClass(){
$("a[@href$=ashx]").addClass('PdfLink');
$("a[@href$=ashx]").attr("target","_blank").attr("title","Download this article as a PDF");
	}
	


