jQuery(document).ready(function(){


// ajax working
$.ajaxSetup ({
			    // Disable caching of AJAX responses */
			    cache: false
			});
			
$().ajaxStart(function() {
			$("#loader").show();
		}).ajaxStop(function() {
			$("#loader").hide();
		}).ajaxError(function(event, request, settings){
		if (request.responseText.indexOf("not authorized")==-1){

						$.growl(request.statusText, ''+request.responseText, 'images/error.png');
						//release any diabled submit buttons
						$(":submit").attr("disabled","");
						
		}else{

			//reset everything
			$("#TheMenu").load("includes/menu.cfm",function(){
				$("#accordion").accordion({ autoHeight: false });
			
			});
			$("#ThePerson").load("content/ThePerson.cfm");
			$("#maincontent").load("content/about.cfm");
			$("#NAVSearch").hide();
			$("#NAVLogout").hide();
			$("#NAVSubscribe").show();
			$("#NAVAbout").show();
			$("#TheBriefcase").hide();
		
		
		}
  		 $("#loader").hide();
 });


// autocomplete for search form 
$("#Search1").autocomplete(	"content/lookup.cfm",{	minChars:2,	delay:200,	autoFill:false,	matchSubset:false,	matchContains:1, selectOnly:1	}	); 
$("#Search2").autocomplete(	"content/lookup.cfm",{	minChars:2,	delay:200,	autoFill:false,	matchSubset:false,	matchContains:1, selectOnly:1	}	); 
$("#Search3").autocomplete(	"content/lookup.cfm",{	minChars:2,	delay:200,	autoFill:false,	matchSubset:false,	matchContains:1, selectOnly:1	}	); 

//Accordion
$("#accordion").accordion({ autoHeight: false });


//Growl Settings


$.growl.settings.displayTimeout = 7200;
  $.growl.settings.dockCss.width = '225px';
  $.growl.settings.dockCss.top = '40px';
  $.growl.settings.noticeTemplate = ''
	+ '<table width="225" border="0" cellpadding="0" cellspacing="0">'
	+ '	<tr>'
	+ '		<td style="background-image: url(images/growl_01.png); width: 225px; height: 38px; background-repeat: no-repeat; color: #fff;">'
	+ '			<img src="%image%" style="max-width: 25px; max-height: 38px; text-align: center; margin-left: 19px; margin-top: 9px;" />'
	+ '			<h1 style="color:#d29113;font-size: 14px; margin: 0pt; margin-left: 5px; margin-bottom: 15px; display: inline;">%title%</h1>'
	+ '		</td>'
	+ '	</tr>'
	+ '	<tr>'
	+ '		<td style="background-image: url(images/growl_02.png); width: 225px; background-repeat: repeat-y; color: #ddd;">'
	+ '			<p style="margin: 15px;color:#0e3369;">%message%</p>'
	+ '		</td>'
	+ '	</tr>'
	+ '	<tr>'
	+ '	<td style="background-image: url(images/growl_03.png); background-repeat: no-repeat; width: 225px; height: 26px;" valign="top" align="right" >'
	+ '		</td>'
	+ '	</tr>'
	'+ </table>';
  $.growl.settings.noticeCss = {
    position: 'relative'
  };

    $('#clickme').click(function() {
  $.growl('title', 'msg', 'images/info.png');
  });


//login form
$("#loginbutton").livequery(function(){
	$(this).click(function(){
		$.post("content/Login_process.cfm",$("#LoginformDiv :input"),function(data){
			$("#TheMenu").load("includes/menu.cfm",function(){
				$("#accordion").accordion({ autoHeight: false });
				});
			$("#ThePerson").load("content/ThePerson.cfm");
			$("#NAVSearch").show();
			$("#NAVLogout").show();
			$("#NAVSubscribe").hide();
			$("#NAVAbout").hide();
			$("#TheBriefcase").show();
			showhide('AdvSearch');
		});
	});
});





//Search Form
$("#ADVSearchButton").click(function(){
$("#maincontent").load('content/SearchResultsPending.cfm');

	$("#maincontent").load('content/SearchResults.cfm',$("#AdvSearch :input:not(.checker),#AdvSearch :input:checked"),function(){
	
		 Shadowbox.setup("a.option");
		 
		//context menu
		$(".SRow").contextMenu({menu: 'SearchResultsMenu'},
	        function(action, el, pos) {
			
			var arrSTR = $(el).attr('id').split( "|" );
			if(action=='view'){
				//Shadowbox.open({
			    //    content:    '/content/display.cfm?uid='+arrSTR[1],
			    //    player:     "iframe",
			    //    title:      Url.decode(arrSTR[0])
			    //});
				window.open('/content/display.cfm?uid='+arrSTR[1]);
				
			}
			if(action=='email'){DoEmail('S',arrSTR[1]);}
			if(action=='case'){$("#insidebriefcase").load("includes/briefcase.cfm",{ SRadd: $(el).attr('id')});}
			}); 
			
		//Draggable
		$(".SRow").draggable({helper:"clone",opacity:0.5})	
		//Pager
		$("#example1").pager("div",{navAttach: 'prepend'});
		//close search page
		showhide('AdvSearch');

			
	});
});

$("#ADVSearchButtonReset").click(function(){
	$("#AdvSearch :input:not(.checker)").attr("value","");
});

//make the briefcase  droppable
$("#BriefcaseDroppable").droppable({tolerance:'pointer',activeClass: 'droppable-active',
hoverClass: 'droppable-hover',accept:".SRow",drop: function(ev, ui){
	$("#insidebriefcase").load("includes/briefcase.cfm",{ SRadd: ui.draggable.attr("id")});	
		} 
});

//load initial briefcase
$("#insidebriefcase").load("includes/briefcase.cfm");	


//livequery for context menu on briefcase
$(".BRow").livequery(function(){
		$(this).contextMenu({menu: 'BriefcaseMenu'},
	        function(action, el, pos) {
			var arrSTR = $(el).attr('id').split( "|" );
			if(action=='view'){
				//Shadowbox.open({
			    //    content:    '/content/display.cfm?uid='+arrSTR[1],
			    //    player:     "iframe",
			    //    title:      Url.decode(arrSTR[0])
			    //});
				window.open('/content/display.cfm?uid='+arrSTR[1],Url.decode(arrSTR[0]));
			}
			if(action=='email'){DoEmail('S',arrSTR[1]);}
			if(action=='delete'){$("#insidebriefcase").load("includes/briefcase.cfm",{ SRdelete: $(el).attr('id')});}
			}); 
});

showhide = function(layer_ref) { 

	if(document.getElementById(layer_ref).style.display=='none'){
		$(document.getElementById(layer_ref)).show("slow");
		if(layer_ref=='menucolumn'){$(document.getElementById('display')).animate({width: "580" }, 500 );};
	}else{
		$(document.getElementById(layer_ref)).hide("slow");
		if(layer_ref=='menucolumn'){$(document.getElementById('display')).animate({width: "100%" }, 500 );};
	}

} 

DoEmail = function(MType,FileName){

	$.post("content/email.cfm",{ TheType: ''+MType,TheFileName: ''+FileName},function(text){
	$.growl('eMail Sent', text, 'images/info.png');
	});

}
 
 
//splash screen
dosplash();

$("#splashclose").click(function(){
	if($("#splash :checked").length){
		$.post("content/splashstop.cfm",{Stop:1});
	}
	$("#splash").hide(2000);
});
 

});


