var xiadstatic ; var yiadstatic ; var opiadstatic; var okay;


$("#mediumsizeimage").hide();
		
jQuery(document).ready(function() {

				
				var img1 = $("#thisbuildingimages").find("img").attr("src"); 
				if(img1){

					setheight_photobox();	
					//OP BD, VIEW EN VIEWFRIEND ZET 'IE DE MEDIUMSIZEIMAGE GOED
					initiate_viewpage1(); //thumbnail in vak plaatsen

					
					var a = location.href; var b = a.indexOf("/bd/");
					if(b!=-1){
						
						remarkablefactsbehavior();
						if(location.hash=="#buzz") $("#rf_toggle").trigger('click');
						}
					
					}
				var imgaddinfo = $("#thisbuildingimages2").find("img").attr("src"); 
				if(imgaddinfo){
					setheight_photobox();
					}

		if((navigator.userAgent).indexOf('Firefox') != -1){
			$("#up_tabmenu").css('top','106px');
			}

		if(window.location.pathname=='/' && window.location.hash=="#upload" ){

					$("#up_tabsearch").hide();
					$("#up_tabupload").show();
					$("#up_taborganize").hide();
					$("#up_tabuploada").addClass("up_active");
					$("#up_tabsearcha").removeClass("up_active");
			}

		if(window.location.pathname=='/'){
				var a = window.location.hash;
				var b = 0;
				if (a=="#searchinterior") b='search_tab2';
				if (a=="#searchpublicspace") b='search_tab3';
				if (a=="#searchclassics") b='search_tab4';
				if(b!=0){
					$("#search_content").load('/getsearch.php',{searchsubject: b}, function(){
					searchtabsbehavior();
					});	
				}
			}
	
		ub_refreshbehavior();
		ub_refreshbehaviorpublish();
		ub_refreshbehaviorpublish3();
		ub_refreshbehavioraccess();
		searchtabsbehavior();
		invitations_refreshbehavior();
		setphotoxsize_nonview();
		autocomplete();


			
}); 	

$(function() {
	$(window).scroll(function(){
		b = 109;
		if((navigator.userAgent).indexOf('Firefox') != -1) b=106;	
		var a = b - $(window).scrollTop();
		
		$("#up_tabmenu").css("position","fixed").css("top",a + 'px');
		$(".premiumaccount").css("position","fixed").css("top",a + 5 + 'px');
		
		}); 

	});


$(window).load(function() {
		var img1 = $("#thisbuildingimages").find("img").attr("src"); 
		if(img1){		
			initiate_viewpage2();
			}

		var pos = $(".lastdiv").offset(); var h = parseInt($(".lastdiv").css("height")); 
		var i = 0 ; var j = ($("#footer").length) ; 
		if(j!=0){
			i = parseInt($("#footer").css("height")) + 6;
			}	
			
		var wh = getWidthHeight(); wh = wh[1];		
		var nh = wh - pos.top - h - i - 24 ;

		if(nh>0){
		var str = '<div class="rightdivthumbs divcolors" style="height:' + nh + 'px; border:1px solid gray"></div>';
		$(".right").append(str);	
		$(".right2").append(str);
		}
	
       $(".enlarge").click(function(){	
			var img1 = $(this).attr("src");
			enlarger(img1);		
			//$.post("/stats.php",{type: 'photo'});
		return false;
	   });	  

       $("#mediumsizeimage").mousewheel(function(event, delta, deltaX, deltaY){	

			if(delta>0) $(".stuffinimage").hide();
			if(delta<0) $(".stuffinimage").show();

		return false;
	   });		   
	   
 }); //einde van window load





function getWidthHeight(){
	if (document.body && document.body.offsetWidth) {
	 winW = document.body.offsetWidth;
	 winH = document.body.offsetHeight;
	}
	if (document.compatMode=='CSS1Compat' &&
		document.documentElement &&
		document.documentElement.offsetWidth ) {
	 winW = document.documentElement.offsetWidth;
	 winH = document.documentElement.offsetHeight;
	}
	if (window.innerWidth && window.innerHeight) {
	 winW = window.innerWidth; 
	 winH = window.innerHeight;
	}
	
	var a = new Array(); a[0] = winW ; a[1] = winH;
	return(a);
}


function checkmediumsizeimage(){
/*
	$("#thisbuildingimages p").remove();

	$(function() {
		$("#mediumsizeimage").error(function(){
			$("#thisbuildingimages p").remove();
			$("#thisbuildingimages").append('<p>the screen size version of this image is not available. If you have just uploaded it it might be still under construction.</p>');
		});
	});
*/
}

// FORMS
jQuery(document).ready(function() {
	$("#registerForm").validate({
			rules: {
				firstname: "required",
				lastname: "required",
				occupation: "required",
				country: "required",
				screenname: {
					required: true,
					minlength: 3,
					remote:{
							url: "/registercheck.php",
							type: "post",
							dataType: "json",
							data: {
								val: function() {
									return $("#screenname").val();
								},
								id:'screenname'

							}
						  }
				},
				password: {
					required: true,
					minlength: 8
				},
				confirm_password: {
					required: true,
					minlength: 8,
					equalTo: "#password"
				},
				
				email: {
					required: true,
					email: true,
					remote:{
							url: "/registercheck.php",
							type: "post",
							dataType: "json",
							data: {
								val: function() {
									return $("#email").val();
								},
								id:'email'

							}
						  }
				},
				
				agree: "required"
			},
			messages: {
				firstname: "Please enter your firstname",
				lastname: "Please enter your lastname",
				occupation: "Enter a description of your occupation.",
				country: "Select a country from the list.",
				screenname: {
					required: "Please enter a screenname",
					minlength: "Your screenname must consist of at least 3 characters",
					remote: "Sorry, this screenname is already taken by another user. Please choose an alternative one."
				},
				password: {
					required: "Please provide a password",
					minlength: "Your password must be at least 8 characters long"
				},
				confirm_password: {
					required: "Please provide a password",
					minlength: "Your password must be at least 8 characters long",
					equalTo: "Please enter the same password as above"
				},
				email: {
					required: "Please provide an email address",
					//email: "Please enter a valid email address",
					remote: "Sorry, this email is in our database already. Probably you created an account before. If you have lost your password you can get a new one via the login form ('forgot password')."
					},
				agree: "You need to accept our policy"
			}
		});	
		
		
	$("#contactform").validate({
		rules: {
			naam: "required",
			//adres: "required",
			//telefoon: "required",			
			email: {
				required: true,
				email: true

			},			
			bericht: "required",
			check: "required"
		},
		messages: {
			naam: "Type your name",
			//adres: "Wat is uw adres?",
			//telefoon: "Hoe kunnen we u bereiken?",


			email: {
				required: "Type your email address",
				email: "This email address is not valid. Please retype."
				},
			bericht: "This field is obligatory.",
			check: "This field is obligatory. It prevents our email being spammed by automated mailsenders."
		}
	});

	$("#rec_text").charCounter(240);
	
	$("#recommendationForm").validate({
		rules: {
			rec_text: {
				required: true,
				minlength: 30
				},
			rec_name: "required"

		},
		messages: {
			rec_text: {
				required: "A text is required",
				minlength: "Your text needs to have at least 30 characters. "
				},
			rec_name: "Your full name is required"

		}
	});
	
	$("#shoutbox").validate({
		rules: {
			name: "required",		
			comment: "required"
		},
		messages: {
			name: "Type your name",
			comment: "Type a comment."
		}
	});

		
});	



$(function() {
	$(".downloadhighres_noaccess2").click(function(){
		var a = confirm("To download the high resolution versions of images you need a free premium account. Would you like to register?" );
		if(a==true) window.location="/register";
		});

	});

$(function() {
	$(".downloadhighres_noaccess3").click(function(){
		var a = confirm("With a (free) premium account you can download the original resolutions. You can upgrade your account by helping us promote the site. Would you like to?" );
		if(a==true) window.location="/bonusprogram";
		});

	});
	
$(function() {
	$(".downloadhighres_noaccess4").click(function(){
		alert("You need to register to get access to this content." );
		});

	});	

	
$(function() {
	$(".beedit, .regbutton, .adstyle, .iadstatic, .enlarge, .uploadbar2, .hoverthing").hover(
			function(){
				$(this).css('cursor','pointer');
			},
			function(){
				$(this).css('cursor','none');
			} 	
		); 
	});	

