﻿/*
 * 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="Belgique (MS Store France)" href="http://emea.microsoftstore.com/fr/fr-FR/?WT.mc_id=StoreCountryToggle_BE" target="_parent">Belgique (MS Store France)</a></dd>';
        countryList += '<dd><a title="België (MS Store Nederland)" href="http://emea.microsoftstore.com/nl/nl-NL/?WT.mc_id=StoreCountryToggle_BE" target="_parent">België (MS Store Nederland)</a></dd>';
        countryList += '<dd><a title="Canada (English)" href="http://www.microsoftstore.ca/shop/" target="_parent">Canada (English)</a></dd>';
        countryList += '<dd><a title="Danmark" href="http://emea.microsoftstore.com/europe/" target="_parent">Danmark</a></dd>';
	countryList += '<dd><a title="Deutschland" href="http://emea.microsoftstore.com/de/de-DE/?WT.mc_id=StoreCountryToggle_DE" target="_parent">Deutschland</a></dd>';
        countryList += '<dd><a title="Espa&ntilde;a" href="http://emea.microsoftstore.com/es/es-ES/?WT.mc_id=StoreCountryToggle_ES" target="_parent">Espa&ntilde;a</a></dd>';
        countryList += '<dd><a title="European Union (English)" href="http://emea.microsoftstore.com/europe/" target="_parent">European Union (English)</a></dd>';        
	countryList += '<dd><a title="France" href="http://emea.microsoftstore.com/fr/fr-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="Italia" href="http://www.microsoftstore.it?WT.mc_id=StoreCountryToggle=IT" target="_parent">Italia</a></dd>';
        countryList += '<dd><a title="Nederland" href="http://emea.microsoftstore.com/nl/nl-NL/?WT.mc_id=StoreCountryToggle_NL" target="_parent">Nederland</a></dd>';
        countryList += '<dd><a title="Norge" href="http://emea.microsoftstore.com/europe/" target="_parent">Norge</a></dd>';   
	countryList += '<dd><a title="Österreich (MS Store Deutschland)" href="http://emea.microsoftstore.com/de/de-DE/?WT.mc_id=StoreCountryToggle_AT" target="_parent">Österreich (MS Store Deutschland)</a></dd>';
        //countryList += '<dd><a title="Schweiz (MS Store Deutschland)" href="http://emea.microsoftstore.com/de/" target="_parent">Schweiz (MS Store Deutschland)</a></dd>';        
       // countryList += '<dd><a title="Suisse (MS Store France)" href="http://emea.microsoftstore.com/fr/" target="_parent">Suisse (MS Store France)</a></dd>';        
	countryList += '<dd><a title="Sverige" href="http://emea.microsoftstore.com/europe/" target="_parent">Sverige</a></dd>';
        //countryList += '<dd><a title="Svizzera (MS Store Italia)" href="http://microsoftstore.it/shop/" target="_parent">Svizzera (MS Store Italia)</a></dd>';        
	countryList += '<dd><a title="United Kingdom" href="http://emea.microsoftstore.com/UK/en-GB?WT.mc_id=StoreCountryToggle_UK" target="_parent">United Kingdom</a></dd>';
        countryList += '<dd><a title="United States" href="http://www.microsoftstore.com/store/msstore/DisplayHomePage/?WT.mc_id=StoreCountryToggle_US" target="_parent">United States</a></dd>';
        countryList += '<dd><a title="日本" href="http://www.microsoftstore.jp/?WT.mc_id=StoreCountryToggle_JP" target="_parent">日本</a></dd>';
        countryList += '<dd><a title="대한민국" href="http://www.microsoftstore.co.kr/?WT.mc_id=206" target="_parent">대한민국</a></dd>';
        $('#intNav dd:last').after(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);
