﻿/* load */
$(document).ready(function() {
    AddStarEvent();
});

/* change the font size of blog */
////function ChangeFont(val) {
////    var fontsize = document.getElementById("divFont").style.fontSize;

////    if (fontsize == "") fontsize = 12 + "px";
////    fontsize = fontsize.substring(0, fontsize.lastIndexOf("px"));

////    if (val == "true") {
////        document.getElementById("divFont").style.fontSize = (parseInt(fontsize) + 3) + "px";
////    }
////    else {
////        document.getElementById("divFont").style.fontSize = (parseInt(fontsize) - 3) + "px";
////    }
////}
/* change the expand/collapse */
function ChangeStatus() {
    $(".content[name='PostContent']").toggle();
}

/* change star width */
function ChangeStarWidth(e, obj) {
    var _offsetX = window.event ? window.event.offsetX : e.originalEvent.layerX;
    var count = Math.floor(_offsetX / 16) + 1;
    var swidth = count * 16 + "px";
    $(obj).find('div').width(swidth);
}

/* the original div width*/

/* clear star width */
function ClearStarWidth(obj) {
    var val = $(obj).find('input.starwidth').val();
    $(obj).find('div').width(val);
}
/* add event for the star */
function AddStarEvent() {
    var obj = $('.star');
    obj.mouseover(function(event) { ChangeStarWidth(event, this); });
    obj.mousemove(function(event) { ChangeStarWidth(event, this); });
    obj.mouseout(function() { ClearStarWidth(this); });
    obj.click(function() { VoteStar(this); });
}
/* hidden/show months */
function HiddenShowYear(obj, baseurl) {
    $('.archiveYear .months').hide();
    $('.archiveYear img').attr('src', baseurl + 'images/arr_down.gif');
    //
    $(obj).find('div.months').show();
    $(obj).find('img').attr('src', baseurl + 'images/arr_up.gif');
}
/* iframeExpand */
function ShowProjectFiles(piid, uid, baseurl) {
    var objid = 'Files_' + piid;
    var tid = 'expandtext_' + piid;
    //set hide
    $('.projectexpand[id != ' + objid + ']').hide();
    $('.expandtext[id != ' + tid + ']').find('a').html('Expand');
    $('.ProjectView').hide();
    //set current object
    var curObj = $('#' + objid);
    var curTxt = $('#' + tid);    
    var obj = curObj.find('iframe');
    if (curObj.is(':hidden')) {
        curTxt.find('a').html('Loading...');
        var url = baseurl + 'public/projectfiles.aspx?piid=' + piid + '&uid=' + uid;
        obj.attr('src', url);
        obj.load(function() {
            $(this).height($(this).contents().find('body').height() + 100);
            curTxt.find('a').html('Collapse');
        });
        curObj.show();
        curObj.siblings('.ProjectView').show();
    }
    else {
        $('#' + tid).find('a').html('Expand');
        obj.height(0);
        curObj.hide();
        window.location = '#pro' + piid;
    }
}
/*vote file*/
function VoteStar(obj) {
    var lblVotes = $(obj).siblings('div').find('.reviewcount');
    var votenumber = lblVotes.html();
    //lblVotes.html('<span class="loading">Loading...</span>');
    var divStarWIdth = $(obj).find('div');
    var objectID = $(obj).find('input.objectid').val();
    var objectType = $(obj).find('input.objecttype').val();
    $.post(BASEURL + "public/publicvote.aspx",
        { objectID: objectID, objectType: objectType, starVal: divStarWIdth.width() },
        function(data) {
            if (data.login.toLowerCase() == "false") {
                var tourl = BASEURL + "login.aspx?ReturnURL=" + document.location.href;
                window.location = tourl;
            } else {
                if (data.update.toLowerCase() == "false") {
                    lblVotes.html(votenumber);
                    $(obj).siblings('span.repeat_vote').show();
                    setTimeout(function() {
                        $(obj).siblings('span.repeat_vote').hide();
                    }, 2000);
                } else {
                    divStarWIdth.width(data.retScore + "px");
                    lblVotes.html(data.retReview);
                    $(obj).find('input.starwidth').val(data.retScore + "px");
                }
            }
        }, "json");
}
/*change images*/
function ChangeImage(obj) {
    $(obj).attr('src', BASEURL + 'images/nophoto_501.jpg');
}
/* change friend photo */
function ChangeFriendPhoto(obj) {
    $(obj).attr('src', BASEURL + 'images/nophoto.jpg');
}