//ALLES OVER DE TABS VAN DE SEARCH TABLE
function searchtabsbehavior(){

		$("#search_tabmenu a").click(function(){
				$("#search_content").html('');	
				var a = $(this).attr('id'); 
				$("#search_content").load('/getsearch.php',{searchsubject: a}, function(){
				searchtabsbehavior();

				});			
			}); 
		
		$(function() {
			$("#addcompany").click(function(e){
					addcompany_makecontent(e);
					});
				});	

		$("#searchboxreset").click(function() {
			$.post("/searchboxreset.php", {id: 1}, function(data){	
				location.reload(true);	
				});
			});

		$(".searchtable input, #descr_country").change(function(){
			var field = $(this).attr('name');
			var value = $(this).val();
			$.post("/searchboxreset.php", {id: 2, field:field, value:value}, function(data){	

				});

			})
			
				
		activatehoverthing();
		autocomplete();

	
}	
	
	
$(function() {
	$("#up_tabsearcha").click(function(){
		$("#up_tabsearch").show();
		$("#up_tabupload").hide();
		$("#up_taborganize").hide();	
		$("#up_tabupload1").show();
		$("#up_tabupload2").hide();	
		$("#up_tabupload3").hide();		
		
		}); 
		return false;
	});


	$(function() {
		$("#up_tabuploada").click(function(){
			$("#up_tabsearch").hide();$("#up_tabsearcha").removeClass("up_active");
			$("#up_tabupload").show();$("#up_tabuploada").addClass("up_active"); $(".up_note").css('filter','none');
			$("#up_taborganize").hide();	
			}); 
			return false;
		});



$(function() {
	$("#up_uploadnext1, #up_uploadprevious1").click(function(){
		$("#up_tabupload1").hide();
		$("#up_tabupload2").show();	
		$("#up_tabupload3").hide();			
		}); 
		return false;
	});

$(function() {
	$("#up_uploadnext2").click(function(){
		$("#up_tabupload1").hide();
		$("#up_tabupload2").hide();	
		$("#up_tabupload3").show();		
		}); 
		return false;
	});	

$(function() {		
		$(".ub_introbutton, .ub_introfloat h2, .ub_introfloatright").hover(function(){
			$(this).css('cursor','pointer');
			},
			function(){
			$(this).css('cursor','none');				
			});
	});

function invitations_refreshcontent(){
		$.post("/invitationsajax.php", {actie: 'refresh'}, function(data){
			$('.generalformcontainer').replaceWith(data);
			invitations_refreshbehavior();
			});	
}	
	
function invitations_refreshbehavior(){
	$("#invitationemail").click(function(){
		if($(this).val()=='type email address') $(this).val('');
		});
	
	$("#addinvitation").click(function(){
		var email = $("#invitationemail").val(); 
		$("#addinvitation").unbind("click");
		$.post("/invitationsajax.php", {actie: 'create', email: email}, function(data){
			//successful invitation, mailaddress is valid and unknown
			if(data==1){
				alert('An invitation to join has been sent. You will get extra diskspace once this invitation has been accepted. ');
				invitations_refreshcontent();
				}else{
					//unsuccessful
					if(data=='The person with this email already subscribed. '){
					//The person is a member already and we're trying to add him as friend
						var a  = confirm(data + 'Would you like to indicate him or her as friend and give access to your unpublished images?');
						if(a==true){
							$.post('/accessajax.php', {actie: 'addemail', email: email}, function(data){
								if(data==0) alert("This is not a valid email address.");
								if(data==1) alert("An invitation has been sent to " + email + '.');
								if(data==2) alert("You can't add yourself to your share list. ");
								if(data==3) alert("This person is already in your share list. ");
								invitations_refreshcontent();
								});							
							}else{
								invitations_refreshcontent();
								}
						}else{
							//there are other reasons, mail is on blacklist, email was not set well, email not valid, person already invited
							alert(data);
							}
					}
			});
		});

}	
	
function ub_refreshcontentaccess(){
	$.post('/accessajax.php', {actie: 'refresh'}, function(data){
		$(".up_paper").html();
		$(".up_paper").html(data);
		ub_refreshbehavioraccess();
		});	
	}
	
function ub_refreshbehavioraccess(){
	$(".ub_accessdeleteemail").click(function(){
			var email = $(this).prev().html(); 
			$.post('/accessajax.php', {actie: 'deleteemail', email: email}, function(data){
				ub_refreshcontentaccess();
				});	
		});
		
	$(".ub_accessdeletedomain").click(function(){
			var domain = $(this).prev().html();  alert(domain);
			$.post('/accessajax.php', {actie: 'deletedomain', domain: domain}, function(data){
				ub_refreshcontentaccess();
				});	
		});

	$("#ub_accessnewemailbutton").click(function(){
			var email = $("#ub_accessnewemail").val(); 
			$.post('/accessajax.php', {actie: 'addemail', email: email}, function(data){
				if(data==0) alert("This is not a valid email address.");
				if(data==2) alert("You can't invite yourself.");
				if(data==3) alert("You already added this person to the list.");
				ub_refreshcontentaccess();
				});	
		});
				
	$("#ub_accessnewdomainbutton").click(function(){
			var domain = $("#ub_accessnewdomain").val(); 
			$.post('/accessajax.php', {actie: 'adddomain', domain: domain}, function(data){
				if(data==0) alert("This is not a valid domain.");
				ub_refreshcontentaccess();
				});	
		});		
	}	

function addcompany_makecontent(e){
	var ypos = e.pageY - 240;
	$('body').append("<div id='addcompanycontent' class='shadow3' style='position:fixed; top:" + ypos + "px; left:" + e.pageX + "px; width:300px; min-height:300px; background-color:white'></div>");
	$.post('/addcompanyajax.php',{actie: 'getcontent'}, function(data){
		$("#addcompanycontent").html(data);
		addcompany_refreshbehavior();
		});
}
	
function addcompany_refreshbehavior(){
	$(".addcompanyhide").hide();
	$("#addcompanycontentsearch").click(function(){
		var term = $("#addcompanycontentsearchterm").val();
		
		if(term.length>2){
			$.post('/addcompanyajax.php',{actie: 'search', term: term}, function(data){		
				$("#addcompanycontentsearchresults").html(data);
				var str = data.substring(0, 3);
				if(str!='The'){
					//$(".addcompanyhide").show();
					var v = 'add "' + $("#addcompanycontentsearchterm").val() + '"';
					$("#addcompanycontentadd").attr('value',v);
					addcompany_refreshbehavior();
					activatehoverthing();
					}
				});
			}else{
				alert("type at least 3 characters");
				}

		});

	$("#addcompany_showhiddendiv").click(function(){

		if($(".addcompanyhide").css('display')=='block'){
			$(".addcompanyhide").hide();
			}else{
				$(".addcompanyhide").show();
				$("#addcompany_showhiddendiv").hide();
			}
		});
		
	$("#addcompanycontentadd").click(function(){

		var term = $("#addcompanycontentsearchterm").val();
		var sum = $("#addcompanycontentsum").val();


		if(sum==2 || sum=='two'){
		
			$.post('/addcompanyajax.php',{actie: 'add', term: term}, function(data){
				if(data!=''){
					$("#addcompanycontent").html('');
					$("#addcompanycontent").html(data);
					addcompany_refreshbehavior();
					activatehoverthing();

					}

				});
			}else{
				if(sum==''){
					alert("answer the question first");
					}else{
						alert("that's the wrong answer");
						}
				}

		});	
		
	$(".addcompanycontentclose").click(function(){
			$("#addcompanycontent").remove();
			});

		
}

function activatehoverthing(){
	$(".hoverthing").hover(
			function(){
				$(this).css('cursor','pointer');
			},
			function(){
				$(this).css('cursor','none');
			} 	
		);  
}
	
function ub_refreshbehaviorpublish3(){

			$("#ub_publishtabs").tabs();
			
			$("#ub_publishtabs p").click(function(){
				$(this).toggleClass("ub_markedtext");
				var tags = '';
				$(".ub_markedtext").each(function(){
					var id = $(this).attr('id');
					var temp = id.split("ar"); id = temp[1];				
					tags = tags + id + ',';
					});
				tags = tags.substring(0, tags.length-1);
				$.ajax({
					url: '/publishajax.php', 
					data: {actie: 'settags', tags: tags}, 
					async: false				
					});
				});			
			
			$("#ub_publishnext3").click(function(){
					$(".ub_publish").css('display','none');
					$("#ub_publish4").css('display','block');
					});
			$("#ub_publishprevious3").click(function(){
					$(".ub_publish").css('display','none');
					$("#ub_publish2").css('display','block');
					});
				
			activatehoverthing();						
	}	
	
	
	
