﻿/// <reference path="jquery-1.2.6-vsdoc.js" />

var folderInvite = false;
var isInAjax = false;
//document.domain = "comet.kiselev.spb.ru";
PrefixChannelUrl = "http://";
function closePlayVideoInMedia() {
    $('#mediaBlocker').hide();
    $('#playVideo, #player').hide();
    var x = getFlashObject("player");
    x.stopStream();
    $('#playVideoComments').html('');
    $('#playVideoInputTitle').val('');
    $('#playVideoTitle').text('');
}
var stringWithContacts = '';
function closeShareVideo() {
    $('#mediaBlocker').hide();
    $('#blocker').hide();
    $('#makePublic').hide();
    $('#AlbumToShare').hide();
    $('#videoToShare').hide();
    $('#shareVideo').hide();
    stringWithContacts = '';
    $('#forSending').html('');
    $('#smartSearch').val('');
    $('#noContactInAlbum').hide();
    $('#contactsInAlbum').hide();
    $('#shareAlbumBlueButton').hide();
    $('#shareVideoBlueButton').hide();
    $('#albms1').hide();
    $('#albms2').hide();
    $('#lbl').text("");
}
var vgv;
var ugv;
var agv;
var iframeContent;
var globalInterval;
var folderInterval;
var anotherAlbum = false;
function someFunc() {
    alert('x');
}
function showVideosInAlbum(folderGUID) {
    nothingMore = true;
    clearInterval(globalInterval);
    clearInterval(folderInterval);
    folderInterval = setInterval("CheckFolderNews('" + folderGUID + "')", 10000);
    $('#VideoLenta').fadeOut();
    $('.singleSharedAlbum a').removeClass('orange');
    $('#' + folderGUID).addClass('orange');
    $('#forIframe').html('<iframe src=\"/Files/handlers/VideoInFolder.aspx?fuid=' + folderGUID + '\"/>');
}
function UpdateLiveChat(LiveChatMessages) {
    if (LiveChatMessages != $('#playVideoComments').html()) {
        $('#playVideoComments').html(LiveChatMessages);
    }
}
function showAlbumInLenta(content) {
    $('#VideoLenta').html(content);
    $('#VideoLenta').width($('.img').length * oneItemWidth);
    $('#VideoLenta').fadeIn();
    $('.videoThumbWrapper').unbind('mouseover').unbind('mouseout').mouseover(function() {
        $(this).css('borderColor', '#F37D01');
    }).mouseout(function() {
        $(this).css('borderColor', '#E9E9E9');
    });
    marginleft = 0;
    $('#leftLentaArrow').addClass('notActiveLentaArrow');
    $('#VideoLenta').css({ 'marginLeft': marginleft });
    if ($('.img').length * oneItemWidth <= initialWidth / 2) {
        $('#rightLentaArrow').addClass('notActiveLentaArrow');
    }
    else {
        $('#rightLentaArrow').removeClass('notActiveLentaArrow');
    }
}
function GetAlbumsForSharing(type) {
    var GetAlbumsAction = type == "video" ? "GetAlbums4VideoSharing" : "getAlbums";
    $.post("/Files/handlers/cmanag.ashx",
        {
            action: GetAlbumsAction,
            u: ugv,
            v: vgv
        },
        function(data) {
            if (data != "NotOK") {
                $('#tableWithAlbumsToShare').html(data);
                if (type == "video") {

                }
            }
            else alert('Something happend');
        });
}
var ValreadySharedWith = "";
var VcontactUids;
var PublState;
function GetPublicityState(videoGuid) {
    $.post("/Files/handlers/cmanag.ashx",
        {
            action: "GetPublicityState",
            v: videoGuid
        },
        function(data) {
            PublState = data.split('|')[0];
            ValreadySharedWith = data.split('|')[1];
            VcontactUids = data.split('|')[1].split(',');
            if (PublState == "public") {
                $('#publicCheckBox').attr("checked", "checked");
            }
            else {
                $('#publicCheckBox').attr("checked", "");
            }
            for (var i = 0; i < VcontactUids.length; i++) {
                $('#scinp' + VcontactUids[i]).attr('checked', 'checked');
            }
            $('#makePublic').show();
        });
}
function processCommentInput(event, isUserPage) {
    if (event.which == 13) {
        LeaveComment(isUserPage);
        return false;
    }
    return true;
};
function ShowShareAlbumDialog(albumGuid, userGuid) {
    $('#AlbumToShare').show();
    $('#shareAlbumBlueButton').show();
    $('#mediaBlocker').show();
    $('#shareVideo').show();

    var albumTitle = $('#albumTitle' + albumGuid).text();
    $('#AlbumToShareTitle').text(albumTitle);
    if (albumTitle == "FaceBook") {
        $('#lbl').text("There is a Video Phlyr box on your Facebook page");
    }
    else {
        $('#lbl').text("");
    }
    $('#AlbumToShareDateCreated').text($('#albumDateCreated' + albumGuid).text());
    $('#AlbumToSharesharedWith').text($('#sharedWith' + albumGuid).text());
    $('#AlbumToSharevideoCount').text($('#videoCount' + albumGuid).text());
    $('#albms2').show();
    $('#smartSearch').val('');
    $('#contactsForSharing div').show();
    $('#contactsForSharing span').hide();
    $('#contactsForSharing .checkbox').attr('checked', '');
    $('#contactsForSharing .emailChecker').attr('checked', '');
    agv = albumGuid;
    ugv = userGuid;
    GetAlreadySharedWith(albumGuid);
    $('#albumComment').show();
    //GetAlbumsForSharing("album");
}
var contactUidsString;
var contactUids;
var emailUidsString;
var emailUids;
function GetAlreadySharedWith(albumGuid) {
    $.post("/Files/handlers/cmanag.ashx",
        {
            action: "GetAlreadySharedWith",
            auid: albumGuid
        },
        function(data) {
            contactUidsString = "";
            emailUidsString = "";
            AllcontactUids = data.split('|');
            for (var i = 0; i < AllcontactUids.length; i++) {
                var type = AllcontactUids[i].split(',')[1];
                var uid = AllcontactUids[i].split(',')[0];
                if (type == "s") {
                    $('#scinp' + uid).attr('checked', 'checked');
                    contactUidsString += uid + "|";
                }
                else if (type == "e") {
                    $('#email' + uid).attr('checked', 'checked');
                    emailUidsString += uid + '|';
                }
                contactUids = contactUidsString.split('|');
                emailUids = emailUidsString.split('|');
            }
        });
}
function playerReady() {
}

