// <summary>
// Global function calls
// </summary>
function ExecuteHandler(){
 if (window.location.href.toLowerCase().indexOf("cmspagemode=edit")>0){
 return false;
 }
	AssignCSSSelectors();
	AssignLinks();
	FixFonts();
 InitializeMenu();
 $(".HorizontalListing>li:eq(2)").addClass("List3");
 $(".HorizontalListing>li:eq(5)").addClass("List3");
 $(".HorizontalListing>li:eq(8)").addClass("List3");
 $(".HorizontalListing>li:eq(11)").addClass("List3");
 if ($(".WrappedCopy").html()==""){$(".WrappedCopy").css({display:"none"})};
 ToggleListItem();
 $(".Video li a").click(function(){
 GB_show_video('', "/Videos/" + $(this).attr("href"), 340, 800, $(this),'');
 return false;
 });
}

// <summary>
//  Setting the dropdown Navigation
// </summary>

function InitializeMenu()
{
	$(".NavHolder2 ul").children().each(function()
	{
		$(this).hover(
		function(){
		 //if (!$(this).hasClass("Highlight"))
		 //{
		 	if ($(this).children("ul").length > 0 )
		 	{
        //$(this).children("ul").animate( { width:"175px"},{queue:false, duration:100,easing: "easeOutQuad",complete:function(){}});  
     $(this).children("ul").css({display:"block"});
		 		$(this).css({position:"relative"});
		 	}
	//	 }	
			
		},
		function(){
		 //if (!$(this).hasClass("Highlight"))
		  //{
		 	 if ($(this).children("ul").length > 0 )
		 	 {
		 	 	 $(this).css({position:"static"});
		     //$(this).children("ul").animate( { width:"0px"},{queue:false, duration:100,easing: "easeInQuint",complete:function(){$(this).css({display:"none"});}});  
 		     $(this).children("ul").css({display:"none"});
		 }
		//}	
	}
		);
	});
}


// <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");
	}
 $(".ImageGallery").find("tr").find("td:last").addClass("EndTd");
}


// <summary>
//  sifr replacement script.
// </summary>
function FixFonts()
{
  $("h2").sifr({
	 font: 'Fonts/BookAntiqa'
  });
}


// <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>
// 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()
{
 $('.ImageGallery a').lightBox();
}

// <summary>
//  To hide the Newsletter subscription thankyou message popup
// </summary>
function HideModalPopup()
{
 $(".NewsletterPopup").hide();
 $(".modalBackground").hide();
 $(".NewsletterText").attr("value","");
 $("input:radio").attr("checked","");
 $(".newsletterPopup").remove();
}

// <summary>
//  setting the google map functionalities for branch network
// </summary>
function googleMapInitialize(strLocation)
{
 if (window.location.href.toLowerCase().indexOf("cmspagemode=edit")>0){
 return false;
 }
 if (GBrowserIsCompatible()) {
  //$("#GoogleMap").css({display: "block"});
  var map = new GMap2(document.getElementById("GoogleMap"));
  var point;
  if (strLocation =="masqat")  
  {
  map.setCenter(new GLatLng(23.624631,58.268839 ), 13);
  point = new GLatLng(23.624631,58.268839);
  map.openInfoWindow(map.getCenter(),"<div class='GooglemapLogo'></div>");
  //<p><strong>The Wave Muscat <br />S.A.O.C<br />Madinat Al Sultan Qaboos<br />PO Box 87, PC 118,<br />Sultanate of Oman </strong><br /></p>
  }  
  
  if (strLocation =="deira")  
  {
    map.setCenter(new GLatLng(25.258941,55.33659), 13);
    point = new GLatLng(25.258941,55.33659);
    map.openInfoWindow(map.getCenter(),"<p><strong>Deira Branch</strong><br />Tel: 800 4354 (Toll Free)</p>");
  }
  if (strLocation =="ShZayedRd")  
  {
    map.setCenter(new GLatLng(25.100222,55.176258), 13);
    point = new GLatLng(25.100222,55.176258);
    map.openInfoWindow(map.getCenter(),"<p><strong>Sheikh Zayed Road Branch</strong><br />Tel: +(9714) 340 2489<br />Fax: +(9714) 340 4430</p>");
  }
  if (strLocation =="AbuDhabi")  
  {
    map.setCenter(new GLatLng(24.47551,54.323326), 13);
    point = new GLatLng(24.47551,54.323326);
    map.openInfoWindow(map.getCenter(),"<p><strong>Abu Dhabi Branch (Marina Mall)</strong><br />Tel: +(9712) 681 8252 <br />Fax:+(9716) 681 8253</p>");
  }
  map.addOverlay(new GMarker(point));
 }
}

// <summary>
//  setting the google map functionalities for branch network
// </summary>
function handleBranches()
{
 if (window.location.href.toLowerCase().indexOf("branchnetwork")<0){
 return false;
 }
 $("body").unload(GUnload());
 
 $("#Branches").children().each(function(){
 $(this).find("a").click(function(){
  $("#Branches").find("a").css({fontWeight: "normal"});
  $(this).css({fontWeight: "bold"});
  var branch = $(this).html();
  if (branch =="Deira Branch")
  {
   googleMapInitialize("deira");
  }
  if (branch =="Sheikh Zayed Road Branch")
  {
   googleMapInitialize("ShZayedRd");
  }
  if (branch =="Sharjah Corniche Road Branch")
  {
   googleMapInitialize("sharjah");
  }
  if (branch =="Abu Dhabi Branch (Marina Mall)")
  {
   googleMapInitialize("AbuDhabi");
  }
 });
 });
 
 $("document").ready(function(){
  $("#Branches a:first").trigger("click");
 });
}

