/* ****************************** */
/* PRODUKT IN DEN WARENKORB LEGEN */
/* ****************************** */ 

function warenKorb(produktId){
	var xmlhttp;
	if (window.XMLHttpRequest)	{xmlhttp=new XMLHttpRequest();}
	else						{xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");}
	xmlhttp.onreadystatechange=function(){

		if(xmlhttp.readyState==4){
			response 	= xmlhttp.responseText.split("|");
			id 			= response.shift();
			wk			= response.shift();
			response 	= response.join("|");
			msg 		= response.split("*"); 
			document.getElementById("WarenkorbText").innerHTML = msg[1];
			document.getElementById("warenkorbButton").style.display = 'block';
			$('#aktionsMsg').fadeOut(500,function(){
				$(this).html(msg[0]);
				$('#aktionsMsg').fadeIn(500);
				$('#warenkorbViewButton').fadeIn(500);
			});
			$('.langLink img').each(function(){
				var domain = 'http://www.' + $(this).parent().attr('title');
				$(this).attr('src', domain + '/img/wk/' + wk + '.gif');
			});
			return;
		}
	}
	switch(lang){
		case 'es': 	var text = 'en la cesta de compra...'; break;
		case 'en': 	var text = 'Putting product into shopping cart...'; break;	
		default: 	var text = 'Produkt wird in den Warenkorb gelegt'; break;
	}
	
	$('#warenkorbViewButton').fadeOut(500);
	$('#aktionsMsg').fadeOut(500,function(){
		$(this).html('<img src="/img/ajax-loader4.gif">'); 
		$('#aktionsMsg').fadeIn(500);
		xmlhttp.open("GET","/shop/sys/ajax.warenkorb.php?id="+produktId+"&lang="+lang,true);
		xmlhttp.send(null);
	});
}

/* ********************************** */
/* PRODUKT AUF DEN MERKZETTTEL SETZEN */
/* ********************************** */

function merkZettel(produktId){
	var xmlhttp;
	if (window.XMLHttpRequest)	{xmlhttp=new XMLHttpRequest();}
	else						{xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");}
	xmlhttp.onreadystatechange=function(){

		if(xmlhttp.readyState==4){
			document.getElementById("aktionsMsg").innerHTML = xmlhttp.responseText;
			return;
		}
	}
	$('#aktionsMsg').html('Produkt wird auf den Merkzettel gesetzt').fadeIn(1500,function(){
		xmlhttp.open("GET","/shop/sys/ajax.merkzettel.php?id="+produktId,true);
		xmlhttp.send(null);																						
	});
}
/* ********************************** */
/* DOM-READY FUNKTIONEN               */
/* ********************************** */


    $(function() {
			   /*
		$('.bgMini a').lightBox({
			overlayBgColor: '#FFF',
			overlayOpacity: 0.6,
			imageLoading: '/sys/jquery/lightbox/images/loading.gif',
			imageBtnClose: (lang=='de') ? '/sys/jquery/lightbox/images/schliessen.gif' : '/sys/jquery/lightbox/images/close.gif',
			imageBtnPrev:  (lang=='de') ? '/sys/jquery/lightbox/images/zurueck.gif' : '/sys/jquery/lightbox/images/prev.gif',
			imageBtnNext:  (lang=='de') ? '/sys/jquery/lightbox/images/vor.gif' : '/sys/jquery/lightbox/images/next.gif',
			containerResizeSpeed: 350,
			txtImage: 'Bild',
			txtOf: 'von'
		});
*/

		$('#tabLeiste .tab').click(function(){
			$('#tabLeiste .tab').removeClass('active');
			$(this).addClass('active');
			$('#tabBox .tabContent').removeClass('active');
			$('#'+$(this).attr('id')+'Content').addClass('active');
				
		});
		
		jQuery('#kollektion').jcarousel({
			vertical: true,
			scroll: 1,   
			auto: 10,     
			wrap: 'circular',
			initCallback: 			mycarousel_initCallback,
        	itemVisibleInCallback: 	{onBeforeAnimation: mycarousel_itemVisibleInCallback},
        	itemVisibleOutCallback: {onAfterAnimation: mycarousel_itemVisibleOutCallback}
		});
		
		jQuery('#simile').jcarousel({
			vertical: true,
			scroll: 1,   
			auto: 10,     
			wrap: 'circular',
			initCallback: 			mycarousel_initCallback,
        	itemVisibleInCallback: 	{onBeforeAnimation: mycarousel_itemVisibleInCallback},
        	itemVisibleOutCallback: {onAfterAnimation: mycarousel_itemVisibleOutCallback}
		});
		
		jQuery('#angebote').jcarousel({
			vertical: true,
			scroll: 1,   
			auto: 10,     
			wrap: 'circular',
			initCallback: 			mycarousel_initCallback,
        	itemVisibleInCallback: 	{onBeforeAnimation: mycarousel_itemVisibleInCallback},
        	itemVisibleOutCallback: {onAfterAnimation: mycarousel_itemVisibleOutCallback}
		});

	});
	
	function mycarousel_initCallback(carousel){
		carousel.itemList = new Array();
		for (var i = 0; i < $('#' + carousel.instanceName + '.jcarousel-list li').length; i++) {
        	carousel.itemList[i] = $('#' + carousel.instanceName + '.jcarousel-list li').eq(i).html();
    	}
		// Disable autoscrolling if the user clicks the prev or next button.
		carousel.buttonNext.bind('click', function() {
			carousel.startAuto(0);
		});
	
		carousel.buttonPrev.bind('click', function() {
			carousel.startAuto(0);
		});
	
		// Pause autoscrolling if the user moves with the cursor over the clip.
		carousel.clip.hover(function() {
			carousel.stopAuto();
			}, function() {
			carousel.startAuto();
		});

	}
	
	function mycarousel_itemVisibleInCallback(carousel, item, i, state, evt){
		// The index() method calculates the index from a
		// given index who is out of the actual item range.
		var idx = carousel.index(i, carousel.itemList.length);
		carousel.add(i, carousel.itemList[idx - 1]);
	};
	
	function mycarousel_itemVisibleOutCallback(carousel, item, i, state, evt){
		carousel.remove(i);
	};

