
// reload
var loc = String(document.location);
if(loc.indexOf("http://www")<0){
	self.location.href = loc.replace("http://","http://www.");
}

function debug(str){
	//
	var el;
	//
	el = $("debug");
	//
	el.set('text', str);
	//el.setStyle('display','none');
	//	el.adopt(str);
}

/*
target muss noch geladen werden, parent offen
target muss noch geladen werden, parent geschlossen
target geladen, parent offen
target geladen, parent geschlossen
*/


/* variables */

var slidesSection = new Array();
var slidesDetail = new Array();

var isLoading = false;
var isScrolling = false;

var queuedSection;
var queuedDetail;

var req; // request
var fxScroll; // scroll
var fxScrollSection;

var isLocked;

var db = "";
	
window.addEvent('domready', function() {

	var pathRequestDetails = getPathRequestDetails();
	
	/* window scrolling */
	fxScroll = new Fx.Scroll(window,{
		offset: {
        'x': 0,
        'y': -100
    	},
    	onComplete: function(){
        	onScrollComplete();
    	}
	});
	fxScrollSection = new Fx.Scroll(window,{
		offset: {
        'x': 0,
        'y': -100
    	},
    	onComplete: function(){
        	onScrollSectionComplete();
    	}
	});

	// request object, can be reused many times.
	req = new Request.HTML({ 
		//onSuccess: function(html) {
		onSuccess: function(responseTree, responseElements, responseHTML, responseJavaScript){
			
			//
			var id;
			var elName;
			//
			
			isLoading = false;
			
			//
			id = this.url.split("/").pop();
			
			
			/* TEST */
			db = responseHTML;
			//debug(">"+responseHTML);
//alert("on Success: "+id+":"+responseHTML+":"+responseTree);
//alert(html);
			onDetailLoaded(responseTree);
			
			/* DELETE
			//if(!isScrolling){
				//showQueuedDetail();
			//}
			
			///updateDetail(id,html);
			//
			//showDetail(id);
			//
			*/
			//
			
			// TODO VIDEO
			/*
			toggleDetails(id);
			updateRelated();
			
			if($("gallery"+id).hasClass("videos")){
				$$('#gallery'+id+' div').each(function(el) {
					var container_id = el.getAttribute("id");
					var path;
					var w;
					var h;
					$$('#'+container_id+' a').each(function(elLink) {
						path = elLink.getAttribute("rel");
					});
					$$('#'+container_id+' img').each(function(elThumb) {
						w = elThumb.getAttribute("width");
						h = elThumb.getAttribute("height");
					});
					showVideo(container_id,path,w,h);
				});								
			}*/
		},
		//Our request will most likely succeed, but just in case, we'll add an
		//onFailure method which will let the user know what happened.
		onFailure: function() {
			alert("sorry, something went wrong");
			//$('result').set('text', 'The request failed.');
		}
	});
		
	/* sections */			
	$$('div.category').addEvent('click', function(e) {
		//
		var id;
		var slide;
		var b;
		var el;
		//
		e.stop();
		//
		
		if(!isLocked()){
			
			lock();
			
			//
			el = $(this.id);
	
			id = getSectionID(this.id);
	
			slide = getSectionSlide(id);
	
			b = true;
			
			if(!slide.open){
	
				t = el.getPosition().y;
			
				if(t>200){
					setQueuedSection(id);
					b = false;
					fxScrollSection.start(0,t);
				}
			
			}
			//
			
			/* orig
			//scrollSection(this.id);

			//
			id = getSectionID(this.id);
		
			*/
			//if(hasVideos(this.id)){
				pauseSWF(id,false);
				//pauseVideos(id,false);
			//}
			if(b){
				updateSection(id,"toggle");
			}
			//
			
		
			// arrows
			updateArrows(this);
		
		}
		//
		
	});	
	
	/* single product */
	$$('tr.facts').addEvent('click', function(e) {
		//
		var id;
		var el;
		var path;
		var b;
		//
		e.stop();
		//
		
		//debug(">"+isLocked());
		if(!isLocked()){
			
			id = this.id.substr(5);		
			//
			lock();
			
			// update arrows
			updateArrows($("facts"+id));
			updateArrows($("arrow"+id));
			
			/* TEST */
			//debug(">"+isLocked()+"_"+id);
			
			loadDetail(id);
		
		}
		/*
		// handle content
		el = getDetail(id);

		queuedDetail = {id:id};
		
		if(elIsEmpty(el)){
			path = pathRequestDetails+id;
			req.url = path;
			req.get(path);
			b = true;
		}
		else{
			b = false;
			//toggleDetail(id);
		}
		
		isLoading = b;
		
		focusDetail(id);
		*/
		
		
		
	});
	
	/* products */
	$$('div.products').each(function(el) {
		//
		var id;
		var slide;
		//
		id = el.id.substr(7);
		//
		slide = new Fx.Slide(el);
		slide.addEvent('complete', function(el) {
			onSectionSlideComplete(el);
		});
		slide.hide();
		// add to list
		setSectionSlide(id,slide);
	});


	/* specials */
	//if($$('div#special img').length==0){
		//disableSpecials();
	//}
	//else{
		$$('div#special a.jumpToSpecial').each(function(el) {
			
				//
				//e.stop();
				//
				if(el.id){
					el.addEvent('click', function(e) {
						//
						
						e.stop();
						
						if(!isLocked()){
						
							lock();
						
							

							jumpToDetail(el.id);
					
							closeSpecial(el);
						
						}

						/*closeSpecial(el.id);
						disableSpecials();
						*/
					
					});	
				}
				//closeSpecial(el.id);
				//disableSpecials();
			/*
			if(el.id){
				el.addClass('teaser');
				el.addEvent('click', function(e) {
					//
					e.stop();
					//
					jumpToDetail(el.id);
					
					closeSpecial(el.id);
					disableSpecials();
					
				});	
			}*/			
		});
		/*
		$$('div#special img').each(function(el) {
			if(el.id){
				el.addClass('teaser');
				el.addEvent('click', function(e) {
					//
					e.stop();
					//
					jumpToDetail(el.id);
					
					closeSpecial(el.id);
					disableSpecials();
					
				});	
			}			
		});
		*/
		$$('div#special a.closeSpecial').each(function(el) {
			el.addEvent('click', function(e) {
				//
				e.stop();
				//
				
				closeSpecial(el);
				disableSpecials();
				//
				/*
				e.stop();
				//
				disableSpecials();	
				*/											
			});				
		});
	//}

	/* sortable table */
	$$('table.sortTable').each(function(sort) { 
		new tableSoort(sort.id);
	});

	/* products */
	$$('table.products').each(function(el) {
		el.setStyle('visibility','visible');
	});
	
	disableSpecials();
	//jumpToDetail(27);
	
	unlock();
	
});

