$(document).ready(function(){
		
	$(".menu_sortable").sortable({
		handle: $(".sortable_handle"),
		//items: $(".menu_sortable li"),
		cancel: $(".notsortable"),
		placeholder: 'sortable_placeholder',
		update: function(){
				newSave($(this).sortable('serialize'));
		}
	});
	
	$("#menu1sortable li:not(.notsortable),  #menu2sortable li:not(.notsortable)").mouseover(function(){
		$(this).css({ border:"1px #006ea5 solid"});
	}).mouseout(function(){
		$(this).css({ border:"1px #d2d9de solid"});
	});
	
	
	function newSave(serialized){
		$.ajax({
			url: "http://www.sportbedrijfamstelveen.nl/navigatie/volgordeopslaan",
			//url: "http://vertrigo/S/sportbedrijfamstelveen.nl/nieuwe_site/navigatie/volgordeopslaan",
			type: "POST",
			data: serialized,
			// complete: function(){},
			success: function(feedback){ setAjaxmsg('De volgorde is aangepast en opgeslagen.'); },
			error: function(feedback,e,b){alert(e+': '+b)}
		});
	}
	
	
//JS for navigation items index (changing order)
	$("#mainnav_index").sortable({
		handle: $(".mainsortable"),
		//items: $("#mainnav_index li"),
		cancel: $("#mainnav_index li.notsortable"),
		update: serializeMain
	});
	
	$("#mainnav2_index").sortable({
		//handle: $(".mainhandle"),
		update: serializeMain2
	});

	$(".subnav_index").sortable({
		//handle: $(".subhandle"),
		update: serializeSub
	});
	
	$(".opensub").click(function(){
		$(".subnav_div").removeClass("subvisible");
		$("#submenu"+$(this).attr('name')).addClass("subvisible");
	});
		
	function serializeMain(place){
		saveOrder($('#mainnav_index').sortable('serialize'));
	}
	
	function serializeMain2(){
		saveOrder($('#mainnav2_index').sortable('serialize'));
	}
	
	function serializeSub(){
		//alert($("#submenu"+$(".subvisible").attr('name')+' ul').sortable('serialize'));
		saveOrder($("#submenu"+$(".subvisible").attr('name')+' ul').sortable('serialize'));
	}
	
	function saveOrder(serialized){
		$.ajax({
			url: "http://www.sportbedrijfamstelveen.nl/navigatie/volgordeopslaan",
			//url: "http://vertrigo/S/sportbedrijfamstelveen.nl/nieuwe_site/navigatie/volgordeopslaan",
			type: "POST",
			data: serialized,
			// complete: function(){},
			success: function(feedback){ setAjaxmsg('De volgorde is aangepast en opgeslagen.'); },
			error: function(feedback,e,b){alert(e+': '+b)}
		});
	}
	
	function setAjaxmsg(msg){
		$("#ajaxreturn").html(msg);
		 $("#ajaxreturn").fadeIn('slow');
		 $("#ajaxreturn").animate({opacity: 1.0}, 3000);
		 $("#ajaxreturn").fadeOut('slow');
	}
	
//JS for input navigation items
	$("input[name='data[Navigation][menutype]']").click(function(){
		if($(this).attr('value')==0){
			$("#radioplace").show();
			$("#selectparentid").hide();
		}
		else if($(this).attr('value')==1){		
			$("#selectparentid").show();
			$("#radioplace").hide();
		}
	});
	
//JS for input datepickers
	$(".datepicker").datepicker({ dateFormat: 'dd-mm-yy' })

//JS for galleries
	$("#galleryorder").sortable({
		handle: $(".mainhandle"),
		placeholder: 'galleryorder-placeholder',
		update: saveGalleryOrder
	});
	
	function saveGalleryOrder(){
		var serialized = $("#galleryorder").sortable('serialize');

		$.ajax({
			url: "http://www.sportbedrijfamstelveen.nl/fotos/volgordeopslaan",
			//url: "http://vertrigo/S/sportbedrijfamstelveen.nl/nieuwe_site/fotos/volgordeopslaan",
			type: "POST",
			data: serialized,
			// complete: function(){},
			success: function(feedback){ setAjaxmsg('De volgorde is aangepast en opgeslagen.'); },
			error: function(feedback){alert(feedback)}
		});
	}
	
	$("ul#fotogalerie li").mouseover(function(){
		$(this).css({backgroundColor:"#f2f2f2"});
	}).mouseout(function(){
		$(this).css({backgroundColor:"#fff"});
	});
	
	$(".imgcontainer").mouseover(function(){
		$(this).css({border:"1px #006ea5 solid"});
	}).mouseout(function(){
		$(this).css({border:"1px #d2d9de solid"});
	});
	
//JS for images in gallery
	$("#imageorder").sortable({
		handle: $(".mainhandle"),
		//items: $(".imgcontainer"),
		placeholder: 'imgcontainer-placeholder',
		update: saveImageOrder
	});
		
	function saveImageOrder(){
		var serialized = $("#imageorder").sortable('serialize');
		
		$.ajax({
			url: "http://www.sportbedrijfamstelveen.nl/fotos/fotovolgordeopslaan",
			type: "POST",
			data: serialized,
			// complete: function(){},
			success: function(feedback){ setAjaxmsg('De volgorde is aangepast en opgeslagen.'); },
			error: function(feedback){alert(feedback)}
		});
	}
	
 	
	$(".showimage a[href*='galleries']").lightBox({
		imageLoading: 'http://www.sportbedrijfamstelveen.nl/img/lightbox/loading.gif',
		imageBtnClose: 'http://www.sportbedrijfamstelveen.nl/img/lightbox/closelabel.gif',
		imageBtnPrev: 'http://www.sportbedrijfamstelveen.nl/img/lightbox/prevlabel.gif',
		imageBtnNext: 'http://www.sportbedrijfamstelveen.nl/img/lightbox/nextlabel.gif',
		imageBlank: 'http://www.sportbedrijfamstelveen.nl/img/lightbox/blank.gif',
		txtImage: 'Foto',
		txtOf: 'van',
		fixedNavigation:true
	});
	
	$(".showimage").mouseover(function(){
		$(this).css({border:"1px #006ea5 solid"});
	}).mouseout(function(){
		$(this).css({border:"1px #d2d9de solid"});
	});
	
//JS for tooltips

	$('.tooltip').tooltip({   	
	    track: true, 
	    delay: 0, 
	    showURL: false, 
	    showBody: " - ", 
	    left: -120 
	}); 
	
//JS for subnavigation hover

	$("#submenu ul li:not(.subactive)").mouseover(function(){
		$(this).addClass("subactive");
	}).mouseout(function(){
		$(this).removeClass("subactive");
	});
	
//JS for newsitems hover

	$(".newsindex, #front_newsitems .item").mouseover(function(){
		$(this).css({backgroundColor:"#f2f2f2"});
	}).mouseout(function(){
		$(this).css({backgroundColor:"#fff"});
	});
	
	$(".newsindex, #front_newsitems .item").click(function(){
		window.location = 'http://www.sportbedrijfamstelveen.nl'+$(this).attr('name');
	});
	
});
