$(document).ready(function() {

	////////////////////////////////////////////////////////////////////////////
	
	var activImage = 2;
	var timer;

	$('div.teaser-switch').find('ul > li').hide();
	$('div.teaser-switch').find('ul > li:first').show();

	$('#teaser-switch-menu').appendTo('div.teaser-switch')

	function teaserTimeSwitcher() {

		var item = $('div.teaser-switch').find('ul > li:nth-child('+activImage+')');

		if(item.length != 0) {
			$('div.teaser-switch').find('ul > li').fadeOut(2000);
			$(item).fadeIn(2000);

			if(activImage == $('div.teaser-switch').find('ul > li').length) {
				activImage = 1;
			} else {
				activImage+=1;
			}
		}

		timer = setTimeout(teaserTimeSwitcher, 6000);
	}
	timer = setTimeout(teaserTimeSwitcher, 6000);


	////////////////////////////////////////////////////////////////////////////
	/**
	 * Hover Menu
	 *
	 *
	 */
	var activMenuItem;
    var wait;

	var hideMenu = function() {
		$('ul.hover').hide();

		$('#navigation-neu li.active').removeClass('active');
	};

	var hideMenuItem = function(item) {
		$(item).children('ul.hover').hide();
		$(item).removeClass('activ');
	};



	$('#navigation-neu > li').hover(function() {
		var that = $(this);
        wait = window.setTimeout(function() {
			activMenuItem = $(that).attr('id');
			$(that).addClass('active');
			$('#navigation-neu > li').each(function() {
				if($(this).attr('id') != activMenuItem) {
					hideMenuItem(this);
					$(this).removeClass('active');
				} else {
					$(this).addClass('active');
				}
			});
			var hover = $(that).children('ul.hover');

			
			clearTimeout(timer);

			$(that).children('ul.hover').bgiframe().show();

	
			hover.children('li:last').addClass('last');

			

		},370)
	}
	,function() {
		clearTimeout(wait);
		timer = window.setTimeout(hideMenu,500); 
	});

	////////////////////////////////////////////////////////////////////////////

	$('.bordered.boxed').find('div.image-container').each(function(i, item){
		var image = $(this).children('img');
		
		image
			.css('margin-top',  ($(image).height() / 2) * -1)
			.css('margin-left',  ($(image).width() / 2) * -1)

	})

	////////////////////////////////////////////////////////////////////////////
	/**
	 * Artikel Suche onblur/onfocus
	 */
	var search = $('#search-value').val();
	$('#search-value').focus(function() {
		$(this).val('');
	})
	$('#search-value').blur(function() {
		if($(this).val() == '' ) {
			$(this).val(search);
		}
	});

	/**
	 * Newsletter onblur/onfocus
	 */
	var email = $('#email').val();
	$('#email').focus(function() {
		$(this).val('');
	})
	$('#email').blur(function() {
		if($(this).val() == '' ) {
			$(this).val(email);
		}
	});

	$('ul.jcarousel-skin-tegut').jcarousel({
		visible:4
	});

	$('ul.jcarousel-skin-products').jcarousel({
		visible:4
	});
	$('ul.jcarousel-skin-products2').jcarousel({
		visible:5
	});

	$("a.tiplink").simpletooltip({
		effect: "fadeIn"
	}); 
	////////////////////////////////////////////////////////////////////////////
	/**
	 * Lightbox
	 */
	$('a[rel*=lightbox]').fancybox({
		'overlayShow': true
	});

	$('a.inline').fancybox({
		'overlayShow': true,
		'frameWidth' : 660,
		'frameHeight': 520 
	});

	/**
	 * Tabs
	 */
	$(".tab-container").tabs();



	/**
	 *  List / Gallery View Switcher
	 */
	$('#products-view-list').click(function() {
		$('#products-view-switcher li').removeClass('active');
		$(this).parent('li').addClass('active');
		$('ul.products').switchClass('gallery', 'list');

	});
	$('#products-view-gallery').click(function() {
		$('#products-view-switcher li').removeClass('active');
		$(this).parent('li').addClass('active');
		$('ul.products').switchClass('list', 'gallery');
	 });

	 /**
	  * print
	  */
	 $('.product-functions-print a').click(function() {
		 window.print();
	 })


	 /**
	  * Category Menu
	  */
	$('.navigation-neu > ul.level-1 > li.active > a').css({
		'font-weight'  : 'bold',
		'color'        : '#515254'
	});
	$('ul.level-2 > li.active > a').css({
		'font-weight'  : 'bold',
		'color'        : '#515254'
	});
	$('ul.level-3 > li.active > a').css({
		'font-weight'  : 'bold',
		'color'        : '#515254'
	});

	/**
	 * Versandarten & Zahlungsarten
	 */
	$('.product-delivery').hover(function() {
		$(this).addClass('hover');
	}, function() {
		$(this).removeClass('hover');
	})
	$('.product-payment').hover(function() {
		$(this).addClass('hover');
	}, function() {
		$(this).removeClass('hover');
	})


	$(document).ready(function(){
        $(document).pngFix();
    }); 


 /**
 	         * NL PopUp
 	         */
/**	        var newsletterPopUp = (function() {
 	       
	
	                var popup       = $('<div>'),
	                        form    = $('<form>'),
 	                        input   = $('<input>'),
	                        close   = $('<div>'),
	                        submit  = $('<div>'),
	                        value   = "Tragen Sie Ihre E-Mail Adresse ein...";
	
	                popup
	                        .attr('id','nl_popup')
 	
	                close
	                        .addClass('close')
	                        .click(function() {
	                                $.cookie('newsletterPopUp', 1, {expires: 30});
	                                $('#nl_popup').fadeOut();
	                        })
	
 	                submit
	                        .addClass('submit')
	                        .click(function() {
	                                $.cookie('newsletterPopUp', 1, {expires: 30});
	                                $('#nl_popup').fadeOut();
	                                window.location.href ="../newsletter.php?email=" + input.val()
	                        })
	
	                form
	                        .attr('action','newsletter.php')
	                        .attr('methode','POST')
	
	                form.submit(function() {
	                        $.cookie('newsletterPopUp', 1, {expires: 30});
	                        $('#nl_popup').fadeOut();
	                        window.location.href ="../newsletter.php?email=" + input.val()
	                        return false;
	                });
	
	                input
	                        .attr('email','email')
	                        .addClass('text')
	                        .val(value)
	                       
	                input.focus(function() {
	                        $(this).val('') 
	                });
	                input.blur(function() {
	                        if($(this).val() == "") {
	                                $(this).val(value);
	                        }
	                });
	
	                form.append(input);
	                popup
	                        .append(form)
	                        .append(close)
	                        .append(submit);
	                       
	                popup.appendTo('#wrapper');
	        });
	
	        if(!$.cookie('newsletterPopUp') && $('#preview-iframe').length == 0) {
	                newsletterPopUp();
	        }**/

	
		var shipping_services_disable = function(service_id, toggle) {
	$("#zusatz_"+service_id).find("input[type=checkbox]").each(function(index) {
	   if($(this).attr('disabled') && toggle == 1) {
	        $(this).attr('disabled', false);
	   } else {
                $(this).attr('checked', false);
	        $(this).attr('disabled', true);
	   }
	   });
	};
	
	// init page start select services
	$(".del_serv_chb1 input[type=checkbox]").not(":checked").each(function(index,item) {
	    shipping_services_disable($(this).attr("id"),0);
	});

	$(".del_serv_chb1 input[type=checkbox]").click(function() {
	    shipping_services_disable($(this).attr("id"),1);
	});	
});