function ub_refreshbehaviorpublish(){

			$(".ub_thumborder img").each(function(){
				$(this).error(function(){
					var src = $(this).attr('src'); 
					var filename = src.substring(src.lastIndexOf('/')+1); 
					$(this).attr('src',"/images2/small/" + filename);


				});

			});

	
			$(function() {
				$( ".autocomplete2" ).autocomplete({minLength:"2",
					source: '/autocomplete_architects.php'
				});
			});
	
			$("#ub_publishtabs").tabs();			

			$(".up_publishradio").change(function(){
				var p1 = ($("#p1").attr("checked")) == 'checked';
				var p2 = ($("#p2").attr("checked")) == 'checked';
				var p3 = ($("#p3").attr("checked")) == 'checked';
				var p4 = ($("#p4").attr("checked")) == 'checked';
				var p5 = ($("#p5").attr("checked")) == 'checked';
				
				var project=-1; if(p1==true) project=0;; if(p2==true) project=1;
				var quality=-1; if(p3==true) quality=0; if(p4==true) quality=1; if(p5==true) quality=2;
				
				var str = '' + p1 + ',' + p2 + ',' + p3 + ',' + p4 + ',' + p5;
				$.post('/publishajax.php', {actie: 'projectrating', project: project, quality: quality}, function(data){

					});		
				});	
			
			$(".up_publishradio0").change(function(){
				var p1 = ($("#t1").attr("checked")) == 'checked';
				var p2 = ($("#t2").attr("checked")) == 'checked';
				var p3 = ($("#t3").attr("checked")) == 'checked';
				var p4 = ($("#t4").attr("checked")) == 'checked';
				
				var subject=-1; if(p1==true) subject=1; if(p2==true) subject=2; if(p3==true) subject=3; if(p4==true) subject=4;
				$.post('/publishajax.php', {actie: 'projectsubject', subject: subject}, function(data){
					$("#ub_publish3").html('');
					$("#ub_publish3").html(data);
					ub_refreshbehaviorpublish3();
					});		
				});

			$("#ub_projectdatafields input, #ub_country").change(function(){
				var val = $(this).val();
				var id = $(this).attr('id');
				$.post('/publishajax.php', {actie: 'projectdata', val:val, id:id}, function(data){
					if(data!=0) alert(data);
					});		
			
				});
			
			$(".ub_publishnext").click(function(){
					var visiblediv = '';
					$(".ub_publish").each(function(){
						if($(this).css('display')=='block') visiblediv = $(this);
						});			
					$(".ub_publish").css('display','none');
					var id = visiblediv.attr('id');	var str = id.split("sh");  id = parseInt(str[1],10); newid = "#ub_publish" + (id+1);	
					if((id+1) == 5){
						$.post('/publishajax.php', {actie: 'refreshpublish5'}, function(data){
							$(newid).html(data);
							$(newid).css('display','block');
							$("#ub_publishformbutton").click(function(){
								var a = 0;
								$.post('/publishajax.php', {actie: 'checkform'}, function(data){
									if(data==''){
										window.location = "/publish.php";
										}else{
											alert(data);
											}
									});	
								return false;
								});

							$("#ub_forcedprevious").click(function(){
								$("#ub_publish5").css('display','none');
								$("#ub_publish4").css('display','block');
								});	
								
							$(".ub_thumb img").each(function(){
								$(this).error(function(){
									var src = $(this).attr('src'); 
									var filename = src.substring(src.lastIndexOf('/')+1); 
									$(this).attr('src',"/images2/small/" + filename);


								});

							});							
							activatehoverthing();
							});	
						}else{								
							$(newid).css('display','block');
							}						
				}); 

			$(function() {
				$(".ub_publishprevious:not(#ub_publishprevious3)").click(function(){
						var visiblediv = '';
						$(".ub_publish").each(function(){
							if($(this).css('display')=='block') visiblediv = $(this);
							});		
						
						$(".ub_publish").css('display','none');
						var id = visiblediv.attr('id'); var str = id.split("sh");  id = parseInt(str[1],10); newid = "#ub_publish" + (id-1);
						$(newid).css('display','block');							
					}); 					
				});

			$(function() {
				$(".hoverthing, .ub_thumb, .ub_thumbsmall, .ub_thumblarge").hover(
						function(){
							$(this).css('cursor','pointer');
							$(this).find("img").css('opacity','0.8');
						},
						function(){
							$(this).css('cursor','none');
							$(this).find("img").css('opacity','1.0');
						} 	
					); 
				});	
	
			$("#ub_publishtabs p").click(function(event){
				$(this).toggleClass("ub_markedtext");
				var tags = '';
				$(".ub_markedtext").each(function(){
					var id = $(this).attr('id');
					var temp = id.split("ar"); id = temp[1];				
					tags = tags + id + ',';
					});
				tags = tags.substring(0, tags.length-1);
				$.ajax({
					url: '/publishajax.php', 
					data: {actie: 'settags', tags: tags}, 
					async: false				
					});
				event.stopPrpagation();
				});			

			$("#sortablepublish").sortable({

						update: function(){							
							var str = '';
							$(".ub_thumborder").each(function(){
								var src = $(this).find('img').attr('src');
								src = src.split("/");  src = src[src.length - 1];
								str = str + src + ',';
								});
							str = str.substr(0,str.length-1);

							$.post('/publishajax.php', {actie: 'publish1', string: str}, function(data){

								});
							}
						});	
	}



	
function ub_refreshcontent(){
			$.post('/organizeajax.php', {actie: 'refresh'}, function(data){
				$("#photobox").html(data);
				ub_refreshbehavior();
				});	
	}


$(function() {
	$(".ub_emptygroupwarning").click(function(){
		alert("this group is empty");
		});
	return false;
	})
	
$(function() {
	$(".ub_friendwithoutphotoswarning").click(function(){
		alert("this friend doesn't have groups or sets in his or her private webspace");
		});
	return false;
	})	
	
