var rootDir = get_url_root();

var frontSidebar = {
	init: function(){
		$("#locaties").bind("click", function(){
			frontSidebar.slideUpDown('#tags_locaties');
			frontSidebar.showHide("#locaties  .plus_image  .minus_image");
		});

		$("#merken").bind("click", function(){
			frontSidebar.slideUpDown('#tags_merken');
			frontSidebar.showHide("#merken  .plus_image  .minus_image");
		});

		$("#typen").bind("click", function(){
			frontSidebar.slideUpDown('#tags_typen');
			frontSidebar.showHide("#typen  .plus_image  .minus_image");
		});

		$("#decoratie").bind("click", function(){
			frontSidebar.slideUpDown('#tags_decoratie');
			frontSidebar.showHide("#decoratie  .plus_image  .minus_image");
		});
		$("#tags").bind("click", function(){
			frontSidebar.slideUpDown('#list_tags');
			frontSidebar.showHide("#tags  .plus_image  .minus_image");
		});

		$("#archief").bind("click", function(){
			frontSidebar.slideUpDown('#list_archief');
			frontSidebar.showHide("#archief  .plus_image  .minus_image");
		});
		$("#auteurs").bind("click", function(){
			frontSidebar.slideUpDown('#list_auteurs');
			frontSidebar.showHide("#auteurs  .plus_image  .minus_image");
		});
	},
	showHide: function(element){
		if($(element).css("display") == 'block' || $(element).css("display") == '' || $(element).css("display") == 'inline'){
			$(element).hide();
		}else{
			$(element).show();
		}
	},
	slideUpDown: function(element){
		if($(element).css("display")=='block' || $(element).css("display")==''){
			$(element).slideUp('slow');
		}else{
			$(element).slideDown();
		}
	}
}

var explanation = {
	init: function(){
		$("#expl_herkomst").bind("click", function(){
			explanation.slideUpDown("#expl_herkomst_p");
		});
		$("#expl_herkomst_p a.close").bind("click", function(){
			explanation.slideUpDown("#expl_herkomst_p");
		});

		$("#expl_informatie").bind("click", function(){
			explanation.slideUpDown("#expl_informatie_p");
		});
		$("#expl_informatie_p a.close").bind("click", function(){
			explanation.slideUpDown("#expl_informatie_p");
		});

		$("#expl_vervaardiging").bind("click", function(){
			explanation.slideUpDown("#expl_vervaardiging_p");
		});
		$("#expl_vervaardiging_p a.close").bind("click", function(){
			explanation.slideUpDown("#expl_vervaardiging_p");
		});


		$("#expl_datering").bind("click", function(){
			explanation.slideUpDown("#expl_datering_p");
		});
		$("#expl_datering_p a.close").bind("click", function(){
			explanation.slideUpDown("#expl_datering_p");
		});


		$("#expl_afkomst").bind("click", function(){
			explanation.slideUpDown("#expl_afkomst_p");
		});
		$("#expl_afkomst_p a.close").bind("click", function(){
			explanation.slideUpDown("#expl_afkomst_p");
		});

		$("#expl_afmeting").bind("click", function(){
			explanation.slideUpDown("#expl_afmeting_p");
		});
		$("#expl_afmeting_p a.close").bind("click", function(){
			explanation.slideUpDown("#expl_afmeting_p");
		});


		$("#expl_materiaal").bind("click", function(){
			explanation.slideUpDown("#expl_materiaal_p");
		});
		$("#expl_materiaal_p a.close").bind("click", function(){
			explanation.slideUpDown("#expl_materiaal_p");
		});

		$("#expl_draft").bind("click", function(){
			explanation.slideUpDown("#expl_draft_p");
		});
		$("#expl_draft_p a.close").bind("click", function(){
			explanation.slideUpDown("#expl_draft_p");
		});


		$("#expl_uploaden_hoofd").bind("click", function(){
			explanation.slideUpDown("#expl_uploaden_hoofd_p");
		});
		$("#expl_uploaden_hoofd_p a.close").bind("click", function(){
			explanation.slideUpDown("#expl_uploaden_hoofd_p");
		});


		$("#expl_uploaden_overig").bind("click", function(){
			explanation.slideUpDown("#expl_uploaden_overig_p");
		});
		$("#expl_uploaden_overig_p a.close").bind("click", function(){
			explanation.slideUpDown("#expl_uploaden_overig_p");
		});

		$("#expl_omschrijving").bind("click", function(){
			explanation.slideUpDown("#expl_omschrijving_p");
		});
		$("#expl_omschrijving_p a.close").bind("click", function(){
			explanation.slideUpDown("#expl_omschrijving_p");
		});

		$("#expl_merken").bind("click", function(){
			explanation.slideUpDown("#expl_merken_p");
		});
		$("#expl_merken_p a.close").bind("click", function(){
			explanation.slideUpDown("#expl_merken_p");
		});

	},
	showHide: function(element){
		if($(element).css("display") == 'block' || $(element).css("display") == '' || $(element).css("display") == 'inline'){
			$(element).hide();
		}else{
			$(element).show();
		}
	},
	slideUpDown: function(element){
		if($(element).css("display")=='block' || $(element).css("display")==''){
			$(element).slideUp('slow');
		}else{
			$(element).slideDown();
		}
	}
}

