// JavaScript Document

/*var rateequiry_urls = {
    'HKD': { 'title': 'Hong Kong Dollar', 'url': '/hongkong/personal/accounts/rateenquiry/dep_rates_hkd.html'},
    'USD': { 'title': 'United States Dollar', 'url': '/hongkong/personal/accounts/rateenquiry/dep_rates_usd.html'},
    'RMB': { 'title': 'Renminbi', 'url': '/hongkong/personal/accounts/rateenquiry/dep_rates_cny.html'},
    'AUD': { 'title': 'Australian Dollar', 'url': '/hongkong/personal/accounts/rateenquiry/dep_rates_aud.html'},
    'CAD': { 'title': 'Canadian Dollar', 'url': '/hongkong/personal/accounts/rateenquiry/dep_rates_cad.html'},
    'CHF': { 'title': 'Swiss Franc', 'url': '/hongkong/personal/accounts/rateenquiry/dep_rates_chf.html'},
    'EUR': { 'title': 'Euro', 'url': '/hongkong/personal/accounts/rateenquiry/dep_rates_eur.html'},
    'GBP': { 'title': 'Pound Sterling', 'url': '/hongkong/personal/accounts/rateenquiry/dep_rates_gbp.html'},
    'JPY': { 'title': 'Japanese Yen', 'url': '/hongkong/personal/accounts/rateenquiry/dep_rates_jpy.html'},
    'NZD': { 'title': 'New Zealand Dollar', 'url': '/hongkong/personal/accounts/rateenquiry/dep_rates_nzd.html'},
    'SGD': { 'title': 'Singapore Dollar', 'url': '/hongkong/personal/accounts/rateenquiry/dep_rates_sgd.html'},
    'ZAR': { 'title': 'South Africa Rand', 'url': '/hongkong/personal/accounts/rateenquiry/dep_rates_zar.html'}
};*/
/**
 * ========================================
 *
 *
 * common functions 
 * ----------------------------------------
 *
 */
jQuery.fn.extend
({
    removeCss: function(cssName) {
        return this.each(function() {
            var curDom = $(this);
            jQuery.grep(cssName.split(","),
                    function(cssToBeRemoved) {
                        curDom.css(cssToBeRemoved, '');
                    });
            return curDom;
        });
    }
});

function isNotEmpty(string)
{
    return (string != undefined && string != '')
}

function isDefined(item)
{
    return (item != undefined)
}

function checkSelector(selector)
{
    if (selector == undefined || !isObject(selector)) {
        return false;
    } else {
        return true;
    }
}

/* from http://www.blueshop.com.tw/board/show.asp?subcde=BRD20030701132700YFZ */
function isFunction(a) {
    return typeof a == 'function';
}

/* from http://www.blueshop.com.tw/board/show.asp?subcde=BRD20030701132700YFZ */
function isObject(a) {
    return (typeof a == 'object' && !!a) || isFunction(a);
}

function MM_preloadImages() { //v3.0
  var d=document; if(d.images){ if(!d.MM_p) d.MM_p=new Array();
    var i,j=d.MM_p.length,a=MM_preloadImages.arguments; for(i=0; i<a.length; i++)
    if (a[i].indexOf("#")!=0){ d.MM_p[j]=new Image; d.MM_p[j++].src=a[i];}}
}

function MM_swapImgRestore() { //v3.0
  var i,x,a=document.MM_sr; for(i=0;a&&i<a.length&&(x=a[i])&&x.oSrc;i++) x.src=x.oSrc;
}

function MM_findObj(n, d) { //v4.01
  var p,i,x;  if(!d) d=document; if((p=n.indexOf("?"))>0&&parent.frames.length) {
    d=parent.frames[n.substring(p+1)].document; n=n.substring(0,p);}
  if(!(x=d[n])&&d.all) x=d.all[n]; for (i=0;!x&&i<d.forms.length;i++) x=d.forms[i][n];
  for(i=0;!x&&d.layers&&i<d.layers.length;i++) x=MM_findObj(n,d.layers[i].document);
  if(!x && d.getElementById) x=d.getElementById(n); return x;
}

