﻿// JScript File
var sMaxFooterBannerEntries;
var currentFooterBanner=0;


var BgBanners;
var sMaxBgBanners;
var currentbgBanner=-1;
$(document).ready(function () {
    /* Background Banners Initial setup start */
    BgBanners = document.getElementById("ctl00_header_hidbgBanners").value; // '/abudhabi.ae/en/_resources_new/_images/top-image.jpg@/abudhabi.ae/en/_resources_new/_images/bg_topimage1.jpg'
    sMaxBgBanners = BgBanners.split('@').length;
    ChangeBackGround();
    /* Background Banners Initial setup End */

    /* Prepare Language seletion start */
    $("#ulLangs").mousedown(function () { PrepareLangSelection() })
    
    /* Prepare Language seletion End */

    /* Menu Middle Animation start */
    PreapareMiddleMenuAnimation();
    /* Menu Middle Animation End */

    /* Footer Banners intial setup start */
    obj = $("#footerRotateBanners");
    sMaxFooterBannerEntries = $("li", obj).length;
    if (sMaxFooterBannerEntries > 0) {
        SetFooterBanners();
        $("#bannerPrev").click(function () { PreviousBanner() })
        $("#bannerNext").click(function () { NextBanner() })
        window.setTimeout(NextBanner, 10000);
    }

    /* Footer Banners intial setup ENd */

    /* Bookmark and share */
    BookShare();



});

/* Prepare Language seletion start */
 function PrepareLangSelection()
 {
   var pos=$("#ulLangs").position()
   $("#divFlags").css({
            position:"absolute",
            left: pos.left-49,
            top: pos.top+27
            
          })
   $("#divFlags").slideToggle("Slow");
 }
 /* Prepare Language seletion End */
 
 /* Home Send To friend Start */
 
 function emailNew()
 {
 
   var pos=$("#divShare").position()
   $("#dvSendHome").css({
        position:"absolute",
        left: pos.left-10,
        top: pos.top+160
      })
            
       $("#dvSendHome").show("Slow");
   
 }
 function ecloseNew()
 {
   $("#dvSendHome").hide("Slow");
 }
 /* Home Send to Friend End */
 
/* Middle menu animation start */
function PreapareMiddleMenuAnimation() {

    $("#navmiddle li.navitem").prepend("<span></span>"); //Throws an empty span tag right before the a tag

    $("#navmiddle li.navitem").each(function() { //For each list item...
        var linkText = $(this).find("a").html(); //Find the text inside of the <a> tag
        $(this).find("span").show().html(linkText); //Add the text in the <span> tag
    });

    $("#navmiddle li.navitem").hover(function () {	//On hover...
        
        $(this).find("span").stop().animate({
            marginTop: "-40" //Find the <span> tag and move it up 40 pixels
        }, 250);
    }, function () { //On hover out...
        $(this).find("span").stop().animate({
            marginTop: "0"  //Move the <span> back to its original state (0px)
        }, 250);
    });
    
}
/* Middle menu animation End */

/* Footer Banners Rotate Start */

function SetFooterBanners()
{
 obj.find("li").hide();
 obj.find("li").eq(0).show();
}
function PreviousBanner()
{
 currentFooterBanner--;
 if(currentFooterBanner < 0)  currentFooterBanner=sMaxFooterBannerEntries-1
 SetCurrentBanner();
}

function NextBanner() {
 currentFooterBanner++;
 if(currentFooterBanner > sMaxFooterBannerEntries-1)  currentFooterBanner=0
 SetCurrentBanner();
        window.setTimeout(NextBanner, 10000);
}
function SetCurrentBanner()
{
 obj.find("li").hide();
 //obj.find("li").stop();
 //obj.find("li").eq(currentBanner).show();
 obj.find("li").eq(currentFooterBanner).animate(
                                              {
                                                width: ['toggle', 'swing'],
                                                height: ['toggle', 'swing'],
                                                opacity: 'toggle'
                                              }, 200, 'linear', function() {}
                                         );
}

/* Footer Banners Rotate End */