var topToolbar = {
	init: function(){
	 	if($("#header_options").length == 0) return;

	 	/* place wrappers */
		$("#header_options").after("<div id=\"header_options_aanmelden\"></div>");
		$("#header_options_zoeken").after("<div id=\"header_options_inloggen\"></div>");

	 	topToolbar.closeAll();
	 	topToolbar.fillWrappers();
	 	topToolbar.initPanes();

	 	if(document.location.hash == '#login'){
	 		topToolbar.closeAll('header_options_inloggen');
			$('#header_options_inloggen').slideToggle();
			window.scroll(0,0);
	 	}
	 	if(document.location.hash == '#aanmelden'){
	 		topToolbar.closeAll('header_options_aanmelden');
			$('#header_options_aanmelden').slideToggle();
			window.scroll(0,0);
	 	}
	},
	// place forms in wrappers and hijack forms with ajax
	fillWrappers: function(){
		// fill wrappers with forms and init forms
	 	//$.post(rootDir+"/users/register", null, function(view){
	 	// WM: aangepast voor directory view
	 	$.post(rootDir+"users/register", null, function(view){
			$("#header_options_aanmelden").html(view);
			ajaxFormSubmit.init("#UserRegisterForm", "#header_options_aanmelden");
		});
		//$.post(rootDir+"/users/login", null, function(view){
		// WM: aangepast voor directory view
		$.post(rootDir+"users/login", null, function(view){
			$("#header_options_inloggen").html(view);
			ajaxLogin.init("#UserLoginForm", "#header_options_inloggen");
		});
	},
	// init toggling forms
	initPanes: function(){
		// header aanmelden
		$("#butt_aanmelden, #footer_butt_aanmelden").bind("click", function(ev){
			topToolbar.closeAll('header_options_aanmelden');
			$('#header_options_aanmelden').slideToggle();
			window.scroll(0,0);
			ev.preventDefault();
		});

		// header inloggen
		$("#butt_inloggen, #link_inloggen,  #footer_butt_inloggen").bind("click", function(ev){
			topToolbar.closeAll('header_options_inloggen');
			$('#header_options_inloggen').slideToggle();
			window.scroll(0,0);
			ev.preventDefault();
		});

		// header zoeken
		$("#butt_zoeken").bind("click", function(ev){
			topToolbar.closeAll('header_options_zoeken');
			$('#header_options_zoeken').slideToggle();
			window.scroll(0,0);
			ev.preventDefault();
		});
	},
	closeAll: function(currentPane){
		if(currentPane != 'header_options_aanmelden') $("#header_options_aanmelden").hide();
		if(currentPane != 'header_options_inloggen') $("#header_options_inloggen").hide();
		if(currentPane != 'header_options_zoeken') $("#header_options_zoeken").hide();
	}
}

/*
	hijacks login form with ajax and redirects user after valid login
*/
var ajaxLogin = {
	formId: null,
	updateView: null,
	init: function(formId, updateView){
		if ($(formId).length == 0) return;
		if ($(updateView).length == 0) return;

		ajaxLogin.formId = formId;
		ajaxLogin.updateView = updateView;

		$(ajaxLogin.formId).submit(function(){
			var params = {};

			$(this).find("input[@checked], input[@type='text'], input[@type='hidden'], input[@type='password'], input[@type='submit'], option[@selected], textarea")
			.filter(":enabled")
			.each(function() { params[ this.name || this.id || this.parentNode.name || this.parentNode.id ] = this.value; });

			$("li.button").hide();
			$("li.loader").show();

			$.post(this.getAttribute("action"), params, function(view){
				$(ajaxLogin.updateView).html(view);
				ajaxLogin.loginCheck();
				$("li.button").show();
				$("li.loader").hide();
			});
			return false;
		});
		return this;
	},
	loginCheck: function(){
		$("#UserEmail").val("");
		$("#UserPassword").val("");
		$.post(rootDir+'users/checkUser', null, function(result){
			if(result.charAt(0) == "1"){
				window.location.href = rootDir+'profiles/edit';
			}else{
				ajaxLogin.init(ajaxLogin.formId, ajaxLogin.updateView);
			}
		});
	}
}