function MM_swapImage() { //v3.0
  var i,j=0,x,a=MM_swapImage.arguments; document.MM_sr=new Array; for(i=0;i<(a.length-2);i+=3)
   if ((x=MM_findObj(a[i]))!=null){document.MM_sr[j++]=x; if(!x.oSrc) x.oSrc=x.src; x.src=a[i+2];}
}

/* global variables define here */
var currentPath=location.href.toString();
/**
 * ========================================
 *
 * chLang
 * ----------------------------------------
 *
 */
 
/*function chLang(lang) {
	var switchTc='/hongkong_tc/';
	var switchSc='/hongkong_sc/';
	var switchEn='/hongkong/';
	lang = '/'+lang+'/';

	switch (lang){
		case '/hongkong/':
			currentPath=currentPath.replace(switchTc, switchEn);
			currentPath=currentPath.replace(switchSc, switchEn);
			break;
		case '/hongkong_tc/':
			currentPath=currentPath.replace(switchEn, switchTc);
			currentPath=currentPath.replace(switchSc, switchTc);
			break;
		case '/hongkong_sc/':
			currentPath=currentPath.replace(switchTc, switchSc);
			currentPath=currentPath.replace(switchEn, switchSc);
			break;
		default:
	}

	document.location=currentPath;
}

function detectLang(){
	var userLang = (navigator.language) ? navigator.language : navigator.userLanguage;
	alert ("The language is: " + userLang);	
}*/