/* Main Background changing start */
function ChangeBackGround()
{
if(currentbgBanner == "-1")
{
  currentbgBanner++;
  SetCurrentBgBanner();
  timer1=window.setTimeout(ChangeBackGround,20000);
}
else 
{
  currentbgBanner++;
 
  if(currentbgBanner >= sMaxBgBanners)
  {
   currentbgBanner=0
  }
  SetCurrentBgBanner();
  timer1=window.setTimeout(ChangeBackGround,20000);
}
 
}
function SetCurrentBgBanner()
{
  var data = BgBanners.split('@')
  bgimage=data[currentbgBanner]
  $(".containerouter").animate({
    //backgroundPosition: '0px center' 
    
  }, 1000,'linear', function(){
                         $(".containerouter").css("background", "url("+ bgimage+") no-repeat center top ")
                         
//                         $(".containerouter").animate({backgroundPosition: 'center 150px'}) 
//                         .animate({backgroundPosition: 'center -150px'}) 
                         
                       })
  //$(".containerouter").css("background", "url("+ bgimage+") no-repeat center top ")
  //$(".containerouter").animate({backgroundPosition:'(0px -45px)'},200,"fast",function(){});  
//  $(".containerouter").animate(
//                                  {
//                                    
//                                  }, 200, 'fast', function() {$(".containerouter").css("background", "url("+ bgimage+") no-repeat center top ")}
//                             );
  
}
/* Main Background changing End */

/* Book mark and share start */
function BookShare()
{
   $("#dvSendHome").hide();
   
   var PopupBookmarkShare=$(".bookShare")
    PopupBookmarkShare.each(function(i){
    $(this).mousedown(function(){
    var pos=$(this).position()
     $("#divShare").css({
        position:"absolute",
        left: pos.left-200,
        top: pos.top-180
      })
            
     $("#divShare").slideToggle("Slow");
    })
  });
}

function digg()
{
  var diggurl='http://digg.com/submit?phase=2&url='+encodeURIComponent(document.location.href)+' ';
  window.open(diggurl,'DiggWindow');
  document.getElementById('divShare').style.display = 'none';

}
function twitter()
{
   var twitterurl='http://twitter.com/home?status=Currently reading '+ location.href ;
   window.open(twitterurl,'TwitterWindow');
   document.getElementById('divShare').style.display = 'none';
}

function Addtofavorites()
{
if (window.sidebar) 
{ // Mozilla Firefox Bookmark		
  window.sidebar.addPanel('Visit abudhabi', location.href,"");
  document.getElementById('divShare').style.display = 'none';
}
else if( window.external )
{ // IE Favorite
 window.external.AddFavorite(location.href, 'Visit abudhabi'); 
 document.getElementById('divShare').style.display = 'none';
}
}

function delicious()
{
   var deliciousurl='http://delicious.com/save?v=5&noui&jump=close&url='+ location.href ;
   window.open(deliciousurl,'DeliciousWindow');
   document.getElementById('divShare').style.display = 'none';
  
}
function Google()
{
    var Googleurl='http://www.google.com/bookmarks/mark?op=edit&bkmk='+ location.href ;
    window.open(Googleurl,'GoogleWindow');
    document.getElementById('divShare').style.display = 'none';
}

function Live()
{
    var Liveurl='https://favorites.live.com/quickadd.aspx?marklet=1&url='+ location.href ;
    window.open(Liveurl,'LiveWindow');
    document.getElementById('divShare').style.display = 'none';
}

function Buzz()
{
    var Buzzurl='http://buzz.yahoo.com/submit/?submitUrl='+ location.href ;
    window.open(Buzzurl,'BuzzWindow');
    document.getElementById('divShare').style.display = 'none';
    
}
function closeShareMe()
{
    document.getElementById('divShare').style.display = 'none';
}
function facebook()
{
  var facebookurl='http://www.facebook.com/share.php?u='+location.href;
  window.open(facebookurl,'FaceBookWindow');
}
function Linkedin() {
    var linkedinurl = 'http://www.linkedin.com/shareArticle?mini=true&url=' + location.href;
    window.open(linkedinurl, 'LinkedinWindow');
}
/* Book mark and share End */
/* Flags langugae changes  start*/
function English(id)
{
    var LangId=id;
    
    if(document.getElementById('ctl00_hidLangurl') != null)
    {
       var Urls = location.href;
       if(Urls.length > 0)
       {
            var fixpath = Urls.split("/en/en-us/");
            if(fixpath.length > 1)
            {
                location.href = apath+"en/en-us/"+fixpath[fixpath.length-1];
            }
            else
            {
                var getpath = Urls.split("/en/");
                location.href = apath+"en/"+getpath[getpath.length-1];
            }
       }
       else
       {
        location.href = apath+"en/";
       }
    }
    else
    {
        location.href = apath+"en/";
    }
}

