$(document).ready(function(){
    var phoneNumber = $("#phone-number");
    phoneNumber.val("");
    phoneNumber.mask("(999) 999-9999");
    var visitorName = $("#name");
    visitorName.val("");

    phoneNumber.focus(function() {
       phoneNumber.addClass('white-background');
    }).blur(function() {
        if( this.value.length <1 ) {
            phoneNumber.removeClass('white-background');}
    });
    
     visitorName.focus(function() {
       visitorName.addClass('white-background');
    }).blur(function() {
        if( this.value.length <1 ) {
            visitorName.removeClass('white-background');}
    });
    
    // Get google analytics LoggedInUser cookie
    var ckGoogle = $.cookie("__utmv");
        
    // Does cookie exist?
    if(ckGoogle == null){ 
        // Cookie does not exist, so run geo location logic
        $.get("geo-ip/geoip.aspx", { act: "get" }, 
            function(data) { 
                //alert("Return: " + data);
                if(data != ""){
                    // JSON data object
                    var oResults = window.eval('(' + data + ')');                    
                    $("#citiesText").html(oResults.NearbyCities);
                    $("#ctl00_ipd").val(oResults.ipd);
                    $("#ctl00_no_consultation").hide();
                    $("#ctl00_consultation").show('medium');
                }
            });
    }
});

function ProcessConsult(obj){
    
    // check phone number, jquery mask will make it always empty if it is not valid
    if($("#phone-number").val() == ""){
        $("#cities").hide();
        $("#error").show();
        return;
    }

    // Send request to geoip.aspx
    $.post("geo-ip/geoip.aspx?act=post", { phone: $("#phone-number").val(), name: $("#name").val(), data: $("#ctl00_ipd").val() }, 
        function(data) { 
            //alert("Return: " + data);
            if(data == "Invalid Phone"){
                $("#cities").hide();
                $("#error").show();
            }
            else if(data == "Success"){                    
                urchinTracker("/default.aspx?resp=thanks");
                $("#ctl00_consultation").hide('fast');
                $("#ctl00_no_consultation").hide('fast');
                $("#thanks").show('fast');
            }
            else {
                $("#cities").show('fast');
                $("#error").hide('fast');
            }
        });
}

function LoadVideoBar() {
    var videoBar;
    var options = {
        largeResultSet : !true,
        horizontal : true,
        thumbnailSize : GSvideoBar.THUMBNAILS_MEDIUM,
        autoExecuteList : {
          cycleTime : GSvideoBar.CYCLE_TIME_MEDIUM,
          cycleMode : GSvideoBar.CYCLE_MODE_LINEAR,
          executeList : ["ytchannel:culturalcare mom"]
        }
      }

    videoBar = new GSvideoBar(document.getElementById("videoBar-bar"),
                              GSvideoBar.PLAYER_ROOT_FLOATING,
                              options);
}
// arrange for this function to be called during body.onload
// event processing
GSearch.setOnLoadCallback(LoadVideoBar);