/*
djConfig = { isDebug: false, parseOnLoad: true };

dojo.require("dojo.parser");
(function(){
	var d = dojo;
	var theme = "soria";//nihilo";//tundra
	var themeCss = d.moduleUrl("dijit.themes",theme+"/"+theme+".css");
	var themeCssRtl = d.moduleUrl("dijit.themes",theme+"/"+theme+"_rtl.css");
	document.write('<link rel="stylesheet" type="text/css" href="'+themeCss+'" />');
	document.write('<link rel="stylesheet" type="text/css" href="'+themeCssRtl+'" />');
	
	//document.write('<link rel="stylesheet" type="text/css" href="fileadmin/template/main/css/Lightbox.css" />');
	document.write('<link rel="stylesheet" type="text/css" href="'+d.moduleUrl('nop.layout')+'resources/SlidePane.css'+'" />');

	d.addOnLoad(function() {
		// set the classes
		if(!d.hasClass(d.body(),theme)){ d.addClass(d.body(),theme); }
		if(dojo.config._deferParsing){ d.parser.parse(d.body()); }      
		
		/**
		 // Use a CDN?
		 // AOL seems to be faster
		<script src="http://ajax.googleapis.com/ajax/libs/dojo/1.4.1/dojo/dojo.xd.js"></script>
		<script src="http://o.aolcdn.com/dojo/1.4.1/dojo/dojo.xd.js"></script>
		**/
