
/**
 * @author tdr
 */

if (typeof(window['wielertoerist_widget_width']) == "undefined")
    wielertoerist_widget_width = 300;



if (typeof(window['wielertoerist_widget_type']) == "undefined" || typeof(window['wielertoerist_widget_identifier']) == "undefined")
    alert('You have to provide a type and an identifier');//TODO change this
else {
    var url = 'http://www.wielertoerist.be/website/getwidget.php?callback=wtHtmlCallback';

    url += '&type=' + escape(wielertoerist_widget_type) +
        '&identifier=' + escape(wielertoerist_widget_identifier) +
        '&width=' + escape(wielertoerist_widget_width);

    // Optional Parameters
    if (typeof(window['wielertoerist_widget_timestamp']) != "undefined") {
        url += '&timestamp=' + escape(wielertoerist_widget_timestamp);
    }
    if (typeof(window['wielertoerist_widget_avatars']) != "undefined") {
        url += '&avatars=' + escape(wielertoerist_widget_avatars);
    }

    if (typeof(window['wielertoerist_widget_range']) != "undefined") {
        url += '&range=' + escape(wielertoerist_widget_range);
    }

    if (typeof(window['wielertoerist_widget_color_link']) != "undefined") {
        url += '&colorlink=' + escape(wielertoerist_widget_color_link);
    }

    if (typeof(window['wielertoerist_widget_color_text']) != "undefined") {
        url += '&colortext=' + escape(wielertoerist_widget_color_text);
    }

    if (typeof(window['wielertoerist_widget_color_background']) != "undefined") {
        url += '&colorbackground=' + escape(wielertoerist_widget_color_background);
    }
    if (typeof(window['wielertoerist_widget_top']) != "undefined") {
        url += '&top=' + escape(wielertoerist_widget_top);
    }
    if (typeof(window['wielertoerist_widget_top_color_background']) != "undefined") {
        url += '&topcolorbackground=' + escape(wielertoerist_widget_top_color_background);
    }
    
    if (typeof(window['wielertoerist_widget_fixedheight']) != "undefined") {
        url += '&fixedheight=' + escape(wielertoerist_widget_fixedheight);
    }
    if (typeof(window['wielertoerist_widget_height']) != "undefined") {
        url += '&height=' + escape(wielertoerist_widget_height);
    }
    if (typeof(window['wielertoerist_widget_autowidth']) != "undefined") {
        url += '&autowidth=' + escape(wielertoerist_widget_autowidth);
    }


    url += '&referer=' + escape(window.location.href) +
        '&utm_source=' + escape(window.location.href) +
        '&utm_medium=widget' +
        '&utm_campaign='+escape(wielertoerist_widget_type);
    
    var workoutboard="empty";
    function wtHtmlCallback(workouts){
    workoutboard = workouts;
    handleWorkout();
    }
    function handleWorkout() {
            document.write(workoutboard);
        }
    document.write('<link href=\"http://static.wielertoerist.be/website/template/wtwidget.css\" rel=\"stylesheet\" type=\"text/css\"/>');
    document.write('<style>.wt-widget a {  color: '+wielertoerist_widget_color_link+';}</style>');
    document.write('<script src=\"' + url + '\" type=\"text/javascript\"></script>');

}