function ShowShareVideoDialog(videoGuid, userGuid) {
    if ($('#' + videoGuid + ' .isAdult1').length) {
        alert('Sorry, you can not share this video. It has been flagged as inappropriate and is being reviewed.');
    } else {
        $('#shareVideoBlueButton').show();
        $('#videoToShare').show();
        $('#mediaBlocker').show();
        $('#shareVideo').show();
        $('#albms1').show();
        $('#shareVideoButton').text('Share');
        $('#videoToShareTitle').text($('#Title' + videoGuid).text());
        $('#videoToShareThumb').css({ 'backgroundImage': 'url(/Files/handlers/picture.aspx?video=' + videoGuid + '&size=116x79)' });
        $('#videoToShareDateCreated').text($('#dateCreated' + videoGuid).text());
        $('#smartSearch').val('');
        $('#contactsForSharing .checkbox').attr('checked', '');
        $('#contactsForSharing .emailChecker').attr('checked', '');
        $('#contactsForSharing span').hide();
        $('#contactsForSharing div').show();
        ugv = userGuid;
        vgv = videoGuid;
        GetPublicityState(vgv);
        //    GetAlbumsForSharing("video");
    }
}
function DeleteSelectedContact(contactGuid) {
    $('#selected' + contactGuid).remove();
    $('#' + contactGuid).attr('disabled', '').removeClass('gray');
    stringWithContacts = stringWithContacts.replace(contactGuid + '|', '');
}
function AddSelectedContacts() {
    $('#contactsInAlbum :selected').each(
        function(i, selected) {
            if (stringWithContacts.indexOf($(selected).val()) < 0) {
                stringWithContacts += $(selected).val() + '|';
                $('#forSending').append("<span id='selected" + $(selected).val() + "' class='friendToSend'><nobr>" + $(selected).text() + "<input type='image' src='/Files/images/gdelete.png' class='deleteMedia' onclick=\"DeleteSelectedContact('" + $(selected).val() + "'); return false\" /></nobr></span> ");
                $('#selected' + $(selected).val()).fadeIn();
            }
            $(selected).attr('disabled', 'disabled').addClass('gray').attr('selected', '');
        });
}
function ShowNotAssignedContacts() {
    $('#noContactInAlbum').hide();
    $('#contactsInAlbum').hide();
    $('.shareAlbum').removeClass('selectedAlbum');
    $('#AnotAssignedAlbums').addClass('selectedAlbum');
    $.post("/Files/handlers/cmanag.ashx",
        {
            action: "getNotAssignedContacts",
            uid: ugv
        },
        function(data) {
            if (data != "NotOK") {

                if (data == '') {
                    $('#noContactInAlbum').show();
                    $('#contactsInAlbum').hide();
                    $('#addButton').hide();
                }
                else {
                    $('#contactsInAlbum').show();
                    $('#noContactInAlbum').hide();
                    $('#contactsInAlbum').html(data);
                    $('#addButton').show();
                }
            }
            else alert('Something happend');
        });
}
function ShareAlbum() {
    stringWithContacts = '';
    stringToUnshare = '';
    stringAllChecked = '';
    stringAllEmailChecked = '';
    stringSendEmail = '';
    stringToUnemail = '';
    $('#contactsForSharing .checkbox:checked').each(function() {
        var CheckedUID = this.id.replace('scinp', '');
        stringAllChecked += CheckedUID + '|';
        if (contactUidsString.indexOf(CheckedUID) == -1) {
            stringWithContacts += CheckedUID + '|';
            $('#albums' + CheckedUID).append("<span id='f" + agv + CheckedUID + "'>[" + $('#AlbumToShareTitle').text() + " <input type='image' class='deleteUserFromAlbum' onclick=\"DeleteUserFromAlbum('" + agv + "','" + CheckedUID + "'); return false\" src='/Files/images/gdelete.png'/>]</span>");
        }
    });
    $('#contactsForSharing .emailChecker:checked').each(function() {
        var CheckedUID = this.id.replace('email', '');
        stringAllEmailChecked += CheckedUID + '|';
        if (emailUidsString.indexOf(CheckedUID) == -1) {
            stringSendEmail += CheckedUID + '|';
        }
    });

    for (var i = 0; i < emailUids.length; i++) {
        contU = contactUids[i]
        if (stringAllEmailChecked.indexOf(contU) == -1) {
            stringToUnemail += contU + '|';
        }
    }
    for (var i = 0; i < contactUids.length; i++) {
        contU = contactUids[i]
        if (stringAllChecked.indexOf(contU) == -1) {
            stringToUnshare += contU + '|';
            $('#f' + agv + contU).remove();
        }
    }
    if (stringWithContacts == '' && stringToUnshare == '' && stringSendEmail == '' && stringToUnemail == '') {
        alert('No contact was choosen');
    }
    else {
        $('#shareAlbumButton').text('Working...');
        $.post("/Files/handlers/cmanag.ashx",
            {
                action: "ShareAlbum",
                cGds: stringWithContacts,
                emailTo: stringSendEmail,
                albumGuid: agv,
                unshare: stringToUnshare,
                unemail: stringToUnemail
            },
            function(data) {
                closeShareVideo();
                $('#shareAlbumButton').text('Share album');
                ShowIndicatorWithText('Album successfully shared');
                setTimeout("HideIndicator()", 5000);
                if (data == "OK") {

                }
                //                else alert('Something happend');
            });
    }
}
function SetPublicityState(videoGuid, state) {
    if (state == 1) {
        $('#' + videoGuid + ' div').removeClass('ispublic0').addClass('ispublic1');
    }
    else {
        $('#' + videoGuid + ' div').removeClass('ispublic1').addClass('ispublic0');
    }
    $.post("/Files/handlers/cmanag.ashx",
        {
            action: "SetPublicityState",
            st: state,
            v: videoGuid
        },
        function(data) {
            if (data == "OK") {

            }
            else alert('Something happend');
        });
}
function Share() {
    $('#shareVideoButton').text('Working...');
    stringWithContacts = '';
    stringAllChecked = '';
    stringToUnshare = '';
    stringSendEmail = '';
    $('#contactsForSharing .checkbox:checked').each(function() {
        var CheckedUID = this.id.replace('scinp', '');
        stringAllChecked += CheckedUID + '|';
        if (ValreadySharedWith.indexOf(CheckedUID) == -1) {
            stringWithContacts += CheckedUID + '|';
        }
    });
    $('#contactsForSharing .emailChecker:checked').each(function() {
        var CheckedUID = this.id.replace('email', '');
        stringSendEmail += CheckedUID + '|';
    });
    for (var i = 0; i < VcontactUids.length; i++) {
        contU = VcontactUids[i]
        if (stringAllChecked.indexOf(contU) == -1) {
            stringToUnshare += contU + '|';
        }
    }

    pState = $('#publicCheckBox').attr("checked") == false ? "notPublic" : "public";
    if (stringWithContacts == '' && stringToUnshare == '' && PublState == pState) {
        closeShareVideo();
        HideIndicator();
    }
    else {
        var pu = pState == PublState ? "" : pState;
        $.post("/Files/handlers/cmanag.ashx",
            {
                action: "Share",
                cGds: stringWithContacts,
                vidGuid: vgv,
                emailTo: stringSendEmail,
                publ: pu,
                unshare: stringToUnshare
            },
            function(data) {
                $('#shareVideoButton').text('Share video');
                ShowIndicatorWithText('Video successfully shared');
                setTimeout("HideIndicator()", 5000);
                //SetPublicityState(vgv, $('#publicCheckBox').attr("checked") == false ? 0 : 1);
                closeShareVideo();
                if (pState == "public") {
                    $('#' + vgv + ' div').removeClass('ispublic0').addClass('ispublic1');
                }
                else if (pState == "notPublic") {
                    $('#' + vgv + ' div').removeClass('ispublic1').addClass('ispublic0');
                }
            });
    }
}
function ShowContactsInAlbum(albumID) {
    $('#noContactInAlbum').hide();
    $('#contactsInAlbum').hide();
    $('.shareAlbum').removeClass('selectedAlbum');
    $('#shareAlbumID' + albumID).addClass('selectedAlbum');
    $.post("/Files/handlers/cmanag.ashx",
        {
            action: "getContactsInAlbum",
            aid: albumID
        },
        function(data) {
            if (data != "NotOK") {

                if (data == '') {
                    $('#noContactInAlbum').show();
                    $('#contactsInAlbum').hide();
                    $('#addButton').hide();
                }
                else {
                    $('#contactsInAlbum').show();
                    $('#noContactInAlbum').hide();
                    $('#contactsInAlbum').html(data);

                    $('#addButton').show();
                }
            }
            else alert('Something happend');
        });
}
function LeaveComment(userPage) {
    var isUserPage = "false";
    if (userPage) isUserPage = "true"
    isInAjax = true;
    if ($('#leaveCommentTA').val() != '') {
        var LeaveCommentAction = vtype == '2' ? 'LeaveComment' : 'LeaveLiveComment';
        ShowIndicator();
        $.post("/Files/handlers/cmanag.ashx",
        {
            action: LeaveCommentAction,
            v: vgv,
            a: ugv,
            c: $('#leaveCommentTA').val(),
            up: isUserPage
        },
        function(data) {
            isInAjax = false;
            if (data != "NotOK") {
                $('#noComments').remove();
                $('#playVideoComments').prepend(data);
                $('#leaveCommentTA').val('');
                HideIndicator();
                updateComments();
            }
            else alert('Something happend');
        });
    }
}
var complained = "";
function ShowInappropriate() {

        complained = $.cookie('complained') == null ? "" : $.cookie('complained');
        if (complained.indexOf(vgv) == -1) {
            $('#inappropriateLink').show();
        }
        else {
            $('#inappropriateLink').hide();
        }
   
}
function Complain() {
    if (userGuid != '00000000-0000-0000-0000-000000000000') {
        var answer = confirm("Do you really want to Flag this video as inappropriate?")
        if (answer) {
            isInAjax = true;
            $.cookie('complained', complained + vgv);
            $('#inappropriateLink').hide();
            $.post("/Files/handlers/cmanag.ashx",
            {
                action: "Complain",
                v: vgv,
                u: userGuid
            },
            function(data) {
                isInAjax = false;
                if (data == "OK") {
                    $('#ld' + vgv).remove();
                    $('#VideoLenta').width($('.img').length * oneItemWidth);
                    alert('Your concern about the video was sent to our review team.');
                }
                else alert('Something happend');
            });
        }
    }
    else {
        alert('Register first please');
    }
}
function GetComments(VideoGuid, type, owner, where) {
    var ow = "";
    if (owner != undefined) {
        ow = "owner";
    }
    if (!where) {
        where = "#playVideoComments";
    }
    var CommentsAction = type == '2' ? 'GetComments' : 'GetLiveComments';
    $(where + ' *').fadeOut();
    if (CommentsAction == 'GetComments') {
        $('#fLCf').html('');
        $.post("/Files/handlers/cmanag.ashx",
        {
            action: CommentsAction,
            v: VideoGuid,
            o: ow
        },
        function(data) {
            if (data != "") {
                $(where).html(data);
                $('#playVideoComments.defaultPage').css({ height: 110 });
                $('#comments').css({ 'visibility': 'visible', 'height': 'auto' });

            }
            else {
                $(where).html("<div id='noComments'>Comments(0)</div>");
                if (userGuid == '00000000-0000-0000-0000-000000000000') {
                    $('#playVideoComments.defaultPage').css({ height: 0 });
                    $('#comments').css({ 'visibility': 'hidden', 'height': '60px' });
                }
            }
            $(where + ' *').show();
        });
    }
    else {
        $('#fLCf').html('<iframe src=\"http://c2.comet.kiselev.spb.ru/Files/handlers/LiveChat.aspx?LiveGUID=' + VideoGuid + '\"/>');
    }

}
function DeleteComment(commentID) {
    if (!isInAjax) {
        isInAjax = true;
        $.post("/Files/handlers/cmanag.ashx",
            {
                action: 'DeleteComment',
                id: commentID
            },
            function(data) {
                isInAjax = false;
                if (data == "OK") {
                    $('#comment' + commentID).remove();
                    updateComments();
                }
            });
    }

}
var alreadyPlayedInMedia = false;
var playerObject;
function ViewVideo(userguid, videoguid) {
    vgv = videoguid;
    ugv = userguid;
    NewWindow('/Files/handlers/PopupPlayer.aspx?vgv=' + vgv + '&ugv=' + ugv, videoguid, '650', '360', 'no');
    /*
    $('#mediaBlocker').css({ 'position': 'absolute', 'top': '0', 'left': '0', 'width': '100%', 'height': '100%' });
    $('#mediaBlocker').show();
    $('#playVideo').show();
    var vidTitle = $('#Title' + videoguid).length ? $('#Title' + videoguid).text() : $('#videoTitleInComments' + videoguid).text();
    $('#playVideoTitle').text(vidTitle);
    $('#playVideoInputTitle').val($('#Title' + videoguid).text());
    var dateVidCreated = $('#dateCreated' + videoguid).length ? $('#dateCreated' + videoguid).text() + ' ' + $('#timeCreated' + videoguid).text() : $('#DateAndTimeCreated' + videoguid).text()
    $('#playVideoDateCreated').text(dateVidCreated);
    $('#leaveCommentTA').val('');
    GetComments(vgv, '2', userguid);
    vtype = '2';

    if (!alreadyPlayedInMedia) PlayVideoInMedia(videoguid, userguid, RelayName, 2);
    else {
    ShowPlayer();
    playerObject = getFlashObject("player");
    setTimeout("ps('" + vgv + "')", 200);
    }
    */
}
function ps(vvgv) {
    playerObject.playStream(vvgv, '2', '1');
}
function ShowPlayer() {
    $('#player').show();
}
function PlayVideoInMedia(videouid, userguid, relay, type) {
    var flashvars = { user_guid: userguid, stream_guid: videouid, view_type: 1, stream_type: type, database: relay, server: serverName };
    var params = { "wmode": "transparent" };
    swfobject.embedSWF("/Files/swf/phlyr.swf?r=" + Math.random(), "MediaPlayer", 320, 240, "9.0.0", null, flashvars, params, false);
    alreadyPlayedInMedia = true;
}
function Playchannel(el) {
    alert(el.id);
}
function ShowIndicatorWithText(text) {
    $('#indicator').text(text);
    $('#indicator').show();
}
function ShowIndicator() {
    $('#indicator').show();
}
function HideIndicator() {

    $('#indicator').fadeOut(function() { $('#indicator').text('Loading...'); });
}

