$(document).ready(function() {

//var active = false;
//$('.controlled-interval', demos).find('.start').css("cursor", "pointer").click(function() {
//    if (!active) {
//        active = !active;
//        $(this).parents("div").find('ul').everyTime(1000, 'controlled', function() {
//            $(this).append("<li>New One</li>");
//        });
//    }
//}).end().find('.stop').css("cursor", "pointer").click(function() {
//    if (active) {
//        active = !active;
//        $(this).parents("div").find('ul').stopTime('controlled');
//    }
//});


//if 
    $.ajax({
        type: "POST",
        data: '{}',
        url: "MyWebService.asmx/GetShouts",
        contentType: "application/json; charset=utf-8",
        dataType: "json",
        success: function(response) {
            var data = (typeof response.d) == 'string' ? eval('(' + response.d + ')') : response.d;
            for (var i = 0; i < data.length; i++) {
                $('#ShoutBox').empty().append(data[i].HtmlOutput);
                var objDiv = document.getElementById("ShoutBox");
                objDiv.scrollTop = objDiv.scrollHeight;
            }
        },
        failure: function(msg) {
        }
    });


    $('#shoutSubmit').click(function(e) {
        e.preventDefault();
        $('#txtShout').removeClass('highlight');
        $('label#lblError').html('');
        var userCheck = false;
        var userID = '';
        var cookieUser = $.cookie('cookieUser');
        var sessionUser = $.session('sessionUser');

        if (typeof cookieUser != 'undefined' && cookieUser != null) {
            userCheck = true;
            userID = cookieUser;
        } else if (typeof sessionUser != 'undefined' && sessionUser != null) {
            userCheck = true;
            userID = sessionUser;
        }

        if (userCheck == true) {
            $.ajax({
                type: "POST",
                data: '{text: "' + $('#txtShout').val() + '",' +
                    'userID: "' + userID + '"}',
                url: "MyWebService.asmx/CreateShout",
                contentType: "application/json; charset=utf-8",
                dataType: "json",
                success: function(response) {
                    $('#txtShout').val('');
                    var data = (typeof response.d) == 'string' ? eval('(' + response.d + ')') : response.d;
                    for (var i = 0; i < data.length; i++) {
                        $('#ShoutBox').empty().append(data[i].HtmlOutput);
                        var objDiv = document.getElementById("ShoutBox");
                        objDiv.scrollTop = objDiv.scrollHeight;
                    }
                },
                failure: function(msg) {
                }
            });

        }
        else {
            $('#txtShout').addClass('highlight');
            $('label#lblError').html('Must be logged in to Shout!');
        }

    });






});





