// JavaScript Document$(document).ready(function () {

$(document).ready(function() {
	$(document).mousemove(function(evt) {
		if ($('#overview-preview').is(':visible')) {
			var x = evt.pageX - $('#wrapper').position().left;
			var y = evt.pageY - $('#wrapper').position().top;
			
			if (evt.pageX + $('#overview-preview').width() + 50 > document.body.clientWidth) {
				x = document.body.clientWidth - $('#overview-preview').width() - 50 - $('#wrapper').position().left;	
			}
			
			$('#overview-preview').css({
				top: y + 20,
				left: x + 20
			});
		}
	});
	
	$('#categories div.product-line').hover(function() {
		if ($(this).find('div.overview').html().indexOf('Keine Dokumente') < 0) {
			$(this).find('div.overview').show();
		}
	}, function() {
		$(this).find('div.overview').hide();
	});
									
	$('a[rel=edition]').removeAttr('href');
				
	$('#dropdown a[title=Produktlinie]').remove();	
	$('div.product-list a[title=Produktlinie]').remove();		
	
	$('div.product-list div').hide();
	$('div.product-list div:first-child').show();
	
	$('div.product-lines img').click(function() {
		if ($(this).hasClass('active')) {
			return;
		}
		$('div.product-lines img').removeClass('active');
		$(this).addClass('active');
		$('div.product-list div').hide().eq($(this).index()).show();
	});
				
	$('#dropdown div.categories div img').mouseenter(function(evt) {
		var top = $(this).position().top + $(this).height() / 2 - $('#active-category').height() / 2;
		
		$('#active-category').css('top', top);
		
		$('#dropdown div.overview div').hide();
		$('#dropdown div.overview div.' + $(this).parent().parent().attr('class')).show();
	});	
	
	$('#dropdown div.overview a').hover(function(evt) {
		$('#overview-preview img').attr('src', $(this).find('img').attr('src')).attr('alt', $(this).find('img').attr('alt'));
		$('#overview-preview p').html($(this).attr('title'));
		$('#overview-preview').show();
		
	}, function(evt) {
		if (!evt) var evt = window.event;
		
		var related_target = evt.relatedTarget || evt.toElement;
		
		if ($('#dropdown div.overview a').has(related_target).length == 0) {
			$('#overview-preview').hide();	
		}
	});
	
	$('#dropdown').data('products_active', $('#naviMain ul.outer > li.last').hasClass('active'));
	
	$('#naviMain ul.outer > li.last a').click(function(evt) {
		if ($('#dropdown').length == 0) {
			return true;	
		}
		
		evt.preventDefault();
		
		if ($('#dropdown').is(':visible')) {
			if ($('#dropdown').data('products_active') == false) {
				$(this).parent().removeClass('active');
				$('#dropdown').slideUp();
			}
		}
		else {
			$(this).parent().addClass('active');
			$('#dropdown').slideDown();	
		}		
	});
							
	/* SUBNAVIGATION */
						   
	if ($("#naviSub .inner").length > 0){
		$("#naviSub .level_1 .inner").addClass("flow");
		$("#naviSub .level_2 .inner").removeClass("flow");
		$("#naviSub .outer").tabs("#naviSub .flow", {tabs: 'span', effect: 'slide', initialIndex: null});
	};



	/* FURNITURE DESCRIPTION */

	$(".furnitureDescription .description").tabs(".furnitureDescription .description .item", {
			tabs: '.head', 
			effect: 'slide', 
			initialIndex: 0,
			onBeforeClick: function(index) {
				this.getCurrentTab().unbind('click', closeDescription);
			},
			onClick: function(index) {
				this.getCurrentTab().click(closeDescription);
			}
	});
	
	

	/* KOLLECTION SCOLLER */
	
	if ($(".furnitureItem").not("flow")) {
		$(".furnitureItem").click(function() {
			if ($('.description', this).is(':visible')) {
				return;	
			}
			$('.link .image img').unbind('click');
			$('.link .more').removeClass('close').unbind('click');
			$('.link .more', this).addClass('close');
			$('.furnitureItem .link .more').html('Details');
			$(".furnitureItem").removeClass("flow");
			$('.furnitureItem .description').hide();
			$(this).addClass("flow");
			$('.description', this).fadeIn(500);
			$('.link .more', this).html('schlie&szlig;en').click(closeDetails);
			
			$('.link .image img', this).click(closeDetails);
		});
	};
	

	/* KOLLECTION SCOLLER */

	$(".collectionImages").scrollable({

		circular: true, 
		mousewheel: false,
		speed: 500,
		easing: 'easeInExpo'
		
	}).navigator({

		navi: ".collectionThumbs",
		naviItem: 'li',
		activeClass: 'current'
		
	});
	
	
	/* KOLLECTION SCOLLER FIRST ACTIVE */

    if ($('.collectionThumbs li').not('current')) {
	  	$(".collectionThumbs li:first-child").addClass('current');
    };


	/* KOLLECTION DETAILS */

	$('.fabric .collectionImages .image').hover(
		
		function(event) {				
				$(this).addClass('hover');		  
				$(".details", this).stop(false, true).fadeOut(300);	
				$(".text", this).stop().animate({height: '100%'}, 300, 'easeOutExpo', function() {	  
					$(".title", this).css('borderBottom', '1px solid #666').animate({
						paddingTop: '50px', 
						fontSize: '20px'
					}, 300);			  
					$(".more", this).fadeIn(300);																																																				  
				});
		},
		function(event) {
				$(this).removeClass('hover');					  			  
				$(".title", this).stop().animate({paddingTop: '5px', fontSize: '14px', borderBottom: '0'}, 200 );			  									  
				$(".more", this).fadeOut("fast", function() {																  
					$(this).parent().stop().animate({height: '30px'}, 200, 'easeInExpo');
				});				  
				$(".details", this).stop(false, true).fadeIn(300);	
		}
	);
	
	
	/* SHADOWBOX MATERIAL 
	
	$('.furnitureItem .description > .item .list .item a, .furnitureDescription .description > .item .list .item a').click(function(event) {
		$('body').css('overflow', 'hidden');
		Shadowbox.open({
			content: $('.colors', $(this).parent()).html(),
			player: 'html',
			title: '',
			width:'960px',
			height: '700px',
			gallery: 'colors'
		});
		event.preventDefault();
	});
	
	*/
	
});


