dbug.cookie(true);

var debugLocation = "js/dev/";
var deployLocation = "js/deploy/";

// all browsers
//var debugScripts = ["Selectors.js", "clientcide-trunk-2.1.0.js", "OuterClick.js", "MooTooltips.js", "class.noobSlide.js", "formcheck/lang/de.js", "formcheck/formcheck.js", "moo.rd_v1.3.2.js", "Ratings.js", "domready.js"];
//var debugScripts = ["Selectors.js", "OuterClick.js", "MooTooltips.js", "class.noobSlide.js", "formcheck/lang/de.js", "formcheck/formcheck.js", "moo.rd_v1.3.2.js", "Ratings.js", "domready.js"];
var debugScripts = ["Selectors.js", "OuterClick.js", "MooTooltips.js", "class.noobSlide.js", "formcheck/lang/de.js", "formcheck/formcheck.js", "Ratings.js", "Crumbs.js", "domready.js"];
var deployScripts = ["min.js"];

// IE6 incompatible scripts
/*if(window.ie6!==undefined){
	debugScripts.splice(-2, 0, "dev/Ratings.js");
	deployScripts.splice(-2, 0, "Ratings.js");
}
*/

var baseLocation = getDomain(window.location.href);
var baseProtocol = window.location.protocol;

if (baseLocation == 'winfried-hoffmann.de' || baseLocation == 'www.winfried-hoffmann.de' || baseLocation == 'plamundo.schlucht.lan' || baseLocation == '/Volumes' || baseLocation == '/Users' || baseLocation == 'localhost') { // demo
	var locationID = "demo";
	if (baseLocation == "/Volumes") { // local
		locationID = "local";
	}
	dbug.log('Location = ' + locationID);
	var livesite = false;
	var ccAssetLocation = "../../static/common/assets/clientcide";
	var uri_cart_put = "../../ajax/cart/data_overflow.json";
	var uri_cart_delete = "../../ajax/cart/data.json";
	var uri_cart_refresh = "../../ajax/cart/data_empty.json";
	var uri_cart_get = "../../ajax/cart/data_empty.json";
	var uri_review_put = "../../ajax/comment/";
	baseLocation = "static/common/";
} else { // web
	dbug.log('Location: Web');
	var locationID = "web";
	var livesite = true;
	var ccAssetLocation = "/static/common/assets/clientcide";
	var uri_cart_put = "/ajax/cart/";
	var uri_cart_delete = uri_cart_get = uri_cart_refresh = uri_cart_put;
	var uri_review_put = "/ajax/comment/";
	baseLocation = "/static/common/";
}

function dbugScripts(baseurl,libs){
	var value = document.cookie.match('(?:^|;)\\s*jsdebug=([^;]*)');
	var debugCookie = value ? unescape(value[1]) : false;
	if (window.location.href.indexOf("basePath=this")>0){
		var path=baseurl.substring(baseurl.substring(7,baseurl.length).indexOf("/")+8,baseurl.length);
		var href=window.location.href;
		baseurl=href.substring(href.substring(7,href.length).indexOf("/")+8,href.length);
	}
	if (window.location.href.indexOf("jsdebug=true")>0 || window.location.href.indexOf("jsdebugCookie=true")>0 || debugCookie == 'true'){ 
		includeScripts(baseurl,libs);
		return true;
	}
	return false;
};

function includeScripts(baseurl,libs){
	if (libs) {
		for(var i=0;i<libs.length;i++){
			document.write("<scri"+"pt src=\""+baseurl+libs[i]+"\" type=\"text/javascript\"></scr"+"ipt>");
		}
	} else {
		document.write("<scri"+"pt src=\""+baseurl+"\" type=\"text/javascript\"></scr"+"ipt>");
	}
}

function getDomain(url) {
   return url.match(/:\/\/(.[^/]+)/)[1];
}


debugLocation = baseLocation + debugLocation;
deployLocation = baseLocation + deployLocation;
//dbug.log('debugLocation = ' + debugLocation);
//dbug.log('deployLocation = ' + deployLocation);

if (locationID == "local") {
	dbug.log('Loading local debug scripts...');
	dbug.log('debugLocation = ' + debugLocation);
	includeScripts(debugLocation, debugScripts);
} else if (!dbugScripts(debugLocation, debugScripts)) {
	// compressed library code goes here
	dbug.log('Loading deploy scripts...');
	dbug.log('deployLocation = ' + debugLocation);
	includeScripts(deployLocation, deployScripts);
}