$(document).ready(function() {
	/* SG Landing - Footer Links */
	checkDevice();
	var total = $('#header').width();
          
    if(document.getElementById('dbs-Wrapper') != null)
    {
       if (total <= 1150) 
	   {
			$('#dbs-Wrapper table.ms-main tbody tr hr.horizonLine').attr('width','1024');
		   
		} else {
			 $('#dbs-Wrapper table.ms-main tbody tr hr.horizonLine').attr('width','1280');
		}
       
    }
	

	/* End SG Landing - Footer Links */ 

    /* BOF Country Selector */
    if(document.getElementById('jsSelectLocalSite') != null && document.getElementById('LocalSiteList') != null)
    {
        hideLocalSiteList();

        $(document).click(function(){
            if ($('#LocalSiteList').css('display') !== 'none') {
                hideLocalSiteList();
            }
        })	
        
        $('#jsSelectLocalSite').bind('click', function(e){	
            if ($('#LocalSiteList').css('display') == 'none') {
                showLocalSiteList();
            } else {
                hideLocalSiteList();
            }
            return false;
        })

        $('#jsSelectLocalSite').bind('mouseover', function(e){	
            if ($('#LocalSiteList').css('display') == 'none') {
                $('#jsSelectLocalSite').removeClass('dbsSelectLocalSiteExt01');
                $('#jsSelectLocalSite').addClass('dbsSelectLocalSiteExt03');
            }
            return false;
        })

        $('#jsSelectLocalSite').bind('mouseout', function(e){	
            if ($('#LocalSiteList').css('display') == 'none') {
                $('#jsSelectLocalSite').removeClass('dbsSelectLocalSiteExt03');
                $('#jsSelectLocalSite').addClass('dbsSelectLocalSiteExt01');
            }
            return false;
        })
    }
    /* BOF Country Selector */
    
    if (document.getElementById('helper') != null) updtMenu();
    if (document.getElementById('MSOPageViewerWebPart_WebPartWPQ2')) {
        //iframeHeightAdjust();
        var fileSrc = document.getElementById('MSOPageViewerWebPart_WebPartWPQ2').src;
        var code = '<iframe scrolling="no" frameBorder="0" id="MSOPageViewerWebPart_WebPartWPQ2" width="100%" src="' + fileSrc + '" style="height: 11em"></iframe>';
        $('iframe#MSOPageViewerWebPart_WebPartWPQ2').replaceWith(code);
    }
    if (document.getElementById('list') != null) {
        if (document.getElementById('list').className == 'listStyle02') homepageInit(); // /sg/ homepage script
    }
    if (document.getElementById('sidebarProdsContent') != null)
    {
        sidebarProdsInit();
    }
    if (document.getElementById('newsContent') != null) newsInit();
    if (document.getElementById('shareContainer') != null) populateShareThis(); // for Share This Function
    if (document.getElementById('shareContainerChina') != null) populateChinaShareThis(); // for Share This Function in China
    if (document.getElementById('corporateSlides') != null) corporateInit(); // Corporate Landing Page
    if (document.getElementById('dbsshareticker') != null) {
        updtIndex();
        setInterval("updtIndex()", 300000);
    }
    if (document.getElementById('language_selector') != null) languageSelectorInit();
    if (document.getElementById('contentToggler') != null) contentTogglerInit();
    
    /* 1280 */
    /* Changing existing content2 container width */
   
  /* 1280 China */
    var total = $('#header').width();
    
    if(document.getElementById('content2') != null)
    {
        if(document.getElementById('content2').className == 'fourthLevel')
        {
            


            if (total <= 1150) {

                $('#content2').css('width','548px');
                $('#content2.fourthLevel .productBnr').css('background-image','url('+ $('#content2.fourthLevel .productBnr img').attr('src') +')');
               // $('#content2.fourthLevel .productBnr img').attr('src','/common/img/spacer.gif');
                $('#content2.fourthLevel .productBnr ').attr('width','548');
                $('#content2.fourthLevel .productBnr ').attr('height','103');
                $('.product ').css('width','252');
            } else {
                $('#content2').css('width','725px');
                $('#content2.fourthLevel .productBnr').css('background-image','url('+ $('#content2.fourthLevel .productBnr img').attr('src') +')');
                //$('#content2.fourthLevel .productBnr img').attr('src','/common/img/spacer.gif');
                $('#content2.fourthLevel .productBnr ').attr('width','725');
                $('#content2.fourthLevel .productBnr ').attr('height','103');
                $('.product ').css('width','341');
            }
        }
    }

    /* 1280 china */
    
    /* 1280 DBS Group */

    /* 1280 DBS Group */

    /* DBS Group Tabs */
	/*    if(document.getElementById('divTab1') != null) {
        $('#divTab1').css('display', 'block');
    }
    if(document.getElementById('divTab2') != null) {
        $('#divTab2').css('display', 'none');
    }
    if(document.getElementById('divTab3') != null) {
        $('#divTab3').css('display', 'none');
    }
    if(document.getElementById('divTab4') != null) {
        $('#divTab4').css('display', 'none');
    }*/
    
    
    /* DBS Group Tabs */
    
    openLeftNav();
});