/*
	hijacks form submit with ajax
	this way you don't need javascript validation, because it's uses the backend validation (controller/action)
*/

var ajaxFormSubmit = {
	init: function(formId, updateView){
		if ($(formId).length == 0) return;
		if ($(updateView).length == 0) return;

		$(formId).submit(function(){
			var params = {};

			$(this).find("input[@checked], input[@type='text'], input[@type='hidden'], input[@type='password'], input[@type='submit'], option[@selected], textarea")
			.filter(":enabled")
			.each(function() { params[ this.name || this.id || this.parentNode.name || this.parentNode.id ] = this.value; });

			$("li.button").hide();
			$("li.loader").show();

			$.post(this.getAttribute("action"), params, function(view){
				$("li.button").show();
				$("li.loader").hide();
				$(updateView).html(view);
				ajaxFormSubmit.init(formId, updateView);
			});
			return false;
		});
		return this;
	}
}

var carousel = {
	activeImgId:null,
	init: function(){
		if($("#mycarousel").length == 0) return;
		jQuery("#mycarousel").jcarousel();
		$("#mycarousel li div img").click(function(){
				var params = this.className.split("_");
				var imgNr = params[1];
				var imgId = params[2];

				carousel.updateImageCounter(imgNr);
				var itemtype = $("#image_container").parent().attr("id");
				carousel.activeImgId = imgId;
				carousel.loadImage(itemtype);
			}
		);
	},
	updateImageCounter: function(imgNr){
		$("#active_image").html(imgNr);
	},
	showPreloader: function(){
		$("#active_img").html("<img src='"+rootDir+"img/carousel-loader.gif' id='ajax-loader' />");
	},
	loadImage: function(itemtype){
		carousel.showPreloader();
		if (itemtype == "artikel") {
			$.post(rootDir+"images/carouselImagePr/"+carousel.activeImgId, null, function(view){carousel.showImagePrint(view);});
		}
		else {
			$.post(rootDir+"images/carouselImage/"+carousel.activeImgId, null, function(view){carousel.showImage(view);});
		}
	},
	showImage: function(view){
		$("#active_img").html(view);
		$(".carousel_img").hide();
		$(".carousel_img").fadeIn('slow');
		popImage.init();
	},
	showImagePrint: function(view){
		$("#active_img").html(view);
		$(".carousel_img").hide();
		$(".carousel_img").fadeIn('slow');
		popImage.init();
	}
}

var carouselpr = {
	activeImgId:null,
	init: function(){
		if($("#mycarouselpr").length == 0) return;
		jQuery("#mycarouselpr").jcarousel();

		$("#mycarouselpr li div img").click(function(){
				var params = this.className.split("_");
				var imgNr = params[1];
				var imgId = params[2];

				carousel.updateImageCounter(imgNr);

				carousel.activeImgId = imgId;
				carousel.loadImage();
			}
		);
	},
	updateImageCounter: function(imgNr){
		$("#active_image").html(imgNr);
	},
	showPreloader: function(){
		$("#active_img").html("<img src='"+rootDir+"img/carousel-loader.gif' id='ajax-loader' />");
	},
	loadImage: function(){
		carousel.showPreloader();
		$.post(rootDir+"images/carouselImagePr/"+carousel.activeImgId, null, function(view){carousel.showImagePrint(view);}); 
	},
	showImagePrint: function(view){
		$("#active_img").html(view);
		$(".carousel_img").hide();
		$(".carousel_img").fadeIn('slow');
		popImage.init();
	}
}

