﻿// JScript File
Type.registerNamespace('PhotoScript');

PhotoScript.Failed = function(response) {
    //var result = Sys.Serialization.JavaScriptSerializer.serialize(response);
    //alert(result);
}

Type.registerNamespace('PhotoScript.PhotoList');

PhotoScript.PhotoList.TotalItem = null;
PhotoScript.PhotoList.PhotoListById = function(iTotal) {
    PhotoScript.PhotoList.TotalItem = iTotal;    
    Facemap.PhotoService.PhotoListOrderById(iTotal, PhotoScript.PhotoList.LoadSuccess, PhotoScript.Failed);
}

PhotoScript.PhotoList.PhotoListByUserId = function(iUserId,iTotal) {
    PhotoScript.PhotoList.TotalItem = iTotal;
    Facemap.PhotoService.PhotoListByUserId(iUserId, iTotal, PhotoScript.PhotoList.LoadSuccess, PhotoScript.Failed);
}

PhotoScript.PhotoList.HotList = function(iUserId,iDateDiff,iTotal) {
    PhotoScript.PhotoList.TotalItem = iTotal;
    Facemap.PhotoService.ListMostViewed(iUserId,iDateDiff,iTotal, PhotoScript.PhotoList.LoadSuccess, PhotoScript.Failed);    
}

PhotoScript.PhotoList.OnlineList = function(iUserId,iTotal) {
    PhotoScript.PhotoList.TotalItem = iTotal;
    Facemap.PhotoService.ListOnline(iUserId,iTotal, PhotoScript.PhotoList.LoadSuccess, PhotoScript.Failed);    
}

PhotoScript.PhotoList.BirthdayList = function(iUserId,iTotal) {
    PhotoScript.PhotoList.TotalItem = iTotal;
    Facemap.PhotoService.ListBirthdays(iUserId,iTotal, PhotoScript.PhotoList.LoadSuccess, PhotoScript.Failed);    
}

PhotoScript.PhotoList.NewMemberList = function(iUserId,iDateDiff,iTotal) {    
    PhotoScript.PhotoList.TotalItem = iTotal;
    Facemap.PhotoService.ListNewMembers(iUserId,iDateDiff,iTotal, PhotoScript.PhotoList.LoadSuccess, PhotoScript.Failed);    
}


//PAGING
Type.registerNamespace('PhotoScript.Paging');

PhotoScript.Paging.PageItemsDefault = 54;
PhotoScript.Paging.PageItemsWithPaging = 52;

PhotoScript.Paging.CurrentPage = 1;
PhotoScript.Paging.TotalPage = 1;
PhotoScript.Paging.TotalItems = 0;

PhotoScript.Paging.LoadPagingSuccess = function(response) {        
    var iTotal = response;
    PhotoScript.Paging.TotalItems = iTotal;
    if (iTotal > PhotoScript.Paging.PageItemsDefault) {
        PhotoScript.Paging.TotalPage = Math.ceil(iTotal / PhotoScript.Paging.PageItemsWithPaging);
    } else {PhotoScript.Paging.TotalPage = 1;}    
}

PhotoScript.Paging.SetCurrentPage = function(index) {    
    var page = PhotoScript.Paging.CurrentPage + index;
    if (page > 0) {PhotoScript.Paging.CurrentPage = page;}
    else {PhotoScript.Paging.CurrentPage = 1;}
}

//PhotoScript.PhotoList.FavouriteListByUserId = function(iUserId,iTotal,iCountDefault,iCountWithPaging) {   
//    PhotoScript.PhotoList.TotalItem = iTotal;
//    PhotoScript.Paging.PageItemsDefault = iCountDefault;
//    PhotoScript.Paging.PageItemsWithPaging = iCountWithPaging;

//    Facemap.PhotoService.CountFavouriteListByUserId(iUserId, iTotal, PhotoScript.Paging.LoadPagingSuccess, PhotoScript.Failed);    
//    Facemap.PhotoService.FavouriteListByUserId(iUserId, iTotal, PhotoScript.Paging.CurrentPage, PhotoScript.Paging.TotalPage, PhotoScript.Paging.PageItemsDefault, PhotoScript.Paging.PageItemsWithPaging, PhotoScript.PhotoList.LoadSuccess, PhotoScript.Failed);    
//}