function ub_refreshbehavior(){

				if((navigator.userAgent).indexOf('Firefox') != -1){
					$("#up_tabmenu").css('top','106px');
					}

				$(".ub_thumb img, .ub_thumbsmall img, .ub_replacethumb img").each(function(){
					$(this).error(function(){
						var src = $(this).attr('src'); 
						var filename = src.substring(src.lastIndexOf('/')+1); 
						$(this).attr('src',"/images2/small/" + filename);

						
						//$("#id0").find('p').remove();
						//$("#id0").find('h4').after('<p class="small">Some images are still being processed. Sorry for the delay, we\'re working on fastening things up. Press F5 to refresh.</p>');
						
					});

				});
				
				


				$("#ub_helpbuttonorganize").click(function(){
					if($("#ub_helptext").length==0){
							$.post("/organizeajax.php",{actie: 'help'}, function(data){
							$(".ub_left").prepend(data);
							$("#ub_helptext label").click(function(){
								$("#ub_helptext p").hide();
								$(this).next().next().show();
								//ub_refreshbehavior();
								ub_setuppaperheight();
								});	
							$("#ub_helptextclose").click(function(){
								$("#ub_helptext").remove();
								});

							});
						}
				});

				$(".ub_unsortedcssclose").click(function(){
					$(this).parent().hide();
					$.post('/organizeajax.php', {actie: 'removesharebox'}, function(data){
						});	
					});

				$(".ub_photosetheaderview, .ub_photosetheaderpublish").click(function(){
					var len = $("#ub_save").length;
					var nphotos = $(this).parent().parent().find(".ub_photosetthumbs").find('.ub_thumbsmall').size();

					if((len==0 && nphotos>2) || ($(this).hasClass('ub_photosetheaderview') && len==0)){
						return true;
						}else{
							if(nphotos<3 && ($(this).hasClass('ub_photosetheaderpublish'))){
								alert('A set needs at least 3 photographs if you want to publish it.');
								}else{
									alert('Save your work first');
									}
							
							return false;
							}
					});

				$(".ub_noview, .ub_nopublish").click(function(){
					if($(this).hasClass("ub_noview")){
						alert("you can't view an empty set");
						return false;
						}
					if($(this).hasClass("ub_nopublish")){
						alert("you can't publish empty sets");
						return false;
						}
					});

				ub_setuppaperheight();
				//$("#up_taborganize1").hide();
				//$("#up_taborganize2").show();	
				
				$(".ub_off").click(function(){
					$(this).parent().hide();
					});

				$("#ub_save").click(function(){

					$.post('/organizeajax.php', {actie: 'save'}, function(data){
						if(data==0){
							var a  = confirm('To save your work you need to subscribe first. Would you like to?');
							if(a==true) window.location	= "/register";								
								}else{
								window.location	= "/organize";
								}
						});	
					});	
				
				
				$("#up_fullscreen").click(function(){
					var doc_width = $(document).width(); 
					var doc_height = $(document).height();
					var wh = getWidthHeight(); var doc_height = wh[1]; var doc_width = wh[0];
					var w = (doc_width - 20) + "px" ; var h = (doc_height - 20) + "px" ; 
					var isfullscreen = 0;
					if($(".up_paper").css("position") == "relative"){
							$(".up_paper").css("position","fixed").css("top","0px").css("left","0px").css("width",w).css("height",h);
							isfullscreen = 1;	
							$("#up_tabmenu").hide();
							$("#up_fullscreen").html('close');
							}else{															
								$(".up_paper").css("position","relative").css("width","auto").css("height","800px");
								$("#up_tabmenu").show();
								$("#up_fullscreen").html('full screen');
								}
					//set variabele $_SESSION['ub_isfullscreen']
					$.post('/organizeajax.php', {actie: 'setfullscreen', isfullscreen: isfullscreen, width: w, height: h}, function(data){
						});
					ub_setuppaperheight();
					});				
				
				
				$(function() {
					$(".ub_help").hover(function(e){
						var onoff = $("#ub_helpboxonoff").is(':checked');
						if(onoff==true){
							$("#ub_helpbox").text('');
							var a = $(this).attr('id');
							var onoff = $("#ub_helpboxonoff").is(':checked');
							$("#ub_helpbox").show().css("top",e.pageY-10).css("left",e.pageX+20);
							if(a=="id0"){
								$("#ub_helpbox").text("Your new uploads. You can drag them onto your photosets.");
								}
							if(a=="ub_addgroup"){
								$("#ub_helpbox").text("Create a new group.");
								}
							if(a=="ub_selectall"){
								$("#ub_helpbox").text("Select all new uploaded photographs and drag them as a group to a photoset.");
								}
							if(a=="ub_collapse"){
								$("#ub_helpbox").text("When on, only one group will be open at a time.");
								}
							if(a=="ub_helpboxonoff"){
								$("#ub_helpbox").text("Turn off the tooltips.");
								}
							if(a=="ub_helpbuttonorganize"){
								$("#ub_helpbox").text("Go to the help files.");
								}
							if(a=="ub_save" || a=="ub_savedisabled"){
								$("#ub_helpbox").text("Save the changes in your photocollection with this button (works only for registered users).");
								}
							if(a=="up_fullscreen"){
								$("#ub_helpbox").text("Switch to fullscreen mode.");
								}
							if($(this).hasClass('ub_thumb')){
								$("#ub_helpbox").text("Images can be dragged onto photosets. ");
								}
							if($(this).hasClass('ub_thumbsmall')){
								$("#ub_helpbox").text("Images can be dragged onto other photosets or back onto the 'your uploads' box. You can select multiple images and drag them as group by using Ctrl-click.");
								}
							if($(this).hasClass('ub_groupheader')){
								$("#ub_helpbox").text("A group can contain one or more photosets.");
								}								
							if($(this).hasClass('ub_groupheadertitle')){
								$("#ub_helpbox").text("Edit the title of the group by clicking on it. After editing click enter to save the new name.");
								}
							if($(this).hasClass('ub_groupheaderdelete')){
								$("#ub_helpbox").text("Delete the group with this button.");
								}	
							if($(this).hasClass('ub_groupheadertoggle')){
								$("#ub_helpbox").text("Open or close this group with this button.");
								}		
							if($(this).hasClass('ub_groupheaderdelete')){
								$("#ub_helpbox").text("You can delete a group with this button, but only if the group doesn't contain photosets.");
								}		
							if($(this).hasClass('ub_groupheadernewset')){
								$("#ub_helpbox").text("Create a new photoset within this group.");
								}		
							if($(this).hasClass('ub_photosetheadertitle')){
								$("#ub_helpbox").text("You can edit the title of a photoset by clicking on it. Save your new title by pressing enter.");
								}		
							if($(this).hasClass('ub_photosetheaderdelete')){
								$("#ub_helpbox").text("Delete the photoset with this button. Be carefull as the photographs in this set will be deleted as well.");
								}		
							if($(this).hasClass('ub_photosetheaderview')){
								$("#ub_helpbox").text("Click this if you want to view the photos in this set in the main BuildingButler viewer.");
								}									
							if($(this).hasClass('ub_photosetheaderpublish')){
								$("#ub_helpbox").text("Publish any of your photosets on BuildingButler, accessible for everyone. You will be asked to choose a first image and give appropriate tags and titles to the set.");
								}
							if($(this).hasClass('ub_photosetheader')){
								$("#ub_helpbox").text("Photosets can be dragged onto other groups.");
								}
							}
						},
						function(){
						$("#ub_helpbox").text('').hide();
					
						});
					});
							
				$(".ub_notlogged").click(function(){
					var a  = confirm('You can only publish content on the main site after registration. Would you like to?');
					if(a==true) window.location	= "/register";
					return false;
					});
				
				$("#ub_collapse").bind('change',function(){
						var onoff = $("#ub_collapse").is(':checked');
						$.post('/organizeajax.php', {actie: 'autocollapse', onoff: onoff}, function(data){
							});	
						});

				$("#ub_helpboxonoff").bind('change',function(){
						var onoff = $("#ub_helpboxonoff").is(':checked');
						$.post('/organizeajax.php', {actie: 'helpboxonoff', onoff: onoff}, function(data){
							});	
						});							

				$(".ub_groupheadertoggle").click(function(){
						var a = $(this).parent().parent().css('height'); a=parseInt(a);;
						var autocollapse=0;
						if(a<28){
							//alles collapsen als autocollapse aan staat
							if($("#ub_collapse").is(':checked')){
								var autocollapse=1;
								$(".ub_groupheadertoggle").each(function(){
									var a = $(this).parent().parent();
									var h = $(a).css('height');
									if(h!="24px"){
										$(a).css('min-height','24px');
										$(a).css('height','24px');
										$(a).find(".ub_groupheadertoggle").removeClass('ub_closedgroup');
										$(a).find(".ub_groupheadertoggle").addClass('ub_opengroup');
										}
									});
								}						
							$(this).parent().parent().css('height','auto');
							$(this).parent().parent().css('min-height','180px');
							var open=1;
							$(this).removeClass('ub_opengroup');
							$(this).addClass('ub_closedgroup');
							}else{
								$(this).parent().parent().css('height','24px');
								$(this).parent().parent().css('min-height','24px');
								var open=0;
								$(this).removeClass('ub_closedgroup');
								$(this).addClass('ub_opengroup');
								}						
						var id = $(this).parent().parent().attr('id');		
						//checken van de state van autocollapse						
						$.post('/organizeajax.php', {actie: 'groupopenclose', id: id, open: open, autocollapse: autocollapse}, function(data){
							});							
						ub_setuppaperheight();
						}); 						

				$(function() {
					$(".hoverthing, .ub_thumb, .ub_thumbsmall").hover(
							function(){
								$(this).css('cursor','pointer');
								$(this).find("img").css('opacity','0.8');
							},
							function(){
								$(this).css('cursor','none');
								$(this).find("img").css('opacity','1.0');
							} 	
						); 
					});					


				$(".ub_photosetheaderdelete").click(function(){	
						var r = confirm("Are you sure you want to delete this set? Photographs in the set will be deleted as well.");
						if (r==true){ 
							var id = $(this).parent().parent().attr('id');
							var type = id.substring(0,3);  id = id.substring(3,50); 
							$.post('/organizeajax.php', {actie: 'removecollection', type: type, id: id}, function(data){
								ub_refreshcontent();				
								});	
							}
						});

				$(".ub_groupheaderdelete").click(function(){
						var r = confirm("Are you sure you want to delete this group?");

						if (r==true){ 				
							var id = $(this).parent().parent().attr('id');
							var type = id.substring(0,4);  id = id.substring(4,50);							
							$.post('/organizeajax.php', {actie: 'removegroup', type:type, id: id}, function(data){
								if(data==0) alert('To delete a group you first need to remove or delete the photosets inside.');
								ub_refreshcontent();				
								});	
							}

						});
				



				$(".ub_groupheadernewset").click(function(){
						var group = $(this).parent().parent().attr('id');
						type = group.substring(0,4);  
						group = group.substring(4,36); 
						$.post('/organizeajax.php', {actie: 'addcollection', group: group, type: type}, function(data){

							ub_refreshcontent();				
							});	

						});
						
				$("#ub_addgroup").click(function(){	
						$.post('/organizeajax.php', {actie: 'addgroup'}, function(data){
							ub_refreshcontent();				
							});	
						});

				
				$(".ub_photosetheadertitle").click(function(){	
						//$("#id0").append('<input type="text">');
						var coltitle = $(this).text();
						lios = coltitle.lastIndexOf("(");						
						coltitle = coltitle.substr(0,lios-1);
						var g = $(this).parent().parent().attr('id');
						var a = "t" + g; 
						$(this).unbind('click');
						$(this).html('<input type="text" id="' + a + '" value="' + coltitle + '">');						
						
						var aa = "#" + a;
						$(aa).keyup(function(event){
							  if(event.keyCode == 13){
									var newname = $(aa).val();
									var id = $(this).attr('id'); 
									var type = id.substring(0,4); var id = id.substring(4,50); 
									$.post('/organizeajax.php', {actie: 'renamecollection', newname: newname, type: type, id: id}, function(data){
										ub_refreshcontent();
										//alert(data);
										});
							  }
							});							
						});		

				$("#ub_selectall").click(function(){

						$("#id0").find(".ub_thumb").toggleClass("ub_multidrag");
				
					});
				
				$(function() {
					$(".ub_groupheadertitle").hover(
								function(){	
								$(this).css('background-color','yellow');
								},
								function(){	
								$(this).css('background','none');
								}
							);
						});				
				
				$(".ub_groupheadertitle").click(function(){	
						$(this).css('background','none');
						var grouptitle = $(this).text();
						lios = grouptitle.lastIndexOf("(");						
						grouptitle = grouptitle.substr(0,lios-1);
						var g = $(this).parent().parent().attr('id');
						var a = "tt" + g; 
						$(this).unbind('click');
						$(this).html('<input type="text" id="' + a + '" value="' + grouptitle + '">');						
						
						var aa = "#" + a;
						$(aa).keyup(function(event){
							  if(event.keyCode == 13){
									var newname = $(aa).val();
									var id = $(this).attr('id'); 
									type = id.substring(2,6);  
									id = id.substring(6,38); 
									$.post('/organizeajax.php', {actie: 'renamegroup', type: type, newname: newname, id: id}, function(data){
										ub_refreshcontent();
										//alert(data);
										});
							  }
							});							
						});								
	 
				$(".ub_thumb, .ub_thumbsmall").click(function(e){
					if (e.ctrlKey){
						//$(this).toggleClass('ub_multidrag');
						}
					});
					
				
				$(".ub_photosetthumbs").sortable({
						containment: 'document',
						connectWith: '.ub_photosetthumbs',
						clone: true,
						//update fired ofwel een keer (bij schuiven binnen dezelfde set) ofwel twee keer (bij verplaatsen naar connected set)
						//safariproblee: fired enkel voor de ontvangende dinges
						receive: function(event,ui){
							var id = $(this).parent().attr("id");	
							var type = id.substring(0,3); id = id.substring(3,50);
							var filename = ui.item.find("img").attr("src");
							//alert(id);
							/*
							var arr = '';
							$(this).children().each(function(){
								arr = arr + ($(this).children(0).attr('src'));
								arr = arr + ',';
								});
							arr = arr.substring(0,arr.length-1);
							*/
							
							$.post('/organizeajax.php', {actie: 'moveimage', type: type, id:id, filename:filename}, function(data){
								//alert(data);
								ub_refreshcontent();
								});
							
							},			

						zIndex: 9999
				
						});
				

				
				$(".uploadbarcollections:not(#id0)").draggable({
						delay:200
						});


				$(".uploadbargroups").droppable({
						tolerance: 'pointer',
						accept:".uploadbarcollections",
						drop: function(event,ui){	
							
							var collectionid = $(ui.draggable).attr('id');
							var collectiontype = collectionid.substring(0,3); var collectionid = collectionid.substring(3,50); 

							var groupid = $(this).attr('id'); 
							var grouptype = groupid.substring(0,4); var groupid = groupid.substring(4,50); 
							
							$.post('/organizeajax.php', {actie: 'movecollection', collectionid: collectionid, groupid: groupid, collectiontype: collectiontype, grouptype: grouptype}, function(data){
								//alert(data);
								ub_refreshcontent();
								});
							}
						});	
				}