var miniCarousel = {
	limit:3,
	init:function(wrapper, postUrl){
		if($("#"+wrapper).length == 0 || postUrl == null) return;
		miniCarousel.buildUI(wrapper, postUrl, 1);
	},
	buildUI: function(wrapper, postUrl, currentPage){
		$("#"+wrapper).append("<div class=\"navigation\"></div>");
		$("#"+wrapper+" .navigation").append("<a class=\"button_left\" id=\""+wrapper+"_prev\">&nbsp;</a>");
		$("#"+wrapper+" .navigation").append("<a class=\"button_right\" id=\""+wrapper+"_next\">&nbsp;</a>");

		$("#"+wrapper+"_prev").click(function() {
			currentPage--;
			$.post(postUrl+"/"+miniCarousel.limit+"/"+currentPage, null, function(view){
				$("#"+wrapper+" .canvas").html(view);
			});
			miniCarousel.updateUI(wrapper, postUrl, currentPage);
			return false;
		});

		$("#"+wrapper+"_next").click(function() {
			currentPage++;
			$.post(postUrl+"/"+miniCarousel.limit+"/"+currentPage, null, function(view){
				$("#"+wrapper+" .canvas").html(view);
			});
			miniCarousel.updateUI(wrapper, postUrl, currentPage);
			return false;
		});
		miniCarousel.updateUI(wrapper, postUrl, currentPage);
	},
	updateUI: function(wrapper, postUrl, currentPage){
		if(currentPage == 1){
			$("#"+wrapper+"_prev").hide();
		}else{
			$("#"+wrapper+"_prev").show();
		}

		if($("#"+wrapper+" .pagesCount").val() == currentPage){
			$("#"+wrapper+"_next").hide();
		}else{
			$("#"+wrapper+"_next").show();
		}

		if($("#"+wrapper+" .pagesCount").val() == 0){
			$("#"+wrapper+"_next").hide();
			$("#"+wrapper+"_prev").hide();
		}
	}
}

var tooltip = {
	init: function(selector){
		if($(selector).length == 0) return;

		$(selector).tooltip({
			track: true,
		    delay: 0,
		    showURL: false,
		    showBody: false,
		    extraClass: "pretty",
		    fixPNG: true,
		    fade: 250,
		    opacity: 0,
		    top:-150,
		    left: -500,
		    bodyHandler: function() {return "<p class='balloon'>Dit stuk is toegevoed door een thuis gebruiker en vormt geen onderdeel van de GM collectie</p>";}
		});
	}
}

var googleMap = {
	map: null,
	xmlUrl: rootDir+"locations/mapXml",

	init: function(){
		if (GBrowserIsCompatible()) {
			googleMap.map = new GMap2(document.getElementById("map-container"));
			googleMap.map.setCenter(new GLatLng(52.006336,4.364834), 13);
			googleMap.map.addControl(new GLargeMapControl());
			googleMap.map.addControl(new GMapTypeControl());
			googleMap.loadUrl();
		}
	},
	loadUrl: function(){
		GDownloadUrl(googleMap.xmlUrl, function(data) {
			var xml = GXml.parse(data);

			/* console.log(xml); */
			var markers = xml.documentElement.getElementsByTagName("marker");
			for (var i = 0; i < markers.length; i++) {

				var id = (markers[i].getAttribute("id") != null) ? markers[i].getAttribute("id") : "";
				var name = (markers[i].getAttribute("name") != null) ? markers[i].getAttribute("name") : "";
				var street = (markers[i].getAttribute("street") != null) ? markers[i].getAttribute("street") : "";
				var postcode = (markers[i].getAttribute("postcode") != null) ? markers[i].getAttribute("postcode") : "";
				var city = (markers[i].getAttribute("city") != null) ? markers[i].getAttribute("city") : "";
				var pdf = (markers[i].getAttribute("pdf") != null) ? markers[i].getAttribute("pdf") : "";
				var point = new GLatLng(parseFloat(markers[i].getAttribute("lat")),
				                        parseFloat(markers[i].getAttribute("lng")));

				var marker = googleMap.createMarker(point, id, name, street, postcode, city, pdf);
				googleMap.map.addOverlay(marker);

				if(marker.id == MyGoogleMap.active){
					googleMap.map.panTo(point);
					GEvent.trigger(marker,'click')
				}
			}
		});
	},
	createMarker: function(point, id, name, street, postcode, city, pdf) {
		var markerOpts = {};
		markerOpts = {
			"id": id,
			"clickable": true,
			"labelOffset": new GSize(-5, -9)
		};
		var marker = new GMarker(point, markerOpts);

		if(pdf != ""){
			var pdf = "<br/><b>Download geschiedenis:</b><br/><a class='pdf' href='"+rootDir+"files/upload/docs/location/pdf/"+pdf+"' target='_blank'>"+name+".pdf</a>"
		}

	   	var html = "<div class='gmap_contens'><h1>" + name + "</h1>" + street + "<br/>" + postcode + " " + city + pdf + "</div>";
	   	GEvent.addListener(marker, 'click', function() {
			marker.openInfoWindowHtml(html);
		});

	   return marker;
	 }
}