// variables used for topMenu functionality
var menuItems;
var mid;
/**
 * ========================================
 *
 * topMenu functions
 * ----------------------------------------
 *
 */
 //////////////////////////////////////////////////////////////////////////////////////////////////////////////
 initTopMenu = function(){
    $.ajax({
        type: 'get',
        dataType: 'xml',
		async: false,
        url: 'xml/menu.xml',
        success: function(xml)
        {
            menuItems = xml;
		
            createTabMenu($(xml).find('section').not('section[hide]'));

			$("#topMenu .menu-item").hover(function(){
				$(".menu-item").each(function(){	
					$(this).removeClass('hover');
				});
				$(this).addClass('hover');

	 		}, function(e){
			    var section_id = $(this).attr('data-section');
				//alert(e.pageY);
				if ((e.pageY >30 && e.pageY <80))
				{
					$(this).removeClass('hover');
					$(".menu-item").each(function(){	
						$(this).removeClass('hover');
					});
					$('#subMenus .subMenuBox').each(function(){	
						$(this).hide();
						$("#hideSelectIFrame").hide();
					});
				}
				if (!$('#topMenu').has('.menu-item[data-section="'+section_id+'"][has-category="yes"]').length)
				{
					$(this).removeClass('hover');
					$(".menu-item").each(function(){	
						$(this).removeClass('hover');
					});
					$('#subMenus .subMenuBox').each(function(){	
						$(this).hide();
					});
				}

	 		});	

		
			$("#topMenu .menu-item").hover(function(){
                var section_id = $(this).attr('data-section');

				var section_img = $(this).attr('data-img');	
				var section_title = $(this).attr('data-title');	
				var section_desc = $(this).attr('data-desc');	
				

				var rollover_box = $('#subMenus').find('.rollover');

				if (section_img != '' && section_desc != '')
				{
				rollover_box.find('.title').html(section_title);
				}
                rollover_box.find('.rollover_image').attr('src', section_img);        
                rollover_box.find('.desc').html(section_desc);

				$('#subMenus').find('.subMenuBox').hide();
				
					if ($('#topMenu').has('.menu-item[data-section="'+section_id+'"][has-category="yes"]').length)
					{
						
						$('#subMenus').find('.subMenuBox[data-section="'+section_id+'"]').show();
						$("#hideSelectIFrame").show();
					
					}

	 		}, function(e){

				var section_id = $(this).attr('data-section');



				//for fixing IE6
				if(isIE6 = /msie|MSIE 6/.test(navigator.userAgent))
				{		
					//alert(e.pageY);
					if ((e.pageY >40 && e.pageY <60))
					{
						
						$('#subMenus').find('.subMenuBox').hide();
					//$('#subMenus').find('.subMenuBox[data-tab="'+tab_id+'"][data-section="'+section_id+'"]').show();
					}
				}
				else
				{
					$('#subMenus').find('.subMenuBox').hide();
				}



	 		});	
			
			
			
			$("#subMenus .subMenuBox").hover(function(){
                var section_id = $(this).attr('data-section');
				var section_img = $(this).attr('data-img');	
				var section_title = $(this).attr('data-title');	
				var section_desc = $(this).attr('data-desc');	
				

				var rollover_box = $('#subMenus').find('.rollover');

				if (section_img != '' && section_desc != '')
				{
				rollover_box.find('.title').html(section_title);
				}
                rollover_box.find('.rollover_image').attr('src', section_img);        
                rollover_box.find('.desc').html(section_desc);
				
					if ($('#topMenu').has('.menu-item[data-section="'+section_id+'"][has-category="yes"]').length)
					{
						
						$('#subMenus').find('.subMenuBox[data-section="'+section_id+'"]').show()
					
					}

	 		}, function(e){
				var section_id = $(this).attr('data-section');


				//for fixing IE6
				if(isIE6 = /msie|MSIE 6/.test(navigator.userAgent))
				{		
					//alert(e.pageY);
					if ((e.pageY >90 && e.pageY <250) || (e.pageY>100 && (e.pageX >20 && e.pageX <760)))
					{
						$('#subMenus').find('.subMenuBox').hide();	
					}
				}
				else
				{
				//alert(e.pageY);
				//if (!(e.pageY >60 && e.pageY <90))
				//{
					$('#subMenus').find('.subMenuBox').hide();	
				//}
				}
				$('#topMenu .menu-item').removeClass('hover');
				$('#subMenus .subMenuBox').each(function(){	
					$(this).hide();
				});
				
				$("#hideSelectIFrame").hide();
				
	 		});				

            var page_selector = {};
            if ($('meta[name=page-section]').size()>0) {
                page_selector.section = $('meta[name=page-section]').attr('content');
                
                if ($('meta[name=page-category]').size()>0) {
                    page_selector.category = $('meta[name=page-category]').attr('content');
                    
                    if ($('meta[name=page]').size()>0) {
                        page_selector.page = $('meta[name=page]').attr('content');
                    }
                }
            }
            setCurrentPage(page_selector);
            
        },
        error: function(XMLHttpRequest, textStatus, errorThrown)
        {
            alert(textStatus);
        }
    });
}
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
setCurrentPage = function(selector)
{
    if (checkSelector(selector))
    {
       if (isDefined(selector.section)) 
       {
           highlightSection(selector);
           initSectionMenu(selector);
           /* If you want this script to fill helper items automatically, uncomment the following line */
           //setHelpItemLists(selector);
           if (isDefined(selector.page))
           {
                highlightPage(selector);
           }
       }
       return true;
    } else {
        return false;
    }
}
//getXMLFaction({ tab: 'personal', section: 'account', category: 'consolidated' })

getXMLFaction = function(selector)
{
    if (checkSelector(selector)) {
        var selection = 'section[id="'+selector.tab+'"]';
        if (isNotEmpty(selector.category))
        {
            selection += ' > category[id="'+selector.category+'"]';
            if (isNotEmpty(selector.page)) selection += ' > page[id="'+selector.page+'"]';
        }
        return $(menuItems).find(selection);
    } else {
        return {};
    }
}

