function update_leaflet(){
	// update which element is last
	$("#sidebar_merkzettel .last").removeClass("last");
	$("#sidebar_merkzettel .sidebar_element:last").addClass("last");

	// update count
	var count = $('a.delitem').length + 1;
	$('.num_articles').html("("+ count +")");
}




// show and hide elements in comparison chart (taken from old site)
function toggle_visibility(id) {
var e = document.getElementById(id);
if(e.style.display == 'block')
e.style.display = 'none';
else
e.style.display = 'block';
}

$(document).ready(function(){

	$('#list_merkzettel').load(http+"views/request_information/index.php");

	$("a.mainlogo").hover(function(event) {
			$("div.submenu").each(function(){
		  		$(this).hide();
		  	});
		  	$('#'+($(this).attr("rel"))).show();
		},
		function () {

      	}

	);


	$("a.menu").hover(function(event) {

			event.preventDefault();

			var active_menu=this.id;

			$(this).css("background-image","none");



			$("a.menu").each(function(){
				if (active_menu!=this.id) {
					if ($(this).css("background-image")=='none') {
		  				$(this).css("background-image","url("+http+"public/images/nav.gif)");
					}
				}
			});



			$('#'+($(this).attr("rel"))).show();

			var active=$(this).attr("rel");
			$("div.submenu").each(function(){
				if (active!=this.id) {
		  			$(this).hide();
				}
		  	});

		},
		function () {

      	}
     );

	// $("a.menu").mouseleave(function(event){
	//	$(this).css("background-image","url("+http+"public/images/nav.gif)");
	 //});



	var ajax_url = http+"inc/ajax.php";

	// add product to leaflet
	$(".addToList").click(function(event){

		event.preventDefault();
		
		pageTracker._trackEvent("Merkzettel", "ADD", $(this).attr("rel"));
		
		$(this).html('Produkt wurde hinzugef&uuml;gt');

		// leaflet is hidden on front page; make sure it is shown
		$("#sidebar_merkzettel").show();

		// add product to SESSION
		$.get(ajax_url, { name: $(this).attr("rel") }, function(data){

			// add product to list
			$("#sidebar_merkzettel .sidebar_bottom").before(data);

			// update dom
			update_leaflet();
			$('#list_merkzettel').load(http+"views/request_information/index.php");

		});

	});

	// remove product from leaflet (with event delegation)
	$("#sidebar_merkzettel").click(function(event){

		if($(event.target).hasClass("removeFromList")){

			event.preventDefault();

			var product = $(event.target).attr("rel");

			// remove product from SESSION
			$.get(ajax_url, { del: product });

			// remove product from DOM
			$(event.target).parents("div:first").remove();

			// update dom
			update_leaflet();
		}

	});

	// add shadow to elements with class "add_shadow"
	var shadow_wrapper 	= '<div class="shadow"></div>';
	var shadow_image	= '<img src="' + http + 'public/images/icon_shadow.gif" alt="" class="shadow" />';
	$(".add_shadow").wrapInner(shadow_wrapper);
	$("div.shadow").append(shadow_image);

	// remove style-attribut form Google Customized Search which messes up border and size in IE6+7
	$("#s").attr("style","");
	$("#s").blur(function(){
	    $(this).attr("style","");
	});

	// hide tooltip for help-icon leaflet
	$("#help_tip").hide();


	// tooltip for help-icon leaflet
	$("#help1").jHelperTip({
	 trigger: "click",
	 dC:"#help_tip1",
	 autoClose: true,
	 opacity: 0.9
	});


	//////FUNCITONS FROM MAIN.INC

	var tableToPrint = [];

		$("div#help1").hover(
			function () {
				$("#bedienelemente_blau").css("background-image","url("+ img_path +"bedienfelder_blau_hover.jpg)");
			},
			function () {
				$("#bedienelemente_blau").css("background-image","url("+ img_path +"bedienfelder_blau.jpg)");
			}
		);
		$("div#help1").hover(
			function () {
				$("#bedienelemente_rot").css("background-image","url("+ img_path +"bedienfelder_rot_hover.jpg)");
			},
			function () {
				$("#bedienelemente_rot").css("background-image","url("+ img_path +"bedienfelder_rot.jpg)");
			}
		);
		$("div#help1").hover(
			function () {
				$("#bedienelemente_lila").css("background-image","url("+ img_path +"bedienfelder_lila_hover.jpg)");
			},
			function () {
				$("#bedienelemente_lila").css("background-image","url("+ img_path +"bedienfelder_lila.jpg)");
			}
		);
		$("div#help1").hover(
			function () {
				$("#bedienelemente_orange").css("background-image","url("+ img_path +"bedienfelder_orange_hover.jpg)");
			},
			function () {
				$("#bedienelemente_orange").css("background-image","url("+ img_path +"bedienfelder_orange.jpg)");
			}
		);

		$('#english_box').mouseenter(function() {
			$('#english_box').css("background-position", "0px -21px");
			$('#english_box a').css("color", "#ffffff");
		});

		$('#english_box').mouseleave(function() {
			$('#english_box').css("background-position", "0px 0px");
			$('#english_box a').css("color", "#a7a8aa");
		});

		$('#impressum_box').mouseenter(function() {
			$('#impressum_box').css("background-position", "0px -21px");
			$('#impressum_box a').css("color", "#ffffff");
		});

		$('#impressum_box').mouseleave(function() {
			$('#impressum_box').css("background-position", "0px 0px");
			$('#impressum_box a').css("color", "#a7a8aa");
		});

		$('div.submenu > div.headerLinks > ul > li').each(function (index, domEle) {
			if($(domEle).closest('.submenu').css('display') != 'none') {
				$(domEle).children().each(function(index, domLink) {
					// Anker parsen
					var anker_link = domLink.href;
					var anker_split = anker_link.split("#top");
					$('#list_tables').append('<div style="float:left;width:300px;padding:5px;"><input class="addPrintMap" id="check'+anker_split[1]+'" type="checkbox" name="' + anker_split[1] + '" value="'+anker_split[1]+'">&nbsp;&nbsp;<label for="check'+anker_split[1]+'">' + domLink.innerHTML + '</label></div>');
				});
			}
		});
		$('#list_tables').append('<p style="clear:both;"></p><br><strong><a style="cursor:pointer;" id="printTables">Print selected tables</a></strong>');

		$('.addPrintMap').click(function() {
			cID = '#check' + $(this).val();
			if($(cID).is(':checked')) {
				tableToPrint.push($(this).val());
			} else if($(cID).is(':checked') == false) {
				for(i=0;i<tableToPrint.length;i++) {
					if(tableToPrint[i] == $(this).val()) {
						tableToPrint.splice(i, 1);
					}
				}
			}
		});
		$('#printTables').click(function() {
			$('#list_tables').append('<textarea id="printCache" style="display:none;"></textarea>');
			for(i=0;i<tableToPrint.length;i++) {
				var TabCode = $('#h' + tableToPrint[i]).html() + '<br>' +  $('#t' + tableToPrint[i]).html() + "<br />";
				$('#printCache').append(TabCode);
			}
			newwin = window.open(''+ http +'print.php', '_blank', 'width=860,height=600,scrollbars=yes,resizeable=yes');
		});



	$("#close_img_1").click(function () {
		  $("#list_news_main").slideUp();
		  $("#list_merkzettel_main").slideUp();
		  $("#druck_men").slideUp();
	});
	$("#close_img_2").click(function () {
		  $("#list_news_main").slideUp();
		  $("#list_merkzettel_main").slideUp();
		  $("#druck_men").slideUp();
	});
	$("#close_img_3").click(function () {
		  $("#list_news_main").slideUp();
		  $("#list_merkzettel_main").slideUp();
		  $("#druck_men").slideUp();
	});

	var nav = $('#nav').html();

	$('#nav_case').mouseleave(function(){
		$('.submenu').hide();
		$('#submenu_default').show();


		$("a.menu").each(function(){
			if ($(this).css("background-image")=='none') {
  				$(this).css("background-image","url("+http+"public/images/nav.gif)");
			}
		});

		//$('#nav').html(nav);
	});


});