$(document).ready(function() {
   
	$.historyInit(pageload);
    $("a[href$='.pdf']").prepend(' <img src="../icons/pdf-icon.png" border="0">&nbsp;&nbsp;'); 
	$("a[href$='.PDF']").prepend(' <img src="../icons/pdf-icon.png" border="0">&nbsp;&nbsp;'); 
	$("a[href$='.doc']").prepend(' <img src="../icons/doc-icon.png" border="0">&nbsp;&nbsp;'); 
	$("a[href$='.DOC']").prepend(' <img src="../icons/doc-icon.png" border="0">&nbsp;&nbsp;');
	$("a[href$='.pps']").prepend(' <img src="../icons/ppt-icon.png" border="0">&nbsp;&nbsp;');
	$("a[href$='.ppt']").prepend(' <img src="../icons/ppt-icon.png" border="0">&nbsp;&nbsp;');
	$("a[href$='.zip']").prepend(' <img src="../icons/zip-icon.png" border="0">&nbsp;&nbsp;');
	
	$("div").filter(".onlythis").css({padding:"0 15px 0 0"});
	
	$('a[rel*=facebox]').facebox({
        loading_image : 'loading.gif',
        close_image   : 'closelabel.gif'
    });
	$.facebox.settings.opacity = 0.5;
	
	var myFile = document.location.toString();
	if (myFile.match('#')) { // the URL contains an anchor
	  var myAnchor = myFile.split('#')[1];
	 //alert(myAnchor)
	  showMe(myAnchor);
	}
		
	$("a[rel='history']").click(function(){
			// 
			var hash = this.href;
			hash = hash.replace(/^.*#/, '');
			// moves to a new page. 
			// pageload is called at once. 
			$.historyLoad(hash);
			$(this).preventDefault();
			return false;
		});


	
	
	$("a").click(function(ev) {
   
		if(($(this).is("[href^=#]")))
		{
			//ev.preventDefault();
			var myAnchor = $(this).attr("href").split('#')[1];
			showMe(myAnchor);
			
		}
		if(!(($(this).is("[href^=../]"))||($(this).is("[href^=#]"))||($(this).is("[href^=http://www.utdallas.edu]"))||($(this).is("[href^=http://utdallas.edu]"))||($(this).is("[href^=http://utd.edu]"))||($(this).is("[href^=http://www.utd.edu]"))||($(this).is("[href^=https://www.utd.edu]"))||($(this).is("[href^=https://utd.edu]"))||($(this).is("[href^=https://www.utdallas.edu]"))||($(this).is("[href^=https://utdallas.edu]"))||($(this).is("[href^=https://utsystem.edu]"))||($(this).is("[href^=https://www.utsystem.edu]"))||($(this).is("[href^=http://www.utsystem.edu]"))||($(this).is("[href^=http://utsystem.edu]"))))
		{
			/*if(confirm("You are redirected to a site that is not hosted by UTD."))
				$(this).attr("target","_blank");
			else
			{
				ev.preventDefault();
			}*/
		}
		if($(this).is("[href$=.pdf]"))
		{
			$(this).attr("target","_blank");
		}
		if($(this).is("[href$=.doc]"))
		{
			$(this).attr("target","_blank");
		}
		if($(this).is("[href$=.DOC]"))
		{
			$(this).attr("target","_blank");
		}
		if($(this).is("[href$=.PDF]"))
		{
			$(this).attr("target","_blank");
		}
   });
      
 });  
  
	function showMe(e)
	{
		if(e!='')
		{
			$("div:visible").filter(".test").hide();
			$("#"+e).show();
//			document.getElementById("DivHome").innerHTML=document.getElementById(e).innerHTML;
		}
		else
		{
			$("div:visible").filter(".test").hide();
			$("div").filter(".firstone").show();
		}
		//$("#"+e).animate({ scrollTop: $("#"+e).attr("scrollHeight") }, 3000);
	}
	
	function pageload(hash) {

		// hash doesn't contain the first # character.
		if(hash) {
			// restore ajax loaded state
			$("div:visible").filter(".test").hide();
			$("#"+hash).show();
			//document.getElementById("DivHome").innerHTML=document.getElementById(hash).innerHTML;
		} else {
			// start page
			$("div:visible").filter(".test").hide();
			document.getElementById("DivHome").innerHTML='';
			$("div").filter(".firstone").show();
		}
	}