/* 1280 China */

$(window).resize(function() {
   
      var total = $('#header').width();
          
    if(document.getElementById('content2') != null)
    {
        if(document.getElementById('content2').className == 'fourthLevel')
        {
            


            if (total <= 1150) {

                $('#content2').css('width','548px');
                $('#content2.fourthLevel .productBnr').css('background-image','url('+ $('#content2.fourthLevel .productBnr img').attr('src') +')');
               // $('#content2.fourthLevel .productBnr img').attr('src','/common/img/spacer.gif');
                $('#content2.fourthLevel .productBnr ').attr('width','548');
                $('#content2.fourthLevel .productBnr ').attr('height','103');
                $('.product ').css('width','252px');
            } else {
                $('#content2').css('width','725px');
                $('#content2.fourthLevel .productBnr').css('background-image','url('+ $('#content2.fourthLevel .productBnr img').attr('src') +')');
                //$('#content2.fourthLevel .productBnr img').attr('src','/common/img/spacer.gif');
                $('#content2.fourthLevel .productBnr ').attr('width','725');
                $('#content2.fourthLevel .productBnr ').attr('height','103');
                $('.product ').css('width','341px');
            }
        }
    }
   
   
    if(document.getElementById('content2') != null)
    {
        if(document.getElementById('content2').className == 'fourthLevel')
        {
         
            if (total <= 1150) {
                $('#content2').css('width','548px');
                $('.product ').css('width','252px');
            } else {
                $('#content2').css('width','725px');
                $('.product ').css('width','341px');
            }
           
        }
    }
/* 1280 China */
    
/* 1280 DBS Group */
 
/* 1280 DBS Group */
});

function DBSGroupTabsInit()
{
    if(document.getElementById('content5') != null)
    {
        for(var i=0; i<document.getElementById('content5').childNodes.length; i++)
        {
            var className = '';
            if(document.getElementById('content5').childNodes[i].className != null)
            {
                className = document.getElementById('content5').childNodes[i].className;
            }
            var pos=className.indexOf("content_tab");
            if (pos>=0)
            {
                $(".tab").click(function() {
                    var currentTab = $(this);
                    var checkElement = null;
                    switch(currentTab.attr('id'))
                    {
                        case 'jsTab1':
                            checkElement = $('#divTab1');
                            break;
                        case 'jsTab2':
                            checkElement = $('#divTab2');
                            break;
                        case 'jsTab3':
                            checkElement = $('#divTab3');
                            break;
                        case 'jsTab4':
                            checkElement = $('#divTab4');
                            break;
                    }
                    if((currentTab.is('.tab')) && !(checkElement.css("display") == 'none'))
                    {
                        return false;
                    }
                    if((currentTab.is('.tab')) && (checkElement.css("display") == 'none') && $('.tab_content:visible').size() == 1)
                    {
                        $('.tab:visible').removeClass('tab_on');
                        $('.tab:visible').addClass('tab_off');
                        $('.link_selector').removeClass('tab_off');
                        currentTab.removeClass('tab_off');
                        currentTab.addClass('tab_on');
                        $('.tab_content').css('display', 'none');
                        checkElement.css('display', 'block');
                        return false;
                    }
                });
            }
        }
    }
}
function showHide(layerID) {
    var obj = document.getElementById(layerID);
    if (obj != null) { // check if the object is valid
        if (obj.style.display == 'none') {
            obj.style.display = '';
        } else {
            obj.style.display = 'none';
        }
    }
}

