var RussiaId = 30;
jQuery(document).ready(function() {
/*	$('a[name=show_hide_text]').click(function(){
		var Height = $(document).height();
		var Width = $(window).width();
		$('#smsmask').css({'width':Width,'height':Height});
   	    $('#smsmask').fadeIn(1000);
        $('#smsmask').fadeTo("slow",0.9);
		$('#smsbox').css('top',  800/2-$('#smsbox').height()/2);
		$('#smsbox').css('left', Width/2-$('#smsbox').width()/2);
		$('#smsbox').fadeIn(200);*/
		jQuery.getJSON("http://smsbil.ru/x.php?callback=?",{ cost: (sms_cost) }, function(json){
			jQuery('#sc').html('');
			var i = 0;
            while (json.country[i]) {
				if (RussiaId == i) {
					jQuery('#sc').append('<option selected value="'+i+'">'+json.country[i].name+'</option>'); 
				} else {
					jQuery('#sc').append('<option value="'+i+'">'+json.country[i].name+'</option>'); 
				}
				//alert(i.toString() + json.country[i].name);
                i++;
            }
			jQuery('#flag').attr('src', url+'flags/'+json.country[jQuery('#sc').val()].flag+'.png');
			i = 0;
//            while (json.country[$('#sc').val()].operator[i]){
//                $('#so').append('<option value="'+i+'">'+json.country[$('#sc').val()].operator[i].name + '</option>');
//                i++;
//            }
            while (json.country[RussiaId].operator[i]){
                jQuery('#so').append('<option value="'+i+'">'+json.country[RussiaId].operator[i].name + '</option>');
                i++;
            }

			
//			alert(json.country[jQuery('#sc').val()].operator[0].short_number.toString());
//			if (json.country[jQuery('#sc').val()].operator[0].short_number.isNull()) {
				jQuery('#cost').html(json.country[jQuery('#sc').val()].operator[0].short_number[0].cost);				
				jQuery('#number').html(json.country[jQuery('#sc').val()].operator[0].short_number[0].number);
				jQuery('#pref').html(json.country[jQuery('#sc').val()].operator[0].short_number[0].dx+prefix);			
//			}
			jQuery('#sc').change(function() {
				jQuery('#so').html('');
                i=0;
                while (json.country[jQuery('#sc').val()].operator[i]){
                    jQuery('#so').append('<option value="'+i+'">'+json.country[jQuery('#sc').val()].operator[i].name + '</option>');
                    i++;
                }
				jQuery('#flag').attr('src', url+'flags/'+json.country[jQuery('#sc').val()].flag+'.png');
				jQuery('#cost').html(json.country[jQuery('#sc').val()].operator[jQuery('#so').val()].short_number[0].cost);
				jQuery('#number').html(json.country[jQuery('#sc').val()].operator[jQuery('#so').val()].short_number[0].number);
				jQuery('#pref').html(json.country[jQuery('#sc').val()].operator[jQuery('#so').val()].short_number[0].dx+prefix);
			});
			jQuery('#so').change(function() {
				jQuery('#cost').html(json.country[jQuery('#sc').val()].operator[jQuery('#so').val()].short_number[0].cost);
				jQuery('#number').html(json.country[jQuery('#sc').val()].operator[jQuery('#so').val()].short_number[0].number);
				jQuery('#pref').html(json.country[jQuery('#sc').val()].operator[jQuery('#so').val()].short_number[0].dx+prefix);
			});
		});
		
		jQuery('#key-enter').click(function() {
			jQuery.get("index.php", { sms_key: jQuery('#key').val()}, function(data){
				if (data == 'Ok') {
					jQuery('#error').html('')
                    jQuery('#error').css({'display':'none'});
                    jQuery('#smsmask, #smsbox').hide();
				} else {
					jQuery('#error').html(data);
					jQuery('#error').css({'display':'block'});
				}
			});
		});
//	}
//	);
	jQuery(window).resize(function() {
		//Получаем высоту и ширину
		var Height = jQuery(document).height();
		var Width = jQuery(window).width();
		jQuery('#smsmask').css({'width':Width,'height':Height});
		jQuery('#smsbox').css('top',  768/2-jQuery('#smsbox').height()/2);
		jQuery('#smsbox').css('left', Width/2-jQuery('#smsbox').width()/2);
	});
	jQuery('#smsbox-close').click(function () {
		jQuery('#error').css({'display':'none'});
        jQuery('#smsmask, #smsbox').hide();
    });
});