jQuery(document).ready(function(){
	var speed=300;
		
	$('.product .price').css('opacity', '0.0');
	$('.productlist li.selected .productimage').css('opacity', '0.3');

	$('.product').hover(
		// mouseover
		function () {
			if (!$(this).hasClass('sold')) {
				$(this).find('.moreinfo').fadeIn(speed);
				if (!$(this).parent().parent().hasClass('selected')) {
					$(this).find('.productimage').animate({opacity: '0.3', speed: speed});
				}
				$(this).find('.price').animate({opacity: '1.0', speed: speed});
			}
		},
		// mouseout
		function () {
			if (!$(this).hasClass('sold')) {
				$(this).find('.price').animate({opacity: '0.0', speed: speed});
				if (!$(this).parent().parent().hasClass('selected')) {
					$(this).find('.productimage').animate({opacity: '1', speed: speed});
				}
				$(this).find('.moreinfo').fadeOut(speed);
			}
		}
	);

	$('ul.selectionlist li').hover(
		function() {
			id = $(this).children('img').attr('id');
			id = id.split('_');
			list = id[2];
			listitem = id[3];
			$('#selectionItem_'+list+'_'+listitem).fadeIn(speed);
		},
		function() {
			id = $(this).children('img').attr('id');
			id = id.split('_');
			list = id[2];
			listitem = id[3];
			$('#selectionItem_'+list+'_'+listitem).fadeOut(speed);
		}
	);

	$('ul.selectionlist li').click(
		function() {
			$(this).parent().children('li').removeClass('selected');
			$(this).addClass('selected');
			id = $(this).children('img').attr('id');
			id = id.split('_');
			list = id[2];
			listitem = id[3];
			$('#selectedSelectionItem_'+list).attr('src', $('#selectionItem_'+list+'_'+listitem).attr('src'));
			$('#selection_'+list).val(listitem);
			$('.tocart input.button').css('visibility', 'visible');
		}
	);
	
	$('ul.selectionlist2 li').hover(
		function() {
			id = $(this).children('img').attr('id');
			id = id.split('_');
			list = id[2];
			listitem = id[3];
			$('#selectionItem_'+list+'_'+listitem).fadeIn(speed);
		},
		function() {
			id = $(this).children('img').attr('id');
			id = id.split('_');
			list = id[2];
			listitem = id[3];
			$('#selectionItem_'+list+'_'+listitem).fadeOut(speed);
		}
	);

	$('ul.selectionlist2 li').click(
		function() {
			$(this).parent().children('li').removeClass('selected');
			$(this).addClass('selected');
			id = $(this).children('img').attr('id');
			id = id.split('_');
			list = id[2];
			listitem = id[3];
			$('#selectedSelectionItem_'+list).attr('src', $('#selectionItem_'+list+'_'+listitem).attr('src'));
			$('#selection_'+list).val(listitem);
			$('.tocart input.button').css('visibility', 'visible');
		}
	);

	$('#selection_hint a').click(function() {
		$('#selection_hint').fadeOut(speed);
	});
	
	$('select[name^=aproducts]').change(
		function() {
			id = $(this).attr('id');
			id = id.split('_');
			basketindex = id[3];
			$('#id_basketitem_select_image_'+basketindex).attr('src', $('#id_basketitem_select_image_'+basketindex).attr('src').replace($('#id_basketitem_select_image_'+basketindex).attr('title'), $(this).find(':selected').text()));
			$('#id_basketitem_select_image_'+basketindex).attr('alt', $(this).find(':selected').text());
			$('#id_basketitem_select_image_'+basketindex).attr('title', $(this).find(':selected').text());
		}
	);
	
	$('#checkall').change(
		function() {
			if ($(this).attr('checked')) {
				$('input[name^=aproducts]').attr('checked', true);
			}
			else {
				$('input[name^=aproducts]').attr('checked', false);
			}
		}
	);
	

	$('.samples').hover(
		// mouseover
		function () {
			elm = $(this).parent().children('.active');

			if (elm.attr('id') != undefined) {
				if ($(this).attr('id') != undefined) {
					if (elm.attr('id') != $(this).attr('id')) {
						// hide active
						sActiveId = elm.attr('id').replace(/th_/, '');
						$('#'+sActiveId).fadeOut('slow');
					
						// show current
						sNewId = $(this).attr('id').replace(/th_/, '');
						$('#'+sNewId).fadeIn('slow');
					}
				}
			}
		},
		// mouseout
		function () {
			elm = $(this).parent().children('.active');

			if (elm.attr('id') != undefined) {
				if ($(this).attr('id') != undefined) {
					if (elm.attr('id') != $(this).attr('id')) {
						// hide current
						sNewId = $(this).attr('id').replace(/th_/, '');
						$('#'+sNewId).fadeOut('slow');
					
						// show active
						sActiveId = elm.attr('id').replace(/th_/, '');
						$('#'+sActiveId).fadeIn('slow');
					}
				}
			}
		}
	);

   $('.samples').click(function() {
		elm = $(this).parent().children('.active');
		sNewId = $(this).attr('id').replace(/th_/, '');
		if (elm.attr('id') != undefined) {
			// hide active
			sActiveId = elm.attr('id').replace(/th_/, '');
			if (sActiveId != sNewId) {
				$('#'+sActiveId).fadeOut('slow');
			}
		}
		$('#'+sNewId).fadeIn('slow');

		$(this).parent().children().removeClass('active');
		$(this).addClass('active');
		
		return false;
   });


	$('.combi').hover(
		// mouseover
		function () {
			// hide active
			elm = $(this).parent().children('.active');

			if (elm.attr('id') == undefined) {
				if (elm.attr('id') != undefined) {
					sActiveId = elm.attr('id').replace(/th_/, '');
					$('#'+sActiveId).fadeOut('slow');
				}
				
				// show current
				sNewId = $(this).attr('id').replace(/th_/, '');
				$('#'+sNewId).fadeIn('slow');
			}
		},
		// mouseout
		function () {
			elm = $(this).parent().children('.active');

			if (elm.attr('id') == undefined) {
				// hide current
				sNewId = $(this).attr('id').replace(/th_/, '');
				$('#'+sNewId).fadeOut('slow');
				
				// show active
				if (elm.attr('id') != undefined) {
					sActiveId = elm.attr('id').replace(/th_/, '');
					$('#'+sActiveId).fadeIn('slow');
				}
			}
		}
	);

   $('.combi').click(function() {
		elm = $(this).parent().children('.active');
		sNewId = $(this).attr('id').replace(/th_/, '');
		if (elm.attr('id') != undefined) {
			// hide active
			sActiveId = elm.attr('id').replace(/th_/, '');
			if (sActiveId != sNewId) {
				$('#'+sActiveId).fadeOut('slow');
			}
		}
		$('#'+sNewId).fadeIn('slow');

		$(this).parent().children().removeClass('active');
		$(this).addClass('active');

		id = $(this).attr('id');
		id = id.split('_');
		index = id[3];
		$('#selection_0').val(index);
		$('#id_tocart').removeClass('vh');
		
		return false;
   });


}); 

function checkSelection() {
	if ($('#selection_0').val() == '') {
		$('#selection_hint').fadeIn(speed);
		return FALSE;
	}
	else {
		return TRUE;
	}
}
