var stepsRight = 0;
var shownItems = 5;
var bkgSign = '';
var bkgHeight = 219;
var itemIndex = 8;
var itemToRemovePosition = -1;
var editableContent = '';
var fakeDate = '88 september 8888';

function initContent () {}

(function( $ ) {
	$.extend( {
			 
		getDetailsResponce: function(index) {
		
		Plus.Services.Wines.Carousel.ResponseProvider.GetCarouselItemDetails(index, updateCarouselItemDetails);		
		},
		init: function() {
			
			Cufon.replace('.plContent h1');
			Cufon.replace('.plLinkFooter h3');
			Cufon.replace('.plWide .plBottle em');
			Cufon.replace('.plWide .plBottle em sup');
			Cufon.replace('.plHeader fieldset a', {fontFamily: 'Frutiger LT Std 700'});
			Cufon.replace('.plColumn02 h2');
			Cufon.replace('.plExtraWidgets .plPostItem h2', {fontFamily: 'Frutiger LT Std 100'});
			Cufon.replace('.plColumn02 h3');
			Cufon.replace('.plSelectionColumn h3');
			Cufon.replace('.pl2SectionsButton em');
			Cufon.replace('.pl2SectionsButton a');
			Cufon.replace('.plTasteMatrix li a ins strong', {fontFamily: 'Frutiger LT Std 900'});
			Cufon.replace('.plTasteMatrix li a ins em', {fontFamily: 'Frutiger LT Std 400'});
			Cufon.replace('.plDate em', {fontFamily: 'Frutiger LT Std 400'});
			Cufon.replace('.plDate p', {fontFamily: 'Frutiger LT Std 400'});
			Cufon.replace('.plPriceMatrix > label');
			Cufon.replace('.plSelection ul li a');
			Cufon.replace('.plSelectionColumn .plSelection .plSearch label');
			Cufon.replace('.plBackToSelection span', {fontFamily: 'Frutiger LT Std 100'});
			Cufon.replace('.plBackToSelection strong');
			Cufon.replace('.plContent .plDescriptionColumn h2', {fontFamily: 'Frutiger LT Std 100'});
			Cufon.replace('.plCombinedInfo tr td h4 span', {fontFamily: 'Frutiger LT Std 100'});
			Cufon.replace('.plBigBottlePrice .plOldPrice', {fontFamily: 'Frutiger LT Std 100'});
			Cufon.replace('.plCombinedInfo tr td h4 strong');
			Cufon.replace('.plCombinedInfo tr td em');
			Cufon.replace('.plImageColumn .plButton');
			Cufon.replace('.plImageColumn .plButtonKept');
			Cufon.replace('.plBigBottlePrice strong');
			Cufon.replace('.plBigBottlePrice .plNewPrice', {fontFamily: 'Frutiger LT Std 700'});
			Cufon.replace('.plBigBottlePrice .plSinglePrice', {fontFamily: 'Frutiger LT Std 700'});
			Cufon.replace('.plBigBottleSinglePrice .plSinglePrice', {fontFamily: 'Frutiger LT Std 700'});
			Cufon.replace('.plAlternativesColumn h2', {fontFamily: 'Frutiger LT Std 100'});
			Cufon.replace('.plAlternative .plBottlePrice', {fontFamily: 'Frutiger LT Std 700'});
			Cufon.replace('.plColumnsGrid .plHomeHeader a', {fontFamily: 'Frutiger LT Std 300', hover:true});
			Cufon.replace('.plColumnsGrid .plHomeBoldHeader');
			Cufon.replace('.plHomeBigMenu li a');
			Cufon.replace('.plHomeBigMenu li label');
			Cufon.replace('.plHomeBigMenu li a em', {fontFamily: 'Frutiger LT Std 300'});
			Cufon.replace('.plPricePair .plShortDescription h4');
			Cufon.replace('.plSubColumn02 .plPostItem h2', {fontFamily: 'Frutiger LT Std 100'});
			Cufon.replace('.plSecondWideColumn h2', {fontFamily: 'Frutiger LT Std 100'});
			Cufon.replace('.plSecondWideColumn h2 strong');
			Cufon.replace('.plDetailedInfo table tr td h3', {fontFamily: 'Frutiger LT Std 400'});
			Cufon.replace('.plButtonPlus');
			Cufon.replace('.plButtonNext');
			Cufon.replace('.plBiggestHeader');
			Cufon.replace('.plBigButton01 em');
			//Cufon.replace('.plBigButton02 em');
			//Cufon.replace('.plBigButton03 em');
			Cufon.replace('.plBigButton04 em');
			Cufon.replace('.plBigButton04 a');
			Cufon.replace('.plBlog .plColumn02 .plPostItem h2', {fontFamily: 'Frutiger LT Std 100'});
			Cufon.replace('.plSelectionList li a', {fontFamily: 'Frutiger LT Std 700'});
			Cufon.replace('.plCarouselReplacement div', {fontFamily: 'Frutiger LT Std 700'});
			
			Cufon.replace('.plMyTopList h2', {fontFamily: 'Frutiger LT Std 100'});
			Cufon.replace('.plMyTopList h2 strong', {fontFamily: 'Frutiger LT Std 900'});
			Cufon.replace('.plMyTopList ul li em', {fontFamily: 'Frutiger LT Std 900'});
			Cufon.replace('.plMyTopList ul li a', {fontFamily: 'Frutiger LT Std 900'});
			Cufon.replace('.plForYouSelected h2', {fontFamily: 'Frutiger LT Std 100'});
			Cufon.replace('.plForYouSelected h2 strong', {fontFamily: 'Frutiger LT Std 900'});

			Cufon.replace('.plForYouSelected h3', {fontFamily: 'Frutiger LT Std 900'});
			Cufon.replace('.plColumn002 .plDetailedInfo table tr td h3', {fontFamily: 'Frutiger LT Std 100'});
			
			Cufon.replace('.plColumn002 .plDetailedInfo table tr td .plButtons .plButtonRemove', {fontFamily: 'Frutiger LT Std 900'});
			Cufon.replace('.plColumn002 .plDetailedInfo table tr td .plButtons .plButtonAddToShopping', {fontFamily: 'Frutiger LT Std 900'});
			Cufon.replace('.plColumn003 h4', {fontFamily: 'Frutiger LT Std 900'});

			
			
			
			$(window).load(function(){
			
				var postsWithTumb = $(".plPostItem > .plThumb");					
				//alert(postsWithTumb.length);
				for (var i=0; i < postsWithTumb.length; i++) {
					$(postsWithTumb).parent().addClass("plGotThumb");
				}

				// Print
				$(".plListPrint").click(function() {
					window.print();								 
				});
				
				// Editable Content
				
				var editableCells = $("td.plSeparated");
				//alert(editableCells.length);
				
				for (var i=0; i<editableCells.length; i++) {
					if (editableCells[i].getElementsByTagName('a')[0]) editableCells[i].getElementsByTagName('a')[0].onclick = function () {
							if (this.parentNode.getElementsByTagName('p')[0]) {
								
								editableContent = this.parentNode.getElementsByTagName('p')[0].innerHTML;	
								this.parentNode.getElementsByTagName('p')[0].style.visibility = 'hidden';
								var editor = document.createElement('textarea');
								editor.className = 'plInlineEditor';
								editor.innerHTML = editableContent;
								var pHeight = this.parentNode.getElementsByTagName('p')[0].scrollHeight;
								if(pHeight<40)
								    pHeight = 40;
								editor.style.height = pHeight + "px";
								editor.style.marginTop = (-1) * (this.parentNode.getElementsByTagName('p')[0].scrollHeight + 74) + "px";
								$(this.parentNode).append(editor);
								//editor.select();
								//editor.focus();
								
								//alert(editableContent);
							}
							var editLink = this.parentNode.getElementsByTagName('a')[1];
							
							if (editLink) {
								editLink.style.visibility = 'visible';
							}
							
							this.style.visibility = 'hidden';
							
							editLink.onclick = function () {
								if (this.parentNode.getElementsByTagName('p')[0] && this.parentNode.getElementsByTagName('textarea')[0] && this.parentNode.getElementsByTagName('strong')[0]) {
									this.parentNode.getElementsByTagName('p')[0].style.visibility = 'visible';
									
									var wineNote = this.parentNode.getElementsByTagName('textarea')[0].value;
									if(wineNote !=editableContent)
									{
									    var ean = this.attributes["ean"].value;
									    Plus.Services.Wines.Carousel.ResponseProvider.AddWineNote(ean, wineNote);
									}
									
									this.parentNode.getElementsByTagName('p')[0].innerHTML = wineNote;
									//this.parentNode.getElementsByTagName('strong')[0].innerHTML = fakeDate;						
									this.parentNode.removeChild(this.parentNode.getElementsByTagName('textarea')[0]);
									this.style.visibility = 'hidden';
									this.parentNode.getElementsByTagName('a')[0].style.visibility = 'visible';
								}
							}
							
					}
					
				}
			
				// Star Rating
			
			  	var ratingClassNames = ['nostar', 'onestar','twostar','threestar','fourstar','fivestar'];
				
				var ratings = $(".rating");
				
				for (var i=0; i<ratings.length; i++) {
					ratings[i].className += " " + ratingClassNames[parseInt(ratings[i].title)];
					
					// Reset on doubleclick
					ratings[i].ondblclick = function () {
						this.className = 'rating nostar';
						this.title = "0";
					}
					
				}
				
				var innerLinks = $(".rating li a");
				
				for (var i=0; i<innerLinks.length; i++) {
					innerLinks[i].onclick = function () {
						this.parentNode.parentNode.title = this.title;	
						//alert(ratingClassNames[parseInt(this.title)]);
						this.parentNode.parentNode.className = 'rating';
						$(this.parentNode.parentNode).addClass(ratingClassNames[parseInt(this.title)]);
						//alert(this.clientWidth)
						
						var ean = this.parentNode.parentNode.attributes["wineEan"].value;
						Plus.Services.Wines.Carousel.ResponseProvider.AddWineRating(ean, this.title);
					}
				}
				//	===========

				//var footer = $(".plFooter");
				//var tail = $(footer).height() + $(footer).offset().top;
				//alert(tail);
				//$(footer).css({paddingBottom: $(document).height() - tail + 1 + "px"});
				//alert(tail);
				//$(".plWrapper").css({height: $(document).height() + 1 + "px"});
				
				//
				//alert($(document).height() - $(".plLinkFooter").height() - $(".plFooter").height() + "px");
				var deltaHeight = $(document).height() - $(".plLinkFooter").offset().top - $(".plLinkFooter").height() - $(".plFooter").height() - 90;
				//alert(deltaHeight);
				if (deltaHeight > 0) { $(".plLinkFooter").css({marginTop: deltaHeight + 1 + "px"});}
				

				
				/*var linkFooter = $(".plLinkFooter");*/

				var content = $(".plContent");
				var linkFooter = $(".plLinkFooter");
				var delta = $(linkFooter).offset().top - ($(content).offset().top + $(content).height());
				if (delta < 0) {
					// Need Adjustment
					//alert(delta);
					$(linkFooter).css({marginTop: -30 + "px"});
				}
				
				$(".plSelectionList li a").mouseover(function () {
					this.style.color = '#ffffff';	
					Cufon.replace(this, {fontFamily: 'Frutiger LT Std 700'});									   
				});
				
				$(".plSelectionList li a").mouseout(function () {
					if (this.parentNode.className.indexOf('plCurrent') < 0) {
						this.style.color = '#73003f';	
						Cufon.replace(this, {fontFamily: 'Frutiger LT Std 700'});
					}
				});
				
				initContent();
				
			});			
			
			/*$(window).resize(function() {
				$(".plWrapper").css({height: $(document).height() + 1 + "px"});									  
			});*/
			
			// Product Page Sluit Link Toggle
			$(".plSwitch").click(function() {
				$(".plSwitchContent").toggle();					 
				$(".plSwitch").toggleClass('plSwitchClosed');
			});
			
						// Big Buttons Hover Re-draw of the titles
			$(".plBigButton02").mouseover (function() {
				//Cufon.replace('.plBigButton02 em');										
			});
			
			$(".plBigButton02").click (function() {
				$(this).addClass(' plBigButton02Active');
				//Cufon.replace('.plBigButton02 em');										
			});
			
			$(".plBigButton02").mouseout(function() {
				//alert($(this).css("color"));
				//Cufon.replace('.plBigButton02 em');										
			});
			
			//Delete from orders list
			InitRemoveButton();
			
			// Taste Matrix
			initTasteMatrix();
			
			//Price selector
			initPriceSelector();
			
			
            // Sync Underlining

            $(".plPostItem h2 a").mouseover(function () {
            $(this).parents(".plPostItem").children(".plMoreLink").addClass("plMoreLinkHover");										
            });

            $(".plPostItem h2 a").mouseout(function () {
            $(this).parents(".plPostItem").children(".plMoreLink").removeClass("plMoreLinkHover");										
            });
			
            // Carousel
            initCarousel();
        
        
            var additionalDispatching = $(".plColumn001 .plAlternativeWrap");
		    if (additionalDispatching) { 
					bkgSign = $(additionalDispatching).attr("title");
					//alert(bkgSign);
					$(additionalDispatching).attr("title", "");
					var bkgOffsetY = 0;
					if (bkgSign == '00') {
						bkgOffsetY = 0;
					} else if (bkgSign == '10') {
						bkgOffsetY = (-1)*bkgHeight;
					} else if (bkgSign == '20') {
						bkgOffsetY = (-2)*bkgHeight;
					} else if (bkgSign == '30') {
						bkgOffsetY = (-3)*bkgHeight;
					} else if (bkgSign == '0b') {
						bkgOffsetY = (-4)*bkgHeight;
					} else if (bkgSign == '1b') {
						bkgOffsetY = (-5)*bkgHeight;
					} else if (bkgSign == '2b') {
						bkgOffsetY = (-6)*bkgHeight;
					} else if (bkgSign == '3b') {
						bkgOffsetY = (-7)*bkgHeight;
					}
					$(additionalDispatching).css({backgroundPosition: "85% " + bkgOffsetY + "px"});													
		      }
    		  
		      var moreAdditionalDispatchings = $(".plColumn002 .plAlternativeWrap");
		      //alert(moreAdditionalDispatchings.length);
		      for (var i=0; i < moreAdditionalDispatchings.length; i++) { 
					    bkgSign = $(moreAdditionalDispatchings[i]).attr("title");
					    //alert(bkgSign);
					    $(moreAdditionalDispatchings[i]).attr("title", "");
					    var bkgOffsetY = 0;
					    if (bkgSign == '00') {
						    bkgOffsetY = 0;
					    } else if (bkgSign == '10') {
						    bkgOffsetY = (-1)*bkgHeight;
					    } else if (bkgSign == '20') {
						    bkgOffsetY = (-2)*bkgHeight;
					    } else if (bkgSign == '30') {
						    bkgOffsetY = (-3)*bkgHeight;
					    } else if (bkgSign == '0b') {
						    bkgOffsetY = (-4)*bkgHeight;
					    } else if (bkgSign == '1b') {
						    bkgOffsetY = (-5)*bkgHeight;
					    } else if (bkgSign == '2b') {
						    bkgOffsetY = (-6)*bkgHeight;
					    } else if (bkgSign == '3b') {
						    bkgOffsetY = (-7)*bkgHeight;
					    }
					    $(moreAdditionalDispatchings[i]).css({backgroundPosition: "90% " + bkgOffsetY + "px"});													
		      }		  

            var topLis = $(".plMyTopList ul li");
            if (topLis[0]) {
                topLis[0].className = 'plSelect';
            }
            for (var i=0; i < topLis.length; i++) {
                if (Math.ceil(i%2)) {
                    topLis[i].className += 'plOdd';  
                }
            }

		}
	} );
} )(jQuery);