createTabMenu = function(sections)
{
    var menu = $('#topMenu');
	
	//var subMenuCnt = 1;
	//var catCnt;

    $.each(sections, function(key, section)
    {
        var section_id = $(section).attr('id');
		//var cnt = 1;
		//var subMenuStr = '';
		
		//if ($(section).children('category').size() > 0)
		//{
			var subMenu = $('#subMenus').append('<div class="subMenuBox" data-section="'+section_id+'"></div>').find('.subMenuBox:last');
			//catCnt = $(section).children('category').size();

            $(section).find('category').not('category[hide]').each(function(key){	
                var cat_id = $(this).attr('id');
                var submenu_item_title = $(this).children('title').text();
                var submenu_item_href = ($(this).children('url').size() > 0) ? $(this).children('url:eq(0)').text() : 'javascript:void(0);';
                var submenu_item_img = $(this).children('image').text();
                var submenu_item_desc = $(this).children('description').text();
                //alert(key);
                if (key % 6 == 0)
                {
                    subMenu.append('<ul class="col"></ul>');
                }
                subMenu.find('ul:last')
                    .append('<li><a href="' + submenu_item_href + '" data-section="'+section_id+
                    '" data-category="'+cat_id+'" data-image="'+submenu_item_img+'" data-desc="'+submenu_item_desc+'">'+ submenu_item_title +'</a></li>\n');
            });	
            //alert(subMenu.find('ul').find('li a').size());
            subMenu.find('ul').find('li a').mouseenter(function()
            {
                var rollover_box = $(this).parents('.subMenuBox:eq(0)').find('.rollover');
				
				if ($(this).attr('data-image') != '' && $(this).attr('data-desc') != '')
				{
				rollover_box.find('.title').html($(this).html());
				}
                rollover_box.find('.rollover_image').attr('src', $(this).attr('data-image'));        
                rollover_box.find('.desc').html($(this).attr('data-desc'));
            });
            var first_item = $(section);
			if (subMenu.find('ul').find('li a').attr('data-image') != '' && subMenu.find('ul').find('li a').attr('data-desc') != '')
			{			
            	subMenu.append('<div class="rollover"><img class="rollover_image" src="'+$(first_item).children('image').text()+'" style="float:left"/><p class="title">'+$(first_item).children('title').text()+'</p><p class="desc">'+$(first_item).children('description').text()+'</p></div>');
			}
			else
			{
            	subMenu.append('<div class="rollover"><img class="rollover_image" src="/hongkong/images/spacer.gif" style="float:left"/><p class="title">'+'</p><p class="desc">'+'</p></div>');				
			}
			/*subMenuStr += '</ul>\n';
			subMenuStr += '<div id="subMenuDiv'+ subMenuCnt+'" class="desc">\n';
			subMenuStr += '<div id="subImg'+ subMenuCnt+'"><img src="/hongkong/images/personal/menu_rollover/accounts/menu_rollover0.jpg" style="float:left"/></div>\n';
			subMenuStr += '<p class="tit">Consolidated Banking</p>\n';
			subMenuStr += '<p class="descTxt">Personalize your banking as you like it </p>\n';
			subMenuStr += '</div>\n';
			subMenuStr += '<span class="bg"></span>\n';
			subMenu.append(subMenuStr);
			subMenu.append('</div>');
			subMenuCnt++;*/
		//}		
		
        var href = ($(section).children('url').size() > 0) ? $(section).children('url:eq(0)').text() : 'javascript:void(0);';
        var title = ($(section).children('title').size() > 0) ? $(section).children('title:eq(0)').text() : 'Untitled';

	var img_src = ($(section).children('image').size() > 0) ? $(section).children('image:eq(0)').text() : '';
	var desc = ($(section).children('description').size() > 0) ? $(section).children('description:eq(0)').text() : '';

        var section_id = $(section).attr('id');
		//menu.append('<li class="menu-item" data-tab="'+tab_id+'" data-section="'+section_id+'"><a href="'+href+'">'+title+'</a></li>\r\n');
		
		if ($(section).children('category').size() > 0)
		{
			menu.append('<li class="menu-item" data-title="'+title+'" data-desc="'+desc+'" data-img="'+img_src+'" data-section="'+section_id+'" has-category="yes"><a href="'+href+'">'+title+'</a></li>\r\n');			
		}
		else
		{
			menu.append('<li class="menu-item" data-section="'+section_id+'"><a href="'+href+'">'+title+'</a></li>\r\n');			
		}
    });

    menu.find('li:first').addClass('cancelBg').end()
        .find('.menu-item:first').hover(function() { $(this).addClass('hover-first') }, function() { $(this).removeClass('hover-first') })
        .siblings('.menu-item').hover(
            function() { 
                //$(this).addClass('hover');
                var section_id = $(this).attr('data-section');
                //$('#subMenus').find('.subMenuBox[data-tab="'+tab_id+'"][data-section="'+section_id+'"]').show()
                    //.siblings('.subMenuBox').hide();
            }, function() {
                //$(this).removeClass('hover');
				
				//var section_id = $(this).attr('data-section');
                //var tab_id = $(this).attr('data-tab');
				//$('#subMenus').find('.subMenuBox[data-tab="'+tab_id+'"][data-section="'+section_id+'"]').removeClass('hover');
				
				
                /*var section_id = $(this).attr('data-section');
                var tab_id = $(this).attr('data-tab');
                $('#subMenus').find('.subMenuBox').hide();*/
            }					
        );
		
			//alert($('#topMenu').has('.menu-item[has-category="yes"]').length);








        
        /*$('#topMenu .menu-item').mouseover(function() {
            //alert($('#subMenus').children('.subMenuBox[data-tab="'+tab_id+'"][data-section="'+section_id+'"]').size());
            //alert(section_id);
        });*/
		
        /*$('#subMenus .subMenuBox').mouseleave(function() {
            var section_id = $(this).attr('data-section');
            var tab_id = $(this).attr('data-tab');
            $('#subMenus').find('.subMenuBox').hide();
        });*/
}

