// JavaScript Document


// SIFR

if(typeof sIFR == "function"){
	sIFR.replaceElement(named({sSelector:"h1", sFlashSrc:"/fileadmin/develop/js/sifr/meta.swf", sWmode:"transparent", sColor:"#084279", sLinkColor:"#084279", sHoverColor:"#084279", sCase : "upper"}));	
};


// jquery.equalHeights

$(function(){ $('.equalboxes').equalHeights(120); });


// Jquery.Carousell
$(function() {
	$('.gastro-slide-fce').each(function() {
		$(this).find('.thumbnailImage').attr('src', $(this).find('.slide ul li img.thumbnail:eq(0)').attr('src'));
	});

    $(".slide div").each(function() {
		if ($(this).find('li').length <= 3) {
			$(this).parent().find('.next').hide();
			$(this).parent().find('.prev').hide();
		}
	
		$(this).jCarouselLite({
			btnNext: ".next",
			btnPrev: ".prev"
		});
	});
});

$.ui.dialog.defaults.bgiframe = true;
$(function() {
	$("#dialog-product").dialog({
		autoOpen: false,
		width: 400
	});	
	$('.openDialogProduct').click(function() {
		openProductDialog($(this));
	});
	
	$('#dialog-chargenumber').dialog({
		autoOpen: false
	});
	
	$('#chargeNumberInfoButton').click(function() {
		$('#dialog-chargenumber').dialog('open');
		return false;
	});
	
	$('.content-product-previous').click(function() {
		var aTag = $('.product-thumb li:eq(' + $(this).data('listIndex') + ') a');
		openProductDialog(aTag);
	});
	
	$('.content-product-next').click(function() {
		var aTag = $('.product-thumb li:eq(' + $(this).data('listIndex') + ') a');
		openProductDialog(aTag);
	});
	
	function openProductDialog(clickedATag) {
		var listElement = clickedATag.parent();
		
		$('.content-product-previous').hide();
		$('.content-product-next').hide();
		if (listElement.prev().length) {
			$('.content-product-previous').show();
			$('.content-product-previous').data('listIndex', $('.product-thumb li').index(listElement.prev()));
		}
		
		if (listElement.next().length) {
			$('.content-product-next').show();
			$('.content-product-next').data('listIndex', $('.product-thumb li').index(listElement.next()));
		}
	
		$('#dialog-product img.content-product-image').attr('src', clickedATag.find('img.big').attr('src'));
		$('#dialog-product span').html(clickedATag.find('span.text').html());
	
		$('#dialog-product').dialog('open');
		return false;
	}
});

$(function() {
	$('#dialog').hide();

	$("#dialog-info").dialog({
		autoOpen: false
	});	
	$('.openDialogInfo').click(function() {
		$('#dialog-info img').attr('src', $(this).find('img.big').attr('src'));
		$('#dialog-info').dialog('open');
		return false;
	});	
});

// product list image
$(function() {
	var defaultKeyvisual = $('#image-overlay-visual img').attr('src');
	
	// preload images
	$('.product-list li a').each(function() {
		imageObj = new Image();
		imageObj.src = $(this).attr('rel');
	});

	$('.product-list li a').hover(function() {
		var imageName = $(this).attr('rel');
		if ($.browser.msie) {
			$('#image-overlay-visual img').attr('src', imageName).show();
		}
		else {
			$('#image-overlay-visual img').stop().fadeTo('fast', 0, function() {
				$(this).attr('src', imageName).fadeTo('fast', 1);
			});
		}
	},
	function() {
		if ($.browser.msie) {
			$('#image-overlay-visual img').attr('src', defaultKeyvisual).show();
		}
		else {
			$('#image-overlay-visual img').stop().fadeTo('fast', 0, function() {
				$(this).attr('src', defaultKeyvisual).fadeTo('fast', 1);
			});
		}
	});
	
	$('h2.mB-30:empty').hide();
});

// gastro tip image gallery
$(function() {
	$('.gastro-slide-fce .slide ul li img').each(function() {
		$(this).data('fce', 1);
	});
	
	$('.slide ul li img').click(function() {
		if ($(this).data('fce') == 1) {
			$('.gastro-slide .thumbnailImage').attr('src', $(this).parent().find('img.thumbnail').attr('src'));
			$('.gastro-slide .thumbnailImage').data('fce', 1);
			$('.gastro-slide .thumbnailImage').data('largeImage', $(this).parent().find('img.large').attr('src'));
		}
		else {
			var imageName = $(this).attr('alt');
			$('.gastro-slide .thumbnailImage').attr('src', 'uploads/tx_carogastrotipp/thumbnail/' + imageName);
			$('.gastro-slide .thumbnailImage').attr('alt', imageName);
		}
	});
	
	$('.thumbnailImage').click(function() {
		if ($(this).data('fce') == 1) {
			$('#dialog img').attr('src', $(this).data('largeImage'));
		}
		else {
			var imageName = $(this).attr('alt');
			$('#dialog img').attr('src', 'uploads/tx_carogastrotipp/big/' + imageName);
		}
		
		$('#dialog').dialog({
			autopOpen: true
		});
		$('#dialog').dialog('open');
	});
});

// cocktail page
$(function() {
	var activeCocktail = null;
	$('.cocktailName').click(function() {
		if (activeCocktail != $(this).text()) {
			$('.cocktailName').parent().removeClass('active');
			$(this).parent().addClass('active');
			activeCocktail = $(this).text();
			var cocktailDetails = $(this).next('.cocktailDetails').html();
			if ($.browser.msie) {
				$('#cocktailDetail').html(cocktailDetails);
			}
			else {
				$('#cocktailDetail').stop().fadeTo('fast', 0, function() {
					$(this).html(cocktailDetails).fadeTo('fast', 1);
				});
			}
		}
	});
});

// Show & Hide der Formulare
function show(no){
	var nummer = no.options[no.selectedIndex].value;
	var count = no.options.length;

	for (i =1; i < count; i++) {
		document.getElementById('div' + i).style.display = 'none';

		if (nummer > 0) {
			document.getElementById('div' + nummer).style.display = 'block';
		}
	}
}