/*
	});
})();
*/
var ua = navigator.userAgent.toLowerCase();
var dialog = null, imageTextPic = null;
dojo.addOnLoad(function() {
	
	/*
	 * 
	 * DOJO LANGUAGE NAVIGATION ACTION
	 */
	var languageElement = dojo.query(" .language-elements ", "language-navigation");
	if(languageElement.length > 0) {
		var activateLink = dojo.query(" .activate-language-elements ", "language-navigation");
		//console.dir(languageElement);
		dojo.connect(activateLink[0], 'onclick', languageElement,
		function() {
			languageElement.forEach(function(node, index, arr) {
				dojo.style(node, {visibility: 'visible'});
			});
		});
	}
	/*
	 * DOJO CONTENT & IMAGE HOVER
	 * 
	 */
	// query after class
	var jsContentWrap = dojo.query(".nop-js-content-wrap", "middle-content");
	var pageTeaserContentWrap = dojo.query(".tx-noppageteaser-subcategory-slider .tx-noppageteaser-pi1-teaser", 'middle-content');
	//var pageTeaserContentWrap = dojo.query(".noppageteaser-teaser-slider", "middle-content");
	
	if(jsContentWrap.length > 0  || pageTeaserContentWrap.length > 0 ) {
		dojo.require('nop.cehko.ContentHover');
		var n = null;
		if(jsContentWrap.length > 0) {	
			
			jsContentWrap.forEach(function(node, index, arr){
				n = new nop.cehko.ContentHover({
					nature: "text",
					animationDirection: "down"
					}, node);
			});
		}
		if(pageTeaserContentWrap.length > 0) {
			pageTeaserContentWrap.forEach(function(node, index, arr){
				n = new nop.cehko.ContentHover({
					nature: "image",
					animationDirection: "down"
				}, node);
			});
		}
	}

	/**
	 *
	 * DOJO Salonfinder CONTENT HOVER LISTVIEW
	 *
	 *
	 */
	// query after class
	//var jsContentWrap = dojo.query(".nop-js-content-wrap", "middle-content");
	var salonFinderContentWrap = dojo.query(".tx-nopacademy-pi2 .salon-list-item", 'middle-content');
	var salonFinderRightBoxContentWrap = dojo.query(".tx-nopacademy-pi3 .tx-nopacademy-pi3-rightbox", "middle-content");
	if(salonFinderContentWrap.length > 0 || salonFinderRightBoxContentWrap.length > 0) {
		dojo.require('nop.cehko.SalonHover');
		var n = null;
		if(salonFinderContentWrap.length > 0) {
			salonFinderContentWrap.forEach(function(node, index, arr){
				n = new nop.cehko.SalonHover({
					nature: "image",
					animationDirection: "down",
					minHeight:205
				}, node);
			});
		}
		if(salonFinderRightBoxContentWrap.length > 0) {
			console.debug(salonFinderRightBoxContentWrap);
			salonFinderRightBoxContentWrap.forEach(function(node, index, arr){
				n = new nop.cehko.SalonHover({
					nature: "text",
					animationDirection: "down"
				}, node);
			});
		}
	}
	
	// @fixme a[rel=...] auf alle Bilder
		// imageTextPic = dojo.query(".nop-textpic-wrap a[rel=dojo_lightbox]", "middle-content");
		// a[rel=dojo_lightbox]
	/*	var imageTextPic = dojo.query(".nopLightbox", "middle-content");
		
		if (imageTextPic.length > 0) {
			// get all images
			var img = dojo.query(".nopLightbox img", "middle-content");
			dojo.require("dojox.image.Lightbox");
			dialog = new dojox.image.LightboxDialog( {
				templateString : dojo.cache(new dojo._Url("fileadmin/template/main/Lightbox.html"))
			});
			if (dialog) {
				dialog.startup();
				// add all images to dialog
				dojo.forEach(img, function(singleImage, index, array) {
					dialog.addImage( { title : "", href : singleImage.longDesc}, "cehko");
					}
				);
				//dialog.addImage( {
				//	title : "",
				//	href : img[0].longDesc,
				//	group : "cehko"
				//});
				// get image in top span
				var lightboxImage = dojo.query(".lightbox_image img", "middle-content");
				if(lightboxImage.length == 1) {
					lightboxImage = lightboxImage[0];
				}
				// onclick start lightbox if single image than without group parameter
				dojo.connect(imageTextPic[0], 'onclick', imageTextPic[0],
						function() {
							if(img.length > 1) {
								dialog.show( {
									title : '',
									href : lightboxImage.longDesc,
									group : "cehko"
								});	
							} else {
								dialog.show( {
									title : '',
									href : lightboxImage.longDesc
								});
							}
	//						// @dirty fix to get more height
	//						var posInfo = dojo.position(dialog.domNode);
	//						dojo.style(dialog.containerNode, {
	//							height: (posInfo.h + 100) + 'px'
	//						});
						});
			}
		
			spanSmallImages = dojo.query(".single-item-small-images", "middle-content");
			if(spanSmallImages.length > 0) {
				var images = dojo.query(".single-item-small-images img ", "middle-content");				
				images.forEach(function(images) {
					dojo.connect(images, 'onclick', img[0],  function() {
						dojo.attr(img[0], {
							"src" : images.src,
							"longDesc" : images.longDesc,
							"group" : "cehko"
						});
					});
				});
			}
		}*/
	});

		
