/* jQuery functions */
$(document).ready(function()	{
						   
	extendBorder();					
	
	pdfLinks();
	
	adminMenu();
	
	serviceForm();
	
	//historyFlash();
	
});

function extendBorder()	{
	// Make sure borders on home page extend fully						
	items = $("#content_home ul").find("li");
	contentHeight = $("#content_home").height();
	$(items).each(function(i)	{
		pHeight = $(items[i]).find("p").height();
		imgHeight = $(items[i]).find("img.headline").height();			
		newHeight = (contentHeight - imgHeight);
		$(items[i]).find("p").height(newHeight);
	});		
}

function pdfLinks()	{
	// Make all .pdf links open in a new window
	$("a[href*=.pdf]").click(function(){
		window.open(this.href);
		return false;
	});	
}

function adminMenu()	{
	// Admin Menu
	closedHeight = $("#admin a:first").height();
	theWidth = $("#admin").width();
	$("#admin").height(closedHeight);
	$("#admin a:first").toggle(openAdmin, closeAdmin);	
}

	function openAdmin(e)	{
		e.preventDefault();
		totalHeight = $("#admin div").height() + closedHeight;
		$("#admin").animate({ height : totalHeight });
		$("#admin a:first").text("- Admin Menu");
	}
	
	function closeAdmin(e)	{
		e.preventDefault();	
		$("#admin").animate({ height : closedHeight });
		$("#admin a:first").text("+ Admin Menu");
		
	}

function serviceForm()	{
	
	// Define all my variables
	
	// Set of inputs
	businessInputs = "#webform-component-type_of_business input";
	serviceInputs = "#webform-component-service_request input";
	
	// Div around Other input box
	businessDiv = "#webform-component-please_specify_business";
	serviceDiv = "#webform-component-please_specify_service";
	
	// ID of Other input box
	businessValue = 'edit-submitted-type-of-business-Other';
	serviceValue = 'edit-submitted-service-request-Other';
	
	$(businessDiv).hide();
	$(serviceDiv).hide();
	
	$(businessDiv + " label").append('<span style="color:#ff0000;">*</span>');
	$(serviceDiv + " label").append('<span style="color:#ff0000;">*</span>');
	
	// Type of business
	$(businessInputs).click(function()	{
		if(this.id !== businessValue)	{
			$(businessDiv).fadeOut("slow");
		} else if($(businessDiv).css("display") == 'none')	{					
			$(businessDiv).fadeIn("slow");
		}
		});
		
	// Service requested
	$("input#" + serviceValue).change(function () {
		if($(this).attr("checked") === true) {
			//do the stuff that you would do when 'checked'
			$(serviceDiv).fadeIn("slow");
			return;
		}
		//Here do the stuff you want to do when 'unchecked'
		$(serviceDiv).fadeOut("slow");
    
});
}	

function historyFlash()	{
	if($("#content_inside").find("history_flash"))	{
		 var so = new SWFObject("/sites/all/themes/valleyproteins/flash/history.swf", "history_flash", "500", "500", "8", "#ffffff");
		 so.addParam("wmode", "transparent");
		 so.write("history_flash");	
	}
}
															