function clearField(elementId, txtValue, typeValue) {
    var txtField = document.getElementById(elementId);
    if (!typeValue) typeValue = 'text';
    if (txtField.value == txtValue) {
        txtField.value = '';
        txtField.type = typeValue;
    }
}

function fillField(elementId, txtValue, typeValue) {
    var txtField = document.getElementById(elementId);
    if (!typeValue) typeValue = 'text';
    if (txtField.value == '') {
        txtField.value = txtValue;
        txtField.type = typeValue;
    }
}

function populateShareThis() {
    var pageLnk = encodeURIComponent(window.location.href);
    var pageTtl = encodeURIComponent(document.title);
    var toggler = $("#shareContainer").prev('a');
    $("#shareContainer").removeAttr('style');
    toggler.removeAttr('style');
    toggler.click(function() {
        showHide('shareContainer');
        return false;
    });

    //check if the object is valid
    if (document.getElementById('shareDi') != null) {
        document.getElementById('shareDi').href = "http://digg.com/submit?phase=2&url="+pageLnk+"&title="+pageTtl;
    }
    if (document.getElementById('shareFb') != null) {
        document.getElementById('shareFb').href = "http://www.facebook.com/share.php?u="+pageLnk;
    }
    if (document.getElementById('shareDe') != null) {
        document.getElementById('shareDe').href = "http://del.icio.us/post?url="+pageLnk+"&title="+pageTtl;
    }
    if (document.getElementById('shareSu') != null) {
        document.getElementById('shareSu').href = "http://www.stumbleupon.com/submit?url="+pageLnk+"&title="+pageTtl;
    }
    $('#shareContainer').css('display','none');
}

function populateChinaShareThis() {
    var pageLnk = encodeURIComponent(window.location.href);
    var pageTtl = encodeURIComponent(document.title);
    var toggler = $("#shareContainerChina").prev('a');
    $("#shareContainerChina").removeAttr('style');
    toggler.removeAttr('style');
    toggler.click(function() {
        showHide('shareContainerChina');
        return false;
    });

    //check if the object is valid
    if (document.getElementById('shareKx') != null) {
        document.getElementById('shareKx').href = "http://www.kaixin001.com/login/?flag=1&url="+pageLnk;
    }
    if (document.getElementById('shareRr') != null) {
        document.getElementById('shareRr').href = "http://share.renren.com/share/buttonshare.do?link="+pageLnk+"&title="+pageTtl;
    }
    if (document.getElementById('shareDb') != null) {
        document.getElementById('shareDb').href = "http://www.douban.com/recommend/?url="+pageLnk+"&title="+pageTtl;
    }
    if (document.getElementById('shareSn') != null) {
        document.getElementById('shareSn').href = "http://t.sina.com.cn/?url="+pageLnk;
    }

    $('#shareContainerChina').css('display','none');
}

function sidebarProdsInit() {
    $('.contentList').hide();
    $('.catHeader:first').removeClass('con');
    $('.catHeader:first').addClass('exp');
    $('.contentList:first').show();
    $('.catHeader').click(function() {
        var checkElement = $(this).next();
        if (checkElement.is(':visible')) {
            return false;
        }
        if (!checkElement.is(':visible')) {
            $('.catHeader').removeClass('exp');
            $('.catHeader').addClass('con');
            $(this).removeClass('con');
            $(this).addClass('exp');
            $('.contentList:visible').slideUp('normal');
            checkElement.slideDown('normal');
            return false;
        }
    });
    $('.catHeader').css('cursor','pointer');
    $('.catHeader').css('display','block');
}

