  var choose_country = {
	cos : undefined,
	gameId : undefined,
	language : undefined,
	curCountry : undefined,
	changeBut : undefined,
	type : undefined,

	init : function( curCountry, language, gameId ) {
		this.curCountry = curCountry;
		this.language = language;
		this.gameId = gameId;
		$.getJSON('/active_countries.json?lang='+this.language,
		function( data ) {
			choose_country.cos = data;
			choose_country.firstLoad();	
		});
	},
	
	initPc : function( curCountry, language, gameId, type) {
		this.curCountry = curCountry;
		this.language = language;
		this.gameId = gameId;
		this.type = type;
		$.getJSON('/active_countries.json?lang='+this.language,
		function( data ) {
			choose_country.cos = data;
			choose_country.firstLoad();	
		});
	},
	
	createUI : function() {
		this.changeBut = $('#choose-country-but');
		this.el = $('#choose-country');
		this.el.hide();
		var curCountry = this.curCountry;

		if( this.el != null ) {
			for(var i=0; i < this.cos.length; i++) {
				var opt = $( document.createElement( 'option' ) );
				opt.attr( 'value', this.cos[i].code );
				opt.html( this.cos[i].name );
				this.el.append( opt );
				if( this.cos[i].code == curCountry.toUpperCase()) {
					opt.attr('selected', 'selected');
				}
			}
		}

		this.changeBut.show();
		this.el.change( function() { choose_country.doRequest(); } );
		this.changeBut.click( function() {
			choose_country.el.show();
			choose_country.changeBut.hide();
		} );
		//choose_country.doRequest();
	
	},
		
	doRequest : function() {
		this.curCountry = this.el.val();
		var needRedirect = false;
		if(this.curCountry=="BR"||this.curCountry=="MX"){//таск wap-368 - для редиректа на локализации мексики и бразилии
		    needRedirect = true;
		}
		  $('#buy-short').load(
			  '/buy_short_co.txt?game_id=' + this.gameId + '&co=' + this.curCountry + '&lang=' + this.language + '&type=' + this.type,
			  {},
			  function() {
				  choose_country.createUI();
				  if(needRedirect==true){
				    window.location.reload(true);//Это для редиректа на локализации
				  }   
			  }
		  );
		
	},
	
	firstLoad : function() {
		$('#buy-short').load(
			'/buy_short_co.txt?game_id=' + this.gameId + '&co=' + this.curCountry + '&lang=' + this.language + '&type=' + this.type ,
			{},
			function() {
				choose_country.createUI();
			}
		);
		  
	}
	  

}
