// <summary>
// Global function calls
// </summary>
function ExecuteHandler(){
$(document).ready(function(){
	AssignCSSSelectors();
	AssignLinks();
	InitializeMenu();
	ToggleListItem();
 AutoFit();
 setFeedbackWindow();
 FixSitemap();
 fixFooter();
 PrintForm();
 MailtoFriend();
});
}

// <summary>
//  Setting the dropdown Navigation
// </summary>

function InitializeMenu()
{
$("#Navigation ul li.LastChild a") .wrap("<span></span>");
	$("#Navigation").children().each(function()
	{
		$(this).hover(
		function(){
$(this).addClass("SubNavigation");
			
		},
		function(){
$(this).removeClass("SubNavigation");
		 }
		);
	});
}
// <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() 
{
 $("tr:first-child").addClass("First");
	$("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()
{
		$("li:first-child").addClass("FirstChild");
		$("li:last-child").addClass("LastChild");
		$("td:last").addClass("LastChild");
  $("tr:first").addClass("FirstChild");
}

function PrintForm()
{
 $("#Submitprint").click(function(){
 $(".Message").hide();
 window.print();
 });
}

// <summary>
//  sifr replacement script.
// </summary>
function fixFonts()
{
 $(".Style1").sifr({
			path: '/globalvillage.website/fonts/',
			color: '#be1200'
		});
 $(".Style2").sifr({
			path: '/globalvillage.website/fonts/',
			color: '#be1200'
		});
}


// <summary>
//  function to fix the page layout issues in lower resolutions
// </summary>

function AutoFit()
{
  if ($(window).width()<1100)
  {
   $(".HeaderLeftBg,.HeaderRightBg,#FooterLeftBg,#FooterRightBg").css({ width:"993px", overflow:"hidden",padding:"0",background:"none" })
  }
}

/// <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>
//  These function changes input types dynamically
// </summary>
function changeInputType(OldObject, ObjectType,DefaultText,TextType) 
{
  var NewObject = document.createElement('input');
  NewObject.type = ObjectType;
  if(OldObject.size) NewObject.size = OldObject.size;
  if(OldObject.value) NewObject.value = OldObject.value;
  if(OldObject.name) NewObject.name = OldObject.name;
  if(OldObject.id) NewObject.id = OldObject.id;
  if(OldObject.className) NewObject.className = OldObject.className;
  NewObject.focus();
 	NewObject.onfocus = new Function("InputTextOnFocusHandler(this,'" + DefaultText + "','" + TextType +"' );");
	 NewObject.onmouseout = new Function("InputTextOnBlurHandler(this,'" + DefaultText + "','" + TextType +"' );");
  OldObject.parentNode.replaceChild(NewObject,OldObject);
}

// <summary>
//  Google map function
// </summary>
function googleMapInitialize()
{
 if (GBrowserIsCompatible()) {
  $("#GoogleMap").css({display: "block"});
  var map = new GMap2(document.getElementById("GoogleMap"));
  var point;
  map.setCenter(new GLatLng(25.050069,55.25754), 13);
  point = new GLatLng(25.050069,55.25754);
  map.openInfoWindow(map.getCenter(),"<p><strong>Global Village</strong></p><p>P.O. Box 117777, Dubai<br />United Arab Emirates</p>");
  map.addOverlay(new GMarker(point));
 }
}

// <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>
//  setting the lightbox for image gallery
// </summary>
function SetLightBox()
{
 $('.SlideShow a').lightBox();
}

// <summary>
//  To hide the Newsletter subscription thankyou message popup
// </summary>
function HideModalPopup()
{
$(".NewsletterPopup").hide();
$(".modalBackground").hide();
$(".EmailField").attr("value","Email");
$("input:radio").attr("checked","");
$(".newsletterPopup").remove();
}

// <summary>
//  feedback form
// </summary>
function setFeedbackWindow()
{
 $("#FeedbackLink").click(function(){
  $("#feedbackForm").show(500);  
  var feedbackOffset = $(this).offset();
  $("#infoMessage").hide();
  $("#formContent").show();
  $("#ctl00_ucFooter_txtfeedbackText").val("Submit your feedback*");
 });
 $("#feedbackclose").find("a").click(function(){
  $("#feedbackForm").hide(500);  
 });
 
 $(".submitButton").click(function(){
  var feedbackVal = $("#ctl00_Footer_txtfeedbackText").val();

  var ajxURL= "/ajaxFeedBack.aspx?feedback=" + feedbackVal;
  $("#infoMessage").hide();
  $("#formContent").show();
  if ((feedbackVal=="") || (feedbackVal=="Submit your feedback *"))
  {
   alert ("Please fill in your feedback");
   return false;
  }
		$.extend($.blockUI.defaults.overlayCSS, { backgroundColor: '#edece7' });
  $('#feedbackForm').block('<img src="/Images/Generic/Bigrotation.gif" border="0" />',{ background: 'transparent', border: '0' });

  $.ajax({
  type: "GET",
  url: ajxURL,
  success: function(msg){
   $("#formContent").hide();
   $("#infoMessage").html("<p>" + msg + "</p>");
   $('#feedbackForm').unblock();
   $("#infoMessage").show();
  }
  });
 });
}

// <summary>
//  this function is to fix the sitemap layout
// </summary>
function FixSitemap()
{
$(".Sitemap>li:eq(3)").css({clear:"both"});
}

// <summary>
//  fixing the footer for to stick always with the bottom of the screen
// </summary>
function fixFooter()
{
if ($("#Master").height() < $(window).height())
{
  $(".Content").height($(window).height()-350)
}
}


function MailtoFriend()
{
var MailtoString="mailto: ?subject=EIMA: Course details&body="+window.location.href.toLowerCase();
$("p.MailtoFriend a").attr({href : MailtoString}); 
}

function MediaSpace(){
//if ($("#s5").find("img").length<=1)
//{
//$("#output").hide();
//}
$('#s5').cycle({
    fx:     'fade',
    timeout: 4000,
    before:  onBefore,
    after:   onAfter,
    next:   '#next2',
    prev:   '#prev2'
      });
}

function onBefore() {
    //$('#output').html("Scrolling image:<br />" + this.src);
   //window.console.log(  $(this).parent().children().index(this) );
   // $('#output').fadeOut(500); 
}
function onAfter(){
//if (this.alt !="" ){
//alert('boo');
    //$('#output').html('<h5>' + this.alt + '</h5>');
   // $('#output').fadeIn(500); 
   // }
   var n = $(".MediaRight img").length;
     var index = $(".MediaRight img").index(this);
     var count=index+1;
        $(".nav span").html("Image "+count+"/"+n);
     
  //alert(index);
}