var totalCat;
var activeCat = 'helpSet1';

function initSelector() {
    for (var $i = 1; $i <= totalCat; $i++) {
        document.getElementById('helpSet'+$i).style.display = 'none';
    }
}

function updtMenu() {
    initSelector();
    var helpQ1 = document.getElementById('helpQ1');
    selected = helpQ1.options [helpQ1.selectedIndex];
    document.getElementById(selected.value).style.display = '';
    activeCat = selected.value;
}

function gotoPage() {
    var el = document.getElementById(activeCat);
    selected = el.options [el.selectedIndex];
    if ((selected.value=='') || (selected.value=='Select one...')) {
        el.style.backgroundColor = '#FFFFDD';
        alert('Please select a product to proceed.');
    } else {
        this.top.location.href = selected.value; // to fix iframe problem, permanently
    }
}

function gotoPagePersonal() {
    var el2 = document.getElementById('personal');
    selected = el2.options [el2.selectedIndex];
    if ((selected.value=='') || (selected.value=='Select one...')) {
        el2.style.backgroundColor = '#FFFFDD';
        alert('Please select a product to proceed.');
    } else {
        this.top.location.href = selected.value; // to fix iframe problem, permanently
    }
}

function gotoPageTreasures() {
    var el3 = document.getElementById('treasures');
    selected = el3.options [el3.selectedIndex];
    if ((selected.value=='') || (selected.value=='Select one...')) {
        el2.style.backgroundColor = '#FFFFDD';
        alert('Please select a product to proceed.');
    } else {
        this.top.location.href = selected.value; // to fix iframe problem, permanently
    }
}

function gotoPageInstitutional() {
    var el4 = document.getElementById('institutional');
    selected = el4.options [el4.selectedIndex];
    if ((selected.value=='') || (selected.value=='Select one...')) {
        el4.style.backgroundColor = '#FFFFDD';
        alert('Please select a product to proceed.');
    } else {
        this.top.location.href = selected.value; // to fix iframe problem, permanently
    }
}



/* BOF /sg/ hompage scripts */
function homepageInit() {
    hpSelectorClr();
    $(".hpSelector").click(function() {
        hpSelectorClr();
        $(this).parent().addClass('selected');
        showHide($(this).attr('id').substr(4));
        return false;
    });
    $('#living-asia').css('display','');
    $('#anc-living-asia').parent().addClass('selected');

    $('#jvsPanelSetWrapper .jvsPanelTarget').hide();
    $('.jvsTriggerLink').addClass('closePanel');
    $('#jvsPanelSetWrapper .jvsPanelTarget:first').css("display", "block");
    $('#dbsContainer05').height(360);
    $('#jvsPanelSetWrapper .jvsPanelTrigger').click(function() {
        var checkElement = $(this).next();
        //if it is the targetted panel but is already visible, do nothing
        if((checkElement.is('div.jvsPanelTarget')) && !(checkElement.css("display") == 'none')) {
            return false;
        }
        //if it is the targetted panel but is not displayed, show it and hide other panels
        if((checkElement.is('div.jvsPanelTarget')) && (checkElement.css("display") == 'none') && $('#jvsPanelSetWrapper .jvsPanelTarget:visible').size() == 1) {
            //this part add closePanel to other panels to indicate closed arrow
            $('.jvsTriggerLink').addClass('closePanel');
            //this part remove closePanel to triggered object to indicate opened arrow
            $(this).contents().find('.jvsTriggerLink').removeClass('closePanel');
            //this part closes the panels
            $('#jvsPanelSetWrapper .jvsPanelTarget:visible').animate(
            {
                "height": "toggle",
                "filter":"none"
            }, {
                duration: "normal"
            }
            )
            //this part opens the panel for the triggered object
            checkElement.animate(
            {
                "height": "toggle",
                "filter":"none"
            }, {
                duration: "normal"
            }
            )
            return false;
        }
    });
    $('.jvsPanelTrigger:first').contents().find('.jvsTriggerLink').removeClass('closePanel');
}
function hpSelectorClr() {
    $(".contentNode").css("display", "none");
    $(".hpSelector").parent().removeClass('selected');
}
/* EOF /sg/ hompage scripts */