function closeSpecial(el){
	el.getParent().getParent().addClass("invisible");
}

/* ------------------------------------------------- */

function unlock(){
	locked = false;
}
function lock(){
	locked = true;
}
function isLocked(){
	if(locked){
		var el = $("main");
		var str;
		if(el.hasClass("en")){
			str = "please... not that fast!";
		}
		else{
			str = "tststs... so schnell sind wir nicht...";
		}
		//alert(str);
	}
	return locked;
}

/* ------------------------------------------------- */

/* sections */

function scrollSection(id){
	//
	var t;
	var el;
	var slide;
	//
	
	el = $(id);
	
	id = getSectionID(id);
	
	slide = getSectionSlide(id);
	
	if(!slide.open){
	
		t = el.getPosition().y;
		if(t>200){
			fxScrollSection.start(0,t);
		}
		
	}		
	//id = getSectionID(this.id);
}

function updateSection(id,mode){
	
	// slide
	slide = getSectionSlide(id);
	
	switch(mode){
		case "toggle":
			slide.toggle();
			break;
		case "in":
			slide.slideIn();
			//showVideos();
			break;
		case "slideOut":
			slide.slideOut();
			break;
	}	
	
}
function onSectionSlideComplete(el){
	//
	var id;
	var slide;
	var b;
	//
	id = el.id.substr(7);
	slide = getSectionSlide(id);
	if(slide.open){
		//if(hasVideos(el.id)){
			pauseSWF(id,true);
			//pauseVideos(id,true);
		//}
	}
	//
//	debug("finished:"+Math.floor(Math.random()*100));
	unlock();

}
function adjustSection(el,duration){
	//
	var id;
	//
	id = el.getParent().getParent().getParent().getParent().getParent().getParent().getAttribute("id").substr(7);
	//
	slide = getSectionSlide(id);
	//
	setSlideDuration(slide,duration+200);
	//
	updateSection(id,"in");
}
function getSectionID(str){
	return str.substr(8);
}
function getSectionSlide(id){
	return slidesSection[id];
}
function setSectionSlide(id,slide){
	slidesSection[id] = slide;
}


