﻿// <summary>
// Global function calls
// </summary>
function executeHandler(){
  if (window.location.href.toLowerCase().indexOf("cmspagemode=edit")>0){  // exiting if in the sitefinity edit mode
   $(".MediaBorder").css({top:"30px"});
   $(".Hidden").css({position:"relative"});
   $("body").css({direction:"ltr"});
  return false;
 }

$(document).ready(function(){
AssignCSSSelectors();
AssignLinks();
InitializeMenu();
Captionslide();
HandleMediaSpace();
});
}

// <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() 
{
  if (window.location.href.toLowerCase().indexOf("applicationform")>0){
 return false;
 }
	$("a[rel='external']").attr("target","_blank");
	$("a[href='#']").click(function(){
		return false;
	});
}

// <summary>
//  Dropdown Navigation initialize function
// </summary>

function InitializeMenu(){
try{
  $(".horizontal").children().each(function(){
   $(this).hover(
    function(){
    try
    {
     if ($(this).children(".slide").length > 0)
     {
      $(this).find("ul").css({display:"block"});
      //$(this).find("ul").css({left: $(this).offset().left-offset.left});
      //var ulwidth = $(this).find("ul").find("li").width() * $(this).find("ul").children("li").length + 40;
      //$(this).find("ul").width(ulwidth);
      //var curRightPos = $(this).find("ul").offset().left - offset.left + ulwidth;
      // if (curRightPos > rightPos);
       //{ 
        //var ErrVal =curRightPos - rightPos;
        //$(this).find("ul").css({marginLeft: "-" + ErrVal + "px"});
       //}
      }
     }
     catch(obj)
     {
     }
      
    },
    function(){
     //$(this).find("ul").css({marginLeft: "0px"});
     $(this).find("ul").css({display:"none"});
    });
   });
 }
 catch(obj)
 {
 }
}


// <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");
}


// <summary>
//  These functions handle events generated by an Input Text box
// </summary>

function InputTextOnFocusHandler (InputTag, DefaultText)
{
	try
	{  		
		if (InputTag.value == DefaultText)
		{
			InputTag.value = "";
		}
	}
	catch (ExceptionObject)
	{
	}
}

function InputTextOnBlurHandler (InputTag, DefaultText)
{
	try
	{
		if (InputTag.value == "")
		{
			InputTag.value = DefaultText;	
		}
	}
	catch (ExceptionObject)
	{
	}
}



// <summary>
//   Navigation  hover effect initialize 
// </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 ul").children().hover(
  //function(){
   //$(this).addClass("Active");
 // },
  //function(){
   //$(this).removeClass("Active");
  //});  
	}
	catch (ExceptionObject)
	{
	}
}




function FixFonts()
{

 $("hs2").sifr({
	 path: 'Fonts/',		 	
   color: '#ceac54'	
   });
  }

  
  
  
