﻿$(function(){
    InitImageTeam();
    InitImageMember();
    InitVote();
    
    $('#btnVote').click(function(){
        OnClickVote();
    });
    
});

function InitVote(){
    var upPer =((100 - $('#hiddenVotePercent').val())>2)?100 - $('#hiddenVotePercent').val():2;
    $("#divGraphVoteUp").css('height', 60).animate({ 
                                height: upPer+"%"
                                ,duration: 'fast'
                                }, 2000 );
    $("#divGraphVoteDown").css('height', '0%').animate({ 
                                height: $('#hiddenVotePercent').val()+"%"
                                ,duration: 'fast'
                                }, 2000,function(){$('#divNumPercent').html($('#hiddenVotePercent').val()+"%");} );    
}

function InitImageTeam(){
    $(window).load(function() {
        var images = $('.profileLeft .noborderImg');
        $.each(images, function() {
            $(this).removeAttr("width").removeAttr("height");
            //console.log($(this).attr("width") > $(this).attr("height"));
            if($(this).width() >= $(this).height()){
                $(this).width(180);
            }
            else{
                $(this).height(180);
            }
        });
        images.show();
    });
}

function InitImageMember(){
    $(window).load(function() {
        var images = $('.member img');
        $.each(images, function() {
            $(this).removeAttr("width").removeAttr("height");
            //console.log($(this).attr("width") > $(this).attr("height"));
            if($(this).width() >= $(this).height()){
                $(this).width(150);
            }
            else{
                $(this).height(150);
            }
            if($(this).height() > 150)
            {
                $(this).height(150);
            }
        });
        images.show();
    });
}

function onLoadPopup(arg){
    $('#divStoryBoard').modal();
     $.ajax({
        url: arg
        , complete: function() {
            }
        , error: function(xml, status) {
                alert("Connection Fail.");
            }
        , success: function(data, status) {
                $("#divStoryBoard").html(data);
        }
    });
    return false;
}

function OnClickVote(){
    $('#divLoadVote').modal({close:false, containerCss:{'width':400, height:200}});
    $('#divLoadVote').html("<table width='400' height='200'><tr><td align='center' valign='middle'><font size=2>รอซักครู่ระบบกำลังดำเนินการ </font><font size=5><b>..</b></font><img src='/images/ajax-loader.gif' align='bottom' /></td></tr></table>");
    $.ajax({
        url: '/remote/profile/vote.aspx?rad='+Math.floor(Math.random()*10000)
        , data: {team:$('#hiddenId').val()}
        , type: "get"
        , complete: function() {
            }
        , error: function(xml, status) {
                alert("Connection Fail.");
            }
        , success: function(data, status) {
                $('#btnVote').hide();
                $('#divLoadVote').html(data);
                $('#hiddenVotePercent').val($('#hiddenVotePercentChange').val())
                $('#btnClose').click(function(){
                    $.modal.close();
                    InitVote(); 
                });
                $('#btnBack').click(function(){
                    window.location = "/A2_profile/th/announcement2.aspx";
                });
        }
    });
}