var win = null;
function NewWindow(mypage, myname, w, h, scroll) {
    LeftPosition = (screen.width) ? (screen.width - w) / 2 : 0;
    TopPosition = (screen.height) ? (screen.height - h) / 2 : 0;
    settings = 'height=' + h + ', width=' + w + ', top=' + TopPosition + ', left=' + LeftPosition + ',scrollbars=' + scroll + ',resizable';
    window.open(mypage, '', settings);
}
function suChckBxChanged(el) {
    if (el.checked) {
        $('#ctl00_ContentPlaceHolder1_ImageButton1').show();
    }
    else {
        $('#ctl00_ContentPlaceHolder1_ImageButton1').hide();
    }
}

function showImportFromSystem() {
    $('#divImportFromSystem').show();
    $('#aImportFromSystem').hide();
    $('#aImportFromOutlook').show();
    $('#divImportFromOutlook').hide();
}
function showImportFromOutlook() {
    $('#divImportFromOutlook').show();
    $('#aImportFromOutlook').hide();
    $('#aImportFromSystem').show();
    $('#divImportFromSystem').hide();
}
function ImportFromOutlook() {
}
function CancelImportFromOutlook() {
    $('#aImportFromOutlook').show();
    $('#divImportFromOutlook').hide();
}
function importFromEmailAccount() {
}
function CancelImportFromEmailAccount() {
    $('#aImportFromSystem').show();
    $('#divImportFromSystem').hide();
}
function HideModal() {
    $('.modal').hide();
    $('#blocker').hide();
}
function SendInvitation() {
    $('#addFriendDialog').fadeOut();
    $('#blocker').hide();
}
function DeleteUserFromAlbum(albumid, guid) {
    if (confirm('Contact "' + $('#contact' + guid + ' .contactName').text() + '" will be removed from album "' + $('#albumTitle' + albumid).text() + '". Continue?')) {
        ShowIndicatorWithText('Deleting');
        $.post("/Files/handlers/cmanag.ashx",
        {
            action: "RemoveContactFromAlbum",
            g: guid,
            f: albumid
        },
        function(data) {
            if (data == "OK") {
                HideIndicator();
                $('#f' + albumid + guid).fadeOut();
                $('#f' + albumid + guid).remove();
                var i = parseInt($('#sharedWith' + albumid).text());

                i--;
                $('#sharedWith' + albumid).text(i);
            }
            else alert(data);
        });
    }
}
function DeleteVideoFromAlbum(videoguid, folderguid) {
    if (confirm('Video "' + $('#Title' + videoguid).text() + '" will be removed from album "' + $('#albumTitle' + folderguid).text() + '". Continue?')) {
        ShowIndicatorWithText('Deleting');
        $.post("/Files/handlers/cmanag.ashx",
        {
            action: "DeleteVideoFromAlbum",
            v: videoguid,
            f: folderguid
        },
        function(data) {
            if (data == "OK") {
                HideIndicator();
                $('#vidal' + videoguid + folderguid).fadeOut();
                $('#vidal' + videoguid + folderguid).remove();
                var i = parseInt($('#videoCount' + folderguid).text());
                i--;
                $('#videoCount' + folderguid).text(i);
                if ($('#albumsTable' + videoguid).height() < 120) {
                    $('#vidAlbums' + videoguid).height('119px');
                    $('#albumsTable' + videoguid).css({ 'marginTop': '0px' });
                    $('#scrolldown' + videoguid).hide();
                    $('#scrollup' + videoguid).hide();
                }
            }
            else alert(data);
        });
    }
}
function updateComments() {
    if ($('#CommentsWrapper:visible').length) {
        commentsPage = -1;
        LoadOlderComments();
    }
}
function DeleteVideo(guid) {

    var lastVidOnThisPage = $('.mediaThumb:last').attr('id');

    if (confirm('Video "' + $('#Title' + guid).text() + '" will be removed. Continue?')) {
        ShowIndicatorWithText('Deleting video');
        $('#video' + guid).fadeOut();
        $.post("/Files/handlers/cmanag.ashx",
        {
            action: "RemoveVideo",
            g: guid,
            last: lastVidOnThisPage
        },
        function(data) {
            if (data.status == "1") {
                $('#ctl00_ContentPlaceHolder1_Button1').click();

                //
            }
            else if (data.status == "2") {
                //ничего нового
                HideIndicator();
                updateComments();
                $('#video' + guid).remove();
            }
        }, 'json');
    }

}
function DeleteContact(guid) {
    if (confirm('Contact "' + $('#contact' + guid + ' .contactName').text() + '" will be removed from you contact list. Continue?')) {
        ShowIndicatorWithText('Deleting contact');
        $('#contact' + guid).fadeOut();
        $.post("/Files/handlers/cmanag.ashx",
        {
            action: "RemoveContact",
            g: guid
        },
        function(data) {
            if (data == "OK") {
                HideIndicator();

                $('#contact' + guid).remove();
            }
            else {
                $('#contact' + guid).show();
                alert(data);
            }
        });
    }
}
function DeleteAlbum(guid) {
    if (confirm('Album "' + $('#albumTitle' + guid).text() + '" will be removed, but videos and contacts, which were in this album will stay. Continue?')) {
        ShowIndicatorWithText('Deleting album');

        $('#albm' + guid).fadeOut();
        $.post("/Files/handlers/cmanag.ashx",
        {
            action: "DeleteAlbum",
            g: guid
        },
        function(data) {
            if (data == "OK") {
                HideIndicator();
                $('#albm' + guid).remove();
                $('[id^=f' + guid + ']').remove();
                $('[id$=' + guid + ']').remove();
            }
            else {
                alert(data);
            }
        });
    }
}