highlightSection = function(selector)
{
    if (checkSelector(selector))
    {
        var section_id = selector.section;
        var class_name = ($('#topMenu').find('.menu-item:first').attr('data-section') == section_id) ? 'highlight-first' : 'highlight';
        $('#topMenu').find('.menu-item[data-section="'+section_id+'"]').addClass(class_name);
        return true;
    } else {
        return false;
    }
}

highlightCategory = function(selector)
{
    if (checkSelector(selector))
    {
        var tab_id = selector.tab;
        var section_id = selector.section;
        var category_id = selector.category;
        $('#section-menu').find('.section-menu-item[data-section="'+section_id+'"][data-category="'+category_id+'"] > a').addClass('selected');
        return true;
    } else {
        return false;
    }
}

highlightPage = function(selector)
{
    if (checkSelector(selector))
    {
        var tab_id = selector.tab;
        var section_id = selector.section;
        var category_id = selector.category;
        var page_id = selector.page;
        $('#section-menu').find('.category-menu-item> a[data-section="'+section_id+'"][data-category="'+category_id+'"][data-page="'+page_id+'"]').addClass('selected');
        return true;
    } else {
        return false;
    }
}

initSectionMenu = function(selector)
{
    if (checkSelector(selector))
    {
        var section_id = selector.section;
        var current_category = selector.category;
        var categories = $(getXMLFaction({section: section_id})).children('category');
		
		var http_path = document.URL;
               
        $('#section-menu').attr('data-section', section_id);
        $.each(categories, function(key, category)
        {
            var cat_id = $(category).attr('id');
            var href = ($(category).children('url').size() > 0) ? $(category).children('url:eq(0)').text() : 'javascript:void(0)';
            var target = (isDefined($(category).children('url:eq(0)').attr('target'))) ? $(category).children('url:eq(0)').attr('target') : '_self';
            var title = $(category).children('title:eq(0)').text();
            
            // TODO: Remove the following commented lines once this function works properly
            //var section_menu_item = $('#section-menu > ul')	
			
			/*if (http_path.search('consolidated') != -1) // not necessary since the current category will be highlighted later
			{			
				if (title == "Consolidated Banking")
				{
				var section_menu_item = $('#section-menu > ul')
                .append('<li class="section-menu-item" data-tab="'+tab_id+'" data-section="'+section_id+'" data-category="'+cat_id+'"><a href="'+href+'" target="'+target+'"><b><font color="#00317D">'+title+'</font></b></a></li>\r\n')
                .find('.section-menu-item:last');
				}
				else
				{
				var section_menu_item = $('#section-menu > ul')
                .append('<li class="section-menu-item" data-tab="'+tab_id+'" data-section="'+section_id+'" data-category="'+cat_id+'"><a href="'+href+'" target="'+target+'">'+title+'</a></li>\r\n')
                .find('.section-menu-item:last');
				}				
			}
			else
			{
				var section_menu_item = $('#section-menu > ul')
                .append('<li class="section-menu-item" data-tab="'+tab_id+'" data-section="'+section_id+'" data-category="'+cat_id+'"><a href="'+href+'" target="'+target+'">'+title+'</a></li>\r\n')
                .find('.section-menu-item:last');				
			}*/
 			var section_menu_item = $('#section-menu > ul')
                .append('<li class="section-menu-item" data-section="'+section_id+'" data-category="'+cat_id+'"><a href="'+href+'" target="'+target+'">'+title+'</a></li>\r\n')
                .find('.section-menu-item:last');	
                
            if ($(category).children('page').size() > 0)
            {
                var cat_menu = section_menu_item.append('<ul class="category-menu" data-section="'+section_id+'" data-category="'+cat_id+'"></ul>\r\n').find('.category-menu');
				
                /* From alex @ 2010/7/5: The following statement is unnecessary 
                since later will show the sub-menu if the cat_menu item has not 
                defined any URL other than javascript:void(0)*/
				/*if (http_path.search('consolidated') != -1)
				{
					cat_menu.show();
				}*/
                
				if (cat_id == current_category)
                {
                    //highlightCategory({tab: tab_id, section: section_id, category: current_category});
                    cat_menu.show();
                } else {
                    cat_menu.hide();
                }
                
				/*Commented on 2010/07/20
                $(section_menu_item).find('a').toggle(
                    function()
                    {
                        if ($(this).siblings('.category-menu').size() > 0) {
                            $(this).siblings('.category-menu').slideDown('fast');
                        }
                        $(this).addClass('selected');
                    }, function()
                    {
                        if ($(this).siblings('.category-menu').size() > 0) {
                            $(this).siblings('.category-menu').slideUp('fast');
                        }
                        $(this).removeClass('selected');
                    }
                 );
                */
				
                var page_count = 0;
                $.each($(category).children('page').not('page[hide]'), function(key, page)
                {
                    page_count++;
                    var page_id = (isDefined($(page).attr('id'))) ? $(page).attr('id') : 'page'+page_count;
                    var href = ($(page).children('url').size() > 0) ? $(page).children('url:eq(0)').text() : 'javascript:void(0)';
                    var title = $(page).children('title:eq(0)').text();
                    cat_menu.append('<li class="category-menu-item"><a href="'+href+'" data-section="'+section_id+'" data-category="'+cat_id+'" data-page="'+page_id+'">'+title+'</a></li>\r\n');
                });
            }
            if (isDefined(current_category) && cat_id == current_category) {
                highlightCategory({section: section_id, category: current_category});
            }
        });
       
        return true;
    } else {
        return false;
    }
}