/* BOF set page as home page script */
function setHomepage() {
    if (document.all) {
        document.body.style.behavior='url(#default#homepage)';
        document.body.setHomePage(window.parent.document.location.href);
    } else if (window.sidebar) {
        if(window.netscape) {
            try {
                netscape.security.PrivilegeManager.enablePrivilege("UniversalXPConnect");
            } catch(e) {
                alert("This action was avoid by your browser. If you want to enable, please enter about:config in your address line and change the value of signed.applets.codebase_principal_support to true.");
                return false;
            }
        }
        var answer = confirm("Would you like to set this page as your home page?");
        if (answer) {
            var prefs = Components.classes['@mozilla.org/preferences-service;1'].getService(Components. interfaces.nsIPrefBranch);
            prefs.setCharPref('browser.startup.homepage', window.parent.document.location.href);
        }
    }
}
/* EOF set page as home page script */

/* BOF News Pane */
function newsInit() {
    $('#news #newsContent a').css('display','none');
    $('#news #newsContent a:first').css('display','');

    $('#news #newsNav a:eq(0)').click(function() {
        updtNewsBtns($(this).attr('id'));
        return false;
    });

    $('#news #newsNav a:eq(1)').click(function() {
        updtNewsBtns($(this).attr('id'));
        return false;
    });

    newsTicker = setInterval("updtNews()", 5000);
	
    $('#newsContent a').mouseover(function() {
        clearInterval(newsTicker);
    });
	
    $('#newsContent a').mouseout(function() {
        newsTicker = setInterval("updtNews()", 5000);
    });
}

function updtNews() {
    var currentNews = $('#news #newsContent').find('a').index($('#news #newsContent').find('a:visible:first'));
    var totalNews =  $('#news #newsContent').find('a').length - 1;
    $('#news #newsContent').find('a').css('display','none');
    if (currentNews < totalNews) $('#news #newsContent').find('a:eq('+ currentNews +')').next().fadeIn('slow');
    else $('#news #newsContent').find('a:eq(0)').fadeIn('slow');
}

function updtNewsBtns(id) {
    var currentNews = $('#news #newsContent a').index($('#news #newsContent a:visible:first'));
    var totalNews =  $('#news #newsContent a').length - 1;
    $('#news #newsContent a').css('display','none');

    if (id == 'next') {
        if (currentNews < totalNews) $('#news #newsContent a:eq('+ currentNews +')').next().fadeIn('slow');
        else $('#news #newsContent a:eq(0)').fadeIn('slow');
    } else if (id == 'prev') {
        if (currentNews !== 0) $('#news #newsContent a:eq('+ currentNews +')').prev().fadeIn('slow');
        else $('#news #newsContent a:eq('+ totalNews +')').fadeIn('slow');
    }
}
/* EOF News Pane */

/* BOF iframe frame height script */
function iframeHeightAdjust(el, val) {
    if (!el) el = 'MSOPageViewerWebPart_WebPartWPQ2';
    if (!val) val = 0;
    if (navigator.userAgent.indexOf("MSIE") != -1) {
        val = val + 7; // IE
    } else {
        val = val - 18;
    }
	
    if (parent.window.document.getElementById(el)) {
        parent.window.document.getElementById(el).height = document.body.offsetHeight - val;
    }
}
/* EOF iframe frame height script */