/* details */
function showDetail(id){
	//
	var slide;
	var el;
	var duration;
	var section;
	var b;
	//

	el = getDetail(id);
	
	duration = el.getHeight()*2;
	/*if(duration==0){
		duration = 1000;
	}*/
	/* TEST */
	//debug("3 : showDetail"+":"+slidesDetail[id]+":"+duration+":"+el.getHeight());
	if(slidesDetail[id] == undefined){	
		//
		
		//
		slide = new Fx.Slide(el,{duration:duration});
		slide.addEvent('complete', function(el) {
			onDetailSlideComplete(el);
		});
		slide.hide();
		//
		setDetailSlide(id,slide);
		//
		//hideVideo(id);
		//
	}

	slide = getDetailSlide(id);
	
	slide.options.duration = duration;
	b = true;
	if(slide.open){
		b = false;
	}
	if(b){
		slide.show();
	}
		//
	adjustSection(el,getSlideDuration(slide));
	//
	if(b){
		slide.hide();
		slide.slideIn();	
	}
			
}
function getScrollTarget(id){
	//
	var el;
	var t;
	var b;
	var limit;
	var pid;
	var slide;
	var offset;
	//
	
	el = getDetailParent(id);
	t = el.getPosition().y;

	//
	limit = window.getSize().y/3;
	limit = 200;
	//debug(window.getSize().y);
	
	offset = 0;
	
	pid = el.getParent().getParent().getParent().getAttribute("id");
	
	if(slidesSection[pid.substr(7)].open==false){
		offset = el.getPosition($(pid)).y;
		slidesSection[pid.substr(7)].show();
		var tmp = el.getPosition().y;
		slidesSection[pid.substr(7)].hide();
		//alert(el.getParent().getParent().getParent().getAttribute("id")+":"+offset); 
		//t-=offset;	
		t = tmp;
		//alert("x");
		
		//t+=2*offset;	
		slide = getDetailSlide(id);
		if(slide!=undefined){
			if(slide.open){
				//alert(offset);
				//alert(getDetail(id).getParent().getHeight());
			//	t+=getDetail(id).getHeight();
				//t+=getDetail(id).getHeight()+getDetail(id).getParent().getHeight();
			}
		}
		//t = posRel + posParent;
		//t = $(pid).getPosition().y + offset;
		//t = tmp;
	}	
	if(t > limit){
		//t -= limit-100;
	}
	//t = el.getPosition().y-100;
	
	var posEl = el.getPosition().y;
	var posRel = el.getPosition($(pid)).y;
	var posParent = $(pid).getPosition().y;
	//debug("id:"+id+" / position:"+el.getPosition().y+" / "+pid+" / offset to parent:"+offset);d
	//t = posRel + posParent;
	//debug("targetY: "+t+" / y:"+posEl+" / yContainer: "+posParent+" / yRel: "+posRel+" / tmp: "+tmp);
	return t;
}