jQuery( function( $ ) {
	$.init(); // Inits content fixes
} );

function initTasteMatrix(){
    $(".plTasteMatrix > li > a").mouseover(function() {
	    //$(this).addClass('plActive');											
	    this.parentNode.className += ' plActive';
	    //alert(this.getElementsByTagName('ins')[0].innerHTML);
	    //alert($(this).attr('style'));
	    var styleValue = '';
	    styleValue = $(this).attr('style');
	    if (styleValue) { /*&& (styleValue.indexOf('blank.gif') < 0)*/ 
		    var innerHTML = $(this).children("ins").html();
		    $(".plCurrentWineName > div").html(innerHTML);
		    Cufon.replace('.plCurrentWineName > div');
	    }
    });


    $(".plTasteMatrix > li > a").mouseout(function() {
	    //$(this).removeClass('plActive');											
	    this.parentNode.className = this.parentNode.className.replace('plActive', '');
    });		

    $(".plTasteMatrix").mouseout(function() {
	    $(".plCurrentWineName > div").html('&nbsp;');								  
    });
			
	$(".plTasteMatrix > li > a").click(function() {
	    var sign = '!';
	    var $inp = $(this).children("input");
		var value = $inp.val();	
		if (value.charAt(0)==sign)
		    $inp.val(value.replace('!',''));
		else
		    $inp.val(sign.concat(value));					   				
	});
}