//FUNCTIE OM IADSTATIC TE CLEAREN
function cleariadstatic(){
$("#iadstatic0").css("height","0px").css("width","0px").css("padding","0px").css("border","none").hide();
$("#iadstatic1").css("height","0px").css("width","0px").css("padding","0px").css("border","none").css('opacity','0.7').css('filter','alpha(opacity=70)').html('').scrollTop("0px").hide();
$("#iadstatic2").css("height","0px").css("width","0px").css("padding","0px").css("border","none").css('opacity','0.5').css('filter','alpha(opacity=50)').html('').hide();
$("#mediumsizeimage").css("opacity",1.0);
}
	
//FUNCTIE OM IADSTATIC OP TE VRAGEN -  NU MET JSON IVM API
//UPDATE : IK HEB JSONP VERVANGEN DOOR JSON, WANT VANAF JQuery 1.5 KREEG IK DAT NIET MEER WERKEND> BETEKENT DAT EEN EVENTUELE API OOK NIET MEER WERKT.
function getiadstatic(img2, screenwidth, screenheight, imagewidth, imageheight) {
					cleariadstatic();
					var jqxhr = $.getJSON("/getiadstatic.php", {img2: img2, requesttype: 'titleonly'}, function() {

					})
					.success(function(data) { 

					
							if(data['title1']!=''){	
									
									var x = $("#mediumsizeimage").position().left + (imagewidth/100)*data['posx1'] ; 
									var y = $("#mediumsizeimage").position().top + (imageheight/100)*data['posy1'] ;	
									var title = '<h4>' + data['title1'] + '</h4>';
									var idtag = '<p>' + data['id1'] + '</p>';
										$("#iadstatic1").css("height","9px").css("overflow","hidden").html(title + idtag ).css('top', y + 'px').css('left', x + 'px').css('padding','5px').css("border","none");	
										var a = title.length; var a = (4 * a) + "px";										
										$("#iadstatic1").css("width",a).show();

									}	
									
							if(data['title2']!=''){	
									var x = $("#mediumsizeimage").position().left + (imagewidth/100)*data['posx2'] ; 
									var y = $("#mediumsizeimage").position().top + (imageheight/100)*data['posy2'] ;	
									var title = '<h4>' + data['title2'] + '</h4><p>' + data['id2'] + '</p>';
										$("#iadstatic2").css("height","9px").css("overflow","hidden").html(title).css('top', y + 'px').css('left', x + 'px').css('padding','5px').css("border","none");	
										var a = title.length; var a = (4 * a) + "px";
										$("#iadstatic2").css("width",a).show();			
									}					
					
					});						

					/*	
					$.post("/ismanufacturer.php", {a: 0}, function(data){
							if(data!=0){
							
								$.post("/getbackofficelink.php",{img2:img2},function(data){
									//$("#topmenu").append(data);
									var a = $("#topmenu").find("a:last");
									var b = a.attr("href"); a.attr("href",data);
									});
									
								}	
							});
							*/
}

function getfulliadstatic(a){
							
			$("#iadstatic1").html(a) ;				
			var doc_width = $(document).width(); var doc_height = $(document).height(); var left = (doc_width-254)/2 - 260 ; var top = doc_height/8 ;
			
			$("#iadstatic1").css("top", top + "px").css("left",left + "px").css("height","auto").css("width","500px").css("opacity","1").css("padding","15px").css("z-index","9999");		
			$("#mediumsizeimage").css("opacity",0.5);	
			
			$("#iadstatic0").css("top", top-10 + "px").css("left",left-10 + "px").css("width","550px").css("height","0px").css("opacity","0.1").css("background-color","white").css("z-index","9998").show();	
			
			//TABS
			$(function(){
				$("#tabs").tabs({
					show: function(){
					$("#iadstatic1").css('filter', 'none');

					var h = parseInt($("#iadstatic1").css("height"));
					$("#iadstatic0").css("height",h+50+"px");	
					}
					});
				});				

			$( "#tabs" ).tabs({
			   show: function(event, ui) { 
				var h2 = parseInt($("#iadstatic1").css("height")); 
				$("#iadstatic0").css("height",h2+50+"px");	
				if(h2>600){
					$("#iadstatic1").css("overflow-y","scroll").css("height","600px")	;	
					$("#iadstatic0").css("height",600+50+"px");	
				
					}else{
					$("#iadstatic1").css("height","auto").css("overflow","hidden")	;
					var hh = parseInt($("#iadstatic1").css("height")); 					
					$("#iadstatic0").css("height",hh+50+"px");						
					}
			   }
			});				
				
			$(function(){
				$(".iadrelated").hover(
					function(){
						$(this).css('background-color','#efefef');
					},
					function(){
						$(this).css('background-color','white');
					} 					
					);
				});	
}
					
$(function() {
	$("#mediumsizeimage").click(function() {
	cleariadstatic();
	});
});

$(function() {
	$("#addcomment").click(function() {
		$(".commentform").toggle();
		//$('#commentboxfirstline').append("<form><br/>write your comment here:<textarea></textarea><br/>your name:</br><input type='text'></input><input type='submit' value='submit your comment'></input></form>");

	});
});

