        /*
            Global Variable
        */

        // Gemius variables
		var m_gemiusIndentifier = 'zZ.gIqu723LlbLawTXPJZ8PJTBN_dB.U62fFpJDLir7.U7';
        var m_prefix = 'shu';
        var m_playerId = 'RTLMostSL_1.0';

        function onSilverlightError(sender, args) {
            var appSource = "";
            if (sender != null && sender != 0) {
                appSource = sender.getHost().Source;
            }

            var errorType = args.ErrorType;
            var iErrorCode = args.ErrorCode;

            if (errorType == "ImageError" || errorType == "MediaError") {
                return;
            }

            var errMsg = "Unhandled Error in Silverlight Application " + appSource + "\n";

            errMsg += "Code: " + iErrorCode + "    \n";
            errMsg += "Category: " + errorType + "       \n";
            errMsg += "Message: " + args.ErrorMessage + "     \n";

            if (errorType == "ParserError") {
                errMsg += "File: " + args.xamlFile + "     \n";
                errMsg += "Line: " + args.lineNumber + "     \n";
                errMsg += "Position: " + args.charPosition + "     \n";
            }
            else if (errorType == "RuntimeError") {
                if (args.lineNumber != 0) {
                    errMsg += "Line: " + args.lineNumber + "     \n";
                    errMsg += "Position: " + args.charPosition + "     \n";
                }
                errMsg += "MethodName: " + args.methodName + "     \n";
            }

            throw new Error(errMsg);
        }
        function silverlightWide() {
            silverlightResize(960, 620);
        }
        function silverlightNormal() {
            silverlightResize(600, 450);
        }
        //Silverlight plug-in object
        var plugin;
        /*
            Purpose: Silverlight Load Event Handler
        */
        function silverlightLoaded(sender, args) {
            plugin = sender.getHost();
        }
        /*
            Purpose: Silverlight Navigate dispatcher
        */
        function silverlightOpenNewWindow(url) {
            window.open(url);
        }
        function silverlightNavigate(url) {
            self.location.href = url;
        }
        /*
            Purpose: Resize silverlight player to specific size
        */
        function silverlightResize(w, h) {
            var d = document.getElementById('silverlightControlHost');
            if (d != null) {
                d.style.width = w + 'px';
                d.style.height = h + 'px';
            }
            plugin.Content.slControl.Resize(w, h);
        }

        /*
            Purpose: log the video play events
            Parameters:
                ts: Time Step of the event in ISO Date Format
                t: type of the video. Possible values: video, advertisement
                m: external media identifier
                p: current position in percent. for example: 50 - means 50%
                tu: tracking Url
        */
        function silverlightAudit(ts, t, m, p, tu) {
            switch (t.toLowerCase()) {
                case 'video':
                    //TO-DO
                    break;
                case 'advertisement':
                    var ur = tu.split(';');
                    switch (ur[0]) {
                        case 'AD':
                            if (ur.length > 3) {
                                if (p == 0) {
                                    silverlightTrackingImage(ur[1], p);
                                } else if ((p >= 48) && (p <= 52)) {
                                    silverlightTrackingImage(ur[2], p);
                                } else if (p == 100) {
                                    silverlightTrackingImage(ur[3], p);
                                }
                            } else if (ur.length == 2) {
                                if (p == 0) {
                                    silverlightTrackingImage(ur[1], p);
                                } else if (p == 100) {
                                    silverlightTrackingImage(ur[2], p);
                                }
                            } else if (ur.length == 1) {
                                if (p == 0) {
                                    silverlightTrackingImage(ur[1]);
                                }
                            }
                            break;
                        case 'DC':
                            if (ur.length > 3) {
                                if (p == 0) {
                                    silverlightDCTracking(ur[1]);
                                } else if ((p >= 48) && (p <= 52)) {
                                    silverlightDCTracking(ur[2]);
                                } else if (p == 100) {
                                    silverlightDCTracking(ur[3]);
                                }
                            } else if (ur.length == 2) {
                                if (p == 0) {
                                    silverlightDCTracking(ur[1]);
                                } else if (p == 100) {
                                    silverlightDCTracking(ur[2]);
                                }
                            } else if (ur.length == 1) {
                                if (p == 0) {
                                    silverlightDCTracking(ur[1]);
                                }
                            }
                            break;
                    }
                    break;
            }
            //window.status = 'ts:' + ts + '|t:' + t + '|m:' + m + '|p:' + p;
        }
        function silverlightDCTracking(pack_code_lcpm) {
            var banner_zone_lcpm = 'rtlklub.hu/';
            var width = 1;
            var height = 1;
            pack_code_lcpm = 'pack=' + pack_code_lcpm;
            var client_time = new Date().getTime();
            var placeHolder = document.createElement('DIV');
            //placeHolder.setAttribute('style', 'display:none');
            var src = document.createElement('SCRIPT');
            src.setAttribute('src', 'http://ad.de.doubleclick.net/adj/' + banner_zone_lcpm + ';' + pack_code_lcpm + ';sz=' + width + 'x' + height + ';ord=' + client_time + '?');
            src.setAttribute('type', 'javascript');
            placeHolder.appendChild(src);
            document.body.appendChild(placeHolder);
        }
        function silverlightTrackingImage(url,p) {
            var placeHolder = document.createElement('DIV');
            //placeHolder.setAttribute('style', 'display:none');
            placeHolder.style.display = 'none';
            var d = document.createElement('IMG');
            if (url.indexOf('?') != -1) {
                url += '&rnd=' + parseInt(Math.random() * 100000);
            } else {
                url += '?rnd=' + parseInt(Math.random() * 100000);
            }
            d.setAttribute('src', url);
            d.setAttribute('title', p);
            placeHolder.appendChild(d);
            document.body.appendChild(placeHolder);

        }
        /*
            Parameters:
                id: a unique material identifier(maximum 64 alpha-numeric characters)
                n: contains the title of the material
                l: total time of the material in seconds
                g: group
                sg: subgroup
                ct:categoryname
                pd: publishdate
        */
        function silverlightTrackingInit(id, n, l, g, sg, ct, pd) {
            gSmConfig.setEncoding('utf-8');
            var customPackage = new Array();
            customPackage.push({ name: 'NAME', value: n });
            customPackage.push({ name: 'TOTAL', value: 'VIDEO' });
            customPackage.push({ name: 'GROUP', value: g });
            customPackage.push({ name: 'SUBGROUP', value: sg });
            customPackage.push({ name: 'CATEGORYNAME', value: ct });
            customPackage.push({ name: 'DATE', value: pd });
	     gSmDebug.trace(["final", "INIT", [id, n, l, g, sg, ct, pd]]);
            gemiusStream.newStream(m_playerId, id, l, customPackage, null, m_gemiusIndentifier, 'http://' + m_prefix + '.hit.gemius.pl');
            window.status = 'init';
        }
        /*
            Parameters:
                id: a unique material identifier(maximum 64 alpha-numeric characters)
                p: current time of the material (spot at which the material is set) in seconds
                t: type of event. Permitted events:
                    · playing  the material has been started to play (automatically or by pressing play)
                    · paused  the material has been temporarily stopped
                    · stopped  the material has been stopped
                    · buffering  the material has been started to buffer (equals pause in behaviour)
                    · seekingStarted  beginning of rewinding or forwarding the material
                    · complete  the material has been played until the end.
        */
        function silverlightTrackingEvent(id,p,t) {
          if (t!='buffering') {
            gemiusStream.event(m_playerId, id, p, t);
            window.status = 'event';
          }
        }
        /*
            Parameters:
                id: a unique material identifier(maximum 64 alpha-numeric characters)
                p: current time of the material (spot at which the material is set) in seconds
        */
        function silverlightTrackingClose(id, p) {
            gemiusStream.closeStream(m_playerId, id, p);
            window.status = 'close';
        }
        /*
            Purpose: retrieve a true value if the silverlight installed on the computer

        */
        function silverlightIsAvailable() {
            return Silverlight.isInstalled('3.0');
        }

        function flashTrackingEvent(filename,id,p,t) {
		if (t!='buffering') {
            gemiusStream.event(m_playerId, id, p, t);
            window.status = 'event';
          }
        }

        function flashTrackingClose(filename,id, p) {
            gemiusStream.closeStream(m_playerId, id, p);
            window.status = 'close';
						gSmDebug.trace(["final", "flashTrackingClose", [id,p]]);
        }