var paginate = {
	activePage: 1,

	init: function(){
		$(".search-page").hide();

		if($("#page_"+paginate.activePage)){
			$("#page_"+paginate.activePage).show();
		}

		if($("#pagination")){
			$("#pagination").show();

			var totalPages = $(".search-page");
			var pageCount = totalPages.length;

			for(var i=0; i<pageCount; i++){
				var active = (paginate.activePage == (i + 1)) ? 'class="active"' : '';
				var pLink = $("#pagination").append("<li><a href='#' "+active+" id='page_id_"+(i + 1)+"'>"+(i + 1)+"</a></li>");

				$("#page_id_"+(i + 1)).click(function(ev){
					var pageId = this.id.split("page_id_");

					$("#page_id_"+paginate.activePage).removeClass('active');
					$("#page_"+paginate.activePage).hide();

					$("#page_"+pageId[1]).fadeIn("slow");
					$(this).addClass('active');

					paginate.activePage = pageId[1];

					ev.preventDefault();
				});

			}
		}
	}
}

/* opens links with class pop_image in popup */
var popImage = {
	init: function(){
		if($(".pop_image").length == 0) return;
		$(".pop_image").click(function(ev){
			var imgSrc = $(this).attr("href");
			var imgPop = window.open("", "Popup", 'toolbar=0,location=0,directories=0,status=1,menubar=0,scrollbars=1,resizable=1,width=800,height=600');
			if (window.focus) {imgPop.focus()}
			imgPop.document.write('<html><head><title>Popup</title><link rel="stylesheet" href="'+rootDir+'css/reset.css"></head><body>');
			imgPop.document.write('<img src="'+imgSrc+'" />');
			imgPop.document.write('</body></html>');
			imgPop.document.close();
			ev.preventDefault();
		});
	}
}

$(document).ready(function(){
	/* looks at controller name and inits overviews */
	var urlProps = document.location.pathname.split('/');
	if(urlProps.toString().indexOf('items') != -1) autoComplete.init("#txt_search_input", rootDir+"items/view", "items");
	if(urlProps.toString().indexOf('news') != -1) autoComplete.init("#txt_search_input", rootDir+"news/view", "news");
	if(urlProps.toString().indexOf('brands') != -1) autoComplete.init("#txt_search_input", rootDir+"brands/view", "brands");
	if($("#map-container").length > 0) googleMap.init();

	/* init stuff */
	if($("#plaats").length > 0) explanation.init();
	thumbnails.init();
	formFiller.fill("#txt_search_input", "zoeken...");
	flashMessage.init(".flash");
	carousel.init();
	topToolbar.init();
	frontSidebar.init();
	tooltip.init('a.tooltip');

	printObj.addPrint(".print");
	popImage.init();
	addItem.init();

	miniCarousel.init("home_carousel1", rootDir+"items/miniCarousel/1");
	miniCarousel.init("home_carousel2", rootDir+"items/miniCarousel/2");
	miniCarousel.init("home_carousel3", rootDir+"items/miniCarousel/3");

	tabsManager.init("#tabs");
	if($("#tabs").length > 0) var $tabs = $('#tabs').tabs(); // first tab selected

	profile.init();

	if($("#add_comment_link").length > 0){
		$('#add_comment_link').click(function(ev) {
		    $tabs.tabs('select', 2);
		    $('#add_comment_link').hide();
		    return false;
		});
	}

	if($("#profile_tab_links").length > 0){
		$('#favorieten_link').click(function() {
		    $tabs.tabs('select', 0);
		    return false;
		});

		$('#reacties_link').click(function() {
		    $tabs.tabs('select', 2);
		    return false;
		});

		$('#stukken_link').click(function() {
		    $tabs.tabs('select', 1);
		    $("#plaats_stuk a").html("Nieuw stuk");
		    return false;
		});

	}

	$('#load').hide();

});