function Captionslide(){
   $('#s5').cycle({
    fx:     'fade',
    timeout: 20000,
    speedIn:  3500, 
    speedOut: 400, 
    next:   '#next2',
    prev:   '#prev2'
      });
}











 function HandleMediaSpace()
{
 var ImageSrc;
 var Caption;
 var CaptionArray;
 $("#Summary").css({opacity:0});
 $("#Numbers").css({opacity:0});
 $("#Summary").css({right:"-150px"});
 //$("#MainImage").css({left:"-858px"});
 $("#Numbers").css({right:"0px"});
 $("#MainImage").animate({opacity: 1},{queue:false,duration:700,easing: "easeInQuad",complete:function(){
    $("#Summary").animate({opacity: 1,right: "22"},{queue:false,duration:500,easing: "easeInQuad",complete:function(){
    $("#MSCaptions h2").animate({opacity: 1},{queue:false,duration:400,easing: "easeInQuart",complete:function(){
     $("#MSCaptions h3").animate({opacity: 1,left:"20px"},{queue:false,duration:400,easing: "easeInQuart",complete:function(){
      $("#Numbers").animate({opacity: 1,right:"0px"},{queue:false,duration:300,easing: "easeInQuart"});
      $("#Numbers li:first").addClass("Active");
     }});
    }});
   }});
  }});
/*


*/

 $("#Numbers").children().each(function(){
  $(this).click(
   function(){
    if ($(this).hasClass("Active")){
     return false;
    }
    $("#Numbers").css({opacity:0});
    $("#Numbers li").removeClass("Active");
    $(this).addClass("Active");
    Caption = $(this).find("a").attr("rel");
    CaptionArray = Caption.split("#");
    ImageSrc = $(this).find("a").attr("href");
    $("#MSCaptions h2").animate({opacity: 0},{queue:false,duration:500,easing: "easeInQuart",complete:function(){
     $(this).html(CaptionArray[1]);
    }});
    $("#MSCaptions h3").animate({opacity: 0},{queue:false,duration:600,easing: "easeInQuart",complete:function(){
     $(this).html(CaptionArray[2]);
    }});
    $("#Summary").animate({opacity: 0,right: "-150px"},{queue:false,duration:500,easing: "easeOutQuad",complete:function(){
     $("#Summary p.Text").html(CaptionArray[0]);
     $("#Summary p.ReadMore a").attr("href",CaptionArray[3]);
     $("#Summary p.ReadMore a").click(function(){
       window.location.href = $(this).attr("href");
     });
    }});

    $(".Hidden").animate({opacity: 0},{queue:false,duration:1400,easing: "easeInQuad",complete:function(){
     $(".Hidden").attr("src",ImageSrc);
     $(".Hidden").animate({opacity: 1},{queue:false,duration:1000,easing: "easeInQuad",complete:function(){
     $("#MSCaptions h2").animate({opacity: 1},{queue:false,duration:500,easing: "easeInQuart"});
     $("#MSCaptions h3").animate({opacity: 1,left:"20px"},{queue:false,duration:600,easing: "easeInQuart",complete:function(){
      $("#Summary").animate({opacity: 1,right: "22"},{queue:false,duration:500,easing: "easeInQuad",complete:function(){
       $("#Numbers").animate({opacity: 1,right:"0px"},{queue:false,duration:400,easing: "easeInQuart"});
       $("#MainImage img").attr("src",ImageSrc);
      }});
     }});

     //$("#MSCaptions h3").sifr({
      // font: '/Fonts/Futura',
       //color: '#c2dfff'
      //});
    // $("#MSCaptions h2").sifr({
      //font: '/Fonts/Futura',
      //color: '#ffffff'
    // });
   }});
  }});
   return false;
  });
 });
}







// <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 (window.location.href.toLowerCase().indexOf("contactus")<0){
 return false;
 }
 if (GBrowserIsCompatible()) {
  //$("#GoogleMap").css({display: "block"});
  var map = new GMap2(document.getElementById("GoogleMap"));
  var point;
  if (strLocation =="Sheikh Saud Foundation")
  {
  map.setCenter(new GLatLng(25.793004,55.946395 ), 14);
  point = new GLatLng(25.793004,55.946395);
  map.openInfoWindow(map.getCenter(),"<div class='GooglemapLogo'><p>Sheikh Saud Foundation</p></div>");
  
  }  
  if (strLocation =="Sheikh Saud Foundation Arabic")
  {
  map.setCenter(new GLatLng(25.793004,55.946395 ), 14);
  point = new GLatLng(25.793004,55.946395);
  map.openInfoWindow(map.getCenter(),"<div class='GooglemapLogo'><p>مؤسسة الشيخ سعود بن صقر القاسمي</p></div>");
  
  }
  
  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());

}



// Fixing Cufon Font >
function  FixCufonFont(){

if (window.location.href.toLowerCase().indexOf("/en/")>0){
 Cufon.replace('h3');
 }
}



function CheckTermsClicked(){
if(!$(".FormCheck").attr("checked")){
alert("Please read and agree the terms and conditions to proceed");
return false;
}
}
//$("#btnSubmit").click(function(){
//if $("#chkAgree").checked = false;
//alert("clear the checkbox");
//});