PhotoScript.PhotoList.FavouriteListByUserId = function(iUserId,iTotal,iCountDefault,iCountWithPaging,bDefaultBlock) {   
    PhotoScript.PhotoList.TotalItem = iTotal;
    PhotoScript.Paging.PageItemsDefault = iCountDefault;
    PhotoScript.Paging.PageItemsWithPaging = iCountWithPaging;

    Facemap.PhotoService.CountFavouriteListByUserId(iUserId, iTotal, PhotoScript.Paging.LoadPagingSuccess, PhotoScript.Failed);    
    
    if(bDefaultBlock == 'true') {        
        Facemap.PhotoService.FavouriteListByUserId(iUserId, iTotal, PhotoScript.Paging.CurrentPage, PhotoScript.Paging.TotalPage, PhotoScript.Paging.PageItemsDefault, PhotoScript.Paging.PageItemsWithPaging, PhotoScript.PhotoList.DefaultBlockLoadSuccess, PhotoScript.Failed);
    } else {
        Facemap.PhotoService.FavouriteListByUserId(iUserId, iTotal, PhotoScript.Paging.CurrentPage, PhotoScript.Paging.TotalPage, PhotoScript.Paging.PageItemsDefault, PhotoScript.Paging.PageItemsWithPaging, PhotoScript.PhotoList.BlockWithExtraLoadSuccess, PhotoScript.Failed);
    }
}

PhotoScript.PhotoList.MatchListByUserId = function(iUserId,iTotal,iCountDefault,iCountWithPaging) {
    PhotoScript.PhotoList.TotalItem = iTotal;
    PhotoScript.Paging.PageItemsDefault = iCountDefault;
    PhotoScript.Paging.PageItemsWithPaging = iCountWithPaging;
    
    Facemap.PhotoService.CountMatchListByUserId(iUserId, iTotal, PhotoScript.Paging.LoadPagingSuccess, PhotoScript.Failed);    
    Facemap.PhotoService.MatchListByUserId(iUserId, iTotal, PhotoScript.Paging.CurrentPage, PhotoScript.Paging.TotalPage, PhotoScript.Paging.PageItemsDefault, PhotoScript.Paging.PageItemsWithPaging, PhotoScript.PhotoList.LoadSuccess, PhotoScript.Failed);    
}

PhotoScript.PhotoList.ListByUserIdAndIPAddress = function(iUserId,sIPAddress,iTotal,iCountDefault,iCountWithPaging) {    
    PhotoScript.PhotoList.TotalItem = iTotal;
    PhotoScript.Paging.PageItemsDefault = iCountDefault;
    PhotoScript.Paging.PageItemsWithPaging = iCountWithPaging;
    
    Facemap.PhotoService.CountListByUserIdAndIPAddress(iUserId, sIPAddress, iTotal, PhotoScript.Paging.LoadPagingSuccess, PhotoScript.Failed);    
    Facemap.PhotoService.ListByUserIdAndIPAddress(iUserId, sIPAddress, iTotal, PhotoScript.Paging.CurrentPage, PhotoScript.Paging.TotalPage, PhotoScript.Paging.PageItemsDefault, PhotoScript.Paging.PageItemsWithPaging, PhotoScript.PhotoList.LoadSuccess, PhotoScript.Failed);    
}

//list of users in group
//PhotoScript.PhotoList.ListSearchResults = function(iSearchId,iUserId,iTotal,iCountDefault,iCountWithPaging) {   
//    PhotoScript.PhotoList.TotalItem = iTotal;
//    PhotoScript.Paging.PageItemsDefault = iCountDefault;
//    PhotoScript.Paging.PageItemsWithPaging = iCountWithPaging;

//    Facemap.PhotoService.CountListSearchResults(iSearchId, iUserId, iTotal, PhotoScript.Paging.LoadPagingSuccess, PhotoScript.Failed);    
//    Facemap.PhotoService.ListSearchResults(iSearchId, iUserId, iTotal, PhotoScript.Paging.CurrentPage, PhotoScript.Paging.TotalPage, PhotoScript.Paging.PageItemsDefault, PhotoScript.Paging.PageItemsWithPaging, PhotoScript.PhotoList.LoadSuccess, PhotoScript.Failed);    
//}

