function TrackingInterface()
{
    this.trackingObject;
}
TrackingInterface.prototype.track = function(trackingObject)
{
    this.trackingObject = trackingObject;
    this.translateTrackingObject();
    
    switch (this.trackingObject.eventType)
    {
        case "click":     this.trackClick();    
                        break;
        case "view"    :    this.trackView();
                        break;
        case "open"    :    this.trackOpen();
                        break;
        case "init"    :    this.trackInit();
                        break;
        case "mediaMeta"    :    this.trackMediaMeta();
                        break;
        case "submit"    :    this.trackSubmit();
                        break;
        default:        this.trackingObject.consoleOutput("Unhandled: " + this.trackingObject.eventType);
                        break;
    }
}

// Edit below
/**
 * Sanitize page headline: Remove HTML, transform colons and spaces in lowercase string
 * 
 * @param {String} str
 */
function sanitizeHeadline(str)
{
    //str = $('<div></div>').html(str).text();  // Decode HTML enities
    str = unescape(str);
    str = str.replace(/<[^>]*>/g, '');        // Remove HTML tags
    str = str.replace(/[!%&\/\+\']/g, '');    // Filter special chars
    str = str.toLowerCase();
    str = str.replace(/:/g, '-');
    str = str.replace(/\s/g, '_');
    return str;
}
/**
 *  Repolace points from the argument string
 * 
 * @param {String} str
 * @return (String) str
 */
function ReplacePoints(str)
{
   str = str.replace(/\./g, "_");
   return str;
}
function getPercent(values) 
{
    var result = (values[3] / values[0]) * 100;
    var value = null;
    if(result <= 10) {
        value = "10";
    }
    else if(result <= 20) {
        value = "20";
    }
    else if(result <= 30) {
        value = "30";
    }
    else if(result <= 40) {
        value = "40";
    }
    else if(result <= 50) {
        value = "50";
    }
    else if(result <= 60) {
        value = "60";
    }
    else if(result <= 70) {
        value = "70";
    }
    else if(result <= 80) {
        value = "80";
    }
    else if(result <= 90) {
        value = "90";
    }
    else if(result <= 100) {
        value = "100";
    }
    else if(result > 100) {
        value = "100+";
    }
    return value;
}

var prefix = "ita.vie.web.flash.raxofix.";
var lastElementID = null;
var wt_param = null;
var wt_be = null;
TrackingInterface.prototype.translateTrackingObject = function()
{
    var translateProperties = new Array("currentLocation", "elementID", "params");
    for(var property in translateProperties)
    {
        if(typeof mappingObject.getTranslation(this.trackingObject[translateProperties[property]]) != "undefined")
        {
            if(translateProperties[property] == "params")
            {
                this.trackingObject[translateProperties[property]] = mappingObject.getTranslation(this.trackingObject[translateProperties[property]], true);
            }
            else
                this.trackingObject[translateProperties[property]] = mappingObject.getTranslation(this.trackingObject[translateProperties[property]], false);
        }
    }
}

TrackingInterface.prototype.trackClick = function()
{
    // remove "/downloads" substring if download is clicked
    if(this.trackingObject.params.match(/downloads/)) {
        this.trackingObject.params = this.trackingObject.params.substr(this.trackingObject.params.lastIndexOf('/') + 1);
    }
    if(this.trackingObject.currentLocation != "init") {
        if (this.trackingObject.elementID == "raxoFullsizePlayer.swf") {
            console.log("Click: no click after elementID == raxoFullsizePlayer.swf");
         }    
        else {
            //console.log("Click: " + prefix + this.trackingObject.currentLocation + "." + this.trackingObject.params);
            wt_be = prefix + sanitizeHeadline(this.trackingObject.currentLocation);
            wt_param = prefix + this.trackingObject.currentLocation + "." + ReplacePoints(this.trackingObject.params); 
            wt_sendinfo(sanitizeHeadline(wt_param),'click');
        }
    }
    else if (this.trackingObject.elementID == "startup") {
        lastElementID = "startup";
    }
    //this.trackingObject.consoleOutput("Tracking");
}
TrackingInterface.prototype.trackView = function()
{    
    if(lastElementID != "startup") {    
        //console.log("PageView: " + prefix + this.trackingObject.currentLocation);
        wt_param = prefix + this.trackingObject.currentLocation;
        wt_sendinfo(sanitizeHeadline(wt_param));
    }
    else {
        lastElementID = null;
    }
    //this.trackingObject.consoleOutput("Tracking");
}
TrackingInterface.prototype.trackInit = function()
{    
        //console.log("PageView: " + prefix + this.trackingObject.elementID);
        wt_param = prefix + this.trackingObject.currentLocation;
        wt_sendinfo(sanitizeHeadline(wt_param));
        //this.trackingObject.consoleOutput("Tracking");
}
// hotspot funktion
TrackingInterface.prototype.trackOpen = function()
{
        //console.log("Click: " + prefix + this.trackingObject.currentLocation + ".hotspot." + this.trackingObject.params);
        wt_be = prefix + sanitizeHeadline(this.trackingObject.currentLocation);
        wt_param = prefix + this.trackingObject.currentLocation + ".hotspot." + this.trackingObject.params; 
        wt_sendinfo(sanitizeHeadline(wt_param),'click');
        //this.trackingObject.consoleOutput("Tracking");    
}
//parameter player = _totaltime, _currentTime(Absprungsekunde), _seekBarUsed (true/false), _dwellTime(Verweildauer (sek.))
TrackingInterface.prototype.trackMediaMeta = function()
{
        //console.log("Click: " + prefix + this.trackingObject.currentLocation + ".media." + this.trackingObject.params);
        wt_be = prefix + sanitizeHeadline(this.trackingObject.currentLocation);
        var values = this.trackingObject.params.split(",");
        var filenameHelp = values[5].split("/");
        var filename = ReplacePoints(filenameHelp[1]);
        var percent = getPercent(values);
        if(values[2] == "false") {
            
        if(values[0] == values[1] ) {
                //console.log("Click: " + prefix + "video." + filename + ".not_seeked.complete." + percent);
                wt_param = prefix + "video." + filename + ".not_seeked.complete." + percent;
            }    
            else {
                //console.log("Click: " + prefix + "video." + filename + ".not_seeked." + percent);
                wt_param = prefix + "video." + filename + ".not_seeked." + percent;
            }        
        }
        else {
            if(values[0] == values[1] ) {
                //console.log("Click: " + prefix + "video." + filename + ".seeked.complete." + percent);
                wt_param = prefix + "video." + filename + ".seeked.complete." + percent;
            }    
            else {    
                //console.log("Click: " + prefix + "video." + filename + ".seeked." + percent);
                wt_param = prefix + "video." + filename + ".seeked." + percent;
            }
            
        }
        
        wt_sendinfo(sanitizeHeadline(wt_param),'click');
        //this.trackingObject.consoleOutput("Tracking");
}
// todo: gesendet und fehlerhaft auf englisch ändern
TrackingInterface.prototype.trackSubmit = function()
{
        //console.log("Click: " + prefix + this.trackingObject.currentLocation + ".form." + this.trackingObject.params);
        wt_be = prefix + sanitizeHeadline(this.trackingObject.currentLocation);
        wt_param = prefix + this.trackingObject.currentLocation + ".form." + this.trackingObject.params; 
        wt_sendinfo(sanitizeHeadline(wt_param),'click');
        //this.trackingObject.consoleOutput("Tracking");
}
