
function D2S(){}
D2S.prototype.dom = {
	setOpacity: function(obj, value){
		if(obj == undefined){
			return;
		}
		if(obj == null){
			return;
		}
		obj = obj.style;
		
		obj.opacity = value/10;
		obj.filter = 'alpha(opacity=' + value*10 + ')';
		obj = null;
	}
};

D2S.prototype.client = {
	isIE: function(){
		if(navigator.appVersion.indexOf("MSIE") != -1){
			return true
		}else{
			return false;
		}
	},
	
	isOpera: function(){
		if(navigator.userAgent.indexOf("Opera") != -1){
			return true;
		}else{
			return false;
		}
	},
	
	isWin: function(){
		if(navigator.appVersion.toLowerCase().indexOf("win") != -1){
			return true;
		}else{
			return false;
		}
	}

};


D2S.prototype.images = {
	change: function(){
		for (var i=0; i<arguments.length; i+=2) {
			document[arguments[i]].src = arguments[i+1];
		}
	}
};

D2S.prototype.flash = {
	isInstalled: function(){
		if(this.getVersion() == -1){
			return false;
		}else{
			return true;
		}
	},

	getVersion: function(){
		var isIE  = (navigator.appVersion.indexOf("MSIE") != -1) ? true : false;
		var isWin = (navigator.appVersion.toLowerCase().indexOf("win") != -1) ? true : false;
		var isOpera = (navigator.userAgent.indexOf("Opera") != -1) ? true : false;

		var flashVer = -1;
		
		if(navigator.plugins != null && navigator.plugins.length > 0){
			if(navigator.plugins["Shockwave Flash 2.0"] || navigator.plugins["Shockwave Flash"]){
				var swVer2 = navigator.plugins["Shockwave Flash 2.0"] ? " 2.0" : "";
				var flashDescription = navigator.plugins["Shockwave Flash" + swVer2].description;
				var descArray = flashDescription.split(" ");
				var tempArrayMajor = descArray[2].split(".");			
				var versionMajor = tempArrayMajor[0];
				var versionMinor = tempArrayMajor[1];
				var versionRevision = descArray[3];
				if (versionRevision == ""){
					versionRevision = descArray[4];
				}
				if(versionRevision[0] == "d") {
					versionRevision = versionRevision.substring(1);
				}else if (versionRevision[0] == "r"){
					versionRevision = versionRevision.substring(1);
					if(versionRevision.indexOf("d") > 0){
						versionRevision = versionRevision.substring(0, versionRevision.indexOf("d"));
					}
				}
				var flashVer = versionMajor + "." + versionMinor + "." + versionRevision;
			}
		}
		else if(navigator.userAgent.toLowerCase().indexOf("webtv/2.6") != -1) flashVer = 4;
		else if(navigator.userAgent.toLowerCase().indexOf("webtv/2.5") != -1) flashVer = 3;
		else if(navigator.userAgent.toLowerCase().indexOf("webtv") != -1) flashVer = 2;
		else if(isIE && isWin && !isOpera){
			var version = -1;
			var axo;
			var e;

			try {
				axo = new ActiveXObject("ShockwaveFlash.ShockwaveFlash.7");
				version = axo.GetVariable("$version");
			} catch (e) {}

			if(!version){
				try {
					axo = new ActiveXObject("ShockwaveFlash.ShockwaveFlash.6");
					version = "WIN 6,0,21,0";
					axo.AllowScriptAccess = "always";
					version = axo.GetVariable("$version");
				} catch (e) {}
			}
			if(!version){
				try {
					axo = new ActiveXObject("ShockwaveFlash.ShockwaveFlash.3");
					version = axo.GetVariable("$version");
				} catch (e) {}
			}

			if(!version){
				try {
					axo = new ActiveXObject("ShockwaveFlash.ShockwaveFlash.3");
					version = "WIN 3,0,18,0";
				} catch (e) {}
			}

			if(!version){
				try {
					axo = new ActiveXObject("ShockwaveFlash.ShockwaveFlash");
					version = "WIN 2,0,0,11";
				} catch (e) {
					version = -1;
				}
			}
			
			flashVer =  version;
		}
		return flashVer;
	},
	
	overwriteWithFlash: function(swfsrc, name, width, height, wmode){	
		if(this.isInstalled() == false){
			return false;
		}
		
		window.setTimeout("new D2S().flash.m_overwriteWithFlash('" + swfsrc + "', '" + name + "', '" + width + "', '" + height + "')", 100);
	},

	m_overwriteWithFlash: function(swfsrc, name, width, height, wmode){
		if(wmode == null){
			wmode = "opaque";
		}
		
		var flash = '<object classid="clsid:d27cdb6e-ae6d-11cf-96b8-444553540000" ';
		flash += 'codebase="http://fpdownload.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=7,0,0,0" ';
		flash += 'width="'+width+'" height="'+height+'" id="oSwf'+name+'" align="middle">';
		flash += '<param name="movie" value="'+swfsrc+'" />';
		flash += '<param name="quality" value="high" />';
		flash += '<param name="wmode" value="'+wmode+'" />';
		flash += '<embed src="'+swfsrc+'" ';
		flash += 'quality="high" ';
		flash += 'width="'+width+'" height="'+height+'" ';
		flash += 'name="oSwf'+name+'" align="middle" type="application/x-shockwave-flash" wmode="'+wmode+'" pluginspage="http://www.macromedia.com/go/getflashplayer" /></object>';			

		var Object = document.getElementById(name);
		if(Object == false){
			return false;
		}else{
			Object.innerHTML = flash;
		}
	}
	
};

