
var venyooEvents = [];
var venyooTitle = "art-things bei venyoo.de";
if(typeof(venyooConfigCustom) == 'undefined') {
var venyooConfigCustom = new Array();
}
var venyoo = {
dom: {
// load external css file
loadStyleSheet: function(url,id) {
var style = document.createElement('link');
style.type = 'text/css';
style.href = url;
style.rel = 'stylesheet'; 
this.addHeadElement(style,id);
},
// load external js file
loadJavascript: function(url,id){
var js = document.createElement('script');
js.type = 'text/javascript';
js.href = url;
this.addHeadElement(js,id);
},
// append element to <html><head>
addHeadElement: function(element,id){
if(id){
element.id = id;
this.removeElementById(element.id);
}
var head = document.getElementsByTagName('head')[0];
head.appendChild(element);
//document.getElementsByTagName('head').item(0).appendChild(stylesTag);
},
// remove element (if set)
removeElementById: function(id){
var old = document.getElementById(id);
if (old) {
old.parentNode.removeChild(old);
delete old;
}
},
// add style tag to <html><head>
addStyleTag: function(css,id){
style = document.createElement('style');
style.type = "text/css";
if(style.styleSheet){
style.styleSheet.cssText = css;
} else {
style.appendChild(document.createTextNode(css));
}
this.addHeadElement(style,id);
}
},
// defaults for config (can not be overridden by configCustom)
config: {
targetTestString: '<a href="http://venyoo.de',
urlHost: 'http://venyoo.de',
link: '/user/events/937/art-things',
width: '100%',
cssURL: 'http://venyoo.de/css/badge_calendar.css'
},
// defaults for custom config (may be overridden by venyooConfigCustom)
configCustomDefaults: {
title: venyooTitle,
displayVenue: true,
displayDescription: true,
targetId: 'venyooTargetDiv',
backgroundColor: null,
listTitle: null,
venyooItem: null,
eventName: null,
description: null,
date: null,
venueName: null,
footer: null,
footerLink: null
},
// creates venyooConfig (merges venyooConfig, venyooConfigCustom, venyooConfigCustomDefaults)
loadCustomConfig: function() {
for(i in this.configCustomDefaults) {
if(typeof(venyooConfigCustom[i]) == 'undefined') {
this.config[i] = this.configCustomDefaults[i];
} else {
this.config[i] = venyooConfigCustom[i];
}
}
},
// inits, creates and writes the widget 
createWidget: function(){
this.loadCustomConfig();
var targetDiv = document.getElementById(this.config.targetId);
if(targetDiv && this.checkBacklink(targetDiv)){
this.dom.loadStyleSheet(this.config.cssURL, 'vnyStyle');
//this.dom.loadStyleSheet(this.config.cssURL, 'vnyStyle');
//this.dom.addStyleTag('div.venyoo-footer { border-top:1px solid #ffeeee; padding:5px; }');
//this.dom.addStyleTag('div.venyoo-footer { border-top:1px solid #ffeeee; padding:5px; }','id1');
//this.dom.addStyleTag('div.venyoo-footer { border-top:1px solid #ffeeee; padding:5px; }','id2');
//this.dom.addStyleTag('div.venyoo-footer { border-top:1px solid #ffeeee; padding:5px; }');
targetDiv.innerHTML = this.createWidgetHTML();
}
},
// inits, creates and writes the widget 
checkBacklink: function(targetDiv){
// checks for targetTestString (backlink)
var stringSuccess = targetDiv.innerHTML.toLowerCase().indexOf(this.config.targetTestString); // toLowerCase: IE returns tags in upper case
if (stringSuccess != -1) {
return true;
}
},
// creates HTML for the widget
createWidgetHTML: function() {
var html = '';
html += '<div class="venyoo-widget" style="';
if (this.config.backgroundColor!=null) {
html += 'background-color:' + this.config.backgroundColor + ';';
}
html += '">';
html += '<div class="venyoo-head">';
html += '<a class="venyoo-logo" href="' + this.config.urlHost + '"><img src="' + this.config.urlHost + '/img/venyoo_16_16.png" width="16" height="16" alt="venyoo.de - Der Veranstaltungskalender"></a>';
html += '<div class="venyoo-title">';
html += '<a href="' + this.config.urlHost + this.config.link + '" style="' + this.config.listTitle + '">';
html += this.config.title;
html += '</a>';
html += '</div>';
html += '</div>';
for(i=0; i<venyooEvents.length; i++) {
html += '<div class="venyoo-item" style="' + this.config.venyooItem + '">';
html += '<div class="venyoo-date" style="' + this.config.date + '">';
html += venyooEvents[i].date;
html += ', ';
html += venyooEvents[i].time;
html += ' Uhr';
html += '</div>';
html += '<div class="venyoo-name">';
html += '<a href="' + venyooEvents[i].url + '" style="' + this.config.eventName + '">';
html += venyooEvents[i].name;
html += '</a>';
html += '</div>';
if(this.config.displayDescription) {
html += '<div class="venyoo-description" style="' + this.config.description + '">';
html += venyooEvents[i].description;
html += ' ';
html += '<a href="' + venyooEvents[i].url + '">...</a>';
html += '</div>';
}
if(this.config.displayVenue) {
html += '<div class="venyoo-info">';
html += '<a href="' + venyooEvents[i].venueUrl + '" style="' + this.config.venueName + '">';
html += venyooEvents[i].venue;
html += ', ';
html += venyooEvents[i].city;
html += '</a>';
html += '</div>';
}
html += '</div>';
}
if (i == 0) {
html += '<div class="venyoo-item">(keine aktuellen Veranstaltungen)</div>';
}
html += '<div class="venyoo-footer" style="' + this.config.footer + '">';
html += '<a href="' + this.config.urlHost + this.config.link  + '" style="' + this.config.footerLink + '">';
html += 'alle Veranstaltungen anzeigen';
html += '</a>';
html += '</div>';
html += '</div>';
return html;
}
}
venyoo.createWidget();