/* PROBLEM

detail ist geladen
- detail : closed, parent : open > OK
- detail : open, parent : open > OK
- detail : closed, parent : closed > OK
- detail : open, parent : closed > falsche position
*/
function focusDetail(id,blocked){
	//
	var el;
	var t;
	var b;
	var limit;
	//
	
	/* DELETE
	el = getDetail(id);
	*/
	//
	
	el = getDetailParent(id);

	//t = el.getPosition().y;
	//
	b = false;

	/*limit = window.getSize().y/3;
	if(t > limit){
		t -= limit-100;
		b = true;
	}
	*/
	t = getScrollTarget(id);
	//if(t != el.getPosition().y){
	if(t>200){
		b = true;
	}
	//b = true;

	isScrolling = b;

	if(!b){
		if(isLoading){
			// do nothing...
		}
		else{
			toggleDetail(id);
		}
		
	}
	else{
		//alert(t);
		if(isLoading){
			// do nothing...
			fxScroll.start(0,t);
			//fxScroll.toElement(el);
		}
		else{
			if(blocked==undefined){
				//
				if(getDetailSlide(id).open){
					toggleDetail(id);
				}
				else{
					// do nothing...
					fxScroll.start(0,t);
			//fxScroll.toElement(el);
				}
			}
			else{
				fxScroll.start(0,t);
			//fxScroll.toElement(el);
			}
		}		
	}
}
function onDetailLoaded(html){
	//
	setQueuedHTML(html);
	
	//debug("onDetailLoaded: "+isScrolling);
	
	if(!isScrolling){
		// content
		insertDetailContent();
		//
	
		// slide
		showQueuedDetail();
	}
	/*
	else{
		setQueuedHTML(html);
	}
	*/
}
function insertDetailContent(){
	//
	var id;
	var html;
	//

	//
	id = getQueuedID();
	html = getQueuedHTML();
	
	//debug("1 : id:"+id+" // "+Math.floor(Math.random()*34));
	//
	//insertDetailVideo(id);
	// inject content
	updateDetail(id,html);
	//
	
	/* ORIGINAL POSITION */
	/*
	insertDetailVideo(id);
	*/
	//
	//
	/*
	$$('div.description p').each(function(el) {
		if(!el.hasClass("vis")){
			//el.addClass("vis");
		}
	});
	*/
}
function showQueuedDetail(){
	//
	var id;
	//
	id = getQueuedID();
	//alert("show detail");
	//debug(">show detail");
	showDetail(id);
}
function setQueuedSection(id){
	queuedSection = {id:id};
}
function getQueuedSection(){
	return queuedSection;
}
function getQueuedDetail(){
	return queuedDetail;
}
function getQueuedID(){
	//
	var o;
	//
	o = getQueuedDetail();
	return o.id;
}
function setQueuedHTML(html){
	queuedDetail.html = html;
}
function getQueuedHTML(){
	//
	var o;
	//
	o = getQueuedDetail();
	return o.html;
}
function jumpToDetail(id){
	//
	var el;
	var slide;
	var isEmpty;
	var isOpen;
	var hasOpenParent;
	var pid;
	//
	el = getDetail(id);
	//
	isEmpty = elIsEmpty(el);
	
	if(isEmpty){
		isOpen = false;
	}
	else{
		slide = getDetailSlide(id);
		isOpen = slide.open;
	}
	if(!isOpen){
		// update arrows
		updateArrows($("facts"+id));
		updateArrows($("arrow"+id));
	}
	//
	if(isEmpty){
		loadDetail(id);
	}
	else{
		
		resetQueuedDetail(id);		
		// 
		updateParentArrows($("facts"+id));
		//
		focusDetail(id,true);
	}
}
function resetQueuedDetail(id){
	queuedDetail = {id:id};
}
function loadDetail(id){

			
	// handle content
	el = getDetail(id);

	resetQueuedDetail(id);
	/*
	queuedDetail = {id:id};
	*/
	
	/* TEST */
	//debug("load Detail: "+elIsEmpty(el));
	if(elIsEmpty(el)){
		path = getPathRequestDetails()+id;
		req.url = path;
		req.get(path);
		b = true;
	}
	else{
		b = false;
	}
		
	isLoading = b;
	
	focusDetail(id);
}
/*
function xxx_loadDetail(id){
	//
	var el;
	var path;
	//
	el = getDetail(id);
	//
	if(elIsEmpty(el)){		
		path = getPathRequestDetails()+id;
		req.url = path;
		req.get(path);
	}
}
*/
function toggleDetail(id){
	//
	var el;
	var b;
	//
	el = getDetail(id);
	//
	slide = slidesDetail[id];
	if(slide != undefined){
		b = slide.open;
		if(b){
			//
			showHideSWF(id,false,true);
			
			//
			slide.options.duration *= 0.5;
			
			slide.slideOut();
		}
		else{
			showDetail(id);
		}
	}
}
function onDetailSlideComplete(el){
	//
	var id;
	var slide;
	var b;
	//
	id = getDetailID(el);
	slide = slidesDetail[id];
	b = slide.open;
	if(!b){
	}
	if(!slide.open){
		adjustSection(el,400);
	}
	// videos
	if(slide.open){
		showHideSWF(id,true,false);
	}
}
function getDetailParent(id){
	//alert(getDetail(id).id);
	return $("facts"+id);
	//return getDetail(id).getParent();
}
function getDetail(id){
	return $("details"+id);
}
function getDetailID(el){
	return el.id.substr(7);
}
function setDetailSlide(id,slide){
	slidesDetail[id] = slide;
}
function getDetailSlide(id){
	return slidesDetail[id];
}
function updateDetail(id,html){
	//
	var el;
	//
	el = getDetail(id);
	//
	el.set('text', '');
	// innerHTML
	el.set('html',db);
	/* orig */
	//el.adopt(html);
	
	
	//el.set('html',html);
	//debug("2 : updateDetail:"+html.toString());
	//alert(html);
	//

	insertDetailSWF(id);
	//
	updateRelated();

}
		