//VERGROOT WIKI EN PLAATS M MIDDEN OP HET SCHERM
$(function() {
	$(".iadstatic").click(function() {
	
			yiadstatic = $(this).css("top"); xiadstatic = $(this).css("left"); opiadstatic = $(this).css("opacity");
			widthiadstatic = $(this).css("width"); heightiadstatic = $(this).css("height"); contentiadstatic = $(this).html();
			paddingiadstatic = $(this).css("padding"); ziadstatic = $(this).css("z-index");
			
			var id1 = parseInt($(this).find("p:first").text());
			
					var jqxhr = $.getJSON("/getiadstatic.php", {id1: id1, requesttype: 'full'}, function() {

					})
					.success(function(data) { 

					tc = "<div id='tabs'><ul><li><a href='#tinfo'>info</a></li>";
					if(data['facts']!='') tc = tc + "<li><a href='#tfacts'>facts</a></li>";
					if(data['company']!='') tc = tc + "<li><a href='#tcompany'>company</a></li>";
					if(data['video']!='') tc = tc + "<li><a href='#tvideo'>video</a></li>";
					if(data['newsletter']!='') tc = tc + "<li><a href='#tnewsletter'>newsletter</a></li>";
					tc = tc + "<li><a href='#trelatedbuildings'>related buildings</a></li></ul>";
					tc = tc + "<div id='tinfo'><div class='topmargin'></div>" + data['info'] + "</div>";
					if(data['facts']!='') tc = tc + "<div id='tfacts'><div class='topmargin'></div>" + data['facts'] + "</div>";
					if(data['company']!='') tc = tc + "<div id='tcompany'><div class='topmargin'></div>" + data['company'] + "</div>";
					if(data['video']!='') tc = tc + "<div id='tvideo'><div class='topmargin'></div>" + data['video'] + "</div>";					
					if(data['newsletter']!='') tc = tc + "<div id='tnewsletter'><div class='topmargin'></div>" + data['newsletter'] + "</div>";
					tc = tc + "<div id='trelatedbuildings'><div class='topmargin'></div>" + data['brelated'] + "</div></div>";
					
					getfulliadstatic(tc);					
			
					
					});			
			
			
			/*niet meer ivm JQuery die ik niet werkend krijg met JSONP
			$.ajax({
				url: "/getiadstatic.php", 
				data:{id1: id1, requesttype: 'full'}, 
				dataType: "jsonp",
				jsonp: false,						
				success: function(data){	

					tc = "<div id='tabs'><ul><li><a href='#tinfo'>info</a></li>";
					if(data['facts']!='') tc = tc + "<li><a href='#tfacts'>facts</a></li>";
					if(data['company']!='') tc = tc + "<li><a href='#tcompany'>company</a></li>";
					if(data['video']!='') tc = tc + "<li><a href='#tvideo'>video</a></li>";
					if(data['newsletter']!='') tc = tc + "<li><a href='#tnewsletter'>newsletter</a></li>";
					tc = tc + "<li><a href='#trelatedbuildings'>related buildings</a></li></ul>";
					tc = tc + "<div id='tinfo'><div class='topmargin'></div>" + data['info'] + "</div>";
					if(data['facts']!='') tc = tc + "<div id='tfacts'><div class='topmargin'></div>" + data['facts'] + "</div>";
					if(data['company']!='') tc = tc + "<div id='tcompany'><div class='topmargin'></div>" + data['company'] + "</div>";
					if(data['video']!='') tc = tc + "<div id='tvideo'><div class='topmargin'></div>" + data['video'] + "</div>";					
					if(data['newsletter']!='') tc = tc + "<div id='tnewsletter'><div class='topmargin'></div>" + data['newsletter'] + "</div>";
					tc = tc + "<div id='trelatedbuildings'><div class='topmargin'></div>" + data['brelated'] + "</div></div>";
					
					doehet(tc);
					}		
				});	
			*/
				
				
		//$.post("/stats.php",{type: 'wiki'});
		});
	});

	

		
//SEARCH BOX INTERACTIVE - SELECT THE RIGHT MANUFACTURERS WHEN SELECTING A BRAND FROM THE LIST
$(function() {
	$("#materialorelement").change(function() {
		var a = $(this).val();
		$("#manufacturer").load('/manufacturerlist.php', {manufacturer: a});
		});
	});
		
  
//Dit gaat over het direct schakelen naar fullscreenmode

jQuery(document).ready(function() {

$(".widescreen2, .hoverthing, .hoverenlarge, #turnoffialabel, #addcomment").hover(
		function(){
			$(this).css('cursor','pointer');
						//$(this).css('opacity','0.6');
						//$(this).css('z-index','-9999');
		},
		function(){
						$(this).css('cursor','none');
						//$(this).css('opacity','1.0');
		} 	
	);  


$(".blogitem").hover(
		function(){
			$(this).css('background-color','#fafafa');

		},
		function(){
						$(this).css('background-color','transparent');

		} 	
	);  
  




//JQuery dialog aanzetten

	





//CHANGE PASSWORD
$("#changepasswordon").click(function(){
			var conf = ('<tr><td>Confirm new password</td><td ><input id="newpassword2" type="password"></td></tr>'); 
			var b = $(this).parent().parent().parent(); b.append(conf); 
			b.append('<tr><td></td><td><a href="" id="changepassword">submit</td></tr>');
			var a = $(this).parent().parent().html('<td>New password</td><td><input id="newpassword1" type="password"></td>');
			
			activatepasswordform();
		
		});		

function activatepasswordform() {
	$("#changepassword").click(function(){			
				var new1 = $("#newpassword1").val();
				var new2 = $("#newpassword2").val();
				var a = (new1==new2);
				if(!a){alert("the two passwords are not the same")} ;			
				var b = (new1.length>6); var c = (new2.length>6);
				if(a && b && c){
					$.post("/changepassword.php", {new1: new1,new2: new2}, function(data){	
					alert(data);	
					location.reload(true);				
					});	
				}
				return false;
			});		
			
	$("#newpassword1").change(function(){
				if($(this).val().length<7){alert("Your new password needs to have at least 7 characters")}			
			});	
	}	
		

	
	
	
//ALTERNATIVE DESCRIPTION FORM VALIDATION
$("#descriptionform").validate({
		rules: {
			buildingname: "required",
			architect: "required",
			year: {
				required: true,
				minlength: 4,
				maxlength: 4
				},
			city: "required"

		},
		messages: {
			buildingname: "Please enter the building name",
			architect: "Please enter the name of the architect",
			year: {
				required: "Please enter the year of completion",
				minlength: "The year needs 4 digits",
				maxlength: "The year needs 4 digits"
				},
			city: "Please enter the name of the city"

		}
	});
	
	
	
	
	
	


//VALIDATION UPLOAD

$("#UploadForm").validate({
		rules: {
			descr_architect: "required",
			descr_buildname: "required",
			descr_year: "required",
			descr_city: "required",	
			'characteristics[1][]': "required",
			'characteristics[3][]': "required",
			'characteristics[4][]': "required",
			'characteristics[5][]': "required"

		},
		messages: {
			descr_architect: " Please enter the architect's name",
			descr_buildname: " Please enter the name of the building",
			descr_year: " Please enter the year of completion",
			descr_city: " Please enter the city",
			'characteristics[1][]': "pick one (or more) materials",
			'characteristics[3][]': "select the dominating color",
			'characteristics[4][]': "select one",
			'characteristics[5][]': "select a function"
		}
	});

$("#UploadForm").click(function(){
	//alert("Yeah");
	var a=$("#uploadphotos").find("img").attr("src");
	if(a==undefined){
		alert("You must upload at least one image. Important notice: everyting you filled in will vanish as soon as you start adding images. Sorry.");
		}
	});
	

//TONEN VAN GEBOUWTITEL
$(".buildinginfo").hover(
		function(){			
			var txt = $(this).attr("alt");
			$("#pagetitle").html('' + txt + '');
			},
		function(){
			$("#pagetitle").html(function() {  
				return "search by visual association - click any thumbnail to get a new set of related buildings";
				});			
			}
	);

$(".buildinginfosearch").hover(
		function(){			
			var txt = $(this).attr("alt");
			$(".rightdivtitles").html('<h4>' + txt + '</h4>');
			},
		function(){
			$(".rightdivtitles").html('');			
			}
	);








//MOUSEOVER VOOR THUMBS
//$("img:not([id='advertisementimage'],[id='mediumsizeimage'],[id='r1'], [id='brickthumb'], [id='advertisement'])").hover(
$(".thumbtotalverysmall").find('img').hover(
		function(){
						$(this).css('cursor','pointer');
						$(this).css('opacity','0.8');

		},
		function(){
						$(this).css('cursor','none');
						$(this).css('opacity','1.0');
		} 	
	);  
	

}); //END DOCUMENT READY	








function autocomplete(){
//AUTOCOMPLETE CITIES	
	$(function() {
		$( "#autocomplete1" ).autocomplete({minLength:"1",
			source: '/autocomplete_cities.php'
		});
	});

//AUTOCOMPLETE ARCHITECTS	
	$(function() {
		$( "#autocomplete2" ).autocomplete({minLength:"2",
			source: '/autocomplete_architects.php'
		});
	});
}

