		// foldable menu it must be here
		var dont_fold_menu = false;
		var mustSave = false;
		var textClicked = false;
		var inputClicked = false;
		
		$(document).ready(function() {
			// reporting box
			$("#report_form").hide();
			$("a.report_link").click(function() {
				var rep_form = $("#report_form");
				if (rep_form.css("display") == "none") {
					rep_form.show().focus();
				}			
				return true;
			});
			$("#report_box_cancel").click(function(){
				$("#report_form").slideToggle('slow');
				
			});
			$("textarea#report_form_textarea").click(function() {
				if(!textClicked){
					this.value = '';
					$(this).css("color", "#444")
					textClicked = true;
				}				
				return true;
			});			
			
			// foldable menu
			if ( $("#login_email").val() != '' ) {
				dont_fold_menu = true;
			}
			$("#login_email").bind('keyup',  function(){
				dont_fold_menu = true;
			});
			if ( dont_fold_menu != true ) $("#top_bar_foldable_content").hide();
			$("#top_bar_foldable_btn > div > a").click(function() {
				var foldler = $("#top_bar_foldable_content");
				if (foldler.css("display") != "none") {
					foldler.hide();
				} else {
					foldler.slideDown("fast");						
				}
				return false;				
			});
			
			//alerts
			$('#close_message').click(function() {
				$('#message_to_user').slideToggle('slow');
			});
			$('#user_change_pass').click(function() {
				$('#wrapper_change_pass').slideToggle('slow');
			});			
			$(".delete_all_contacts").click(function() {								
				return confirm("Are you sure you want to remove all selected users from your contact list?");
			});			
			$('.delete_contact').click(function() {					
				return confirm("Are you sure you want to remove user from your contact list?");
			});
			$('.delete_message').click(function() {					
				return confirm("Are you sure you want to completely delete this thread? All messages within this thread will be deleted.");
			});			
			$(".delete_all_messages").click(function() {								
				return confirm("Are you sure you want to delete all selected threads? All messages within these threads will be deleted");
			});
			$(".remove_employee").click(function(e) {
				var trueClick=e.clientX;
				if (!trueClick) 
					return false;
				else {
					return confirm("Are you sure you want to remove user from your employee list?");
				}
			});
			$(".delete_showcase").click(function() {					
				return confirm("Are you sure you want to delete this showcase? All data will be lost");
			});
			$('.delete_company').click(function() {					
				return confirm("Are you sure you want to delete this company? This will delete all showcases and projects permanently!");
			});				 
			$('.upload_delete_file').click(function() {					
				return confirm("Are you sure you want to remove this file from brandsintrade.com?");
			});
			$("#invitation_recipient_id").click(function() {					
				if(!inputClicked){
					this.value = '';
					$(this).css("color", "#444")
					inputClicked = true;
				}				
				return true;				
			});
			$("#msg_recipient_id_clickable").click(function() {					
				if(!inputClicked){
					this.value = '';
					$(this).css("color", "#444")
					inputClicked = true;
				}				
				return true;								
			});			
			$("#show_name").click(function() {					
				if(!inputClicked){
					if (this.value == 'unnamed') {
						this.value = '';
						$(this).css("color", "#444")
						inputClicked = true;
					}	
				}				
				return true;								
			});
			$("a[@rel$='external']").click(function(){
			     this.target = "_blank";
			});
			
         	$("#s_script").bind('keyup',  function(){
				if ( this.value.length >= 200 ) {
					alert('Too long text. Max text length for this field is 200 characters.');
					this.value = this.value.substring(0, 199);
				}
			});
			$("#desc").bind('keyup',  function(){
				if ( this.value.length >= 1000 ) {
					alert('Too long text. Max text length for this field is 1000 characters.');
					this.value = this.value.substring(0, 999);
				}
			});
			$("#c_part").bind('keyup',  function(){
				if ( this.value.length >= 200 ) {
					alert('Too long text. Max text length for this field is 200 characters.');
					this.value = this.value.substring(0, 199);
				}
			});
			$("#c_cust").bind('keyup',  function(){
				if ( this.value.length >= 200 ) {
					alert('Too long text. Max text length for this field is 200 characters.');
					this.value = this.value.substring(0, 199);
				}
			});
			$("#about_me").bind('keyup',  function(){
				if ( this.value.length >= 1024 ) {
					alert('Too long text. Max text length for this field is 1024 characters.');
					this.value = this.value.substring(0, 1023);
				}
			});
			$("#show_desc").bind('keyup',  function(){
				if ( this.value.length >= 1000 ) {
					alert('Too long text. Max text length for this field is 1000 characters.');
					this.value = this.value.substring(0, 999);
				}
			});
			$("#show_obj").bind('keyup',  function(){
				if ( this.value.length >= 1000 ) {
					alert('Too long text. Max text length for this field is 1000 characters.');
					this.value = this.value.substring(0, 999);
				}
			});
			$("#show_res").bind('keyup',  function(){
				if ( this.value.length >= 1000 ) {
					alert('Too long text. Max text length for this field is 1000 characters.');
					this.value = this.value.substring(0, 999);
				}
			});
			
			
			$("#project_description").bind('keyup',  function(){
				if ( this.value.length >= 2000 ) {
					alert('Too long text. Max text length for this field is 2000 characters.');
					this.value = this.value.substring(0, 1999);
				}
			});
			
			$("#project_results").bind('keyup',  function(){
				if ( this.value.length >= 1000 ) {
					alert('Too long text. Max text length for this field is 1000 characters.');
					this.value = this.value.substring(0, 999);
				}
			});
			$("#message_textarea").bind('keyup',  function(){
				if ( this.value.length >= 5000 ) {
					alert('Too long text. Max text length for this field is 5000 characters.');
					this.value = this.value.substring(0, 4999);
				}
			});
			
			
			$(".publish").click(function() {					
				if (mustSave){
					if (confirm('Are you sure want to publish without saving? All changes will be lost!') != true) {
						mustSave = false;
						return false;						
					}
					else return true;
				}											
			});
			$(".unpublish").click(function() {					
				if (mustSave){
					if (confirm('Are you sure want to unpublish without saving? All changes will be lost!') != true) {
						mustSave = false;
						return false;						
					}
					else return true;
				}											
			});
			$(".preview").click(function() {					
				if (mustSave){
					if (confirm('If you preview without saving all changes will be lost. Are you sure you want to continue without saving?') != true) {						
						mustSave = false;
						return false;
					}
					else return true;
				}											
			});		
			$(".must_save").bind('keyup',  function(){
				mustSave = true;
			});			
			$(".must_save_click").bind('mousedown',  function(){
				mustSave = true;
			});		
			
			//projectts companies auto complete
			$('#project_company_select').bind('change', function() {
				if ( $(this).val() == '0') {
					$("#c_name").val('');
					$("#c_email").val('');
					$("#c_adr").val('');
					$("#c_postal").val('');
					$("#c_city").val('');
					$("#c_tel").val('');
					$("#c_mobile").val('');
					$("#c_fax").val('');
					$("#c_website").val('');
				} else {
					$("#c_name").val(bit_projects['c_name'][$(this).val()]);
					$("#c_email").val(bit_projects['c_email'][$(this).val()]);
					$("#c_adr").val(bit_projects['c_adr'][$(this).val()]);
					$("#c_postal").val(bit_projects['c_postal'][$(this).val()]);
					$("#c_city").val(bit_projects['c_city'][$(this).val()]);
					$("#c_tel").val(bit_projects['c_tel'][$(this).val()]);
					$("#c_mobile").val(bit_projects['c_mobile'][$(this).val()]);
					$("#c_fax").val(bit_projects['c_fax'][$(this).val()]);
					$("#c_website").val(bit_projects['c_website'][$(this).val()]);
					var country = bit_projects['c_country'][$(this).val()]
					$("#c_country option").each( function()  {
						if ( $(this).val() ==  country) {
							this.selected = true;
						} else {
							this.selected = false;
						}
						
					});
				}
			});
			
			
			//$("#google_map *").css('border', '1px solid #000');
			
			//lightbox
			$(function() {	
				$('a.lightbox').lightBox();
			});	
			
			
			
			
			// categories (registration)
			$(":checkbox[name^='cat_']").click(function() {
				$(":checkbox[name^='cat_']").not(this).removeAttr('checked');
			});	
			
			$("#checkboxall").click(function() {			   
			   $("input[name^='ch']").each(function() {
			   		var checked_status = this.checked;
				    this.checked = !checked_status;
			   });
		    });			
			
			$("a#checkboxall").toggle(
		      function () {
		        $(this).html('Deselect all');
		      },
		      function () {
		        $(this).html('Select all');
		      }
		    );
			
		    $(".tooltip").ToolTip({
				className: 'infoTooltip',
				position: 'bottom'
			});
			
	 			
			
	});