﻿/*
 * 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="' + serverSetting + '?store=FR&WT.mc_id=StoreCountryToggle_BE" target="_parent">Belgique (MS Store France)</a></dd>';
        countryList += '<dd><a title="België (MS Store Nederland)" href="' + serverSetting + '?store=NL&WT.mc_id=StoreCountryToggle_BE" target="_parent">België (MS Store Nederland)</a></dd>';
        countryList += '<dd><a title="Canada" href="http://www.microsoftstore.ca" target="_parent">Canada</a></dd>';
        countryList += '<dd><a title="Danmark" href="http://emea.microsoftstore.com/europe/" target="_parent">Danmark</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="European Union (English)" href="http://emea.microsoftstore.com/europe/" target="_parent">European Union (English)</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="Itala" 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="Norge" href="http://emea.microsoftstore.com/europe/" target="_parent">Norge</a></dd>';   
		countryList += '<dd><a title="Österreich (MS Store Deutschland)" href="' + serverSetting + '?store=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="Suomi" href="' + serverSetting + '?store=FI&WT.mc_id=StoreCountryToggle_FI" target="_parent">Suomi</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="' + 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);