function setphotoxsize_nonview(){
	var test=$(".lefttop").css("height"); 
	//zorgen dat op niet-gebouwpagina de photobox de juiste hoogte heeft, en ook ub_paper
	if(test!=undefined){
		var wh = getWidthHeight(); wh=wh[1];
		var a = wh - parseInt($("#photobox").css('padding-top')) - parseInt($("#photobox").css('padding-bottom')) - parseInt($("#photobox").css('margin-top')) + 5;
		
		//a = wh - 135
		if(a>750) {
			//$("#photobox, .todaysphotos").css('height',a - 200);
			$("#photobox").css('height',a - 165); 
			ub_setuppaperheight();
			}else{
				$("#photobox, .todaysphotos").css('height',650);
				//ub_setuppaperheight();
				}
			}
}

function ub_setuppaperheight(){

	var test=$(".lefttop").css("height"); //geen viewpagina
	//zorgen dat op niet-gebouwpagina de photobox de juiste hoogte heeft, en ook ub_paper
	if(test!=undefined){
		var wh = getWidthHeight() ; wh=wh[1];				
		var a = wh - parseInt($("#photobox").css('padding-top')) - parseInt($("#photobox").css('padding-bottom')) - parseInt($("#photobox").css('margin-top')) + 5;

		if(a>750) {
			
			if($(".up_paper").css('position')=='fixed'){
				$("#up_tabmenu").hide();
				var h = (wh - 20);
				$("#up_fullscreen").html('close');
				}else{
					var h=(a-85); 
					}

				$(".up_paper").css("top","0px").css("left","0px").css('height', h);
				$(".latestremarkablefacts").css('height',h-100);
				var ih = $("#invitationslist").css('height'); 
				var ih = parseInt(ih); var maxih = h-280; 
				if(ih>maxih) $("#invitationslist").css('height',maxih).css('overflow-y','scroll');
				
				$(".ub_left").css('height','auto').css('overflow-y','hidden');
				var a = parseInt($(".ub_left").css('height')); //alert("up_paper height=" + h); alert("ub_left: height=" + a);
				
				if((a>(h-70)) ) {
					$(".ub_left").css('height',h-70).css('overflow-y','scroll');
					}else{
					$(".ub_left").css('height','auto').css('overflow-y','hidden');
					}	
					
				}else{			

					$("#photobox").css('height',650);
					$(".up_paper").css("top","0px").css("left","0px").css('height', 720);
					$(".latestremarkablefacts").css('height',620);
					$("#invitationslist").css('height',440).css('overflow-y','scroll');	

					$(".ub_left").css('height',650).css('overflow-y','scroll');	
					
					}
				
			
				
				
		}

	}

//ENLARGER  - 	VOOR ALS JE OP BUILDINGTHUMBS DRUKT
function enlarger(img1){
			var wh = getWidthHeight(); wh=wh[1];
			var a1 = wh - parseInt($("#photobox").css('padding-top')) - parseInt($("#photobox").css('padding-bottom'));

			if(!a1){
				var a1 = document.documentElement.clientHeight - parseInt($("#photobox").css('padding-top')) - parseInt($("#photobox").css('padding-bottom'));
				}
			
			$("#photobox").css('height',a1 - 24); 
			
			var theurlarray = (window.location.pathname.split('/'));
			var theurl = theurlarray[1];
			if(theurl=='view' || theurl=='viewfriend'){
				var img2 = img1; var img2 = img1.replace(/small/g, "large");
				var imgarray = img1.split('/'); var imgname = imgarray[imgarray.length-1];
				filelink = "/download2.php?file=" + imgname ; 		
				}else{
					var img2 = img1; var img2 = img1.replace(/small/g, "large");
					var imgarray = img1.split('/'); var imgname = imgarray[imgarray.length-1];
					filelink = "/download.php?file=" + imgname ; 
					}
			
			$("#downloadhighresa").attr('href',filelink);
			$("#mediumsizeimage").attr('src','');	
			$("#mediumsizeimage").attr('src',img1);		
			var pic = $("#mediumsizeimage"); pic.removeAttr("width"); pic.removeAttr("height");
            var doc_width = parseInt($("#photobox").css('width')) + parseInt($("#photobox").css('padding-left')) + parseInt($("#photobox").css('padding-right')); 
            var doc_height = parseInt($("#photobox").css('height')) + parseInt($("#photobox").css('padding-top')) + parseInt($("#photobox").css('padding-bottom'));
			var image_width = pic.width();
			var image_height = pic.height();
		


			var image_ratio = image_width/image_height; 
			var screen_ratio = doc_width/doc_height;
			if(screen_ratio<image_ratio){
				var new_width = doc_width;
				var new_height = Math.round(new_width/image_ratio);
				var width_offset = 9
				var height_offset = Math.round((doc_height-new_height)/2) + 9;
				}
			else{
				new_height = doc_height;
				new_width = Math.round(new_height*image_ratio);
				var width_offset = Math.round((doc_width-new_width)/2) + 9;
				var height_offset = 9
				}	
			
			$("#mediumsizeimage").attr('width',new_width);	
			$("#mediumsizeimage").attr('height',new_height);
			$("#mediumsizeimage").css('left',width_offset);
			$("#mediumsizeimage").css('top',height_offset);
			$("#mediumsizeimage").attr('src',img2);
			checkmediumsizeimage();	
			getiadstatic(img2, doc_width, doc_height, new_width, new_height);
}	

//ENLARGER0_PHOTOBOXSIZE - ENKEL VOOR VIEWPAGINAS
//ZIT IN DOCUMENT.READY 
//function enlarger0_photoboxsize(){
function setheight_photobox(){
			var wh = getWidthHeight(); wh=wh[1]; 
			var a1 = wh - parseInt($("#photobox").css('padding-top')) - parseInt($("#photobox").css('padding-bottom'));

			if(!a1){
				var a1 = document.documentElement.clientHeight - parseInt($("#photobox").css('padding-top')) - parseInt($("#photobox").css('padding-bottom'));
				}
			
			$("#photobox").css('height',a1 - 24);

	}

//ENLARGER  - 	ENKEL BEDOELD VOOR ALS ER EEN BD OF VIEWPAGINA GELADEN WORDT, OM DE EERSTE FOTO GOED TE PLAATSEN BINNEN DE PHOTOBOX
//WORDT GESTART IN DOCUMENT.READY
function initiate_viewpage1(){
			
			

			var img3 = $("#thisbuildingimages").find("img").attr("src"); 

			
			$("#mediumsizeimage").attr('src',img3);
			
			var pic = $("#mediumsizeimage"); pic.removeAttr("width"); pic.removeAttr("height");
            var doc_width = parseInt($("#photobox").css('width')) + parseInt($("#photobox").css('padding-left')) + parseInt($("#photobox").css('padding-right')); 
            var doc_height = parseInt($("#photobox").css('height')) + parseInt($("#photobox").css('padding-top')) + parseInt($("#photobox").css('padding-bottom'));
			var image_width = pic.width();
			var image_height = pic.height();
		


			var image_ratio = image_width/image_height; 
			var screen_ratio = doc_width/doc_height;
			if(screen_ratio<image_ratio){
				var new_width = doc_width;
				var new_height = Math.round(new_width/image_ratio);
				var width_offset = 9
				var height_offset = Math.round((doc_height-new_height)/2) + 9;
				}
			else{
				new_height = doc_height;
				new_width = Math.round(new_height*image_ratio);
				var width_offset = Math.round((doc_width-new_width)/2) + 9;
				var height_offset = 9
				}	
			
			$("#mediumsizeimage").attr('width',new_width);	
			$("#mediumsizeimage").attr('height',new_height);
			$("#mediumsizeimage").css('left',width_offset);
			$("#mediumsizeimage").css('top',height_offset);
			$("#mediumsizeimage").show();


}	

function initiate_viewpage2(){

			var img2 = $("#thisbuildingimages").find("img").attr("src");

			var img3 = img2.replace(/small/g, "large");
			
			$("#mediumsizeimage").attr('src',img2);
			checkmediumsizeimage();	

			var pic = $("#mediumsizeimage");  pic.removeAttr("width"); pic.removeAttr("height");
            var doc_width = parseInt($("#photobox").css('width')) + parseInt($("#photobox").css('padding-left')) + parseInt($("#photobox").css('padding-right')); 
            var doc_height = parseInt($("#photobox").css('height')) + parseInt($("#photobox").css('padding-top')) + parseInt($("#photobox").css('padding-bottom'));
			var image_width = pic.width(); 
			var image_height = pic.height(); 


			var image_ratio = image_width/image_height; 
			var screen_ratio = doc_width/doc_height;
			if(screen_ratio<image_ratio){
				var new_width = doc_width;
				var new_height = Math.round(new_width/image_ratio); 
				var width_offset = 9
				var height_offset = Math.round((doc_height-new_height)/2) + 9;
				}
			else{
				new_height = doc_height;
				new_width = Math.round(new_height*image_ratio);
				var width_offset = Math.round((doc_width-new_width)/2) + 9;
				var height_offset = 9
				}	
			
			$("#mediumsizeimage").attr('width',new_width);	
			$("#mediumsizeimage").attr('height',new_height);
			$("#mediumsizeimage").css('left',width_offset);
			$("#mediumsizeimage").css('top',height_offset);

			$("#mediumsizeimage").attr('src',img3);
			
			getiadstatic(img3, doc_width, doc_height, new_width, new_height);

	}

		