PhotoScript.PhotoList.ListSearchResults = function(iSearchId,iUserId,iTotal,iCountDefault,iCountWithPaging, bDefaultBlock) {   
    PhotoScript.PhotoList.TotalItem = iTotal;
    PhotoScript.Paging.PageItemsDefault = iCountDefault;
    PhotoScript.Paging.PageItemsWithPaging = iCountWithPaging;

    Facemap.PhotoService.CountListSearchResults(iSearchId, iUserId, iTotal, PhotoScript.Paging.LoadPagingSuccess, PhotoScript.Failed);
        
    if(bDefaultBlock == 'true') {
        Facemap.PhotoService.ListSearchResults(iSearchId, iUserId, iTotal, PhotoScript.Paging.CurrentPage, PhotoScript.Paging.TotalPage, PhotoScript.Paging.PageItemsDefault, PhotoScript.Paging.PageItemsWithPaging, PhotoScript.PhotoList.DefaultBlockLoadSuccess, PhotoScript.Failed);
    } else {        
        Facemap.PhotoService.ListSearchResults(iSearchId, iUserId, iTotal, PhotoScript.Paging.CurrentPage, PhotoScript.Paging.TotalPage, PhotoScript.Paging.PageItemsDefault, PhotoScript.Paging.PageItemsWithPaging, PhotoScript.PhotoList.BlockWithForumLoadSuccess, PhotoScript.Failed);
    }
}

//list of users by input string
PhotoScript.PhotoList.ListSearchInputResults = function(sInput,iUserId,iTotal,iCountDefault,iCountWithPaging) {   
    PhotoScript.PhotoList.TotalItem = iTotal;
    PhotoScript.Paging.PageItemsDefault = iCountDefault;
    PhotoScript.Paging.PageItemsWithPaging = iCountWithPaging;

    Facemap.PhotoService.CountListSearchInputResults(sInput,iUserId, iTotal, PhotoScript.Paging.LoadPagingSuccess, PhotoScript.Failed);    
    Facemap.PhotoService.ListSearchInputResults(sInput,iUserId, iTotal, PhotoScript.Paging.CurrentPage, PhotoScript.Paging.TotalPage, PhotoScript.Paging.PageItemsDefault, PhotoScript.Paging.PageItemsWithPaging, PhotoScript.PhotoList.LoadSuccess, PhotoScript.Failed);    
}



//PhotoScript.PhotoList.Login = function(iTotal) {
//    PhotoScript.PhotoList.TotalItem = iTotal;    
//    Facemap.PhotoService.Login(iTotal, PhotoScript.PhotoList.LoadSuccess, PhotoScript.Failed);
//}

if (typeof(Sys) !== 'undefined') Sys.Application.notifyScriptLoaded();




//mouseover handler
function ShowBothIconBoxes(favouriteClientId,datingClientId) {    
    $get(favouriteClientId).style.display = "block";
    $get(datingClientId).style.display = "block";
}

function HideBothIconBoxex(favouriteClientId,datingClientId) {
    $get(favouriteClientId).style.display = "none";
    $get(datingClientId).style.display = "none";
}

function ShowIconBox(clientId) {    
    $get(clientId).style.display = "block";
}

function HideIconBox(clientId) {
    $get(clientId).style.display = "none";
}

function ShowPhotoLayer(clientId) {
    $get(clientId).className = "fotolayerShowIcon";
}

function HidePhotoLayer(clientId) {
    $get(clientId).className = "fotolayer";
}

//function AddUserToFavourite(ownerId, userId, clientId) {
function AddUserToFavourite(ownerId, userId, clientId, divAnimation) {
    //ownerId : id of the current logged-in user who do the action
    //userId  : id of the user who is added
    //clientId: client id of the star icon (when user is added then disable the display of icon)
    //divAnimation: client id of the animation div
    
    Facemap.PhotoService.AddUserToFavourite(ownerId, userId);
    $get(clientId).style.display = "none";
        
    //show the animation (box moving to the my-faves menu button)
    var objAnime = $get(divAnimation);
    objAnime.style.display = "block";
    $(objAnime).effect("transfer", { to: "#dvHiddenBlock" }, 700);
    objAnime.style.display = "none";
    
}

function AddUserToFavouriteIE6(ownerId, userId, clientId) { //doesn't do the animation
    //ownerId : id of the current logged-in user who do the action
    //userId  : id of the user who is added
    //clientId: client id of the star icon (when user is added then disable the display of icon)    
    
    Facemap.PhotoService.AddUserToFavourite(ownerId, userId);
    $get(clientId).style.display = "none";
            
}

function RemoveUserFromFavourite(ownerId, userId, removeClientId, activeClientId, inactiveClientId) { //doesn't do the animation
    Facemap.PhotoService.RemoveUserFromFavourite(ownerId, userId);
    $get(activeClientId).style.display = "none";
    $get(inactiveClientId).style.display = "block";    
}