/* related */
function updateRelated(){
	$$('div.description a').each(function(el) {		
		if(!el.hasClass("related")){
			el.setAttribute("target","_blank");
		}
	});
	$$('a.related').each(function(el) {	
		if(!el.hasEvent('click')){
			el.addEvent('click',function(e){
				//	
				e.stop();
									
				var id;
				//
				if(!isLocked()){
					
					lock();
					
					
					
					id = this.id.substr(7);
					jumpToDetail(id);
				
				}
				//				
			});
		}	
	});
}


/* arrows */

function updateArrows(el){
		//
		var currClass;
		var newClass;
		//
		var classOpen = "open";
		var classClose = "close";
		//
		if(el.hasClass(classClose)){
			currClass = classClose;
			newClass = classOpen;
		}
		else{
			currClass = classOpen;
			newClass = classClose;
		}

		el.removeClass(currClass);
		el.addClass(newClass);
		
		if(el.id.indexOf("facts")>-1){
			updateParentArrows(el);
		}
}
function updateParentArrows(el){
			var id = el.getParent().getParent().getParent().id.substr(7);			
			el = $("category"+id);
			if(el.hasClass("close")){
				updateArrows(el);
			}
}
/* specials */
function disableSpecials(){
	//
	var b;
	//
	/*
	b = true;
	if($$('div#special img').length==0){
		b = false;
	}
	else{
		b = false;
		$$('div#special img').each(function(el) {
			if(!el.hasClass('hidden')){
				b = true;
			}
		})
	}
	if(!b){
		if($("special")){
			$("special").addClass("hidden");
		}
	}
	*/
}

/* scrolling */

function onScrollComplete(){
	//
	var o;
	//
	isScrolling = false;
	o = getQueuedDetail();
	
	//debug("onScrollComplete: "+isLoading);
	if(!isLoading){
		//
		if(o.html!=undefined){
			
			//alert(o.id+"_"+o.html);
			/*alert("inser");
			*/
			insertDetailContent();
		}
		//
		//alert("showQueuedDetail");
		showQueuedDetail();
	}
}
function onScrollSectionComplete(){
	updateSection(getQueuedSection().id,"toggle");
}
function thisMovie(movieName) {
if(navigator.appName.indexOf("Microsoft") != -1) {
return window[movieName];
} else {
return document[movieName];
}
}


/*
function playerReady(thePlayer) {
	player = window.document[thePlayer.id];
	player.sendEvent("PLAY");
}
*/