/* BOF Corporate Landing Page */
function corporateInit() {
    corpSelectorClr();
    var totalTabs =  $('.slide').length - 1;
    $('.slide:first').css("display", "");
    $("#controller a:first").addClass('selected');
    $("#controller a").click(function() {
        corpSelectorClr();
        $(this).attr("hideFocus", "hidefocus");
        var index = $('#controller a').index(this);
        $('#controller a').eq(index).addClass('selected');
        $('.slide').eq(index).css("display", "");
        return false;
    });
    $("#controller").css("z-index", "99");

    // Slideshow
    corpSlideShow = setInterval("updtCorpSlide()", 10000);
	
    $('#controller a').mouseover(function() {
        clearInterval(corpSlideShow);
    });
	
    $('#controller a').mouseout(function() {
        corpSlideShow = setInterval("updtCorpSlide()", 10000);
    });
	
    $('.slide').mouseover(function() {
        clearInterval(corpSlideShow);
    });
	
    $('.slide').mouseout(function() {
        corpSlideShow = setInterval("updtCorpSlide()", 10000);
    });
}

function updtCorpSlide() {
    var currentSlide = $('.slide').index($('.slide:visible:first'));
    var totalSlide =  $('.slide').length - 1;
    $('.slide').css('display','none');
    if (currentSlide < totalSlide) {
        corpSelectorClr();
        $('.slide:eq('+ currentSlide +')').next().css("display", "");
        $('#controller a').eq(currentSlide).next().addClass('selected');
    } else {
        corpSelectorClr();
        $('.slide:eq(0)').css("display", "");
        $('#controller a').eq(0).addClass('selected');
    }
}

function corpSelectorClr() {
    $(".slide").css("display", "none");
    $("#controller a").removeClass('selected');
}
/* EOF Corporate Landing Page */

/* Stock Ticker */
function updtIndex() {
    $.ajax({
        type: "GET",
        //		url: "http://esite.sgx.com/scripts/GenXML_SGXPriceMDDL.asp?subcode=D05",
        //		url: "/home/dbs.php",
        url: "/home/Pages/dbs.aspx",
        dataType: "xml",
        success: function(xml) {
            $(xml).find('pricefeed').each(function(){
                var dataDateTime = $(this).find('dataDateTime').text();
                var date = dataDateTime.substr(0,10);
                var time = dataDateTime.substr(11);
                var lastvalue = $(this).find('last').text();
                var change = $(this).find('change').text();
                var tickDirection = $(this).find('tickDirection').text();
                tickDirection = ((tickDirection == 'up') || (tickDirection == 'down')) ? tickDirection : 'unchanged';
                $('#dbsshareticker').empty();
                $('#dbsshareticker').append('<strong>DBS Share price: SGD'+lastvalue+' (<img src="/sg/personal/common/img/share-'+tickDirection+'.gif" width="10" height="11" align="baseline" id="tickDirection" /> '+change+')</strong> as at '+time+' +08:00 GMT on '+date);
            });
        }
    });
}
/* Stock Ticker */

/* BOF Regional Treasures */
function languageSelectorInit() {
    var url = window.location.pathname;
    if (url.substr(0,14)=='/treasures/sc/') {
        $('#language_selector a').eq(1).css('display','none');
    } else if (url.substr(0,14)=='/treasures/zh/') {
        $('#language_selector a').eq(2).css('display','none');
    } else if (url.substr(0,14)=='/treasures/id/') {
        $('#language_selector a').eq(3).css('display','none');
        $('#language_selector a').eq(2).addClass('last');
    } else if (url.substr(0,11)=='/treasures/') {
        $('#language_selector a').eq(0).css('display','none');
    }
}
/* EOF Regional Treasures */

