	function getXmlHttpRequestObject() {
		if (window.XMLHttpRequest) {
			return new XMLHttpRequest();
		} else if(window.ActiveXObject) {
			return new ActiveXObject("Microsoft.XMLHTTP");
		} else {
			alert("It's about time to upgrade your browser don't you think?");
		}
	}
	
	$(function(){
		$('.dragbox').each(function(){
		$(this).find('.hide-close').click(
			function() {
				$(this).siblings('.dragbox-content').slideToggle(function() { 
					if($(this).is(":hidden")) { 
						var identify=$(this).parent().attr("id");
						var searchReq = getXmlHttpRequestObject();
						searchReq.open("GET", g_site_url + '/wp-content/themes/newnet/js/closed.php?i=' + identify +'&c=1', true);
						searchReq.send(null);
					}
					if($(this).is(":visible")) { 
						var identify=$(this).parent().attr("id");						
						var searchReq = getXmlHttpRequestObject();
						searchReq.open("GET", g_site_url + '/wp-content/themes/newnet/js/closed.php?i=' + identify +'&c=0', true);
						searchReq.send(null);
					}
				}
			);})
		
		.end()
		});
		
		$('.column').sortable({
			connectWith: '.column',
			handle: 'h2',
			cursor: 'move',
			placeholder: 'placeholder',
			forcePlaceholderSize: true,
			opacity: 0.4,
			stop: function(event, ui){
				$(ui.item).find('h2').click();
				var sortorder='';
				$('.column').each(function(){
					var itemorder=$(this).sortable('toArray');
					var columnId='column';
					sortorder+=columnId+itemorder.toString()+'';
					//sortorder+=itemorder.toString()+'';
				});
				
				var searchReq = getXmlHttpRequestObject();
				
				searchReq.open("GET", g_site_url + '/wp-content/themes/newnet/js/order.php?i=' + sortorder +'&c=1', true);
				searchReq.send(null);
					
			}
		})
		.disableSelection();
	});
	
	var searchReq = getXmlHttpRequestObject();

	function loadContent(id,cat,type,loader,rep) {
		
		//if($(".dragbox-content").is(":hidden")) { $('.dragbox').slideDown("slow"); }
						
		if (searchReq.readyState == 4 || searchReq.readyState == 0) {
		
			$(type).animate({'opacity':'0.3'},300);
			$(type).fadeIn('fast');
						
				searchReq.open("GET", g_site_url + '/wp-content/themes/newnet/ajax.php?s=' + id +'&c=' + cat +'', true);
				searchReq.onreadystatechange = handleSearchSuggest; 
				searchReq.send(null);
				
			$(loader).show();
							
		}
		
	function handleSearchSuggest() {
			
		if (searchReq.readyState == 4) {
			
			$(type).animate({'opacity':'1.0'},500);
			$(type).fadeIn('fast');
						
			var ss = document.getElementById(rep)
			var str = searchReq.responseText.split("\n");
				ss.innerHTML = '';
				for(i=0; i < str.length - 1; i++) {
					//Build our element string.  This is cleaner using the DOM, but
					//IE doesn't support dynamically added attributes.
					var suggest = '' + str[i] + '';
					
					ss.innerHTML += suggest;
					$(loader).fadeOut(600);
				}
			
			$(loader).fadeOut("fast"); 
		}
	}
	
}