
 $(document).ready(function(){
 
	$('#notification').hide();
	$('#notification-alert').hide();
	
	
	if ($('#subnav-wrapper').hasClass('lang-en')) {
		$('.product-action IMG').attr('title', 'For saving the product to the notepad click on the notepad icon; you will find your saved products on the page "Order/Inquiry".');
	} else {
		$('.product-action IMG').attr('title', 'Zum Merken des Produktes: Klicken Sie auf dieses Merkzettel-Icon. Sie sehen die gemerkten Produkte auf der Seite "Bestellung/Anfrage".');		
	}
		
	
 	if ($('BODY').hasClass('bestellung')) {
		// console.log('#printCookie');
		printCookie();
		$('#notification-alert').fadeIn(200);
 	}
 

	$('.product-action IMG').click(function() {
		if ($(this).parent().parent().find('.product-ref')) {
			var clickedRefNrStr = $(this).parent().parent().find('.product-ref').text();			
		} else {
			var clickedRefNrStr = '-';	
		}
		if ($(this).parent().parent().find('.product-name'))
		var clickedProductStr = stripHtmlTags($(this).parent().parent().find('.product-name').text());
		var clickedStr = clickedRefNrStr + '@' + clickedProductStr + '#'; 
		var oldCookieStr = $.cookie('ornamentum');

		if ((oldCookieStr === null)) {
			$.cookie('ornamentum', clickedStr, {path: '/'});
		} else {
			$.cookie('ornamentum', oldCookieStr + clickedStr, {path: '/'});
		}
		
		if ($('#subnav-wrapper').hasClass('lang-en')) {
			var outputStr = 'Product ' + clickedRefNrStr + ' saved';	
		} else {
			var outputStr = 'Produkt ' + clickedRefNrStr + ' auf Merkzettel abgespeichert';			
		}
		$('#notification').text(outputStr);
		$('#notification').slideDown(300).delay(1500).slideUp(300);
			
	});


	$('#notification-alert A').click(function() {
		emptyCookie();
		if ($('#subnav-wrapper').hasClass('lang-en')) {
			var outputStr = 'Product list deleted';	
		} else {
			var outputStr = 'Merkzettel geleert';			
		}
		$('#notification').text(outputStr);
		$('#notification').slideDown(300).delay(1500).slideUp(300);
		$('#notification-alert').fadeOut(600);
		
		return false;
	})
	

	
 });
 
 

printCookie = function() {
	var cookieStr = $.cookie('ornamentum'); 
	if (!cookieStr) return;
	var cookieArr = cookieStr.split('#');
	
	var cookieAnzahl = cookieArr.length;
	if (cookieAnzahl > 10) cookieAnzahl = 10;
	for (var i=0; i<cookieAnzahl; i++) {
		var aIndex = i+1;
		var refNr = cookieArr[i].split('@')[0];
		var produkt = cookieArr[i].split('@')[1];
		
		$('#referenz'+aIndex).val(refNr);
		$('#produkt'+aIndex).val(produkt);
	}
}
 
 

emptyCookie = function() {
	// console.log('#emptyCookie');
	$.cookie('ornamentum', null, {path: '/'}); 
}

stripHtmlTags = function(aString) {
	var outputStr = aString.replace(/(<([^>]+)>)/ig,""); 
	return outputStr;
}
