
if (typeof (WAiLoad) == "undefined") {
    var WAiLoad = false;
}

jQuery('.jso_overlay').live('click', function() {
	$(this).overlay({
	    'click':false,
	    'width': '600',
	    'height': '500',
	    'transparency': '40'
	});
	return false;
});

var showWarningIE6 = function() {
    if (jQuery.browser.msie && (parseInt(jQuery.browser.version) < 7) && window.showIE6overlay) {
        //jQuery('.jsc_ie6warning').overlay({ height: 80 });
        var sMsg = 'Leider verwenden Sie den Internet Explorer 6. Wir optimieren momentan das System für Ihren Browser.<br /> Bitte verwenden Sie, wenn möglich, in der Zwischenzeit einen alternativen Browser.<br />Unterstütze Browser: <a class="ie6warning" href="http://www.mozilla-europe.org/de/firefox/">Firefox 3</a> -<a class="ie6warning" href="http://www.microsoft.com/downloads/details.aspx?DisplayLang=de&FamilyID=9ae91ebe-3385-447c-8a30-081805b2f90b">Internet Explorer 7</a> -<a class="ie6warning" href="http://www.microsoft.com/germany/windows/internet-explorer/default.aspx">Internet Explorer 8</a> -<a class="ie6warning" href="http://www.google.com/chrome/intl/de/landing_win.html?hl=de">Google Chrome</a> -<a class="ie6warning" href="http://www.apple.com/de/safari/">Apple Safari</a> -<a class="ie6warning" href="http://www.opera.com/">Opera</a>';
        
        sMsg.showDiag('err');
    }
}

var sClient     = 'bme';

/* stop initializing for backend */

window.oCfg = {
    'WAiPreview': {
        'NewsUrl': 'http://data.dci-se.de/clients/'+sClient+'/ma/news.php'
    },
    'WAiTicker': {
        'NewsUrl': 'http://data.dci-se.de/clients/'+sClient+'/ma/news.php'
    },
    'AjaxContent': {
		'NewsUrl': '/index.php?id=533',
		'NewsNewUrl': '/index.php?id=586&type=55',
		'NewsArchiveUrl': '/index.php?id=534',
		'VergleichWidget': '/index.php?id=537',
		'pathToMatrix': '/index.php?id=270&category=3',
		'partner': '/index.php?id=587',
		'showcomp2comp': '/index.php?id=588&type=55',
		'aktionen': '/index.php?id=613&type=55',
		'news': '/index.php?id=614&type=55',
		'events': '/index.php?id=615&type=55',
		'produkte': '/index.php?id=616&type=55',
		'niederlassungen': '/index.php?id=617&type=55',
		'schulungen': '/index.php?id=618&type=55',
		'stellenangebote': '/index.php?id=619&type=55',
		'personen': '/index.php?id=620&type=55',
		'prospekte': '/index.php?id=621&type=55',
		'ajaxnews': '/index.php?id=578&type=55',
		'ajaxtermine': '/index.php?id=579&type=55',
		'ajaxjobs': '/index.php?id=580&type=55'
	},
	'Partnerships': {
		'new': '/index.php?id=535',
		'company' : '/index.php?id=287&company='
	},
	'Login': 'index.php?id=31'
}


var sURL        = 'http://data.dci-se.de';
var sVersion    = '1.1';
var sModule     = 'ma';
var sModVersion = '';
var sLang       = '';
var sInit       = '#se_content_inner'; //'#container > div.jsc_tabBox > div.jsc_Box-Inner > div.jsc_tabBox-Inner';


var oLib = {
    'js': [
        'jquery.json',
/*        
        'jquery.ui',
				'jquery.ui.slider',
	    	'jquery.ui.autocomplete',
*/        
				'jquery-ui-1.8.9.custom.min',
	    	'jquery.url',
	    	'jquery.overlay',
        'jquery.color',
        'jquery.metadata',
        'jquery.template',
        'jquery.thickbox',
        'swfobject',
        '../ticker/index'
    ],
    'css': [
        'jquery.ui',    
        'jquery.thickbox',
        'jquery.overlay'
    ]
}

// If js/tpl/css missing -> core.js/.css/.html
// If empty array -> no file loaded
// /js[/X.Y], /css, /...
var oCore = {
    js: [ 'index', 'elements', 'switcher', 'forms', 'tools' ],
    css: []
}

// Same as for core -> index.js/.css/.html
// /js/MOD[/X.Y.Z]
var oModule = {
    //js:      [ ]
    css: []
}

// Same - also index
// /client/CLI/MOD[/X.Y.Z]
var oClient = {
    js:  [ ],
    tpl: [ 'frontend', 'categories' ]
}



/***********************************************************************************************************************************************/


if (sModVersion === -1) sModVersion = '';
else                    sModVersion = sVersion+(sModVersion ? '.'+sModVersion : '');