function AddAlbumToContact(cguid, aguid, albumname) {
    ShowIndicatorWithText('Adding album to contact');
    $.post("/Files/handlers/cmanag.ashx",
    {
        action: "AddAlbumToContact",
        a: aguid,
        c: cguid
    },
    function(data) {
        if (data == "OK") {
            HideIndicator();
            ag = aguid.replace("albm", "");
            cg = cguid.replace("contact", "");
            $('#albums' + cg).append("<span id='f" + ag + cg + "'>[" + albumname + " <input type='image' class='deleteUserFromAlbum' onclick=\"DeleteUserFromAlbum('" + ag + "','" + cg + "'); return false\" src='/Files/images/gdelete.png'/>]</span>");
            var i = parseInt($('#sharedWith' + ag).text());
            i++;
            $('#sharedWith' + ag).text(i);
        }
        else {
            alert(data);
        }
        HideIndicator();
    });
}
function AddAlbumToVideo(cguid, aguid, albumname) {
    ShowIndicatorWithText('Adding album to video');
    $.post("/Files/handlers/cmanag.ashx",
    {
        action: "AddAlbumToVideo",
        a: aguid,
        c: cguid
    },
    function(data) {
        if (data == "OK") {
            HideIndicator();
            ag = aguid.replace("albm", "");
            var i = parseInt($('#videoCount' + ag).text());
            i++;
            $('#videoCount' + ag).text(i);
            var vidGuid = cguid.replace('video', '');
            $('#vidAlbumsWrapper' + vidGuid).hide();
            $('#back' + vidGuid).hide();
            $('#viid' + vidGuid).show();
            $('#vidAlbums' + vidGuid).html('');
        }
        else {
            alert(data);
        }
        HideIndicator();
    });
}
function ShowCreateAlbumDialog() {
    $('#createAlbumDialog').show();
    $('#aCreateAlbum').hide();
    $('#ctl00_ContentPlaceHolder1_NewAlbumTitle').val('');
}
function CancelCreateAlbumDialog() {
    $('#createAlbumDialog').hide();
    $('#aCreateAlbum').show();
}
function showAlbumsOfVideo(vidGuid) {
    if ($('#vidAlbumsWrapper' + vidGuid + ':visible').length) {
        $('#vidAlbumsWrapper' + vidGuid).hide();
        $('#viid' + vidGuid).show();
        $('#vidAlbums' + vidGuid).html('');
        $('#back' + vidGuid).hide();
    }
    else {
        ShowIndicatorWithText('Loading users albums');
        $.post("/Files/handlers/cmanag.ashx",
        {
            action: "GetVideoAlbums",
            g: vidGuid
        },
        function(data) {
            $('#vidAlbums' + vidGuid).html(data);
            HideIndicator();
            $('#vidAlbumsWrapper' + vidGuid).fadeIn();
            $('#viid' + vidGuid).hide();
            $('#back' + vidGuid).show();
            if ($('#albumsTable' + vidGuid).height() > 120) {
                $('#vidAlbums' + vidGuid).height('105px');
                $('#albumsTable' + vidGuid).css({ 'marginTop': '0px' });
                $('#scrolldown' + vidGuid).show();
                $('#scrollup' + vidGuid).hide();
            }
        });
    }
}
function ShowAvatarFileUplod() {
    $('#ChangeAvatarFileUpload').toggle();
    $('#BroadcastingSettings, #ChangePasswordSettings, #ChangeEmail').hide();
}
function ShowBroadCastingSettings() {
    $('#BroadcastingSettings').toggle();
    $('#ChangeAvatarFileUpload, #ChangePasswordSettings, #ChangeEmail').hide();
}
function ShowChangePassword() {
    $('#ChangePasswordSettings').toggle();
    $('#ChangeAvatarFileUpload, #BroadcastingSettings, #ChangeEmail').hide();
    $('#ctl00_ContentPlaceHolder1_tbOldPass, #ctl00_ContentPlaceHolder1_tbNewPass').val('');
}
function ShowChangeEmail() {
    $('#ChangeEmail').toggle();
    $('#ChangeAvatarFileUpload, #BroadcastingSettings, #ChangePasswordSettings').hide();
}
function ScrollDown(guid) {
    $('#albumsTable' + guid).animate({ 'marginTop': $('#vidAlbums' + guid).height() - $('#albumsTable' + guid).height() + 'px' });
    $('#scrolldown' + guid).hide();
    $('#scrollup' + guid).show();
}
function ScrollUp(guid) {
    $('#albumsTable' + guid).animate({ 'marginTop': '0px' });
    $('#scrolldown' + guid).show();
    $('#scrollup' + guid).hide();
}
function closeServiceInfo() {
    $('#serviceInfo, #blocker').hide();
}
var counter = 0;

