function fadeDash(){
	$("#dash").show();
	$("#dash-open").fadeOut("fast");
}


function magic_sort(){
		//magical growing boxes
		if ($("#headline_articles_column_1").height() > $("#headline_articles_column_2").height()){
				var largest_col = $("#headline_articles_column_1").height();
			} else {
				var largest_col = $("#headline_articles_column_2").height();
			}
			
			if ($("#headline_articles_column_3").height() > largest_col) {
				largest_col = $("#headline_articles_column_3").height();
			}


			var col1difference = (largest_col - $("#headline_articles_column_1").height());

		//	alert('column 1 needs to be '+col1difference+'px taller');

			var col1_boxes = $("#headline_articles_column_1 li").length;
			var extra_col1_box = Math.round(col1difference / col1_boxes);

				//alert(extra_col1_box);
				
				
			$("#headline_articles_column_1 li").each(function(e){
			
				$(this).height($(this).height()+extra_col1_box);

				$(this).children('a:first').children('span').css('margin-top',(extra_col1_box/2)+'px');
				$(this).children('div').css('margin-top',(extra_col1_box/2)+'px');
				
				
			
			});



			var col2difference = (largest_col - $("#headline_articles_column_2").height());
			
		//		alert('column 2 needs to be '+col2difference+'px taller');
			
				var col2_boxes = $("#headline_articles_column_2 li").length;
				
				
				var extra_col2_box = Math.round(col2difference / col2_boxes);
				
				
				//alert(extra_col2_box);
				
				
			$("#headline_articles_column_2 li").each(function(e){
			
				$(this).height($(this).height()+extra_col2_box);
				
				$(this).children('a:first').children('span').css('margin-top',(extra_col2_box/2)+'px');
				$(this).children('div').css('margin-top',(extra_col2_box/2)+'px');
			
			});






			var col3difference = (largest_col - $("#headline_articles_column_3").height());
			
//	  	alert('column 3 needs to be '+col3difference+'px taller');
			
			
			var col3_boxes = $("#headline_articles_column_3 li").length;
			var extra_col3_box = Math.round(col3difference / col3_boxes);
			$("#headline_articles_column_3 li").each(function(e){
			
				$(this).height($(this).height()+extra_col3_box);
				
				$(this).children('a:first').children('span').css('margin-top',(extra_col3_box/2)+'px');
				$(this).children('div').css('margin-top',(extra_col3_box/2)+'px');
			
			});



}






/* =DOCUMENT ON READY
-----------------------------------------------------------------------------*/
$(document).ready(function(){

	//clicking on a resource -- count as view
	
		$('.single_resource_sort').click(function(){
			$.ajax({
				url: "/intelligence.ajax.php",
				type: "POST",
				data: "action=resource&id="+$(this).attr('id').substr(4),
				dataType: "html",
				success: function(data){
					//alert(data);
				}, error: function(data){
						
				}
			});
		});
	
		

	$("a.tooltip").hover(function(e){
								  
		this.t = this.title;
		this.title = "";						  
		$("body").append('<p style="border-color:#'+$(this).parent().prevAll('.bordercolor:first').val()+'" id="tooltip">'+ this.t +'</p>');
		$("#tooltip")
			.css("top",(e.pageY + 5) + "px")
			.css("left",(e.pageX + 5) + "px")
			.fadeIn("fast");
			//$("#tooltip").dropShadow({left: 4, top: 4, opacity: 0.1, blur: 3});	
    },
	function(){
		this.title = this.t;
		//$("#tooltip").removeShadow();		
		$("#tooltip").remove();
    });	
	$("a.tooltip").mousemove(function(e){
		$("#tooltip")
			.css("top",(e.pageY + 5) + "px")
			.css("left",(e.pageX + 5) + "px");
			//$("#tooltip").removeShadow();
			//$("#tooltip").dropShadow({left: 4, top: 4, opacity: 0.1, blur: 3});
	});
		
		//if (magic_load_ran == true) {magic_sort();}
				

  		
  		
  		
$(".drag_resource_container").css('cursor','default');  		
  		
  		
$(".drag_resource_container").click(function(){




	
/*
	$(this).parent().siblings().find('.hidenseek').each(function(e){
			$(this).parent().trigger('click');
	});
	

	$(this).siblings().find('.hidenseek').each(function(e){
		$(this).parent().trigger('click');
	});
*/

});



$(".drag_resource_links").click(function(){ 
 		
	$(this).siblings().find('.hidenseek').each(function(e){
		$(this).parent().trigger('click');
	});
		
});
  		
  		
  		
  		

$(".rview").click(function(){
	if ($(this).children('.hidenseek').attr('src') == '/assets/img/ui/hidenseek.png'){
		$(this).children('.hidenseek').attr('src','/assets/img/ui/hidenseek_rev.png');
		$(this).children('strong').text('Hide');
	} else {
		var number_hidden = $(this).siblings('.resource_overflow').length;
		$(this).children('strong').text('View '+number_hidden+' More');
		$(this).children('.hidenseek').attr('src','/assets/img/ui/hidenseek.png');
	}
});


	$(".rview").click(function(){
	//$(this).siblings(".resource_overkill").fadeIn('fast');
		$(this).siblings('.resource_overflow').each(function(){
			if ($(this).is(':hidden')){
				$(this).fadeIn('fast');
			} else {
				$(this).fadeOut('fast');
			}
		});
	});





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

	
	var whereTo = $('#resselect').val();
	
	
	//alert(whereTo);
	
	//alert($('#resources').find(whereTo+' .bordercolor:first').val());
	
	//alert($('#'+whereTo).children('.bordercolor').val());
	


	$(document).scrollTop($('#'+whereTo).offset().top);
	
	
/* 	$('#'+whereTo+' h1').css('background-image','url(\'/assets/headlines/headline.php?b='+$('#'+whereTo).children('.bordercolor').val()+'&f=ffffff&size=14&text='+$('#'+whereTo+' h1').attr('title')+'\')'); */
	



	for (var x=1; x<4; x++){
		var time = 70;
		
		$('#'+whereTo+' li:first').animate({backgroundColor:'#'+$('#'+whereTo).children('.bordercolor').val()},time, function(){
		
			$('#'+whereTo+' h1').css('background-image','url(\'/assets/headlines/headline.php?b='+$('#'+whereTo).children('.bordercolor').val()+'&f=ffffff&size=14&text='+$('#'+whereTo+' h1').attr('title')+'\')');
		});
	
		$('#'+whereTo+' li:first').animate({backgroundColor:'#f7f7f7'},time, function(){
	
			$('#'+whereTo+' h1').css('background-image','url(\'/assets/headlines/headline.php?b=f7f7f7&f='+$('#'+whereTo).children('.bordercolor').val()+'&size=14&text='+$('#'+whereTo+' h1').attr('title')+'\')');
		});
	}
});







	$('#editorsnote_modal .close').click(function(){
		$('#editorsnote_modal').hide();
	});



