$(document).ready(function () {

    // Main tabs/slideshow
    $(".slides").tabs({
        fx: {
            opacity: 'toggle'
        }
    }).tabs('rotate', 5000);
  
    // Video
  
    $(".p-getstarted #video a").click(function(){
        $("#fakebox").show();
        $("#boxcontent").show();
        $("#fakebox, #boxcontent .close").click(function(){
            $("#fakebox").hide();
            $("#boxcontent").hide();
        });

    });
  
    // On the horizon tabs
    $(".features li h3 a").click(function(event) {

        // Reset
        $(".features .end div").hide(); // Hide all slides
        $(".features ul li").removeClass("on");
    
        // Set
        var slideId = $(this).attr("href");
        $(slideId).fadeIn();
        $(this).parents("li").addClass("on");
        event.stopPropagation();

    });

    $('#inp, #inp-from, #ratescheck input, input#callbackNumber').each(function() {
        addPlusSign(this);
    }).trigger('keyup');

    $("#amicasts").load("/proxy.php", {}, function(){
        $("#amicasts div:nth-child(5)").addClass("end");
        $("#amicasts").prepend("<h2>Popular Amicasts <span><a href=\"http://www.amicast.com\">View more Amicasts</a></span></h2>");
    });

});
function addPlusSign(input) {
    $(input).keyup(function() {
        var val = $(this).val();
        

        if (!isNaN(val) && val.length > 4 && val.indexOf('+') == -1) {
            $(this).val('+' + val);
        }
        else if (isNaN(val) && val.indexOf('+') != -1) {
            $(this).val(val.substring(1));        
        }
        else if (isNaN(val) && val.indexOf('+') == -1) {
            $(this).val("");
            popup(input);
        }
        $('.output').text(val);
    });
}

function popup(el){
    $(el).jDialog({
        title : "Please, notice!",
        content : '\
        <div class="dialog_content">\
        <p>Login with your mobile number (including your country code)</p>\
        </div>\
        ',
        width : 200
    });
    return false;
}

