  
//<!--

// JavaScript Document
$(document).ready(
  function(){
 
 
  function twoDigits(digit){
            if (digit < 10) {digit = "0" + digit};
            return digit;
          }
 
 //operacje na datach
      Date.prototype.copy = function () {
      return new Date(this.getTime());
    };
    Date.prototype.addDays = function(d) {
        this.setDate( this.getDate() + d );
      };
      
   Date.prototype.addMonths= function(m) {
     var d = this.getDate();
     this.setMonth(this.getMonth() + m);
   
     if (this.getDate() < d)
    this.setDate(0);
   };
 
      $.getJSON("/Allianz/fundsjs/tfi.action?maxvalue=N&all=BYFUND", function(json){
        x = 0
        tabela = json.fundusze[x];
            
        var myTmpArray = tabela.lastDate.split(", ");
        JSDotDate = myTmpArray[2]+"."+myTmpArray[1]+"."+myTmpArray[0];
           
        $('.notowania .wycena span').html('Wycena z dnia: ' + JSDotDate);
        
    toDate = myTmpArray[0]+"-"+myTmpArray[1]+"-"+myTmpArray[2];
    
    tmpDate = tabela.lastDate.split(', '); 
    fromDate = new Date(tmpDate[0], tmpDate[1]-1, tmpDate[2]);
    fromDate.addDays(-1);
    
    tmpD = fromDate.getDate();
          tmpD = twoDigits(tmpD);
         tmpM = fromDate.getMonth() + 1;
          tmpM = twoDigits(tmpM);
         tmpY = fromDate.getFullYear();
         fromDate = (tmpY + "-" + tmpM + "-" + tmpD);  
    
    $.getJSON("/Allianz/fundsjs/tfi.action?maxvalue=N&from="+fromDate+"&to="+toDate, function(daybefore){
    
        for (x = 0; x < daybefore.fundusze.length; x++) {
          tabela = daybefore.fundusze[x];
          $('table.wyniki_notowan').append('<tr id="jsTd" class="row"><td class="fundusz" valign="middle"><span></span></td><td class="wartosci"><span></span></td><td class="zmiana"><span></span></td></tr>');
          $("tr#jsTd").attr("id", "jsTd" + x);
          var targetRow = $("tr#jsTd" + x);
          $(targetRow).children('td.fundusz').children('span').html(tabela.name);
          if (tabela.valueCurrent == " PLN" || tabela.valueCurrent == " EUR" || tabela.valueCurrent == " USD") {
           $(targetRow).children('td.wartosci').children('span').html("-");
           } else {
           $(targetRow).children('td.wartosci').children('span').html(tabela.valueCurrent);
           }
          
            val1 = tabela.valueCurrent;
            val2 = tabela.valuePrev;
            if (val1 == "-" || val2 == "-") {
              $("tr#jsTd" + x + " td.zmiana").children('span').html("-");
              return false;  
            }
      
            tmp1 = val1.split(" ")
            tmp2 = tmp1[0]
            num1 = parseFloat(tmp2)
            
            tmp1 = val2.split(" ")
            tmp2 = tmp1[0]
            num2 = parseFloat(tmp2)
            
            dif = num1-num2
            div = dif/num2
            result = 100 * div
            if (result !== 0) {
                if (result > 0) {
                  result = result.toFixed(2)
                  $("tr#jsTd" + x + " td.zmiana").addClass('rosnie').children('span').html(result+"%");  
                } else {
                  result = result.toFixed(2)
                  $("tr#jsTd" + x + " td.zmiana").addClass('spada').children('span').html(result+"%");
                }
            } else {
                result = result.toFixed(2)
                  $("tr#jsTd" + x + " td.zmiana").children('span').html(result + "%");
            }
                      
        }
    
    });
    
        
        $('div.content div.wyniki_middle').css('position', 'relative');
        $('table.wyniki_notowan').css('position', 'absolute');
        var top = $('table.wyniki_notowan').css("top","0px")
        var animating = false
        
        $('div.wyniki_top img').click(
          function(){
          if (animating == false) {
            top = $('table.wyniki_notowan').css('top').split('px');
            if (top[0] < -1) {
                animating = true;
                $('table.wyniki_notowan').animate({
                 top: "+=30px"
                }, "normal", function(){animating = false});
              } else { }
          } else {}
          });
        
        $('div.wyniki_bottom img').click(
         function(){
         if (animating == false) {
         top = $('table.wyniki_notowan').css('top').split('px');
         height = "-" + $('table.wyniki_notowan').height();
         top = Number(top[0] - 122);
         height = Number(height);
         if(top > height){
          animating = true;
          $('table.wyniki_notowan').animate({
            top: "-=30px"
            }, "normal", function(){animating = false});
          } else { }
         } else {}
         });
        $('div.wyniki_bottom div.wiecej').css('bottom','0px');
      });
  }
);


 //-->