var profile = {
	init: function(){
		if($(".front_edit_link").length == 0) return;

		$(".front_edit_link").click(function(ev){

			var itemId = this.id.split("_");

			$("#plaats_stuk a").html("Bewerk stuk");
			ev.preventDefault();
			$.post(rootDir+"items/front_edit/"+itemId[1], null, function(view){
				$("#plaats").html(view);
				$('#plaats').ready(function() {
					window.scroll(0,0);
					$('#tabs').tabs('select', 4);
					editItem.init();
					delPhoto.init();
					explanation.init();
				});
			});



		});
	if($("#edit_stukken").length == 0) return;

		$("#edit_stukken").click(function(ev){
			$("#plaats_stuk a").html("Nieuw stuk");
			ev.preventDefault();
			$.post(rootDir+"items/front_add", null, function(view){
				$("#plaats").html(view);
				$('#plaats').ready(function() {
					window.scroll(0,0);
					$('#tabs').tabs('select', 1);
					editItem.init();
					explanation.init();
				});
			});



		});
		
	}
}

var addItem = {
	init: function() {
	$("#ItemFrontAddForm").submit(function() {

		var params = {};

		$(this).find("input[@checked], input[@type='text'], input[@type='hidden'], input[@type='password'], input[@type='submit'], option[@selected], textarea")
		.filter(":enabled")
		.each(function() { params[ this.name || this.id || this.parentNode.name || this.parentNode.id ] = this.value; });
		$.ajax({
			type: "POST",
			url: this.getAttribute("action"),
			data: params,
			cache: false,
			success: function(data){
				$('#plaats').fadeOut();
				endpos = data.indexOf("<!--");
				if (endpos > 0) {
					id = data.substr(0,endpos);
				}
				else {
					id = data;
				}
				$.post(rootDir+"items/front_edit/"+id, null, function(view){
					$("#plaats").html(view);
					$('#plaats').ready(function() {
						window.scroll(0,0);
						explanation.init();
						editItem.init();
						$("#plaats_stuk a").html("Edit stuk");
						$('#plaats').fadeIn("slow");
						flashMessage.init(".flash");
					});
				});
				$.post(rootDir+"profiles/front_overview", null, function(view){
					$("#stukken").html(view);
					delItem.init();
				});
			}
		});
	return false;
	});

	}
}

var editItem = {
	init: function() {
		$("#ItemFrontEditForm").submit(function() {
		var params = {};

		$(this).find("input[@type='hidden'], input[@type='text'], input[@type='checkbox'], input[@type='password'], input[@type='submit'], option[@selected], textarea")
		.filter(":enabled")
		.each(function() { params[ this.name || this.id || this.parentNode.name || this.parentNode.id ] = this.value; });

		$.ajax({
			type: "POST",
			url: this.getAttribute("action"),
			data: params,
			cache: false,
			success: function(data){
				$('#plaats').fadeOut();
				$.post(rootDir+"items/front_add", null, function(view){
					$("#plaats").html(view);
					addItem.init();
				});
				$.post(rootDir+"profiles/front_overview", null, function(view){
					$("#stukken").html(view);
					$("#plaats_stuk").removeClass('ui-tabs-selected');
					$('#stukken').ready(function() {
						window.scroll(0,0);
						$('#tabs').tabs('select', 1);
						$("#plaats_stuk a").html("Plaats stuk");
						$('#stukken').fadeIn("slow");
						delItem.init();
					});
				});
			}
		});
		return false;


	});

	}
}


var delPhoto = {
	init: function() {
	$(".delete_thumb").click(function() {
	$('#load').fadeIn();
	var thumbnail = $(this).parent();
	var id = $(this).attr("id");
	var string = '';
	$.ajax({
	   type: "POST",
	   url: rootDir+"images/delete/"+id,
	   data: string,
	   cache: false,
	   success: function(){
		thumbnail.slideUp('slow', function() {$(this).remove();});
		$('#load').fadeOut();
	  }

	 });

	return false;
	});

	}
}

var delItem = {
	init: function() {
	$(".delete").click(function() {
	$('#load').fadeIn();
	var item = $(this).parent();
	var id = $(this).attr("id");
	id = id.substr(4);
	var string = '';

	$.ajax({
	   type: "POST",
	   url: rootDir+"items/delete/"+id,
	   data: string,
	   cache: false,
	   success: function(){
		item.slideUp('slow', function() {$(this).remove();});
		$('#load').fadeOut();
	  }

	 });

	return false;
	});

	}
}