jQuery(function() {
    var jInit = jQuery(sInit);
    var jImg  = jQuery('#se_content_loading');
    
    if (!jImg.length) {
        jImg = jQuery('<img src="http://data.dci-se.de/img/loading_small.gif" style="position: absolute; top: 30px; left: 50%; margin-left: -8px;" alt="loading ..." />');
        jImg.insertAfter(jInit);
    }
    
    jsoLoader_xLL(oLib, sURL, '', 'lib', '', '', '', function() {
        jsoLoader_xLL(oCore, sURL, '', '', '', sVersion, 'core', function() {
            jsoLoader_xLL(oModule, sURL, '', 'ma', 'ma', sModVersion, 'index', function() {
                jsoLoader_xLL(oClient, sURL, 'clients/'+sClient+'/ma', '', sClient+'.ma', '', 'index', function() {
                    // Necessary, e.g. FF doesn't really include the loaded CSS without the timeout
                    // --> if a js is also loaded, it works without timeout ...?!
                    setTimeout(initThisElements, 25);
                });
            })
        })
    });
    
    var initThisElements = function() {
        if (sLang) window.oL = window.oLang[sLang];
        
        var checkDoc = function() {
            if ($(document).height() !== 0) {
                window.aes.initElements('body', '', 2);
                
                //jImg.fadeOut('fast', function() { jImg.remove(); });
                jImg.remove();
                jInit.css({ 'height': 'auto', 'overflow': 'visible', 'visibility': 'visible' });//.fadeIn('fast');
            }
            else setTimeout(checkDoc, 100);
        };
        
        checkDoc();
    };
});








window.jso_form_data = new Object();
window.jso           = new Object();

window.jso['/smallLogo'] = function() {
    var that = this;
    this.smallLogo = function() {
        var sSrc = that.jE.text();
        that.jE.empty();
        that.jE.css('background-image', 'url('+jQuery.template.helpers.imageVersion(sSrc, 'mini')+')');   
    }
}

var addTemplate = function(sData) {
    if (!jQuery('#jst').length) jQuery('<div />').attr('id', 'jst').css('display', 'none').appendTo('body');
    
    jQuery('#jst').get(0).innerHTML += sData;
    
    // Check if a template already exists, if yes -> delete!
    var aTpls = {};
    jQuery('#jst').children().each(function() {
        if (aTpls[this.id]) jQuery(aTpls[this.id]).remove();
        
        aTpls[this.id] = this;
    });
}


/*** xLazyLoader helper! ***/
var jsoLoader_xLL = function(oData, sURL, sPre, sPost, sTplPre, sVersion, sDefault, cbSuccess) {
    var sPathVersion = (sVersion && sVersion.length) ? sVersion+'/' : '';
    var sUrlVersion  = (sVersion && sVersion.length) ? '&v='+sVersion : '';
    
    if (sPre)    sPre  += '/';
    if (sPost)   sPost += '/';
    if (sTplPre) sTplPre += '.';
    
    if (sURL.substr(sURL.length - 1) != '/') sURL += '/';
    
    //
    // JS
    // 
    if (jQuery.isArray(oData.js)) {
        for (var iI = 0; iI < oData.js.length; iI++) {
			if ((oData.js[iI] == '../ticker/index') && (WAiLoad == true )){
				oData.js[iI] = 'http://codes.wai.de/index.js';
			}
			else{
				oData.js[iI] = sURL+sPre+'js/'+sPost+sPathVersion+oData.js[iI]+'.js';
			}
        }
    }
    else if (oData.js === false) oData.js = [];
    else if (sDefault) oData.js = [ sURL+sPre+'js/'+sPost+sPathVersion+sDefault+'.js' ];
    else oData.js = [];
    
    //
    // CSS
    // 
    if (jQuery.isArray(oData.css)) {
        for (var iI = 0; iI < oData.css.length; iI++) {
            oData.css[iI] = sURL+sPre+'css/'+sPost+sPathVersion+oData.css[iI]+'.css';
        }
    }
    else if (oData.css === false) oData.css = [];
    else if (sDefault) oData.css = [ sURL+sPre+'css/'+sPost+sPathVersion+sDefault+'.css' ];
    else oData.css = [];
    
    //
    // Templates
    //
    if (jQuery.isArray(oData.tpl)) {
        for (var iI = 0; iI < oData.tpl.length; iI++) {
            oData.js.push(sURL+'services/tpl.php?tpl='+sTplPre+oData.tpl[iI]+sUrlVersion);
        }
        
        delete oData.tpl;
    }
    else if (sDefault) oData.js.push(sURL+'services/tpl.php?tpl='+sTplPre+sDefault+sUrlVersion);
    
    //
    // LOAD!
    //
    if (oData.js.length || oData.css.length) {
        oData.success = cbSuccess;
        jQuery.xLazyLoader(oData);
    }
    // noting to load, call cb directly!
    else {
        cbSuccess();
    }
}