/* animations */
/*
function getAnimation(el) {
	//
	var containerID;
	var arr;
	///
	
	containerID = el.getAttribute("id");
	arr = containerID.split("_");
	arr.shift();
	id = arr.join("_");
	return document.getElementsByName("animation_"+id)[0];
};
*/
/* videos */
function getVideoPlayer(el) {
	//
	var containerID;
	var arr;
	///
	
	containerID = el.getAttribute("id");
	arr = containerID.split("_");
	arr.shift();
	id = arr.join("_");
	return document.getElementsByName("player_"+id)[0];
};
function stopVideoPlayer(el){
	//
	var obj;
	//
	obj = getVideoPlayer(el);
	if(typeof obj != "undefined"){
		// problems on IE ...
		if(!Browser.Engine.trident){
			obj.sendEvent("STOP");
		}
		
	}
}
/*
function activateVideoPlayer(el){
	//getVideoPlayer(el).sendEvent("MUTE");
}
*/
/*
function showVideos(){
	$$('div.videos').each(function(el) {
		$$('#'+el.getAttribute("id")+' div').each(function(el) {
			toggleVideoPlayer(el,true);
		});
	});	
	$$('div.animations').each(function(el) {
		$$('#'+el.getAttribute("id")+' div').each(function(el) {
			toggleAnimation(el,true);
		});
	});		
}
*/
/*
function reactivateVideos(id,b){
}
*/
/*
function hasVideos(id){
	//
	var b;
	//
	b = false;
	if($$('#'+id+' div.videos').length>0){
		b = true;
	}
	return b;
}
function hasAnimations(id){
	//
	var b;
	//
	b = false;
	if($$('#'+id+' div.animations').length>0){
		b = true;
	}
	return b;
}
*/
function pauseSWF(id,b){
	//
	var slide;
	//

	slide = getSectionSlide(id);
	
	if(slide.open){
	
		var b = false;
		if($$('#product'+id+' div.videos').length>0){
			b = true;
			var cat = "videos";
		}
		if($$('#product'+id+' div.animations').length>0){
			b = true;
			var cat = "animations";
		}
		if(b){
			$$('div.'+cat+'').each(function(el) {
				var id = el.getAttribute("id").substr(7);
				var slide = getDetailSlide(id);
				if(slide.open){
					$$('#'+el.getAttribute("id")+' div').each(function(el) {
						//alert(cat);
						if(cat=="videos"){
							if(!b){					
								stopVideoPlayer(el);
							}
						}
						toggleSWF(el,b);
					});
				}
			});
		}
	}			
}
/*
function pauseVideos(id,b){
	//
	var slide;
	//

	slide = getSectionSlide(id);
	if(slide.open){
	
	if($$('#product'+id+' div.videos').length>0){
		$$('div.videos').each(function(el) {
			var id = el.getAttribute("id").substr(7);
			var slide = getDetailSlide(id);
			if(slide.open){
				$$('#'+el.getAttribute("id")+' div').each(function(el) {
					if(!b){					
						stopVideoPlayer(el);
					}
					//toggleVideoPlayer(el,b);
					toggleSWF(el,b);
				});
			}
		});
	}
	if($$('#product'+id+' div.animations').length>0){
		$$('div.animations').each(function(el) {
			var id = el.getAttribute("id").substr(7);
			var slide = getDetailSlide(id);
			if(slide.open){
				$$('#'+el.getAttribute("id")+' div').each(function(el) {
					//if(!b){					
					//	stopVideoPlayer(el);
					//}
					//toggleAnimation(el,b);
					toggleSWF(el,b);
				});
			}
		});
	}
	}			
}
*/
function showHideSWF(id,b,stopVideo){	
	if($("gallery"+id).hasClass("videos") || $("gallery"+id).hasClass("animations")){
		$$('#gallery'+id+' div').each(function(el) {
			if($("gallery"+id).hasClass("videos")){
				//alert("x");
				if(stopVideo){
					stopVideoPlayer(el);
				}
			}
			toggleSWF(el,b);
		});
	}			
}
/*
function showHideSWF(id,b,stopVideo){	
	if($("gallery"+id).hasClass("videos")){
		$$('#gallery'+id+' div').each(function(el) {
			if(stopVideo){
				stopVideoPlayer(el);
			}
			//toggleVideoPlayer(el,b);
			toggleSWF(el,b);
		});
	}
	if($("gallery"+id).hasClass("animations")){
		$$('#gallery'+id+' div').each(function(el) {
			//toggleVideoPlayer(el,b);
			//toggleAnimation(el,b);
			toggleSWF(el,b);
		});
	}				
}
*/
/*
function showHideVideo(id,b,stopVideo){	
	if($("gallery"+id).hasClass("videos")){
		$$('#gallery'+id+' div').each(function(el) {
			if(stopVideo){
				stopVideoPlayer(el);
			}
			toggleVideoPlayer(el,b);
		});
	}
	if($("gallery"+id).hasClass("animations")){
		$$('#gallery'+id+' div').each(function(el) {
			toggleAnimation(el,b);
		});
	}				
}
*/
function toggleSWF(el,b){
	//
	var val;
	var bb = false;
	var id = el.id;
	var arr = id.split("_");
	arr[0] = "player";
	id = arr.join("_");

	el = $(id);
	//if(Browser.Engine.trident || Browser.Engine.presto  || Browser.Engine.gecko){
		if(b){
			val = "visible";
		}
		else{
			val = "hidden";
		}
		el.style.visibility = val;
	//}	
}
/*
function toggleAnimation(el,b){
	//
	var val;
	var bb = false;
	var id = el.id;
	var arr = id.split("_");
	arr[0] = "animation";
	arr[0] = "player";
	id = arr.join("_");

	el = $(id);
	//if(Browser.Engine.trident || Browser.Engine.presto  || Browser.Engine.gecko){
		if(b){
			val = "visible";
		}
		else{
			val = "hidden";
		}
		el.style.visibility = val;
	//}						
}
function toggleVideoPlayer(el,b){
	//
	var val;
	var bb = false;
	
	var id = el.id;
	var arr = id.split("_");
	arr[0] = "player";
	id = arr.join("_");

	el = $(id);
	if(Browser.Engine.trident || Browser.Engine.presto  || Browser.Engine.gecko){
		if(b){
			val = "visible";
		}
		else{
			val = "hidden";
		}
		el.style.visibility = val;
	}						
}
*/
/*
function embedAnimation(containerID,file,w,h){
	//
	var arr;
	var pathImage;
	var swfObj;
	var vars;
	//
	arr = containerID.split("_");
	arr.shift();
	id = arr.join("_");
	//
	pathImage = file.substr(0,file.indexOf("."))+".jpg";
	
	pathFile = "../"+file;

	var playerID = "player_"+id;

	vars = null;
	var params =
  	{
    	allowfullscreen:      'true',
    	allowscriptaccess:    'always',
    	wmode:					'wmode'
  	};
  	var attributes =
  	{
    	id:                   playerID,
    	name:                 playerID
  	};
	swfobject.embedSWF(pathFile,playerID,w, h, '9.0.124', false, vars, params, attributes);	
}
function embedVideo(containerID,file,w,h){
	//
	var arr;
	var pathImage;
	var swfObj;
	var vars;
	//
	arr = containerID.split("_");
	arr.shift();
	id = arr.join("_");
	//
	pathImage = file.substr(0,file.indexOf("."))+".jpg";
	
	pathFile = "../"+file;

	var playerID = "player_"+id;
	
	var vars = {
		file:			pathFile,
		image:			pathImage,
		autostart:		'false',
		fullscreen:		'true',
		backgcolor:     'dde0df',
		frontcolor:     '74749E',
		lightcolor:     '333366',
		screencolor:     'dde0df'
	}
	var params =
  	{
    	allowfullscreen:      'true',
    	allowscriptaccess:    'always',
    	wmode:					'wmode'
  	};
  	var attributes =
  	{
    	id:                   playerID,
    	name:                 playerID
  	};

	swfobject.embedSWF("assets/player.swf",playerID,w, h, '9.0.124', false, vars, params, attributes);	
}
*/


