$(document).ready(function() {
   $("a.soon").hover(
	  function () {
	    $(this).prev().append('<span class="coming-soon">&nbsp;</span>');
	    $(this).prev().find("span.coming-soon").delay(100).fadeIn(150);
	  }, 
	  function () {
	    $(this).prev().find('span.coming-soon').remove();
	  }
	).click(function() {
	  return false;
	});

  $('a').bind("focus", function() {
    $(this).blur()
  });
  /**
   * Cufon Fonts
   */
  Cufon.replace('.fein400, #mainnavigation>ul.level1>li>a', {
    fontFamily : 'Fein Pro 400',
    hover : true
  });

  Cufon.replace('.fein800', {
    fontFamily : 'Fein Pro 800'
  });

  Cufon.replace('.fein700Hover, .h a', {
    fontFamily : 'Fein Pro 700',
    hover : true
  });
  Cufon.CSS.ready(function() {
    $('html').addClass('frisch');
  })
  /**
   * 1050px Layout fix
   */

  var w = $(window).width();
  if(w > 1007) {
    $('.page').css({
      'marginLeft' : ( w - 1050) / 2 + 'px'
    })
  } else {
    $('.page').css({
      'marginLeft' : 'auto'
    })
  }
  $(window).resize(function() {
    var new_w = $(window).width();
    if(new_w > 1007) {
      $('.page').css({
        'marginLeft' : ( new_w - 1050) / 2 + 'px'
      })
    } else {
      $('.page').css({
        'marginLeft' : '-20px'
      })
    }
  });
  $('#map area').bind('mouseenter', function() {
    var territory = $(this).attr('alt');
    $('#territoriesMap').attr('src', '/css/countrySelector/img/' + territory + '_hover.jpg');
  });
  $('#map area').bind('click', function() {
    var territory = $(this).attr('alt');
    $('.territoryOverlay').hide();
    var tmp = $('#territoryOverlay-' + territory);
    if(tmp == null || tmp.length == 0) {
      switch(territory) {
        case 'europe': territory = "Europe"; break;
        case 'america': territory = "Aurope"; break;
        case 'asia-pacific': territory = "Asia-Pacific"; break;
      }
    }
    $('#territoryOverlay-' + territory).fadeIn();
  });

  $('#map area').bind('mouseover', function() {
    var m = document.body;
    m.style.cursor = 'pointer';
  });
  
  $('#map area').bind('mouseout', function() {
    var m = document.body;
    m.style.cursor = 'default';
  });
});

  /*
   * close button hover graphics
   */
  $('.territory .closeButton').bind('mouseenter', function() {
    $(this).css('background-image', 'url("/css/countrySelector/img/close_hover.png")');
  });
  $('.territory .closeButton').bind('mouseleave', function() {
    $(this).css('background-image', 'url("/css/countrySelector/img/close.png")');
  });
  /*
   * dynamic country-count dependent overlay width
   */
  $('.territoryOverlay').each(function() {
    
    var $this = $(this);
    var niceUrlName = $this.find('.niceUrlName').html();
    var count = $this.find('#countryCount-' + niceUrlName).html();
    // > 20: default css width

    if(count < 20) $this.css('width', '555px').css('left', '217px');
  })