getCurrentPageHelpItems = function(list, current_page_selector)
{
    if ($(getXMLFaction(current_page_selector)).find(list).size() > 0)
    {
        return $(getXMLFaction(current_page_selector)).find(list).children('item');
    } else {
        return $(getXMLFaction(current_page_selector)).parent().find(list).children('item');
    }
}

setHelpItemLists = function(current_page_selector)
{
    alert('setHelpItemLists is called.');
    if (checkSelector(current_page_selector))
    {
        var lists = ['resources', 'helps_me_on', 'i_want_to'];
        for(var i in lists)
        {
            setDropDownListItems({list: lists[i], items:getCurrentPageHelpItems(lists[i], current_page_selector)});
        }
    }
}

setDropDownListItems = function(options)
{
    if (isNotEmpty(options.list)) {
        var list_selector;
        switch (options.list)
        {
            case 'resources':
                list_selector = '#helpItemList_resouces';
                break;
            case 'helps_me_on':
                list_selector = '#helpItemList_helpsmeon';
                break;
            case 'i_want_to':
                list_selector = '#helpItemList_iwantto';
                break;
        }
        $(list_selector).html('');
        if (isNotEmpty(options.items))
        {
            var item_count = 0;
            $.each(options.items.not('hide'), function(key, item)
            {
                item_count++;
                var href = ($(item).children('url').size() > 0) ? $(item).children('url:eq(0)').text() : 'javascript:void(0)';
                var target = (isDefined($(item).children('url').attr('target'))) ? $(item).children('url:eq(0)').attr('target') : '_self';
                var title = $(item).children('title:eq(0)').text();
                var help_item_id = (isDefined($(item).attr('id'))) ? $(item).attr('id') : 'item'+item_count;
                var help_item_list_id = options.list;
                $(list_selector).append('<a href="'+href+'" target="'+target+'" data-list="'+help_item_list_id+'" data-item="'+help_item_id+'">'+title+'</a>\r\n');
            });
        }
    }    
}