var d2s = new D2S();
D2S.prototype.gallery = {
	_id : 0,
	_databaseTableUri: null,
	_locale: null,
	_contentId: null,
	
	_isTemplateLoaded: false,
	_loadTemplate: function(){
		if(this._isTemplateLoaded == true){
			return true;
		}
		//<!--
			var templateDE = "<div id=\"d2s_gallery\"><div class=\"cover\">&nbsp;</div><table class=\"gallery\"><tbody><tr class=\"head\"><td colspan=\"3\" onclick=\"d2s.gallery.close();\"></td></tr><tr class=\"center\"><td class=\"side_space\" onclick=\"d2s.gallery.close();\"></td><td><div class=\"view\"><table id=\"d2s_gallery_image_table\"><tr><td></td><td class=\"pictures\">Bild&nbsp;<span id=\"d2s_gallery_loader_element\">1</span>&nbsp;von&nbsp;<span id=\"d2s_gallery_loader_elements\">1</span></td><td><div class=\"close_button\"><a href=\"javascript:d2s.gallery.close();\">Fenster schlie&szlig;en</a></div></td></tr><tr><td width=\"1%\"><div class=\"hover_buttons\"><a id=\"d2s_gallery_hover_buttons_left\" href=\"javascript:d2s.gallery.previousImage();\"></a></div></td><td id=\"d2s_gallery_image_table_td\"><img id=\"d2s_gallery_loader\" src=\"/Project/Frontend/Components/d2s_tools/d2s_gallery/images/1px.gif\" alt=\"\"/><a href=\"javascript:d2s.gallery.nextImage();\"><img id=\"d2s_gallery_image\" src=\"/Project/Frontend/Components/d2s_tools/d2s_gallery/images/1px.gif\" alt=\"\"/></a></td><td width=\"1%\"><div class=\"hover_buttons\"><a id=\"d2s_gallery_hover_buttons_right\" href=\"javascript:d2s.gallery.nextImage();\"></a></div></td></tr><tr><td><div class=\"button left_button\"><a class=\"left\" href=\"javascript:d2s.gallery.previousImage();\">&nbsp;</a></div><div style=\"height: 40px;\">&nbsp;</div></td><td><div class=\"content\"><div colspan=\"3\" class=\"headline\"><span id=\"d2s_gallery_headline_text\"></span></div><div colspan=\"3\" class=\"description\"><span id=\"d2s_gallery_description_text\"></span></div></div></td><td><div class=\"button right_button\"><a class=\"right\" href=\"javascript:d2s.gallery.nextImage();\">&nbsp;</a></div><div style=\"height: 40px;\">&nbsp;</div></td></tr></table></div></td><td class=\"side_space\" onclick=\"d2s.gallery.close();\"></td></tr><tr class=\"foot\"><td colspan=\"3\" onclick=\"d2s.gallery.close();\"></td></tr></tbody></table></div>";
		//-->
		if(this._locale == "de"){
			document.body.innerHTML += templateDE;
		}else{
			document.body.innerHTML += templateEN;
		}
		this._isTemplateLoaded = true;
	},
	
	_data: null,
	_dataCache: new Object(),
	_cacheKey: null,
	_loadData: function(){
		if(this._dataCache[this._cacheKey] != null){
			this._data = this._dataCache[this._cacheKey];
			d2s.gallery._setData();
		}else{
			/*
			var url = window.location.protocol + '//' + window.location.host + '/' + this._databaseTableUri + '/' + this._locale + '/id.' + this._id + '.object';
			url += '?type=gallery';
			if(this._contentId != null){
				url += '&content_id=' + this._contentId;
			}
			*/
			var url = window.location.protocol + '//' + window.location.host + '/' + this._locale + '/gallery.ajax';
			url += '?type=gallery';
			if(this._id != null){
				url += '&id=' + this._id;
			}
			if(this._databaseTableUri != null){
				url += '&table_uri=' + this._databaseTableUri;
			}
			if(this._contentId != null){
				url += '&content_id=' + this._contentId;
			}
			
			$.get(url, function(data) {
				d2s.gallery._dataCache[d2s.gallery._cacheKey] = $.parseJSON(data);
				d2s.gallery._data = d2s.gallery._dataCache[d2s.gallery._cacheKey];
				d2s.gallery._setData();
			});
		}
	},
	
	_setData: function(){
		if(this._data[this._currentImageIndex] == null){
			this._currentImageIndex = 0;
		}
		
		var path = null;
		if(this._data[this._currentImageIndex].data["path_resized"] != null){
			path = this._data[this._currentImageIndex].data["path_resized"];
		}else if(this._data[this._currentImageIndex].category["path"] != null){
			path = this._data[this._currentImageIndex].category["path"] + this._data[this._currentImageIndex].data["path"];
		}else{
			path = this._data[this._currentImageIndex].data["path"];
		}
		
		$("#d2s_gallery_image").attr("src", path);
		this._loadingImage = new Image();
		this._loadingImage.src = path;
		
		var titleKey = "title";
		var descriptionKey = "description";
		
		if(this._data[this._currentImageIndex].data[titleKey] != null){
			$("#d2s_gallery_headline_text").html(this._data[this._currentImageIndex].data[titleKey]);
		}
		if(this._data[this._currentImageIndex].data[descriptionKey] != null){
			$("#d2s_gallery_description_text").html(this._data[this._currentImageIndex].data[descriptionKey]);
		}
		
		$("#d2s_gallery_loader_element").html(this._currentImageIndex + 1);
		$("#d2s_gallery_loader_elements").html(this._data.length);
		
		window.setTimeout(function(){
			$("#d2s_gallery_loader").css("display", "block");
			$("#d2s_gallery_image").css("display", "none");
			d2s.gallery._preload();
		}, 250);
	},
	
	_loadingImage: null,
	_preload: function(){
		if(this._loadingImage.complete == true){
			d2s.gallery._showPreload();
			
			$("#d2s_gallery_loader").css("display", "none");
			$("#d2s_gallery_image").css("display", "block");
			
			// $("#d2s_gallery_hover_buttons_left").css("display", "block");
			// $("#d2s_gallery_hover_buttons_right").css("display", "block");
			
			$("#d2s_gallery_headline_text").css("display", "block");
			$("#d2s_gallery_description_text").css("display", "block");
			
			// this._fixHoverButtonsPosition();
		}else{
			window.setTimeout(function(){
				$("#d2s_gallery_loader").css("display", "block");
				$("#d2s_gallery_image").css("display", "none");
				d2s.gallery._preload();
			}, 500);
		}
	},
	
	_showPreload: function(){
		$("#d2s_gallery_image").css("display", "none");
		$("#d2s_gallery_loader").css("display", "block");
		$("#d2s_gallery").css("display", "block");
		
		// $("#d2s_gallery_hover_buttons_left").css("display", "none");
		// $("#d2s_gallery_hover_buttons_right").css("display", "none");
		
		$("#d2s_gallery_headline_text").css("display", "none");
		$("#d2s_gallery_description_text").css("display", "none");
	},
	
	_fixHoverButtonsPosition: function(){
		var width = $("#d2s_gallery_image_table").width() / 3;
		var height = $("#d2s_gallery_image_table").height();
		
		$("#d2s_gallery_hover_buttons_left").css("width", width + "px");
		$("#d2s_gallery_hover_buttons_left").css("height", height + "px");
		
		$("#d2s_gallery_hover_buttons_right").css("width", width + "px");
		$("#d2s_gallery_hover_buttons_right").css("height", height + "px");
		$("#d2s_gallery_hover_buttons_right").css("margin-left", "-" + width + "px");
	},
		
	_fixScrollPosition: function(){
		var pageYOffset = Math.max($(window).scrollTop(), $(document.documentElement).scrollTop());
		var pageXOffset = Math.max($(window).scrollLeft(), $(document.documentElement).scrollLeft());
		
		$("#d2s_gallery").css("left", pageXOffset + "px");
		$("#d2s_gallery").css("top", pageYOffset + "px");
	},
	
	open: function(id, databaseTableUri, locale, contentId){
		this._id = id;
		this._databaseTableUri = databaseTableUri;
		this._locale = locale;
		this._contentId = contentId;
		
		this._cacheKey = this._databaseTableUri + '_' + this._locale + '_' + this._id + '_' + this._contentId;
		this._cacheKey = this._cacheKey.replace(/[^0-9a-zA-z]/, "_");
		
		this._loadTemplate();
		this._showPreload();
		this._loadData();
		this._fixScrollPosition();
	},
	close: function(){
		$("#d2s_gallery").css("display", "none");
	},
	
	_currentImageIndex : 0,
	nextImage: function(){
		var imageWidth = $("#d2s_gallery_image").width();
		$("#d2s_gallery_loader").css("width", imageWidth + "px");
		var imageHeight = $("#d2s_gallery_image").height();
		$("#d2s_gallery_loader").css("height", imageHeight + "px");
		
		this._currentImageIndex++;
		if(this._currentImageIndex >= this._data.length){
			this._currentImageIndex = 0;
		}
		
		this._setData();
	},
	previousImage: function(){
		var imageWidth = $("#d2s_gallery_image").width();
		$("#d2s_gallery_loader").css("width", imageWidth + "px");
		var imageHeight = $("#d2s_gallery_image").height();
		$("#d2s_gallery_loader").css("height", imageHeight + "px");
		
		this._currentImageIndex--;
		if(this._currentImageIndex < 0){
			this._currentImageIndex = this._data.length - 1;
		}
		
		this._setData();
	}
};function ReiseAbenteuer(){}
ReiseAbenteuer.prototype.dom = {
	
	setObjectOpacity: function(intId, svalue){
		var obj = document.getElementById('banner_' + intId );
		if(obj == undefined){
			return;
		}
		obj.style.opacity = svalue/100;
		obj.style.filter = 'alpha(opacity=' + svalue + ')';
		obj = null;
	},
	
	handleBlend: function(){
		if(reise_Properties.boolCFRecursive == true){
			if(reise_Properties.intCFBlendInNumber < 1){
				reise_Properties.intCFActiveNumber = 1;
				reise_Properties.boolCFRecursive = false;
			}else{
				reise_Properties.intCFBlendInNumber -= 1;
				this.setObjectOpacity(reise_Properties.intCFActiveNumber, reise_Properties.intCFBlendInNumber);
			}
			}else{
				if(reise_Properties.intCFBlendInNumber >= 100){
					reise_Properties.intCFBlendInNumber += 1;
				}
				if(reise_Properties.intCFBlendInNumber >= 200){
					if(reise_Properties.intCFActiveNumber == 1){
						this.setObjectOpacity(reise_Properties.intCFMax, "0");
					}else{
						this.setObjectOpacity(reise_Properties.intCFActiveNumber-1, "0");
					}
					if(reise_Properties.intCFActiveNumber == reise_Properties.intCFMax){
						reise_Properties.boolCFRecursive = true;
						return;
					}else{
						reise_Properties.intCFActiveNumber++;
					}
					
					reise_Properties.intCFBlendInNumber = 0;
				}
				
				if(reise_Properties.intCFBlendInNumber < 100){
					reise_Properties.intCFBlendInNumber += 1;
					this.setObjectOpacity(reise_Properties.intCFActiveNumber, reise_Properties.intCFBlendInNumber);
				}
			}
	},
	
	
	initBlend: function(){
	
		
		var counter = 0;
		var collection = document.getElementsByTagName('div');
		for (var i = collection.length;  i--;) {
			if(collection[i].id.indexOf("banner_") == -1){
				continue;
			}
			counter++;
		}
		
		if(counter == 0){
			return;
		}
		
		reise_Properties.oCFInterval = null;
		reise_Properties.intCFBlendInNumber = 0;
		reise_Properties.intCFActiveNumber = 1;
		reise_Properties.intCFMax = (counter+1);

		reise_Properties.boolCFRecursive = false;
		this.setObjectOpacity(1, "100");
		reise_Properties.intCFActiveNumber = 2;
		reise_Properties.oCFInterval = window.setInterval("reise.dom.handleBlend()", 10);
	}
	
	
};

var reise_Properties = new Object();

var reise = new ReiseAbenteuer();
reise.dom.initBlend();