/* SHADOWBOX */

Shadowbox.init({
	overlayOpacity: 0.85,
	onClose: function(lastIndex) {
		$('body').css('overflow', 'auto');
	}
});



/* CLOSE FURNITURE LIST */

function closeDetails(event) {
	var parent = $(this).closest('.furnitureItem');
	parent.removeClass("flow");
	$('.link', parent).removeClass('current');
	$('.description', parent).hide();
	$('.link .more', parent).html('Details').unbind('click').removeClass('close');
	$('.link .image img', parent).unbind('click');
	event.stopPropagation();
}


/* CLOSE MATERIAL */

function closeDescription(event) {
	var api = $(".furnitureDescription .description").data('tabs');
	
	if (api.getCurrentPane().is(':visible')) {	
		api.getCurrentPane().slideUp();
		api.getCurrentTab().removeClass('current');
	}
	else {
		api.getCurrentPane().slideDown();
		api.getCurrentTab().addClass('current');
	}
}


  var _gaq = _gaq || [];
  _gaq.push(['_setAccount', 'UA-7579876-18']);
  _gaq.push(['_trackPageview']);

  (function() {
    var ga = document.createElement('script'); ga.type = 'text/javascript'; ga.async = true;
    ga.src = ('https:' == document.location.protocol ? 'https://ssl' : 'http://www') + '.google-analytics.com/ga.js';
    var s = document.getElementsByTagName('script')[0]; s.parentNode.insertBefore(ga, s);
  })();