function initPriceSelector(){
	
    Cufon.replace('.plPriceMatrix > label');

	pl1Euro=$(".pl1Euro").length!=0?$(".pl1Euro"):$(".pl1EuroActive");
	pl1Euro.mouseover(function() {
	    label=$(".plEuroCheckLable")[0];
	    tempLabel=$(".pl1EuroCheckLable")[0];
	    label.className="plEuroCheckPopupLable";
	    text=label.innerHTML;
	    label.innerHTML=tempLabel.innerHTML;
	    tempLabel.innerHTML=text;
	});
	pl1Euro.mouseout(function() {
	    label=$(".plEuroCheckPopupLable")[0];
	    tempLabel=$(".pl1EuroCheckLable")[0];
	    label.className="plEuroCheckLable";
	    text=label.innerHTML;
	    label.innerHTML=tempLabel.innerHTML;
	    tempLabel.innerHTML=text;			
	});
	pl1Euro.click(function() {
	    $(".pl1EuroCheck")[0].click();
	    $(".plPriceRangeChange")[0].click();
	});

	
	pl2Euro=$(".pl2Euro").length!=0?$(".pl2Euro"):$(".pl2EuroActive");
	pl2Euro.mouseover(function() {
	    label=$(".plEuroCheckLable")[0];
	    tempLabel=$(".pl2EuroCheckLable")[0];
	    label.className="plEuroCheckPopupLable";
	    text=label.innerHTML;
	    label.innerHTML=tempLabel.innerHTML;
	    tempLabel.innerHTML=text;
	});
	pl2Euro.mouseout(function() {
	    label=$(".plEuroCheckPopupLable")[0];
	    tempLabel=$(".pl2EuroCheckLable")[0];
	    label.className="plEuroCheckLable";
	    text=label.innerHTML;
	    label.innerHTML=tempLabel.innerHTML;
	    tempLabel.innerHTML=text;			
	});
	pl2Euro.click(function() {
	    $(".pl2EuroCheck")[0].click();
	    $(".plPriceRangeChange")[0].click();
	});
	
	pl3Euro=$(".pl3Euro").length!=0?$(".pl3Euro"):$(".pl3EuroActive");
	pl3Euro.mouseover(function() {
	    label=$(".plEuroCheckLable")[0];
	    tempLabel=$(".pl3EuroCheckLable")[0];
	    label.className="plEuroCheckPopupLable";
	    text=label.innerHTML;
	    label.innerHTML=tempLabel.innerHTML;
	    tempLabel.innerHTML=text;
	});
	pl3Euro.mouseout(function() {
	    label=$(".plEuroCheckPopupLable")[0];
	    tempLabel=$(".pl3EuroCheckLable")[0];
	    label.className="plEuroCheckLable";
	    text=label.innerHTML;
	    label.innerHTML=tempLabel.innerHTML;
	    tempLabel.innerHTML=text;			
	});
	pl3Euro.click(function() {
	    $(".pl3EuroCheck")[0].click();
	    $(".plPriceRangeChange")[0].click();
	});
	
	Cufon.replace('.plAlternative .plBottlePrice', {fontFamily: 'Frutiger LT Std 700'});
}