function Arabic(id)
{
    var LangId=id;
    
    if(document.getElementById('ctl00_hidLangurl') != null)
    {
       var Urls = location.href;
       if(Urls.length > 0)
       {
            var fixpath = Urls.split("/en/en-us/");
            if(fixpath.length > 1)
            {
                location.href = apath+"ar/ar-ae/"+fixpath[fixpath.length-1];
            }
            else
            {
                var getpath = Urls.split("/en/");
                location.href = apath+"ar/"+getpath[getpath.length-1];
            }
       }
       else
       {
        location.href = apath+"ar/";
       }
    }
    else
    {
        location.href = apath+"ar/";
    }
}

function French(id)
{
    var LangId=id;
    
    if(document.getElementById('ctl00_hidLangurl') != null)
    {
       var Urls = location.href;
       if(Urls.length > 0)
       {
            var fixpath = Urls.split("/en/en-us/");
            if(fixpath.length > 1)
            {
                location.href = apath+"fr/fr-FR/"+fixpath[fixpath.length-1];
            }
            else
            {
                var getpath = Urls.split("/en/");
                location.href = apath+"fr/"+getpath[getpath.length-1];
            }
       }
       else
       {
        location.href = apath+"fr/";
       }
    }
    else
    {
        location.href = apath+"fr/";
    }
}

function German(id)
{
    var LangId=id;
    
    if(document.getElementById('ctl00_hidLangurl') != null)
    {
       var Urls = location.href;
       if(Urls.length > 0)
       {
            var fixpath = Urls.split("/en/en-us/");
            if(fixpath.length > 1)
            {
                location.href = apath+"de/de-DE/"+fixpath[fixpath.length-1];
            }
            else
            {
                var getpath = Urls.split("/en/");
                location.href = apath+"de/"+getpath[getpath.length-1];
            }
       }
       else
       {
        location.href = apath+"de/";
       }
    }
    else
    {
        location.href = apath+"de/";
    }
}

function Russian(id)
{
    var LangId=id;
    if(document.getElementById('ctl00_hidLangurl') != null)
    {
       var Urls = location.href;
       if(Urls.length > 0)
       {
            var fixpath = Urls.split("/en/en-us/");
            if(fixpath.length > 1)
            {
                location.href = apath+"ru/ru-RU/"+fixpath[fixpath.length-1];
            }
            else
            {
                var getpath = Urls.split("/en/");
                location.href = apath+"ru/"+getpath[getpath.length-1];
            }
       }
       else
       {
        location.href = apath+"ru/";
       }
    }
    else
    {
        location.href = apath+"ru/";
    }
}

function Japanese(id)
{
    var LangId=id;
    if(document.getElementById('ctl00_hidLangurl') != null)
    {
       var Urls = location.href;
       if(Urls.length > 0)
       {
            var fixpath = Urls.split("/en/en-us/");
            if(fixpath.length > 1)
            {
                location.href = apath+"jp/ja-JP/"+fixpath[fixpath.length-1];
            }
            else
            {
                var getpath = Urls.split("/en/");
                location.href = apath+"jp/"+getpath[getpath.length-1];
            }
       }
       else
       {
        location.href = apath+"jp/";
       }
    }
    else
    {
        location.href = apath+"jp/";
    }
}
function Italy(id) {
    var LangId = id;
    if (document.getElementById('ctl00_hidLangurl') != null) {
        var Urls = location.href;
        if (Urls.length > 0) {
            var fixpath = Urls.split("/en/en-us/");
            if (fixpath.length > 1) {
                location.href = apath + "it/it-IT/" + fixpath[fixpath.length - 1];
            }
            else {
                var getpath = Urls.split("/en/");
                location.href = apath + "it/" + getpath[getpath.length - 1];
            }
        }
        else {
            location.href = apath + "it/";
        }
    }
    else {
        location.href = apath + "it/";
    }
}
/* Flags languge Changes End */

/* Search Site */
function cSearchNew()
{
    if(document.getElementById(tSearchNew).value == 'Search the site')
    document.getElementById(tSearchNew).value = '';
}

function rSearchNew()
{
    if(document.getElementById(tSearchNew).value == '')
    document.getElementById(tSearchNew).value = 'Search the site';
}
function checksearchNew(oSrc, args)
{
    if(document.getElementById(tSearchNew).value == 'Search the site')
    {
        document.getElementById(tSearchNew).value = '';
        args.IsValid = false;
    }
    else 
    {
        args.IsValid = true;
    }
}
