// JavaScript Document
var myID = "";
var currentDiv = "#c_info";

$(document).ready(function () {
	
	bodyID =  $("body").attr("id");
	
	if(bodyID == "selectBody"){
	
		
		$('#selectBox').sSelect({ddMaxHeight: '200px'});
		$('#categoryBox').sSelect({ddMaxHeight: '200px'});
		
		$("#selectForm").bind("submit",function(){
			
			if($("#selectBox option").index($("#selectBox option:selected")) == 0){
				
				return false;	
			}		  
		 });
		
		$("#categoryForm").bind("submit",function(){
			if($("#categoryBox option").index($("#categoryBox option:selected")) == 0){
				return false;	
			}		  
		 });
		
	} else{
		if(bodyID == "cardBody"){
			var journalTitle = $("#subheader h2").text();
			if(/&reg;/.test(journalTitle)){
				journalHTML = $("#subheader h2").html();
				journalHTML = journalHTML.replace(/&amp;reg;/,"<sup>&reg;</sup>");
				$("#subheader h2").html(journalHTML);
			}
			
			
			
			if (journalTitle.length > 45) {
				if ($("#subheader h2").height() > 50){
					$("#subheader h2").css("font-size","1.1em")
				} else{
					$("#subheader h2").css("font-size","1.3em")	
				}
			}
			
			var contentHTML = $("#content").html();
			contentHTML = contentHTML.replace(/&reg;/,"<sup>&reg;</sup>").replace(/\u00AE/g,"<sup>&reg;</sup>");
			$("#content").html(contentHTML);

			$("#content div.infoDiv").hide();
			$("#c_info").slideDown(500);
			$("#m_info").addClass("on");
			$("div.conDiv").append("<br clear=\"both\" />");
			
			$(".print").bind("click", function(e){
				e.preventDefault;
				print();
			 });
			
			bindMenu();
			
			$("a.parentOpen").bind("click",function(e){
				e.preventDefault;
				if(window.opener){
					window.opener.location= $(this).attr("href");
					return false;
				} else{
					
				}
				
			});
			
			$("a.print").bind("click",function(e){
				e.preventDefault;
				window.print();
				return false;
				
			});
			
			$('table.rateTable tr:odd').addClass('odd');
			$('table.closingTable tr td:first-child').addClass('textLeft');
			$('table.mechTable tr td:first-child').addClass('textLeft');
			$('table.contactTable tr td:first-child').addClass('first');
			$('.mechTable tr td:not(:first-child)').addClass('textnowrap');
		}
		
		
		
		$("a.back").bind("click",function(e){
			e.preventDefault;
			window.location.href="index.php";
			//window.history.back();
			return false;
			
		});
		
		$("a.close").bind("click",function(e){
			e.preventDefault;
			self.close();
			return false;
		});
		
	}

});

function bindMenu(){
	$("#menu li a").bind("click",function(e){
		e.preventDefault;
	
		$("#menu li a").unbind("click");
		
		myID = $(this).parent().attr("id");
		$("#menu li").removeClass("on");
		$(this).parent().addClass("on");
		clickBind();
		return false;
	});
}

function clickBind(e){
	
	$(currentDiv).slideUp(function(){
		
		myID = "#c_" + (myID.substring(2));
		$(myID).slideDown(500);
		currentDiv = myID;
		bindMenu();
		
	});
	
}