function initCarousel(){
        stepsRight = 0;
		 $(".plCarrusel > ul > li").each(function () {
				$(this).addClass("plDispatched"); 											 
				// dispatch background image:
					bkgSign = $(this).attr("rel");
					//$(this).attr("title", "");
					var bkgOffsetY = 0;
					if (bkgSign == '00') {
						bkgOffsetY = 0;
					} else if (bkgSign == '10') {
						bkgOffsetY = (-1)*bkgHeight;
					} else if (bkgSign == '20') {
						bkgOffsetY = (-2)*bkgHeight;
					} else if (bkgSign == '30') {
						bkgOffsetY = (-3)*bkgHeight;
					} else if (bkgSign == '0b') {
						bkgOffsetY = (-4)*bkgHeight;
					} else if (bkgSign == '1b') {
						bkgOffsetY = (-5)*bkgHeight;
					} else if (bkgSign == '2b') {
						bkgOffsetY = (-6)*bkgHeight;
					} else if (bkgSign == '3b') {
						bkgOffsetY = (-7)*bkgHeight;
					}
					$(this).attr("rel", bkgOffsetY);
					$(this).css({backgroundPosition: "right " + bkgOffsetY + "px"});
		   });		  
		  
		  $(".plCarrusel > ul > li").mouseover(function () {
				if (this.className.indexOf('plChosen') < 0) { $(this).addClass("plHover"); } 											 
				// dispatch background image:
					bkgOffsetY = $(this).attr("rel");

					$(this).css({backgroundPosition: "0 " + bkgOffsetY + "px"});
					

		   });
		  
		  $(".plCarrusel > ul > li").click(function() {
					$(".plCarrusel > ul > li").each(function() {
						$(this).removeClass('plChosen');
						var bkgOffsetY = $(this).attr("rel");
						$(this).css({backgroundPosition: "right " + bkgOffsetY + "px"});		
					});
					var lis = $(".plCarrusel > ul > li");
					for (var i=0; i < lis.length; i++) {
						if (lis[i] == this) {
							$.getDetailsResponce(i);	
							break;
						}	
					}									
					$(this).addClass('plChosen');
					bkgOffsetY = $(this).attr("rel");
					$(this).css({backgroundPosition: "0 " + bkgOffsetY + "px"});					

		  });
		  
		   $(".plCarrusel > ul > li").mouseout(function () {
					if (this.className.indexOf('plChosen') < 0) {
					    var bkgOffsetY = $(this).attr("rel");
					    $(this).css({backgroundPosition: "right " + bkgOffsetY + "px"});
					}
		   });
			
		  if ($(".plCarrusel").length) { 
		  	var carouselItems = $(".plCarrusel > ul > li");
			var countedItems = carouselItems.length;
			

			$(".plCarruselPrev").addClass("plArrowDisabled");

			$(".plCarruselNext").click(function() {
				if (this.className != "plArrowDisabled") stepsRight++;

				if (stepsRight > 0) {
					$(".plCarruselPrev").removeClass("plArrowDisabled")
				} 
				if (stepsRight == countedItems-shownItems) {
					$(this).addClass("plArrowDisabled");
				}
				
				if($(this).hasClass("plArrowDisabled")!=true)
				{
				    itemIndex = shownItems+stepsRight+1;
				 
				    var itemsInCarousel = $('.plCarrusel ul > li');
				    //if(itemsInCarousel[itemIndex].innerHTML == '')
				    //{
				        Plus.Services.Wines.Carousel.ResponseProvider.GetCarouselItem(itemIndex, updateCarouselItem);
				    //}
				}
				
			});
			
			$(".plCarruselPrev").click(function() {
				if (this.className != "plArrowDisabled") stepsRight--;
				if (stepsRight == 0) {
					$(".plCarruselPrev").addClass("plArrowDisabled");
				}
				
				$(".plCarruselNext").removeClass("plArrowDisabled");
				
			});
		  
		  	$(".plCarrusel").jCarouselLite({
		        btnNext: ".plCarruselNext",
		        btnPrev: ".plCarruselPrev",
				circular: false//,
				/*mouseWheel: true*/
			});
			
			if ($(".plAlternative div").length) {
				$(".plAlternative div").each(function () {
				});
			}		
			
			$(".plCarrusel ul li .plAlternative > div").each(function () {
				if (this.className != 'plBottlePrice') {
					//alert(this.clientWidth);													 	
					//this.style.width = this.clientWidth*2 + "px";
					$(this).css('clip', 'rect(0px 139px 180px 0)');
					//$(this).css('marginLeft', '-19px');
				}
			});  
		  }
}

