﻿/*
 * country selector 
 */

function iniCountrySelector() {

    if ($('#intNav').length) {
		countryList = '';
		countryList += '<dd><a title="Australia" href="http://www.microsoftstore.com.au?WT.mc_id=StoreCountryToggle=AU" target="_parent">Australia</a></dd>';
        countryList += '<dd><a title="Belgium (French)" href="' + serverSetting + '?store=FR&WT.mc_id=StoreCountryToggle_BE" target="_parent">Belgium (French)</a></dd>';
        countryList += '<dd><a title="Belgium (Dutch)" href="' + serverSetting + '?store=NL&WT.mc_id=StoreCountryToggle_BE" target="_parent">Belgium (Dutch)</a></dd>';
        countryList += '<dd><a title="Deutschland" href="' + serverSetting + '?store=DE&WT.mc_id=StoreCountryToggle_DE" target="_parent">Deutschland</a></dd>';
        countryList += '<dd><a title="Espa&ntilde;a" href="' + serverSetting + '?store=ES&WT.mc_id=StoreCountryToggle_ES" target="_parent">Espa&ntilde;a</a></dd>';
        countryList += '<dd><a title="France" href="' + serverSetting + '?store=FR&WT.mc_id=StoreCountryToggle_FR" target="_parent">France</a></dd>';
        countryList += '<dd><a title="India" href="http://www.microsoftstore.co.in?WT.mc_id=StoreCountryToggle_IN" target="_parent">India</a></dd>';
        countryList += '<dd><a title="Italy" href="http://www.microsoftstore.it?WT.mc_id=StoreCountryToggle=IT" target="_parent">Italy</a></dd>';
        countryList += '<dd><a title="Nederland" href="'+ serverSetting + '?store=NL&WT.mc_id=StoreCountryToggle_NL" target="_parent">Nederland</a></dd>';
        countryList += '<dd><a title="Österreich" href="' + serverSetting + '?store=DE&WT.mc_id=StoreCountryToggle_AT" target="_parent">Österreich</a></dd>';
        countryList += '<dd><a title="United Kingdom" href="' + serverSetting + '?store=UK&WT.mc_id=StoreCountryToggle_UK" target="_parent">United Kingdom</a></dd>';
        countryList += '<dd><a title="United States" href="' + serverSetting + '?store=US&WT.mc_id=StoreCountryToggle_US" target="_parent">United States</a></dd>';
        countryList += '<dd><a title="日本" href="' + serverSetting + '?store=JP&WT.mc_id=StoreCountryToggle_JP" target="_parent">日本</a></dd>';
        countryList += '<dd><a title="대한민국" href="' + serverSetting + '?store=KR&WT.mc_id=206" target="_parent">대한민국</a></dd>';
        $('#intNav dd:last').before(countryList);
        
        toggleCountrySelector();
        countrySelectorTabOrdering();
    }
}

function toggleCountrySelector() {

    $('#intNav #currentLocation').mouseover(function() {
        $('#intNav dd:not(#currentLocation)').css('display', 'block');
    });
    
    $('#intNav dl').mouseleave(function() {
        $('#intNav dd:not(#currentLocation)').css('display', 'none');
    });
}

function countrySelectorTabOrdering()
{
    var all = $("a");
    var inside = $("#intNav a");
    
    var firstIndex = all.index(inside[0]);     
    var lastIndex = all.index(inside[inside.length - 1]);
    
    var ranges = all.slice(firstIndex-1, lastIndex+2);

    $('#intNav #currentLocation a').focus(function() {
        $('#intNav dd:not(#currentLocation)').css('display', 'block');
    });

    $(ranges[0]).focus(function(){
        $('#intNav dd:not(#currentLocation)').css('display', 'none');
    });

    $(ranges[ranges.length-1]).focus(function(){
        $('#intNav dd:not(#currentLocation)').css('display', 'none');
    });
}

$(iniCountrySelector);