//function CheckNews() {
//    $.post(PrefixChannelUrl + location.host + "/Files/handlers/OnlineVideo.aspx",
//        {
//            u: userGuid
//        },
//        function(data) {
//            processDataForFolder(data);
//            setTimeout('CheckNews()', 500);
//        });
//}
function CheckNews() {
    if (!isInAjax) {
        isInAjax = true;
        $.post("/Files/handlers/cmanag.ashx",
        {
            action: "GetNews",
            u: userGuid
        },
        function(data) {
            processDataForFolder(data);
        });
    }
}
function getArchiveToPlay(guid) {
    $('#ld' + guid).removeClass('type1').addClass('type2');
    $('#ld' + guid + ' .titleInLenta').text('Untitled');
    $('#ld' + guid + ' .channel1').fadeOut();
    $('#ld' + guid + ' .livestreaming').hide();
    $('#ld' + guid + ' .timeago').show();
    $.post("/Files/handlers/cmanag.ashx",
        {
            action: "GetArchive",
            vgv: guid
        },
        function(data) {
            PlayAnotherOne(vgv, 2, data);
        },"json");
}
function getFlashObject(movieName) {
    if (window.document[movieName]) {
        return window.document[movieName];
    }
    if (navigator.appName.indexOf("Microsoft Internet") == -1) {
        if (document.embeds && document.embeds[movieName])
            return document.embeds[movieName];
    } else {
        return document.getElementById(movieName);
    }
}
function AddLife(gg, date, Title, l, p) {
    $('#VideoLenta').prepend("<div id='ld" + gg + "' class='videoThumbWrapper type1 generated' style='display:none'><span class='displaynone' id='vidRating" + gg + "'>0</span><div class='titleInLenta'>" + Title + "</div><div style='background:url(/Files/handlers/pic.ashx?channel=" + gg + "&size=116x79) left top no-repeat;' id='" + gg + "' class='img'><div class='channel1'></div></div><div class='date'>" + date + "</div><div class='name'>by " + l + "</div></div>");
    $('#' + gg).unbind("click").click(function() { PlayAnotherOne(gg, '1', p); });
    $('#VideoLenta').width($('.img').length * oneItemWidth)
                              .animate({ 'paddingLeft': oneItemWidth + 'px' }, 'slow', function() {
                                  $('#VideoLenta').css({ 'paddingLeft': '0' });
                                  $('#ld' + gg).slideDown().mouseover(function() {
                                      $(this).css('borderColor', '#F37D01');
                                  }).mouseout(function() {
                                      $(this).css('borderColor', '#E9E9E9');
                                  });
                              });
                          }