renderRateEquiryList = function(selected)
{
    $('#select').html('');
    
    $.each(rateequiry_urls, function(name, item)
    {
        if (name == selected)
        {
            $('#select').append('<option value="'+name+'" selected="selected" data-url='+item.url+'>'+item.title+'</option>');
        } else {
            $('#select').append('<option value="'+name+'" data-url='+item.url+'>'+item.title+'</option>');
        }
    });
    $('#select').bind('change', function()
    {
        if (isDefined($(this).find('option[value="'+$(this).val()+'"]').attr('data-url')))
        {
            location.href = $(this).find('option[value="'+$(this).val()+'"]').attr('data-url');
        }
    });
}
/**
 * ========================================
 *
 * The following statements are executed right after document's DOM tree is initalzied
 * ----------------------------------------
 *
 */
 $(document).ready(function()
 {
	//detectLang();
	$(document).pngFix(); 
    initTopMenu();

	//alert(window.frames["infoCast"].document.getElementById("portlet:j_id22:j_id25").value);

    $(".submitBtn").click(function(){
        $(".countryList").show(); 
    });
    
	$(".countryList").mouseenter(function(){
		$(this).show();	 
	}).mouseleave(function(){
		$(this).hide();	 
	});	
	
	//For fixing IE6 Image Cache problem
	try {
		document.execCommand("BackgroundImageCache", false, true);
	} catch(exception) {
		// other browsers do nothing
	}		
		
    /* bind events to control the respective help item list */
	$(".help .helpItem li[class^='item_']").each(function(index){
		/*$(this).mouseenter(function(){
            $(this).find(".itemList").show();
		})
        .mouseleave(function(){
			$(this).find(".itemList").hide(); 
		});*/
        /*$(this).toggle(function(){
            $(this).find(".itemList").show()
                .parent('li').removeClass('hidden-itemList')
                .siblings('li').addClass('hidden-itemList')
                    .find('.itemList').hide();
        }, function(){
            $(this).find(".itemList").hide()
                .parent('li')
                .siblings('li').removeClass('hidden-itemList');
        });*/
		
		// 20100722: "click" changed to "mouseenter"
        $(this).mouseenter(function()
        {
            if ($(this).hasClass('selected')) // if the list is already clicked on
            {
                $(this).removeClass('selected').find(".itemList").hide()
                    .parent()
                        .siblings('li').removeClass('hidden-itemList');
            } else {
                $(this).addClass('selected').find(".itemList").show()
                    .parent('li').removeClass('hidden-itemList')
                        .siblings('li').removeClass('selected').addClass('hidden-itemList')
                            .find('.itemList').hide();
            }
        }).mouseleave(function()
        {
            $(this).parents().find("li[id^='col3menu']")
                .removeClass('selected').addClass('hidden-itemList')
                .find('.itemList').hide();
        });
	});
});


/**
 * ========================================
 *
 * Main horizontal Menu - mouse over change section image 
 * ----------------------------------------
 *
 */
