$(function() {

		 var div = $('div.sc_menu'),               
		 ul = $('ul.sc_menu'),               
		// unordered list's left margin               
		ulPadding = 15;

	//Get menu width  
	var divWidth = div.width();  
	//Remove scrollbars
	div.css({overflow: 'hidden'});  
	//Find last image container  
	var lastLi = ul.find('li:last-child'); 
	//When user move mouse over menu  
	div.mousemove(function(e){  
						   //As images are loaded ul width increases,  
						   //so we recalculate it each time    
						   var ulWidth = lastLi[0].offsetLeft + lastLi.outerWidth() + ulPadding;
							var left = (e.pageX - div.offset().left) * (ulWidth-divWidth) / divWidth;
							div.scrollLeft(left);  
						   });



	

		$('.deleteclubblad').live('click', function() {
            
			var clubbladID=$(this).attr("id");
			$('#delyes').addClass(clubbladID);
			$.blockUI({ message: $('#delquestion'), css: { width: '275px' } }); 
        }); 
 
        $('#delyes').click(function() { 
            // update the block message 
            $.blockUI({ message: "<h3><img src='images/busy.gif' />Bezig met verwijderen...</h3>" }); 
 
 			var clubbladID=$(this).attr("class");       
			
			
			$.ajax({
					  type: "POST",
					  url: "maken/ajax/__deleteedition.php",
					  data: "w="+clubbladID,
					  success: function(msg){
						  window.location='index.php'; 
						  $.unblockUI();
					  }
					 });
		
							
			
        }); 
 
        $('#delno').click(function() { 
            $.unblockUI(); 
            return false; 
        }); 

		
		$('.searchengines').click(function() { 
			
			var ischecked=$('#searchenginecheckbox').attr('checked')
			if (ischecked==false) {
				$('#searchenginecheckbox').attr('checked', true);
			} else {
				$('#searchenginecheckbox').attr('checked', false);
			}
			$('#searchenginecheckbox').change();
			
		});

		$("#searchenginecheckbox").change(function(){
		   
		  		   
		   $('#ns_ondertitel').html("<img src='images/ajax_small.gif'> bezig met opslaan");
		   
		   var ischecked=$('#searchenginecheckbox').attr('checked')
		   var ns="y";
		   if (ischecked==false) {
				ns="n";
			} else {
				ns="y";
			}

		    $.ajax({
					  type: "POST",
					  url: "maken/ajax/__setsearchengine.php",
					  data: "ns="+ns,
					  success: function(msg){
						  
						  $('#ns_ondertitel').html("Uw club opnemen in zoekmachines?");
					  }
					 });
		   
		});


		$('.editclubblad').live('click', function() {
				
			  $.blockUI({ message: '<h3><img src="images/busy.gif" /> U wordt doorgestuurd naar de editor...</h3>' }); 						  
			  var clubbladID=$(this).attr("id");					
			  
			  
			  //alert(clubbladID);
			  
			  window.location='maken/index.php?clubbladID='+clubbladID+'&page=1';
		});
		
		$('.watchclubblad').live('click', function() {
		
			
			var clubbladID=$(this).attr("id");
			clubbladID=clubbladID.replace("clubblad", "");
			var urltoopen="http://www.clbs.nl/read/?"+clubbladID;
			window.open(urltoopen,""); 
			
		});
		
		
		$('.sendclubblad').live('click', function() {
										  
			var clubbladID=$(this).attr("id");
			$.blockUI({ 
			message: $('#mail'), 
            css: { 
                top:  ($(window).height() - 530) /2 + 'px', 
                left: ($(window).width() - 597) /2 + 'px', 
                width: '597px'
            	} 
        	});
		
		});
		
		$('.indexclubblad').live('click', function() {
			
			$.blockUI({ message: "<h3><img src='images/busy.gif' />Bezig met wijzigen...</h3>" }); 
			
			var clubbladID=$(this).attr("id");
			
			$.ajax({
					  type: "POST",
					  url: "maken/ajax/__googletoggle.php",
					  data: "w="+clubbladID,
					  success: function(msg){
						  //window.location='index.php'; 
						  //$.unblockUI();
						  if (msg=="y") {
							  $('div.indexclubbladresult').html("Klik om deze editie NIET in Google's zoekmachine op te nemen");
						  }
						  if (msg=="n") {
							  $('div.indexclubbladresult').html("Klik om deze editie WEL in Google's zoekmachine op te nemen");
						  }
						  
						  $.unblockUI();
						  
					  }
					 });
			
		});
		
		
		$('.home').click(function() {
								  
			window.location='index.php';
		});
		
		
		$('.register').click(function() {
			
			window.location='index.php?t=8&tn=Aanmelden';
			
		});
		
		$('.aanmelden').click(function() {
			<!-- ook bij #stap1 -->
			//$.blockUI({ 
            //message: $('#signin'), 
            //css: { 
             //   top:  ($(window).height() - 680) /2 + 'px', 
             //   left: ($(window).width() - 755) /2 + 'px', 
             //   width: '755px' 
            //	} 
        	//}); 
								   
		});
		$('.gegevenswijzigen').click(function() {
			<!-- ook bij #stap1 -->
			$.blockUI({ 
            message: $('#gegevens'), 
            css: { 
                top:  ($(window).height() - 680) /2 + 'px', 
                left: ($(window).width() - 715) /2 + 'px', 
                width: '715px' 
            	} 
        	}); 
								   
		});
		
		$('.demofilm').click(function() {
			$.blockUI({ 
            message: $('#instructiefilm'), 
            css: { 
                top:  ($(window).height() - 680) /2 + 'px', 
                left: ($(window).width() - 665) /2 + 'px', 
                width: '665px' 
            	} 
        	}); 
		});
		
		$('.opensuggesties').click(function() {
			$.blockUI({ 
            message: $('#suggestiesdiv'), 
            css: { 
                top:  ($(window).height() - 500) /2 + 'px', 
                left: ($(window).width() - 640) /2 + 'px', 
                width: '640px' 
            	} 
        	}); 
		});
		
		
		
		$('.refresh').click(function() {
			
			window.location='index.php';
										 
		});
		
		$('.closesignin').click(function() {
			
			$.unblockUI();
										 
		});
		
		
		/*
		$(".maghover").live('hover', function() {
			// Mouseover event
			$(this).addClass("highlightfloateven")

		},
		function(){
			// Mouse out event.
			$(this).removeClass("highlightfloateven")
		});
		*/
		
		
		$('.magfloater').live('click', function() {
			
			
			$("#editiemenu").hide();
			$("#editiemenubusy").show();
						
			$('.magfloater').removeClass("magselect");
			$('.magfloater').addClass("maghover");
						
			$(this).addClass("magselect");
			$(this).removeClass("maghover");
			
			
			
			var clubbladID="" + $(this).attr("id");
			
			
			
			$('.editclubblad').attr('id', clubbladID);
			$('.sendclubblad').attr('id', clubbladID);
			$('.copyedition').attr('id', clubbladID);
			$('.watchclubblad').attr('id', clubbladID);
			$('.indexclubbladresult').attr('id', clubbladID);
			$('.deleteclubblad').attr('id', clubbladID);
						
			$.ajax({
					  type: "POST",
					  url: "maken/ajax/__clubbladinfo.php",
					  data: "w="+clubbladID,
					  success: function(msg){
						  //window.location='index.php'; 
						  //$.unblockUI();
						  
						  /*
0 $data["ID"]."\n";
1 $data["clubID"]."\n";
2 $data["clubbladnr"]."\n";
3 $data["paginas"]."\n";
4 $data["kleur"]."\n";
5 $data["header"]."\n";
6 $data["wijzigingsdatum"]."\n";
7 $data["publiceerdatum"]."\n";
8 $data["clubblad_datum"]."\n";
9 $data["clubblad_actief"]."\n";
10 $data["clubblad_index"]."\n";
11 $data["clubblad_omschrijving"]."\n";
12 $stats
						  */
				
						  arr_data = msg.split("\n");
						  
						  if (arr_data[10]=="y") {
							  $('div.indexclubbladresult').html("Klik om deze editie NIET in Google's zoekmachine op te nemen");
						  } else {
							  $('div.indexclubbladresult').html("Klik om deze editie WEL in Google's zoekmachine op te nemen");
						  }
						  //<a href='#'>Deze editie bekijken</a
						  $('div.statsclubblad').html(arr_data[12]); // (statistieken)
						  
						  $('div.editclubbladbijtekst').html("Verder werken aan de laatst opgeslagen versie"); // (opgeslagen op "+arr_data[6]+")
						  
						  //$data["publiceerdatum"]
						  if (arr_data[7]!='' && arr_data[7]!='undefined') {
				
								//if ($data["clubblad_actief"]=="n") {
								if (arr_data[9]=="n") {
									
									//$('div.watchclubblad').html("<font color='red'>Publiceren van deze editie is niet voltooid!</font>");
								  	//$('div.watchclubbladbijtekst').html("Ga naar de editor en publiceer opnieuw");
									$('div.editiebekijken').hide();
									$('div.editiebekijkennietvoltooid').show();
									$('div.editiebekijkennietgepubliceerd').hide();
									$('div.versturenpossible').hide();
								  	$('div.versturennotpossible').show();
									$('div.editiestatistieken').hide();
									
								  	
									
								} else {
									
									$('div.watchclubblad').html("<a href='#'>Deze editie bekijken (gepubliceerd op "+arr_data[7]+")</a>");
	 							    $('div.editiebekijken').show();
									$('div.editiebekijkennietvoltooid').hide();
									$('div.editiebekijkennietgepubliceerd').hide();
									$('div.versturenpossible').show();
								  	$('div.versturennotpossible').hide();
									$('div.editiestatistieken').show();
									
								}
								
						  } else {
							  
							  //$('div.watchclubblad').html("Deze editie is nog niet gepubliceerd");
							  //$('div.watchclubbladbijtekst').html("Publiceren kan vanuit het menu als de editie voltooid is in de editor");
							  $('div.editiebekijken').hide();
							  $('div.editiebekijkennietvoltooid').hide();
							  $('div.editiebekijkennietgepubliceerd').show();
							  $('div.versturenpossible').hide();
  						  	  $('div.versturennotpossible').show();
							  $('div.editiestatistieken').hide();
							  
						  }
						  
						  
						  $("#editiemenubusy").hide();
						$("#editiemenu").show();
						  
						  
					  }
			
						
			
					 });
			
			
			
			
			
		});
		

		
		$('.newedition').click(function() {
		
				$.blockUI({ message: '<h3><img src="images/busy.gif" /> U wordt doorgestuurd naar de editor...</h3>' }); 
										
					// aanmaken
					$.ajax({
					  type: "POST",
					  url: "../maken/ajax/__newedition.php",
					   data: "act=new",
					  success: function(msg){
						 //alert(msg);
						  var clubbladID=msg;					
						  						  
						  window.location='maken/index.php?clubbladID='+msg;
						//  $.unblockUI();
					  }
					 });
		
										
		})
		
		$('.copyedition').click(function() {
		
				$.blockUI({ message: '<h3><img src="images/busy.gif" /> Bezig met kopieren; U wordt doorgestuurd naar de editor...</h3>' }); 
					
					var clubbladID="" + $(this).attr("id");
					
																						
					// aanmaken
					$.ajax({
					  type: "POST",
					  url: "../maken/ajax/__newedition.php",
					   data: "act=kopieren&cID="+clubbladID,
					  success: function(msg){
						  
						  // alert(msg);		 						  
						  if (msg=="error") {
							  alert("Er ging iets fout bij het kopieren...");
						  }
						  var clubbladID=msg;					
						  if (clubbladID=="") {
							  alert("Er ging iets fout bij het kopieren...");
						  } else {
							  window.location='maken/index.php?clubbladID='+msg;
						  }
						  //$.unblockUI();
					  }
					 });
		
										
		})
		
		
		
		
		
	});
	

	
	

	
	