/* BOF 20100330 contentTogglerInit */
function contentTogglerInit() {
    // BOF Insert the Expand/Collapse All Element
    $(".togglerHeader").eq(0).before('<p class="footnote"><a href="#">Expand All</a> &nbsp;|&nbsp; <a href="#">Collapse All</a></p>');
    $("#contentToggler p:first a").eq(0).click(function() {
        $(".togglerHeader .togglerIcon").removeClass('con');
        $(".togglerHeader .togglerIcon").addClass('exp');
        $(".togglerContent").show();
        return false;
    });

    $("#contentToggler p:first a").eq(1).click(function() {
        $(".togglerHeader .togglerIcon").removeClass('exp');
        $(".togglerHeader .togglerIcon").addClass('con');
        $(".togglerContent").hide();
        return false;
    });
    // EOF Insert the Expand/Collapse All Element

    $(".togglerHeader .togglerIcon").removeClass('exp');
    $(".togglerHeader .togglerIcon").addClass('con');
    $(".togglerHeader").next().hide();
    $(".togglerHeader").css('cursor','pointer');

    $('.togglerHeader').mouseover(function() {
        $(this).children('span').css('text-decoration','underline');
    });
	
    $('.togglerHeader').mouseout(function() {
        $(this).children('span').css('text-decoration','none');
    });
    // draw plus minus
    $(".togglerHeader").click(function() {
        if ($(this).next().is(":visible")) {
            $(this).children('.togglerIcon').removeClass('exp');
            $(this).children('.togglerIcon').addClass('con');
            $(this).next().slideUp('fast');
        } else {
            //			contentTogglerReset();
            $(this).children('.togglerIcon').removeClass('con');
            $(this).children('.togglerIcon').addClass('exp');
            $(this).next().slideDown('fast');
        }
    });
}

/*
function contentTogglerReset() {
	$(".togglerHeader .togglerIcon").removeClass('exp');
	$(".togglerHeader .togglerIcon").addClass('con');
	$(".togglerHeader").next().slideUp('fast');	
}
*/

function rtLoadPage() {
    var el = document.getElementById('rtPrivilegesSelector');
    selected = el.options [el.selectedIndex];
    if ((selected.value=='') || (selected.value=='Select one...')) {
        el.style.backgroundColor = '#FFFFDD';
        alert('Please select a location to proceed.');
    } else {
        this.top.location.href = selected.value; // to fix iframe problem, permanently
    }
}
/* EOF 20100330 contentTogglerInit */




/* Left nav look up xml script */
function openLeftNav() {

    var urlstring = window.location.toString();
	var afterdomain = (window.location.pathname).substr(1);
	var folders = afterdomain.split("/");
	var match = false;
    var pathtoxml = "";
    var ref_url = "";
    var leftnav = "";
    var highlight = "";
	var nav_color = "#660000";
	
    if (folders[0] == "sg" && folders[1] == "personal" && folders[2] != "Pages") pathtoxml = "/sg/personal/" + folders[2] + "/";
    if (folders[0] == "treasures" && folders[1] == "sg" && folders[2] != "Pages") pathtoxml = "/treasures/sg/" + folders[2] + "/";
    if (folders[0] == "posb" && folders[1] != "Pages") {
		pathtoxml = "/posb/" + folders[1] + "/";
		nav_color = "#336699";
	}
	if (folders[0] == "security") pathtoxml = "/security/Documents/";
	
    if (pathtoxml != "") {
	
        $.get(pathtoxml+"leftnav.xml", null, function(lnlist) {
	
            $(lnlist).find("nav_entry").each( function() {
	
                ref_url = $(this).attr("url").toString();
                leftnav = $(this).attr("leftnav").toString();
                highlight = $(this).attr("highlight").toString();
				
                //compare url to xml table
                if (urlstring.indexOf(ref_url)!=-1) {
					
                    //bold selected links if applicable
                    if (highlight != "none") {
		               $("#"+highlight).css("font-weight","bold");
    	               $("#"+highlight).css("color", nav_color);
                    }
				
                    //alert("hit! :" + leftnav);
                    if (leftnav != "none") {
                        $("#"+leftnav).trigger("click");
                        match = true;
                        return false;
                    }
                }
				
            });
			
            if (!match) {

                //close all
                $(".contentList").each(function () {
                    $(this).hide();
                    $(this).prev().removeClass('exp');
                    $(this).prev().addClass('con');
                });
            }// end if (!match)
			
        });
	
    } //end if (pathtoxml != "")


}
/* EOF Left nav look up xml script */

function showLocalSiteList(){
    $('#jsSelectLocalSite').removeClass('dbsSelectLocalSiteExt01');
    $('#jsSelectLocalSite').removeClass('dbsSelectLocalSiteExt03');
    $('#jsSelectLocalSite').addClass('dbsSelectLocalSiteExt02');
					
    $('#LocalSiteList').fadeIn('fast');
}