function embedSWF(containerID,file,w,h,media){
	//
	var arr;
	var pathImage;
	var swfObj;
	var vars;
	//
	arr = containerID.split("_");
	arr.shift();
	id = arr.join("_");
	//
	pathImage = file.substr(0,file.indexOf("."))+".jpg";
	
	pathFile = "../"+file;

	var playerID = "player_"+id;

		var vars = null;
		var params = null;
		
		var swf = pathFile;
if(media=="video"){
	var vars = {
		file:			pathFile,
		image:			pathImage,
		autostart:		'false',
		fullscreen:		'true',
		backgcolor:     'dde0df',
		frontcolor:     '74749E',
		lightcolor:     '333366',
		screencolor:     'dde0df'
	}
	var params =
  	{
    	allowfullscreen:      'true',
    	allowscriptaccess:    'always',
    	wmode:					'wmode'
  	};
  	
  	swf = "assets/player.swf";
}

  	var attributes =
  	{
    	id:                   playerID,
    	name:                 playerID
  	};

	swfobject.embedSWF(swf,playerID,w, h, '9.0.124', false, vars, params, attributes);	
}

function insertDetailSWF(id){
	/* problem: nodes not accessible... */
	if($("gallery"+id)==null){
	//	alert("error:"+id);
	}
	if($("gallery"+id)!=null){	
		//
		var swf;
		var classDiv;
		
		swf = null;
		if($("gallery"+id).hasClass("videos")){
			swf = "video";
			classDiv = "player";
		}
		if($("gallery"+id).hasClass("animations")){
			swf = "animation";
			classDiv = "animation";
		}
		if(swf!=null){
			$$('#gallery'+id+' div.'+classDiv+'').each(function(el) {
				//
				var containerID;					
				var path;
				var w;
				var h;
				//
				containerID = el.getAttribute("id");
				$$('#'+containerID+' a').each(function(elLink) {
					path = elLink.getAttribute("rel");
				});
				$$('#'+containerID+' img').each(function(elThumb) {
					w = elThumb.getAttribute("width");
					h = elThumb.getAttribute("height");
				});
				embedSWF(containerID,path,w,h,swf);
			});
		}
		showHideSWF(id,false,false);		
		//
		if($$('a.missingplugin').length>0){
			// unlock...
		}
	}
}
/*
function insertDetailVideo(id){
	//alert($("gallery"+id)+"_"+($("gallery"+id)==null));
	
	// problem: nodes not accessible...
	if($("gallery"+id)==null){
	//	alert("error:"+id);
	}
	if($("gallery"+id)!=null){
		if($("gallery"+id).hasClass("videos")){
			$$('#gallery'+id+' div.player').each(function(el) {
				//
				var containerID;					
				var path;
				var w;
				var h;
				//
				containerID = el.getAttribute("id");
				$$('#'+containerID+' a').each(function(elLink) {
					path = elLink.getAttribute("rel");
				});
				$$('#'+containerID+' img').each(function(elThumb) {
					w = elThumb.getAttribute("width");
					h = elThumb.getAttribute("height");
				});
				//alert(containerID);
				//embedVideo(containerID,path,w,h);
				embedSWF(containerID,path,w,h,"video");
			});								
		}
		if($("gallery"+id).hasClass("animations")){
			$$('#gallery'+id+' div.animation').each(function(el) {
				//
				var containerID;					
				var path;
				var w;
				var h;
				//
				containerID = el.getAttribute("id");
				$$('#'+containerID+' a').each(function(elLink) {
					path = elLink.getAttribute("rel");
				});
				$$('#'+containerID+' img').each(function(elThumb) {
					w = elThumb.getAttribute("width");
					h = elThumb.getAttribute("height");
				});
				//alert(containerID);
				//embedAnimation(containerID,path,w,h);
				embedSWF(containerID,path,w,h,"animation");
			});								
		}
		showHideSWF(id,false,false);		
		//
		if($$('a.missingplugin').length>0){
			// unlock...
		}
	}
}
*/


