/*
Usage:
  To have onClick events automatically added to any page element add a trackClick class to the element.  Then add track_xyz classes to that element as well.  xyz=1 will be sent to lyris. To assign a value use track_xyx_123.  xyz=123 will be sent to lyris..
   <input class="trackClick track_mybutton track_name_john" type="button" value="Do it"/>

Or add your own onclick...
   onclick="callLyris(['mybutton', 'name=john']);"
*/

$(document).ready(function()
        {
            $(".trackClick").click(function ()
            {
                var trackNames = Array();
                jQuery.each($(this).attr('class').split(' '), function(i)
                {
                    //remove track_, then if the remaining name contains an _ replace it with an =
                    //track_Test_me becomes Test=me
                    //track_Test becomes Test
                    if(this.indexOf("track_") != -1)
                        trackNames.push(this.replace("track_", "").replace("_", "="));
                });
                callLyris(trackNames);
                return false;
            });
        });

        function callLyris(trackNames)
        {
            jQuery.each(trackNames, function(i)
            {
                if(this.indexOf("=") != -1)//value contains an =, use it as is
                    trackNames[i] = this;
                else // value dosn't contain an =, add =1 to the end
                    trackNames[i] = this + "=1";
            });

            trackNames.push("Brand=water.com");

            var url = window.location + "?" + trackNames.join("&");
            CT_RecordView(url, 'GET');
        }
