var Dock = {};

$(document).ready(function(){

	// Set over and out events
	$(".navicontainer>ul>li").hover(
		function() {
			$(this).children().next().slideDown(200);
			$(this).children().addClass('active');
		},
		function() {
			$(this).children().next().slideUp(200);			
			$(this).children().removeClass('active');
		}
	);
	
	//ImageFader
	
	$('.imagefader').cycle({
			fx:      'fade',
			width: 		570,
			height:		421,
			pause: 		true,
			speed:  	2000
	});
	
	
	//Produkt-Dock
	if($('.products').length != 0){
		$('.products img').click(function(){
			var clickrel = $(this).attr('rel'); 
	
			//Textfade
			$('.content_left div:visible').fadeOut(400, function(){
				$('#' + 'text_' + clickrel).fadeIn();
			});
	
			//Picfade
			$('.content_right img:visible').fadeOut(400, function(){
				$('#' + 'pic_' + clickrel).fadeIn();
			});
	
			//old
			//$('.content_right img').attr('src', $(this).attr('src').replace(/.jpg/g, '_big.png'));
		});
	}
	Dock.init();
	
	//Gutschein
	if($('#adressswitch').length != 0){
		$('#adressswitch').change(function(){
			if($(this).val() == 'Ja'){
				$('#street_e-label, #street_e-element, #city_e-label, #city_e-element').fadeIn();
			} else {
				$('#street_e-label, #street_e-element, #city_e-label, #city_e-element').fadeOut();				
			}
		});
	}
	
	
});

//Dock
Dock.current = 1;
Dock.boxlenght = 0; 

Dock.init = function(){
	
	Dock.boxlenght = $('.products').width();
	
	$('.product_controll a').click(function(){
		if($(this).hasClass('next')){
			Dock.switchPics('next');
		} else {
			Dock.switchPics('prev');
		}
		return false;
	});
}

Dock.switchPics = function(r){
	if(r == 'prev'){
		if(Dock.current > 1){
			Dock.current--;
			$('.product_wrapper').animate({
				left: ($('.product_wrapper').position().left + Dock.boxlenght) + 'px'
			}, 3000);
		}
	} else {
		if(Dock.current != pic_dock_sum){
			Dock.current++;
			$('.product_wrapper').animate({
				left: ($('.product_wrapper').position().left - Dock.boxlenght) + 'px'
			}, 3000);
		}
	}
}


//Fancybox
$(document).ready(function() {
	 $(".fancy").fancybox({
		'overlayShow' : true,
		'centerOnScroll' : false,
		'titlePosition' : 'over',
		'zoomSpeedIn' : 600,
		'zoomSpeedOut' : 500
  	 });

});


//Scrollbars
$(document).ready(function() {
	$('.content_left .scroll').jScrollPane({
		showArrows: false,
		arrowSize: 12,
		scrollbarWidth: 8,
		scrollbarMargin: 8,
		reinitialiseOnImageLoad: true
	});
});