/* ------------------------------------------------- */

function setSlideDuration(slide,val){
	return setSlideOption(slide,"duration",val);
}
function getSlideDuration(slide){
	return getSlideOption(slide,"duration");
}
function setSlideOption(slide,option,val){
	slide.options[option] = val;
}
function getSlideOption(slide,option){
	return slide.options[option];
}
function elIsEmpty(el){
	//
	var b;
	//
	if(el.get('text')==""){
		b = true;
	}
	else{
		b = false;
	}
	return b;
}

/* ------------------------------------------------- */

function getPathRequestDetails(){
	if(String(document.location).indexOf("localhost")>-1){
		return "http://localhost:8888/ottosauhaus/index.php?ak=detail/show/";
	}
	else{
		return "index.php?ak=detail/show/";
		//return "http://www.selbstbewusstlos.com/clients/ottosauhaus/public/index.php?ak=detail/show/";
		//return "http://www.ottosauhaus.de/ottosauhaus/public/detail/show/";
	}
}

/* ------------------------------------------------- */

Native.implement([Element, Window, Document], {
	hasEvent: function(type){
		var events = this.retrieve('events', {});
		if (events && events[type]) return true;
		else return false;
	}
});

Element.implement({
	setStyles: function(styles) {
		if(typeof styles == 'string')
			styles = $css2obj(styles);
		for (var style in styles) 
			this.setStyle(style, styles[style]);
		return this;
	},
	removeStyles: function(styles) {
		if (typeof styles == 'string') {
			this.setStyles($css2obj(styles, 1));
		}
		else {
			if ($type(styles) == 'array') {
				for (var i = 0; i < styles.length; i++)
					this.removeStyle(styles[i]);
			}
		}
		if(this.getProperty('style') == '') this.removeProperty('style');
		return this;
	},
	removeStyle: function(style) {
		this.setStyle(style, '');
		if(this.getProperty('style') == '') this.removeProperty('style');
		return this;
	}
});