function hideLocalSiteList(){
    $('#jsSelectLocalSite').removeClass('dbsSelectLocalSiteExt02');
    $('#jsSelectLocalSite').removeClass('dbsSelectLocalSiteExt03');
    $('#jsSelectLocalSite').addClass('dbsSelectLocalSiteExt01');
	
    $('#LocalSiteList').fadeOut();
}
/* EOF Country Selector */

/* BOF Language Toggler */
function languageToggler(current_site, new_site) {
    var current_url = window.location.pathname;
    var new_url = current_url.replace(current_site, new_site);
    window.location = new_url;
}
/* EOF Language Toggler */

/* BOF Search Result Language Toggler */
function searchlanguageToggler(current_site, new_site) {
    var current_url = window.location.href;
    var new_url = current_url.replace(current_site, new_site);
    window.location = new_url;
}
/* EOF Search Result Language Toggler */

/* youtube/flash player */

var videoWidth = 320;
var videoHeight = 184;

function checkDevice()
{
	if((navigator.userAgent.match(/iPhone/i)) || (navigator.userAgent.match(/iPod/i)) || (navigator.userAgent.match(/iPad/i))) {
		$('#ytapiplayer').html('<object width="'+videoWidth+'" height="'+videoHeight+'" id="ytPlayer"><param name="movie" value="http://www.youtube.com/v/Gb_ylCIcdtQ?fs=1&amp;hl=en_US&amp;rel=0"></param><param id="objc"></param><param name="allowFullScreen" value="true"></param><param name="allowscriptaccess" value="always"></param><param name="wmode" value="opaque"></param><embed src="http://www.youtube.com/v/Gb_ylCIcdtQ?fs=1&amp;hl=en_US&amp;rel=0" type="application/x-shockwave-flash" wmode="opaque" allowscriptaccess="always" allowfullscreen="true" width="'+videoWidth+'" height="'+videoHeight+'"></embed></object>');
	} else {
		$('#ytapiplayer').html('<img src="/sg/img/video_thumbnail.jpg" width="320" height="184" class="loadyt" style="cursor:pointer;" />');
	}
	
	$('.loadyt').click(function (){
		$('#ytapiplayer').html('<object classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000" id="player" width="320" height="184" codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab"><param name="movie" value="/common/img/player.swf" /><param name="flashvars" value="videoId=Gb_ylCIcdtQ" /><param name="quality" value="high" /><param name="bgcolor" value="#000000" /><param name="wmode" value="opaque"></param><param name="allowScriptAccess" value="sameDomain" /><param name="allowFullScreen" value="true"><embed src="/common/img/player.swf" quality="high" bgcolor="#000000" width="320" height="184" name="player" align="middle" play="true" loop="false" quality="high" allowScriptAccess="sameDomain" allowfullscreen="true" wmode="opaque" type="application/x-shockwave-flash" pluginspage="http://www.macromedia.com/go/getflashplayer"  flashvars="videoId=Gb_ylCIcdtQ"></embed></object>');});

}

// This function is automatically called by the player once it loads
function onYouTubePlayerReady(playerId) {
	ytplayer = document.getElementById("ytPlayer");
    // This causes the updatePlayerInfo function to be called every 250ms to
    // get fresh data from the player
	setInterval(updatePlayerInfo, 250);
	updatePlayerInfo();
	ytplayer.addEventListener("onStateChange", "onPlayerStateChange");
	ytplayer.addEventListener("onError", "onPlayerError");
	//Load an initial video into the player
	ytplayer.cueVideoById("Gb_ylCIcdtQ");
}

function thisMovie(movieName) {
	if (navigator.appName.indexOf("Microsoft") != -1) {
		return window[movieName];
	} else {
		return document[movieName];
	}
}

function sendToActionScript(value) {
	thisMovie("player").sendToActionScript(value);
}
	 
$(window).load(function() {
	checkDevice();
});
