/* 
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

(function( $ ){
  

  $.fn.timeOffsetPlugin = function( ) {
  
    // there's no need to do $(this) because
    // "this" is already a jquery object
    var timeFormater = function(date, format){
             var str="";
             if(format == 'date'){
                    str =  date.getDate()+"."+(date.getMonth()+1)+"."+date.getFullYear();
                        }
            else if(format == 'time'){
                    var min = ( date.getMinutes()<10 ) ? "0"+date.getMinutes() : date.getMinutes();
                   str =  date.getHours()+":"+min
            } 
            else{
                   var min = ( date.getMinutes()<10 ) ? "0"+date.getMinutes() : date.getMinutes();
                   str =  date.getDate()+"."+(date.getMonth()+1)+"."+date.getFullYear()+" - "+date.getHours()+":"+min
            }
           return str;
    };


   // console.log(dif);
    // $(this) would be the same as $($('#element'));
    return this.each(function(tOff){
                var t = $(this).attr("datetimeval");
               // console.log(t)
                t=t.split(".");

                if(t.length>5){
                        var d = new Date();
                        d.setUTCFullYear(t[0], t[1]-1, t[2]);
                        d.setUTCHours(t[3],t[4],t[5]);
                       // console.log(d)
                        var h = d.getHours();

                       /* h += tOff;
                        //console.log(h)
                        d.setUTCHours(h);*/
                       // console.log("   ---  "+d)
                        var formating = $(this).attr("formateto");
                        var timestr = timeFormater(d,formating);
                        $(this).text(timestr)
                }
            })

  };
})( jQuery );

$(document).ready(function(){
    $(".datetime_offset_formater").timeOffsetPlugin();
})