var currentP;                          
function processDataForFolder(data) {
    isInAjax = false;
    if (data != "NotOK") {
        var resultGDS = data.split('|');
        if (resultGDS != "") {
            for (var i = 0; i < resultGDS.length; i++) {
                var gg = resultGDS[i].split('#')[0];
                var date = resultGDS[i].split('#')[1];
                var Title = resultGDS[i].split('#')[2];
                var l = resultGDS[i].split('#')[3];
                var p = resultGDS[i].split('#')[4];
                var response = eval('(' + p + ')');;
                if (!$('#ld' + gg).length) {
                    AddLife(gg, date, Title, l, response);
                }
            }
        }

        $('.type1 .img').each(function() {
            counter++;
            if (counter > 3) {
                $('#' + this.id).css('backgroundImage', $('#' + this.id).css('backgroundImage').replace(')', '&r=' + Math.random() + ')'));
                counter = 0;
            }
            if (data.indexOf(this.id) == -1) {
//                $('#ld' + this.id).removeClass('type1').addClass('type2');
//                $('#ld' + this.id + ' .titleInLenta').text('Untitled');
//                $('#ld' + this.id + ' .channel1').fadeOut();
//                $('#ld' + this.id + ' .livestreaming').hide();
//                $('#ld' + this.id + ' .timeago').show();
//                $('#' + this.id).unbind("click").click(function() { PlayAnotherOne(this.id, '2', currentP); });
//                if (vgv == this.id) PlayAnotherOne(this.id, '2', currentP);
            }
        });
    }
    else {

    }
}
function CheckFolderNews(fid) {
    if (!isInAjax) {
        isInAjax = true;
        $.post("/Files/handlers/cmanag.ashx",
        {
            action: "GetFolderNews",
            u: fid
        },
        function(data) {
            processDataForFolder(data)
        });
    }
}
function RemoveIT(iid) {


}
var initialRating = 0;
function Rate(rating) {
    isInAjax = true;
    $.post("/Files/handlers/cmanag.ashx",
    {
        action: "Rate",
        v: vgv,
        r: rating
    },
    function(data) {
        isInAjax = false;
        if (data != "NotOK") {
            $('#vidRating' + vgv).text(data);
            initialRating = parseInt(data);
            $('.ratingTable tr td').css({ 'cursor': 'default' });
            $('.ratingTable tr td').unbind();
            $.cookie('raited', raited + vgv);
            SetInitialRating();
        }
        else {
            alert('Something bad happened');
        }
    });
}
function SetInitialRating() {
    for (i = 1; i <= initialRating; i++) {
        $('.ratingTable tr #' + i).css({ 'backgroundPosition': '0 0' });
    };
    for (i = initialRating + 1; i <= 5; i++) {
        $('.ratingTable tr #' + i).css({ 'backgroundPosition': '0 -13px' });
    }
}
function MakeRatingActive() {
    raited = $.cookie('raited') == null ? "" : $.cookie('raited');
    if (raited.indexOf(vgv) == -1) {
        $('.ratingTable tr td').css({ 'cursor': 'pointer' });
        $('.ratingTable tr td').unbind().click(function() {
            Rate(this.id);
        }).mouseover(function() {
            var curid = parseInt(this.id);
            for (i = 1; i <= curid; i++) {
                $('.ratingTable tr #' + i).css({ 'backgroundPosition': '0 0' });
            }
            for (i = curid + 1; i <= 5; i++) {
                $('.ratingTable tr #' + i).css({ 'backgroundPosition': '0 -13px' });
            }
        });
        $('.ratingTable').mouseout(function() {
            SetInitialRating();
        });
    }
}
$(document).ready(
    function() {

        $('.blueInput').mouseover(
            function() {
                $(this).addClass('blueInputH');
            }).mouseout(function() {
                $(this).removeClass('blueInputH');
                $(this).removeClass('blueInputP');
            }).mousedown(function() {
                $(this).addClass('blueInputP');
            }).mouseup(function() {
                $(this).removeClass('blueInputP');
            });
        $('.orangeInput').mouseover(
            function() {
                $(this).addClass('orangeInputH');
            }).mouseout(function() {
                $(this).removeClass('orangeInputH');
                $(this).removeClass('orangeInputP');
            }).mousedown(function() {
                $(this).addClass('orangeInputP');
            }).mouseup(function() {
                $(this).removeClass('orangeInputP');
            });
        $('.sideH').click(function() {
            var x = false;
            if ($('#' + this.id + 'Wrapper:visible').length)
                x = true; ;
            $('.rightSideContent').hide();
            $('.sideH').css({ 'backgroundPosition': '20px 5px' });
            if (!x) {
                $('#' + this.id + 'Wrapper').show();
                $(this).css({ 'backgroundPosition': '20px -39px' });
            }
        })
        //$('#Albums').click();
        $('.serviceLinks .link').click(function() {
            //$('#serviceInfo, #blocker').show();
            var sname = $(this).text().replace(/\s/g, '').toLowerCase();
            window.location = '/serviceInfo/' + sname + '.html';
            //$('#theServiceInfo').html('<iframe src="/serviceInfo/'+sname+'.html"></iframe>');
            return false;
        });

    })
    
    