/* SliderNav for Brands */
dojo.addOnLoad(function() {
	var brandItems = dojo.query("#brands-navigation a");
	if (brandItems.length > 0) {
		dojo.require('nop.ProductHover');
		dojo.require('nop.layout.SlidePane');
		
		brandItems.forEach(function(node, index, arr){
			var n = new nop.ProductHover({
				zoomFactor: 1.2,
				scaleUp: true,
				duration: 160,
				showTitle: false
			}, node);
		});
		dojo.style('brands-navigation', 'width', '940px');
		var brandSlider = new nop.layout.SlidePane({
				scrollWidth: '896px'
		}, 'brands-navigation');	
	}
});
/* SliderNav for History */
dojo.addOnLoad(function() {
	var historyItems = dojo.query("#history-navigation a");
	if (historyItems.length > 0) {
		dojo.require('nop.ProductHover');
		dojo.require('nop.layout.SlidePane');
		
		var activeItemNum = 0;
		var i = 0;
		historyItems.forEach(function(node, index, arr) {
			
			// rip the RO image from typo3 over function
			var scaleUpAltImg = false;
			var overStr = String(dojo.attr(node, 'onmouseover'));
			var overCall = overStr.match(/over\(\"[a-z0-9_]+\"\);/);
			if (overCall != null && overCall.length == 1) {
				var name = overCall[0].slice(6, overCall[0].length - 3)
				scaleUpAltImg = eval(name+"_h.src");
			}
			
			var n = new nop.ProductHover({
				zoomFactor: 1.45,
				scaleUp: true,
				scaleUpAltImg: scaleUpAltImg,
				duration: 160,
				showTitle: false
			}, node);
			if (node.className == 'active') {
				//n.disable();
				n.showTitle = false;
				n.disable();
				n.zoomOut();
				activeItemNum = i;
				
			}
			i++;
			
		});
		dojo.style('history-navigation', 'width', '940px');
		var historySlider = new nop.layout.SlidePane({
				scrollWidth: '896px'
		}, 'history-navigation');
		if (activeItemNum > 0) {
			historySlider.gotoItemNo(activeItemNum, false);
		}
	}
});
/* Slider as product subnavi */
dojo.addOnLoad(function() {
	var teasers = dojo.query(".tx-noppageteaser-product-slider", 'head-content');
	if (teasers.length > 0) {
		dojo.require('nop.ProductHover');
		dojo.require('nop.layout.SlidePane');
		
		
		var activeItemNum = 0;
		var i = 0;
		teasers.forEach(function(node, index, arr) {
			
			
			dojo.query("a", node).forEach(function(node, index, arr) {
				var n = new nop.ProductHover({
					zoomFactor: 1.45,
					duration: 200,
					showTitle: true
				}, node);
				//@fixme: search
				if (node.className == 'active') {
					//n.disable();
					n.showTitle = false;
					n.disable();
					n.zoomOut();
					activeItemNum = i;
				}
				i++;
			});
			dojo.style(node, 'width', '734px');
			var n = new nop.layout.SlidePane({
				scrollWidth: '690px',
				duration: 2000,
				easing: dojo.fx.easing.backOut
			}, node);
			
			if (activeItemNum > 0) {
				n.gotoItemNo(activeItemNum, false);
			}
		});
	}
});
/* Slider as product category nav */
dojo.addOnLoad(function() {
	var teasers = dojo.query(".tx-noppageteaser-category-slider .tx-noppageteaser-pi1-teaser", 'middle-content');
	if (teasers.length > 0) {
		dojo.require('nop.SlideTeaser');
		
		var i = 0;
		teasers.forEach(function(node, index, arr) {
			//@fixme: better use teaser-item-left/teaser-item-right instead of i
			i++;
			if (i == 2) {
				var n = new nop.SlideTeaser({fadeOutLeft:true, showSlideOutClass:['teaser-text']}, node);
				i = 0;
			} else {
				var n = new nop.SlideTeaser({fadeOutLeft:false, showSlideOutClass:['teaser-text']}, node);
			}
		});
	}
});
/* Slider for home */
dojo.addOnLoad(function() {
	var teasers = dojo.query(".home-teaser-slider", 'middle-content');
	// if home empty, query for small
	if(teasers.length <= 0) {
		teasers = dojo.query(".small-teaser-slider", 'middle-content');
	}
	if (teasers.length > 0) {
		dojo.require('nop.SlideTeaser');
		
		var i = 0;
		teasers.forEach(function(node, index, arr) {
			//@fixme: better use teaser-item-left/teaser-item-right instead of i
			i++;
			if (i == 2) {
				var n = new nop.SlideTeaser({fadeOutLeft:true, showSlideOutClass:['teaser-text']}, node);
				i = 0;
			} else {
				var n = new nop.SlideTeaser({fadeOutLeft:false, showSlideOutClass:['teaser-text']}, node);
			}
		});
	}
});
