// browser sniffer
var Browser = function(){
  this.uA = navigator.userAgent.toLowerCase();
  this.aN = navigator.appName.toLowerCase();
  this.iE = this.aN.indexOf('microsoft') != -1 ? 1 : 0;
  this.mac =  this.uA.indexOf('mac') != -1 ? 1 : 0;
  this.win = this.uA.indexOf('windows') != -1 ? 1 : 0;
  this.safari =  this.uA.indexOf('webkit') != -1 ? 1 : 0;
  this.opera =  this.uA.indexOf('opera') != -1 ? 1 : 0;
  this.operaMini =  this.uA.indexOf('mini') != -1 ? 1 : 0;
  this.mozilla = this.aN.indexOf('netscape') != -1 && !this.safari ? 1 : 0;
  this.winMozilla = this.mozilla && this.win ? 1 : 0;
  this.winIE = this.iE && this.win && !this.opera ? 1 : 0;
  this.winIE6Down = this.winIE && parseInt(this.uA.split('msie ')[1].substring(0,1)) <= 6 ? 1: 0;
  this.macIE = this.iE && this.mac ? 1 : 0;
};
var browser = new Browser();



// ###################################
// ############## LOADER #############
// ###################################

var Loader = Class({
  actions: [],
  done: false,
  index: 0,
  initialize: function() {
  },
  load: function(){
    var profiler;
    var time;

    if (this.done)
      return;

    this.done = true;
    this.profiler = new Profiler();
    this.next();
  },
  next: function(label, method){
    var loader = this;
    var action = this.actions[this.index++];
    if(!action){
      this.profiler.show();
      return;
    }
    setTimeout(function(){
      var time;
      action.method.bind(window)();
      time = loader.profiler.mark(action.label);
      /*
      if (typeof console != 'undefined')
        console.log(action.label + '(' + time + ')');
      */
      loader.next();
    }, 1);
  },
  schedule: function(label, method, priority){
    var index;
    priority = (priority != undefined) ? priority : Loader.priority.LOW;

    for (index = 0; index < this.actions.length; index++){
      if (this.actions[index].priority > priority)
        break;
    }

    this.actions.splice(index, 0, {
        "label": label,
        "method": method,
        "priority": priority});
  }
});

Loader.priority = {
  HIGH: 0,
  NORMAL: 1,
  LOW : 2 }

var loader = new Loader();

// ###################################
// ############# PROFILER ############
// ###################################

var Profiler = new Class({
  time: 0,
  marks: [],
  initialize: function(){
    this.reset();
  },
  reset: function(){
    this.time = new Date().getTime();
  },
  mark: function(label){
    var time = new Date().getTime() - this.time;
    this.marks.push({
        "label": label,
        "time": time});
    this.reset();
    return time;
  },
  show: function(){
    if(PROFILER) {
      var str = '';
      var total = 0;
      for (var i = 0; i < this.marks.length;i++){
        str += this.marks[i].label + ': ' + this.marks[i].time + '\n';
        total += this.marks[i].time;
      }
      str += '\nTotal: ' + total;
      var el = document.createElement('textarea');
      el.value = str;
      el.style.position = 'absolute';
      el.style.color = '#000';
      el.style.fontSize = '12px';
      el.style.top = '0px';
      el.style.zIndex = '2000';
      el.setAttribute('cols',40);
      el.setAttribute('rows',50);
      el.style.height = '500px';
      document.body.appendChild(el);
    }
  }
});

var PROFILER = 0;

// Use jquery in noConflict mode so we can use Mootools as well
jQuery.noConflict();

// addStyle
var addStyle = function(selector,properties){
  if (document.styleSheets) {
    var s = document.getElementsByTagName('STYLE');
    if (s.length == 0){
      var sheet = document.createElement('style');
      sheet.setAttribute('type','text/css');
      document.getElementsByTagName('HEAD')[0].appendChild(sheet);}
    if (browser.winIE){
      var lastSheet = document.styleSheets[document.styleSheets.length - 1];
      lastSheet.addRule(selector, properties);}
    else {var lastSheet = s[0];
      lastSheet.appendChild(document.createTextNode(selector + ' { ' + properties + ' }'));}
  }
};
addStyle('.drempel','display:none;');

//incl. .js
var jsPath = "/webshaper/store/0js/";
document.write('<scr'+'ipt type="text/javascript" src="' + jsPath + 'jquery.slideviewer.js"><\/scr'+'ipt>');





