moved javascript to jquery plugin