function remarkablefacts(){
				var a = window.location.href; a = a.split("/"); var buildingid = a[(a.length)-1];
				$.post("/getbuildingbuzz.php", {action: 'create', buildingid: buildingid}, function(data){				
					$("#remarkablefacts").html('');			
					$("#remarkablefacts").html(data);							
					remarkablefactsbehavior();
				});	
}

function subscribepopup(){

		var wr = getWidthHeight(); wh=wr[1]; ww=wr[0];
		var w = ww; var h = wh; 
		$('body').append("<div class='blackscreen' style='width:" + w + "px; height:" + h + "px; '></div>");
		var xpos= w/2 - 250; var ypos = h/2-300; if(xpos<0) xpos=0; if(ypos<0) ypos=0;  
		$('body').append("<div id='subscribepopup' class='shadow3 subscribepopup' style=' top:" + ypos + "px; left:" + xpos + "px;'></div>");
		$("#subscribepopup").load("/getsubscribepopup.php",{action: 'create'},function(){
			subscribepopup_refreshbehavior();
			});

		

	}

function subscribepopup_refreshbehavior(){

	
	$(".addcompanycontentclose").click(function(){
		$(".blackscreen").remove();
		$("#subscribepopup").remove();
		});
		
	$("#registerForm").validate({
			rules: {
				firstname: "required",
				lastname: "required",
				occupation: "required",
				country: "required",
				screenname: {
					required: true,
					minlength: 3,
					remote:{
							url: "/registercheck.php",
							type: "post",
							dataType: "json",
							data: {
								val: function() {
									return $("#screenname").val();
								},
								id:'screenname'

							}
						  }
				},
				password: {
					required: true,
					minlength: 8
				},
				confirm_password: {
					required: true,
					minlength: 8,
					equalTo: "#password"
				},
				
				email: {
					required: true,
					email: true,
					remote:{
							url: "/registercheck.php",
							type: "post",
							dataType: "json",
							data: {
								val: function() {
									return $("#email").val();
								},
								id:'email'

							}
						  }
				},
				
				agree: "required"
			},
			messages: {
				firstname: "Please enter your firstname",
				lastname: "Please enter your lastname",
				occupation: "Enter a description of your occupation.",
				country: "Select a country from the list.",
				screenname: {
					required: "Please enter a screenname",
					minlength: "Your screenname must consist of at least 3 characters",
					remote: "Sorry, this screenname is already taken by another user. Please choose an alternative one."
				},
				password: {
					required: "Please provide a password",
					minlength: "Your password must be at least 8 characters long"
				},
				confirm_password: {
					required: "Please provide a password",
					minlength: "Your password must be at least 8 characters long",
					equalTo: "Please enter the same password as above"
				},
				email: {
					required: "Please provide an email address",
					//email: "Please enter a valid email address",
					remote: "Sorry, this email is in our database already. Probably you created an account before. If you have lost your password you can get a new one via the login form ('forgot password')."
					},
				agree: "You need to accept our policy"
			}
		});			
		
}


function remarkablefactsbehavior(){
	var wh = getWidthHeight(); wh = wh[1];
	var a = window.location.href; a = a.split("/"); var buildingid = a[(a.length)-1];
	var b = wh ; $(".rf_scrollcontainer").css("max-height",b-120);
	
	
	
	$(".rf_vote").click(function(){
		var id = $(this).parent().attr('id');factid = id.substring(1,20); 
		var vote = 'min';
		if($(this).hasClass('rf_vote1')) vote='plus';
		$.post("/getbuildingbuzz.php", {action: 'vote', factid: factid, vote: vote}, function(data){
			if(data==0) alert("you can only vote once for this buzz.");
			if(data==1) alert("Some database error occurred, sorry for the inconvenience");
			if(data!=0 && data!=1){
				var a = '#v2' + factid;				
				$(a).html('');$(a).html(data);
				alert('Thanks for your vote! The author of the buzz gets 1 Mb extra webspace.');
				}

			});		
		
		
		});
		

	$(".rf_editthispost").click(function(){
		var id = $(this).attr("id"); factid = id.substring(15,20);  
		
		//var text = $(this).parent().prev().prev().prev().prev().prev().text();  
		var para = $(this).parent().prev().prev().prev().prev().prev().prev();
		
		var para = $(this).parent().prev();

		$.post("/getbuildingbuzz.php", {action: 'editpost1', factid: factid}, function(data){
			//var str = "#rf_editthispostdiv" + factid;
			para.replaceWith(data); 
			remarkablefactsbehavior();
			$(".rf_editthispost").unbind('click');
			});	
		
		})
	
	$("#buildingbuzzmanifesto").click(function(){
		if($("#rf_manifestotext").length==0){
			$(this).parent().append('<div id="rf_manifestotext" class="shadow1"></div>');
			$.post("/getbuildingbuzz.php",{action: 'getmanifesto'}, function(data){
				$("#rf_manifestotext").html(data);
				$("#buildingbuzzmanifestoclose").click(function(){
					$("#rf_manifestotext").remove();
					})
				});
				}else{
					$("#rf_manifestotext").remove();
					}
		});
		
	$("#remarkablefactsshowtextarea").click(function(){
		var txt = $(this).text();
		if(txt=='add buzz'){
			//$(".remarkablefactstextareacontainer").css('display','block');
			$("#rmfnew").css('display','block');
			$(this).text('close');
			}else{
				//$(".remarkablefactstextareacontainer").css('display','none');
				$("#rmfnew").css('display','none');
				$(this).text('add buzz');		
				}
	});
	
	$("#remarkablefacts").show();
	
	$("#remarkablefactstextarea").charCounter(140);
	
	$(".rf_textareaedit").charCounter(140);

	$(".rf_comments").click(function(){
				var ptext = $(this).text();
				var id = $(this).attr("id"); factid = id.substring(11,20); var a = "#rf_commentsdiv" + factid ; 
				if($(a).html()==''){
					$(this).text('close comments');
					$(a).show();
					$.post("/getbuildingbuzz.php", {action: 'getcomments', factid: factid}, function(data){	
						$(a).html('');
						$(a).html(data);
						
						$(".rf_newcomment").click(function(){
									var text = $(this).parent().find("textarea").val(); 
									id = $(this).parent().parent().attr('id'); var factid = id.substring(14,20);
									$.post("/getbuildingbuzz.php", {action: 'addcomment', factid: factid, text: text}, function(data){
										
										if(data==1)	remarkablefacts();
										if(data==0)	subscribepopup();
										//if(data!=0 && data!=1) alert(data);

										});	
							});							
						});	
					}else{
						$(a).html('');
						$(a).hide();
						}
		});	
		
		$("#rf_toggle").click(function(){
			$(this).parent().parent().toggleClass("remarkablefacts1 remarkablefacts2");
			if($(this).parent().parent().hasClass("remarkablefacts2")){
				$("#rf_slogan").show();
				var a = $(this).parent().attr('href'); var b = a.substring(0,(a.length - 5));
				}else{
					$("#rf_slogan").hide();
					}
			});	

		
					
		$("#remarkablefactsnewfact").click(function(){
					$("#remarkablefactsnewfact").unbind('click');
					var text = $(this).parent().find("#remarkablefactstextarea").val();
					var url = $(this).parent().find("#remarkablefactslinkarea").val();
					$.post("/getbuildingbuzz.php", {action: 'addfact', buildingid: buildingid, text: text, url: url}, function(data){

									if(data==1 || data==-1){
										if(data==1)	remarkablefacts();
										if(data==-1) subscribepopup();
										}else{
											alert('A database error occurred. Please try again or contact the site administrator.');
											}

						});	
			});	
			
		$(".rf_edittextbutton").click(function(){

					var text = $(this).parent().find("textarea").val();
					var url = $("#remarkablefactsadjustlink").val();
					var id = $(this).attr("id"); factid = id.substring(11,20); 
					$.post("/getbuildingbuzz.php", {action: 'editpost2', factid: factid , text: text, url: url}, function(data){
								if(data==1){
									remarkablefacts();
									}else{
										alert(data);
										}
						});	
			});	
		}



	