//THIS IS OUR ARTICLE ON CLICK EVENT

	$('.headline_articles li span').click(function(){
		
		$.ajax({
			url: "/intelligence.ajax.php",
			type: "POST",
			data: "action=article&id="+$(this).attr('id').substr(5),
			dataType: "html",
			success: function(data){
				//alert(data);
			}, error: function(data){
					
			}
		});	
		
		
		$('#important_headline li').css('text-decoration','none');
		$('.headline_articles li').css('border','1px solid #eaeaea');
		$('.headline_articles li').css('background-color','#f7f7f7');
	
		$(this).parent().parent().css('border','1px solid #c7dec1');
		$(this).parent().parent().css('background-color','#e4fedd');
		
		//window.open($(this).children('small').children('a').attr('href'),'_blank');
	});
	
	
/*
	$('.headline_articles li span').hover(function(e){
	
		window.status=$(this).children('small').children('a').attr('href');
		
	},function(e){
		
		window.status='';
	
	});
*/
	
	
	

/*
_  _ ____ ____ ___  _    _ _  _ ____    _    _ _  _ _  _    ____ _    _ ____ _  _ ____ 
|__| |___ |__| |  \ |    | |\ | |___    |    | |\ | |_/     |    |    | |    |_/  [__  
|  | |___ |  | |__/ |___ | | \| |___    |___ | | \| | \_    |___ |___ | |___ | \_ ___] 

*/

$('#important_headline li.sortable').click(function(){

		$('.headline_articles li').css('border','1px solid #eaeaea');
		$('.headline_articles li').css('background-color','#f7f7f7');
		$('#important_headline li').css('text-decoration','none');
		
		$(this).css('text-decoration','underline');

		//MARK OUR currently selected items info
		$('#currently_selected_item').val($(this).children('.this_id').val());
		$('#currently_selected_item_type').val('article');

});






/*
___  ____ ____ _  _ 
|  \ |__| [__  |__| 
|__/ |  | ___] |  | 
                    
*/



	$('#dash-open').hide();
	$('#editorsnote_modal').hide();
	$('#dash').click(function(){

	
	

	
		if ($('#dash-open').is(':hidden')){
			$('#dash-open').fadeIn('fast'); 
			//$("#dash_listing").dropShadow({left: 0, top: 4, opacity: "0.30", blur: 5}); 
			$('#dash').fadeOut('slow');
		} else {return false;}
	});
	
	
		$('#dash-open').click(function(){
		subNavTimer = setTimeout('fadeDash()', 1000);
		//$("#dash_listing").removeShadow();
	});
	
	
	
	
	
	
/*
____ ___  _ ___ ____ ____    _  _ ____ ___ ____ 
|___ |  \ |  |  |  | |__/    |\ | |  |  |  |___ 
|___ |__/ |  |  |__| |  \    | \| |__|  |  |___    
                    
*/	
	
	
	

 $('#editorsnote').click(function(){
		if ($('#editorsnote_modal').is(':hidden')) {
			$("#editorsnote_modal").fadeIn('fast', function(){
					//$("#editorsnote_modal").dropShadow({left: 4, top: 4, opacity: "0.20", blur: 5});		
			});
		} else {
					$("#editorsnote_modal").fadeOut('fast', function(){
						//$("#editorsnote_modal").removeShadow();
					});
		}
 });
	


	$(".image_thumb").hover(function(e){
	
		
		
		if ($(this).parent().parent().parent().is('.small')){
	
			var id = $(this).attr('id').substr(4);
							
			$("body").append('<p id="floating_img"><img src="/userimages/'+id+'.jpg" /></p>');
			$("#floating_img")
				.css("top",(e.pageY + 5) + "px")
				.css("left",(e.pageX + 5) + "px")
				.fadeIn("fast");
				//$("#tooltip").dropShadow({left: 4, top: 4, opacity: 0.1, blur: 3});	
			
		 }
    
    },
	function(){
	
	if ($(this).parent().parent().parent().is('.small')){
	
		//$("#tooltip").removeShadow();		
		$("#floating_img").remove();
    
    }
    
    });	
	$(".image_thumb").mousemove(function(e){
	
	if ($(this).parent().parent().parent().is('.small')){
	
		$("#floating_img")
			.css("top",(e.pageY + 5) + "px")
			.css("left",(e.pageX + 5) + "px");
			//$("#tooltip").removeShadow();
			//$("#tooltip").dropShadow({left: 4, top: 4, opacity: 0.1, blur: 3});
	}
	
	});



//end of document on ready
});






