
$(document).ready(function() {

	
	/**
	* Teaser image switch
	*/
	var activImage = 2;
	var timer;
	


	$('div.teaser-switch').find('ul.images > li').hide();
	$('div.teaser-switch').find('ul.images > li:first').show();
	
	$('div.teaser-switch').height($('div.teaser-switch').find('ul.images > li:first').height());
	$('div.teaser-switch').width($('div.teaser-switch').find('ul.images > li:first').width());

	function teaserTimeSwitcher() {

		var item = $('div.teaser-switch').find('ul.images > li:nth-child('+activImage+')');

		if(item.length != 0) {
			$('div.teaser-switch').find('ul.images > li').fadeOut(2000);
			$(item).fadeIn(2000);
	
			if(activImage == $('div.teaser-switch').find('ul.images > li').length) {
				activImage = 1;
			} else {
				activImage+=1;
			}
		}

		timer = setTimeout(teaserTimeSwitcher, 6000);
	}
	timer = setTimeout(teaserTimeSwitcher, 6000);

	/*
	$.ifixpng('/fileadmin/templates/images/clear.gif');
	$('img[src$=.png]').ifixpng();
	*/
	/**
	 * Lightbox & facebox
	 */

	$('a[rel*=facebox]').facebox({
		loadingImage : 'fileadmin/templates/images/facebox/loading.gif',
		closeImage   : 'fileadmin/templates/images/facebox/closelabel.gif',
		opacity	: 0.5
	});
	

	$('ul.jcarousel-skin-tee').find('img').css({
		width:115,
		height:115
	});
	
	$('ul.jcarousel-skin-tee').jcarousel({
		visible:6,
	

		initCallback: function() {
		
			$("li.jcarousel-item").find('a > img').reflect({
				height:0.2			
			});
			$('div.jcarousel-container').append(
				$('<img>').attr('src','fileadmin/templates/images/carousel_end.png').addClass('carousel-end left').ifixpng()
			);
			$('div.jcarousel-container').append(
				$('<img>').attr('src','fileadmin/templates/images/carousel_end2.png').addClass('carousel-end right').ifixpng()
			);
			$("li.jcarousel-item").find('img').hover(function() {
				
				$(this).animate({
					height:120,
					width:120						
				},500);
			}, function() {
				$(this).animate({
					width:115,
					height:115
				},200);
			});
			
		}
	});	
	
	/**
	* odd Mailform
	*/
	$('form > fieldset > div:odd').addClass('odd');
	$('form > fieldset > div > em').each(function(i,item) {
		$(this).appendTo($(this).parent().children('label'));
	});
	$('form > fieldset > div input.submit').parent().addClass('buttons');

	/**
	* bullet List im #CE Bereich odd/even
	*/
	$('#CE').find('ul > li:odd').addClass('odd');
	$('#CE').find('ul > li:even').addClass('even');

	$('#CE').find('ol > li:odd').addClass('odd');
	$('#CE').find('ol > li:even').addClass('even');

	$('#CE').find('table > tbody > tr:even').addClass('tr-odd');
	$('#CE').find('table > tbody > tr:even').addClass('tr-even');
	

	//////////////////////////////////////////////////////
	/**
	* Basket Quick Addd
	*/
	var productSKU = $('#product-sku').val();
	$('#product-sku').focus(function() {
		$(this).val('');
	})
	$('#product-sku').blur(function() {
		if($(this).val() == '' ) {
			$(this).val(productSKU);
		}
	})
	//////////////////////////////////////////////////////
	/**
	* Suche
	*/
	var search = $('#search-value').val();
	$('#search-value').focus(function() {
		$(this).val('');
	})
	$('#search-value').blur(function() {
		if($(this).val() == '' ) {
			$(this).val(search);
		}
	})
	
	/**
	 * Teaser Box
	 */
	$('div.teaser-container > div.teaser:last').addClass('last')
		
	/**
	 * SubMenu Accordion
	 */
	$('#subnavigation > li').each(function(i, item) {
		
		$(this).hover(function() {

			

			if($(this).children('ul').css('display') == 'none') {
				$(this).children('ul').slideDown();
			}
				
		
		}, function() {
			$(this).children('ul').slideUp();		
		});
	});
	
	/**
	 * Produktempfehlungen
	 */
	
	$('div.product-recommendation-container').productRecommendation();
	 
	 
	 /**
	  * Flash IE6 fix
	  *
	 if(!jQuery.support.leadingWhitespace) {
		 $('embed').each(function(i, item) {
			 $(this).before(
					 $('<div>').flash({ src: $(this).attr('src'), width : $(this).attr('width'), height : $(this).attr('height') })
			 ).remove();
		 })
	 }
	 */
	 /**
	  * Schatzsuche Popup
	  */
	 $('a.schatzsuche').click(function() {
		 
		 window.open($(this).attr('href'), 'Schatzsuche', "width=496px,height=550px,status=no,toolbar=no,location=no,menubar=no,resizable=no,scrollbars=yes");
		 
		 return false;
	 })
	 
	 /**
	  * Schatzsusche 
	  */
	 $.treasurehunter({
		 container: '#CE',
		 showAt: '2'
	 });
	 
	 /**
	  * Mailform Hack! for Schatzsusche!
	  */ 
	 var parent = $('#mailformparticipation').parent().addClass('remove');	 
	 $('#mailformparticipation').parent().prev().prepend($('#mailformparticipation'))
	 $('#mailformparticipation').parent().addClass('odd');
	 $('div.remove').remove();

/*
	var url ="http://versand.buenting-tee.de//Spezialitaeten/";
	$img = $('<img src="https://www.buenting-tee.de/fileadmin/templates/images/coloniale_logo.png">');

	$img.css('position','absolute').css('top','4px').css('left','95px');

	$('a[href='+url+']')
		.parent('li.first')
		.css('position', 'relative')

		.append($img);
*/


	var imageList = $("<table>");
	imageList.attr("id","copyrightTable");
	imageList.append($("<tr>")
	    .append($("<td>").html("<strong>Bildnachweis</strong>"))
	);

	var row = "";
	var drawCopyrights = false;
	$("img[copyright]").each(function(i,item) {
		if($(item).attr("copyright").length > 5) {
			drawCopyrights = true;
	    	row = $("<td>");
	    	row.html($(item).attr("copyright"));
	    	imageList.append($("<tr>").html(row));
		}
	});

	if(drawCopyrights) {
		$("#copyrightTable").empty();
		var copyrightContent = $("<div>");
		copyrightContent.attr("id","copyrightContent");
		copyrightContent.html(imageList);
		$("#CE").append('<div style="clear:both"></div>');
		$("#CE").append(copyrightContent);
	}
});

