$(document).ready(function(){
	$('.productListOptions em').hide(); 
	$('.productListOptions a').hover(function(){
		//$(this).siblings('em').show();
		$(this).siblings('em').animate({ opacity: 'show' }, 'slow');
		//$(this).siblings('em').animate({ top: '-10px' }, 'slow');
		}, function(){
			$(this).siblings('em').animate({ opacity: 'hide' }, 'slow');
	});
	setTimeout("pictureFader()", 3000);
});
function getIdLastSelected() {
	var div = document.getElementById('ingredinetsActive');
	if ( !div.childNodes[0] ) {
		idString = false;
	}
	else {
		var li_obj = div.childNodes[0];
		var idString = li_obj.id;
	}
	//var myId = idString.slice(21, idString.length);
	return idString;
}

//callback function to bring a hidden box back
function callback(_id){
	setTimeout(function(){
		$("#"+_id+":hidden").removeAttr('style').hide().fadeIn();
	}, 1000);
};
function addToSelected2( _id ) {
	//aktuell selectetes removen 
	var lastId = getIdLastSelected();
	if ( lastId ) {
		removeFromSelected2(lastId);
	}
	var content = document.getElementById(_id);
	content.onclick = function onclick(event) {
		removeFromSelected2(_id);
	}
	var content = $('#'+_id);
	var options = {};
	$('#'+_id).effect('highlight',options,500);
	$('#'+_id).remove();
	content[0].innerHTML = content[0].innerHTML.replace("beilage_hinzu", "beilage_weg");	
	content[0].innerHTML = content[0].innerHTML.replace("ingredient_add", "ingredient_remove");	
	content[0].innerHTML = content[0].innerHTML.replace("type=checkbox", 'type="checkbox" checked="checked"');	
	content[0].innerHTML = content[0].innerHTML.replace('type="checkbox"', 'type="checkbox" checked="checked"');	
	$(content).prependTo("#ingredinetsActive");
}
function addToSelected( _id ) {
	var content = document.getElementById(_id);
	content.onclick = function onclick(event) {
		removeFromSelected(_id);
	}
	var content = $('#'+_id);
	var options = {};
	$('#'+_id).effect('highlight',options,500);
	$('#'+_id).remove();
	content[0].innerHTML = content[0].innerHTML.replace("ingredient_add", "ingredient_remove");	
	content[0].innerHTML = content[0].innerHTML.replace("type=checkbox", 'type="checkbox" checked="checked"');	
	content[0].innerHTML = content[0].innerHTML.replace('type="checkbox"', 'type="checkbox" checked="checked"');	
	//alert(content[0].innerHTML);
	$(content).prependTo("#ingredinetsActive");
}
function removeFromSelected2( _id ) {
	var content = document.getElementById(_id);
	content.onclick = function onclick(event) {
		addToSelected2(_id);
	}
	var content = $('#'+_id);
	var options = {};
	$('#'+_id).effect('explode',options,500,callback(_id));
	$('#'+_id).remove();	
	content[0].innerHTML = content[0].innerHTML.replace("beilage_weg", "beilage_hinzu");	
	content[0].innerHTML = content[0].innerHTML.replace("ingredient_remove", "ingredient_add");	
	content[0].innerHTML = content[0].innerHTML.replace('checked="checked"', '');	
	$(content).prependTo("#ingredinetsInactive");
}
function removeFromSelected( _id, _alert ) {
	if ( _alert ) {
		check = confirm("Wollen Sie diese Zutat wirklich entfernen?");
	}
	else {
		check = true;	
	}
	if ( check ) {
		var content = document.getElementById(_id);
		content.onclick = function onclick(event) {
			addToSelected(_id);
		}
		var content = $('#'+_id);
		var options = {};
		$('#'+_id).effect('explode',options,500,callback(_id));
		$('#'+_id).remove();	
		content[0].innerHTML = content[0].innerHTML.replace("ingredient_remove", "ingredient_add");	
		content[0].innerHTML = content[0].innerHTML.replace('CHECKED', '');	
		content[0].innerHTML = content[0].innerHTML.replace('checked="checked"', '');	
		//alert(content[0].innerHTML);
		$(content).prependTo("#ingredinetsInactive");
	}
}
function checkProductForm() {
	var okFlag = true, i = 0, j, k, foundFlag;
	var ulArray = $('.menueProductListing');		
	while ( okFlag == true && i < ulArray.length ) {	
		foundFlag = false;
		for ( j = 0; j < ulArray[i].childNodes.length; j++ ) {
			if(ulArray[i].childNodes[j].childNodes[0].checked) {
				foundFlag = true;
			}
		}
		if ( !foundFlag ) {
			okFlag = false;
			alert("Bitte wählen Sie aus");
		}
		i++;
	}	
	return okFlag; 
}
function updateCashpointPrice() {
	var floatString, realString;
	floatString = document.getElementById('cashpoint_fullPriceSave').value;
	/*floatString = document.getElementById('cashpoint_fullPriceFrontend').innerHTML;
	floatString = floatString.replace(',','.');*/
	floatString = parseFloat(floatString)
	
	if ( document.getElementById('cashpoint_plz').value != "9500" ) {
		floatString += 3;
		$("#cashpoint_plz_warning").fadeIn("slow");
	}
	else {
		$("#cashpoint_plz_warning").fadeOut("slow");
	}
	realString = unescape(floatString);
	//realString = realString.replace('.',',');
	document.getElementById('cashpoint_fullPrice').value = floatString;
	document.getElementById('cashpoint_fullPriceFrontend').innerHTML = shopFormat(realString)+".-";
}
function checkCashpointForm() {
	var okFlag = true;
	if ( document.getElementById('cashpoint_firstName').value == '' ) {
		alert("Bitte Vornamen eingeben");
		document.getElementById('cashpoint_firstName').focus();
		okFlag = false;
	}
	else if ( document.getElementById('cashpoint_lastName').value == '' ) {
		alert("Bitte Nachnamen eingeben");
		document.getElementById('cashpoint_lastName').focus();
		okFlag = false;
	}
	else if ( document.getElementById('cashpoint_address').value == '' ) {
		alert("Bitte Adresse eingeben");
		document.getElementById('cashpoint_address').focus();
		okFlag = false;
	}
	else if ( document.getElementById('cashpoint_phone').value == '' ) {
		alert("Bitte Telefonnummer eingeben");
		document.getElementById('cashpoint_phone').focus();
		okFlag = false;
	}
	else if ( document.getElementById('cashpoint_plz').value != "9500" ) {
		if ( document.getElementById('cashpoint_fullPrice').value < 25 ) {
			alert("Mindestbestellwert außerhalb Villachs: 25 €");
			okFlag = false;
		}
	}
	return okFlag;
}
function shopFormat(C) {
    var S = String(Math.round(C*100));
    while (S.length < 3) {
        S = "0" + S;
    }
    return S.replace(/(\d\d)$/, ",$1");
}
function displayIngredients() {
	//ingredients
	$("#description").fadeOut("slow");
	$("#ingredients").show("blind");
}

function pictureFader() {
	//alert("fade");
	var oldActive = activeImage;	
	$("#productImage"+oldActive).fadeOut("slow");
	activeImage++;
	if ( activeImage == numImages ) {
		activeImage = 0;
	}
	$("#productImage"+activeImage).fadeIn("slow");	
	
	setTimeout("pictureFader()", 3000);
}
function orderTomorrow() {
	alert("Wir nehmen zurzeit keine Bestellungen mehr an! Schauen Sie doch später nochmal vorbei.");
}
