$(document).ready(function() {

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

	var activImage = 2;
	var timer;

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



	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 li.active').removeClass('activ');
	};

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



	$('#navigation > li').hover(function() {
		var that = $(this);
        wait = window.setTimeout(function() {
			activMenuItem = $(that).attr('id');

			$('#navigation > li').each(function() {
				if($(this).attr('id') != activMenuItem) {
					hideMenuItem(this);
				}
			});
			var hover = $(that).children('ul.hover');

			$(that).addClass('active');
			clearTimeout(timer);

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

			var width = 0;
			hover.children('li:last').addClass('last');

			hover.children('li').each(function() {
				width+= parseInt($(this).width()) + 35;
			});

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

	////////////////////////////////////////////////////////////////////////////
	/**
	 * Artikel Suche onblur/onfocus
	 */
	var search = $('#search-value').val();
	$('#search-value').focus(function() {
		if($(this).val() == 'Produktsuche' ) {
			$(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-fotopoint').jcarousel({
		visible:4
	});

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

	////////////////////////////////////////////////////////////////////////////
	/**
	 * Lightbox
	 */


	$('a[rel*=lightbox]').fancybox({
		'overlayShow': true
	});

	$('a.button.iframe').fancybox({
		'overlayShow': true,
		'frameWidth' : 660,
		'frameHeight': 520
		}); 
	/**
	 * Tabs
	 */
	$(".tab-container").tabs();


	/**
	 * Warenkorb Link
	 */
	$('a.basket').click(function() {

		var that = $(this);
		$("div.product-image img").effect('transfer', { to: "#basket" }, 1000, function() {
			$('#basket').effect("highlight", { color: '#61b3ca'}, 1000, function() {
				window.location.href = that.attr('href');
			});


		})

	})
	/**
	 *  List / Gallery View Switcher
	 */
	$('#products-view-list').click(function() {
		if($(this).parent('li').hasClass("active")) {
			return;
		}
		var tempId = $('#temp_id').text();

		$('#products-view-switcher li').removeClass('active');

		$(this).parent('li').addClass('active');
		$('ul.products').switchClass('gallery', 'list');
		$.ajax({
			type: "POST",
			url: ajxCon,
			data: "ctrlr=Category&op=setListMode&tempId="+ tempId +"&galleryViewState=1",
			success: function(phpData){

			}
		});

	});
	$('#products-view-gallery').click(function() {
		var tempId = $('#temp_id').text();

		if($(this).parent('li').hasClass("active")) {
			return;
		}


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

		$.ajax({
			type: "POST",
			url: ajxCon,
			data: "ctrlr=Category&op=setListMode&tempId="+ tempId +"&galleryViewState=2",
			success: function(phpData){
			}
		});

	 });

	 /**
	  * print
	  Axel: Kunde wird auf spezielle Druckversion geleitet. Nicht einfach aktuelle Seite drucken
	 $('.product-functions-print a').click(function() {
		 window.print();
	 });
	 */

	$("a.tiplink").simpletooltip({
		effect: "fadeIn"

	});

});

function CrossSelling(url_cross) {
	parameter = 'width=737,height=500,toolbar=no,location=no,directories=no,status=no,menubar=no,scrollbars=yes,resizable=no,copyhistory=yes';
	newwin = window.open(url_cross,'CrossSelling',parameter);
	newwin.focus();
}

function crossSellingShowMoreSwitch(target){
	if ($.browser.msie && $.browser.version == '8.0'){
		//alert("Target: " +  target +" IE:"+$.browser.msie+ " Version: "+$.browser.version);
		$(".c" + target).each(function(i, elem) {
			$(elem).css('display', 'block' );
	     });
		$(".b" + target).each(function(i, elem) {
			$(elem).css('display','none');
	     });


	} else {
		$(".c" + target).slideDown("slow"); 
		$(".b" + target).slideUp("slow");
	}
	
	return false;
}

function checkagb() {
	if(document.basketcheckout.agb.checked) {
		return true;
	} else {
		alert('Bitte lesen und bestätigen Sie erst die AGB!');
		return false;
	}
}

var ajxCon = "index.php";

function rechnen() {


var modus = 1;
var tempId = $('#temp_id').val();

$.ajax({
type: "POST",
url: ajxCon,
data: "ctrlr=Category&op=setListMode&tempId="+ tempId +"&galleryViewState=" + modus,
success: function(phpData){
	alert('done');
}
});
}