// <summary>
//  attaching gray box
// </summary>
function attachGraybox(linkObj)
{
 var t ="";
 //var t = linkObj.title || linkObj.innerHTML || linkObj.href;
 GB_show(t,linkObj,470,600);
 return false;
}

/* Greybox Redux
 * Required: http://jquery.com/
 * Written by: John Resig
 * Based on code by: 4mir Salihefendic (http://amix.dk)
 * License: LGPL (read more in LGPL.txt)
 */

var GB_DONE = false;
var GB_HEIGHT = 400;
var GB_WIDTH = 400;

function GB_show(caption, url, height, width,parentId,urltype) {
	try {
  GB_HEIGHT = height || 400;
  GB_WIDTH = width || 400;
  if(!GB_DONE) {
    $("#GB_window img").click(GB_hide);
    $("#GB_overlay").click(GB_hide);
    
    $(window).resize(GB_position(parentId));
    GB_DONE = true;
  }
  $("#GB_frame").remove();
  $("#GB_image").remove();
  if (urltype=="external")
  {
   $("#GB_window").append("<iframe frameborder='0' scrolling='no' id='GB_frame' src='"+ url +"'></iframe>");
  }
  else
  {
  $("#GB_window").append("<a href='#' onclick='GB_hide();return false;'><img id='closebtn' src='../images/generic/CloseButton.gif' onclick='GB_hide();' style='float:right;padding-bottom: 5px;position: relative;cursor:hand;top:5px;right:25px;z-index:1000' alt='Close window'/></a><EMBED bgcolor='#c6e7f3' SRC='"+url +"' WIDTH=" +width +" HEIGHT = " + height+ " AUTOPLAY=true CONTROLLER=true LOOP=false HREF='"+ url +"' TARGET='myself' PLUGINSPAGE=http://www.apple.com/quicktime/'>");
  }

  $("#GB_caption").html(caption);
  $("#GB_overlay").height($("#Master").height());
  $("#GB_overlay").show();
  $("#GB_window").show();
  //$('embed, object, select').css({ 'display' : 'none' });
  //$('h1,h2').css({ 'display' : 'none' });
  $(".navigation").css({ 'display' : 'none' });
  GB_position(parentId);

  /*if(GB_ANIMATION)
    $("#GB_window").slideDown("slow");
  else
    $("#GB_window").show();*/
	} catch(e) {
		alert( e );
	}
}



function GB_show_video(caption, url, height, width,parentId,urltype) {
	try {
  GB_HEIGHT = height || 400;
  GB_WIDTH = width || 400;
  if(!GB_DONE) {
    $("#GB_window img").click(GB_hide);
    $("#GB_overlay").click(GB_hide);
    $(window).resize(GB_position(parentId));
    GB_DONE = true;
  }
  $("#Master").css({float: "left"});
  $("#GB_frame").remove();
  $("#GB_image").remove();
  if (urltype=="external")
  {
   $("#GB_window").append("<iframe frameborder='0' scrolling='no' id='GB_frame' src='"+ url +"'></iframe>");
  }
  else
  {
  $("#GB_window").append("<a href='#' onclick='GB_hide();return false;'><img id='closebtn' src='../images/generic/CloseButton.gif' onclick='GB_hide();return false' style='float:right;padding-bottom: 5px;position: relative;cursor:hand;top:5px;right:25px;z-index:1000' alt='Close window'/></a><EMBED bgcolor='#c6e7f3' SRC='"+url +"' WIDTH=" +width +" HEIGHT = " + height+ " AUTOPLAY=true CONTROLLER=true LOOP=false HREF='"+ url +"' TARGET='myself' PLUGINSPAGE=http://www.apple.com/quicktime/'>");
  }

  $("#GB_caption").html(caption);
  $("#GB_overlay").height($("#Master").height());
  $("#GB_overlay").show();
  $("#GB_window").show();
  //$('embed, object, select').css({ 'display' : 'none' });
  //$('h1,h2').css({ 'display' : 'none' });
  $(".navigation").css({ 'display' : 'none' });
  GB_position_video(parentId);

  /*if(GB_ANIMATION)
    $("#GB_window").slideDown("slow");
  else
    $("#GB_window").show();*/
	} catch(e) {
		alert( e );
	}
}



function GB_hide() {
  $("#GB_window,#GB_overlay").hide();
  $('embed, object, select').css({ 'display' : 'block' });
  $('h1,h2').css({ 'display' : 'block' });
  $(".navigation").css({ 'display' : 'block' });
  $("#GB_window").html("");
  $("#Master").css({float: "none"});
  GB_DONE = false;
}


function GB_position(parent) {
  var de = document.documentElement;
  var w = self.innerWidth || (de&&de.clientWidth) || document.body.clientWidth;
	 $("#GB_window").css({width:GB_WIDTH+"px",left: ((w - GB_WIDTH)/2)+"px" });
  $("#GB_window").css({top: parent.offset().top + "px",left: ((w - GB_WIDTH)/2)+"px"});
}


function GB_position_video(parent) {
  var de = document.documentElement;
  var w = self.innerWidth || (de&&de.clientWidth) || document.body.clientWidth;
  var h = self.innerHeight || (de&&de.clientHeight) || document.body.clientHeight;
	 $("#GB_window").css({width:GB_WIDTH+"px",left: ((w - GB_WIDTH)/2)+"px",top:((h - GB_HEIGHT)/2)+ document.documentElement.scrollTop });  
}