function updateCarouselItem(result) 
{
    if(result!=''){
        var itemsInCarousel = $('.plCarrusel ul > li');
        if(itemsInCarousel[itemIndex])
        {
            itemsInCarousel[itemIndex].innerHTML = result;
            Cufon.replace('.plAlternative .plBottlePrice', {fontFamily: 'Frutiger LT Std 700'});
        }
    }
}

function updateCarouselItemDetails(result) 
{
	if (result) {
		
		$(".plDetailedInfo table").hide();
		$(".plDetailedInfo").html(result);
		$(".plDetailedInfo table").hide();
		// Cufons
		Cufon.replace('.plDetailedInfo table tr td h3', {fontFamily: 'Frutiger LT Std 400'});
		Cufon.replace('.plCombinedInfo tr td h4 span', {fontFamily: 'Frutiger LT Std 100'});
		Cufon.replace('.plBigBottlePrice .plOldPrice', {fontFamily: 'Frutiger LT Std 100'});
		Cufon.replace('.plCombinedInfo tr td h4 strong');
		Cufon.replace('.plButtonPlus');
		Cufon.replace('.plButtonNext');
		Cufon.replace('.plButtonKept');				
		$(".plDetailedInfo table").show();
	}
}

function AddFavouriteWine(link)
{
    var ean = link.attributes["wineEan"].value;
    var sitecoreId = link.attributes["wineId"].value;
    Plus.Services.Wines.Carousel.ResponseProvider.AddFavouriteWine(ean, sitecoreId, WineAddedToFavourites);
}

