// JavaScript Document
$(document).ready(function() {
						   var cover = ""; //"Leder"
						   var paper = "";//"Schwarz"
						   var coverName = "";
						   var coverTitle ="";//"Gold"
						   var pages = 64;
						   var format = "Carre";
						   
						   cover = $(".coverMaterial img:first").attr("cover");
						   coverName = $(".coverMaterial img:first").attr("covername");
						   paper = $(".paper img:first").attr("paper");
						   coverTitle = $(".coverTitle img:first").attr("covertitle");
						   //alert(cover);
						   
						   //compute();
						   
						   function compute(){
							   $.get('inc/preise.xml', function(data) {

									//alert("test");
									var out1 = $(data).find('book').filter(function (index) {
										//var test = index.text();
										//alert(test);
						                  return $(this).attr("pages") == pages;
					                });
									//alert(out1.text());
									var out2 = out1.filter(function (index) {
						                  return $(this).attr("cover") == cover;
					                });
									//alert(out2.text());
									var out3 =  out2.filter(function (index) {
						                  return $(this).attr("format") == format;
					                });
									$('.total').html(out3.text() + "0 CHF");
							   });
						   }
						   
						   
						   $(".compute span[title='coverMaterial']").text(coverName);
						   $(".compute span[title='paper']").text(paper);
						   $(".compute span[title='coverTitle']").text(coverTitle);
						   
						   $(".coverMaterial img").click(function(){
							   								$("span[title='coverMaterial']").text($(this).attr("coverName"));
							   								cover = $(this).attr("cover");
							   								var picCover = "fileadmin/bilder/layers/" + $(this).attr("pic");
							   								$("img.material").attr("src",picCover);
							   								compute();
														   });
						   
						   $(".paper img").click(function(){
														   $("span[title='paper']").text($(this).attr("paper"));
														   paper = $("span[title='paper']").text();
														   var picPaper = "fileadmin/bilder/layers/" + $(this).attr("pic");
							   								$("img.vorsatz").attr("src",picPaper);
														   compute();
														   });
						   
						   $(".coverTitle img").click(function(){
							   								$(".compute span[title='coverTitle']").text($(this).attr("coverTitle"));
							   								var picTitle = "fileadmin/bilder/layers/" + $(this).attr("pic");
							   								$("img.text").attr("src",picTitle);
							   								compute();
														   });
						   
						   $("select[name='pages']").change(function () {
						          $("select[name='pages'] option:selected").each(function () {
						                pages = $(this).text();
						              });
						          //alert(pages);
						          compute();
						        })
						        .change();
						   
						   $("select[name='format']").change(function () {
						          $("select[name='format'] option:selected").each(function () {
						                //format = $(this).text();
                                                                format = $(this).val();
						              });
						          compute();
						        })
						        .change();

});