function WineAddedToFavourites(result)
{
    if(result != '')
    {
        window.location = result; //redirect to login page to add favourite wine
    }
    else
    {
        //if response was empty then wine was added successfully
        var addButton = $('a.plButtonPlus');
        if(addButton)
        {
            addButton[0].innerHTML = "Bewaard";
            addButton[0].attributes["class"].value = "plButtonKept";
            Cufon.replace('.plButtonKept');
        }
    }
}

function RemoveFavouriteWine(link)
{
    var ean = link.attributes["wineEan"].value;
    itemToRemovePosition = link.attributes["position"].value;
    Plus.Services.Wines.Carousel.ResponseProvider.RemoveFavouriteWine(ean, WineRemovedFromFavourites);
    
}

function WineRemovedFromFavourites(result)
{
    if(result == '')
    {
        var position = parseInt(itemToRemovePosition);
        var divToRemove = $(".plDetailedInfo[position='"+position+"']");
        divToRemove.remove();
    }
}

function AddToOrderList(link)
{
    var ean = link.attributes["wineEan"].value;
    var sitecoreId = link.attributes["sitecoreId"].value;
    Plus.Services.Wines.Carousel.ResponseProvider.AddToOrderList(ean, sitecoreId, AddedToOrderList);
    
}

function AddedToOrderList(result)
{
    if(result!='')
    {
        $(".plColumn003 >ul").append(result);
        InitRemoveButton();
    }
}

function InitRemoveButton()
{
    $(".plKill").attr("href", "#null");
    $(".plKill").click(function() {
		var ean = this.attributes["wineean"].value;
        var sitecoreId = this.attributes["sitecoreId"].value;
        Plus.Services.Wines.Carousel.ResponseProvider.RemoveFromOrderList(ean, sitecoreId, RemovedFromOrderList);
        
        
        $(this.parentNode).remove();
	});
}
function RemovedFromOrderList(result)
{
    
}

function NoteAdded(result)
{
    //if note was added then result contains ean and date to display
    if(result!='')
    {
        var results = result.split(",");
        var ean = results[0];
        var date = results[1];
        
        //TODO: insert date
    }
}


