


$(document).ready( function()
{
	

	
	/* collapseable panels */
	
	var animObj = {};
	var cssDec = /AppleWebKit/.test(navigator.userAgent) ? "max-height":"height";
	function toggle(e, dontAnimate)
	{
		var jthis =  $(this);
		var jelm = $(this).parent();
		var elm = jelm.get(0);				
		elm.closed = (elm.closed==undefined) ? false : !elm.closed;
		jthis.toggleClass("closed", elm.closed);
		var height = elm.closed ? elm.scrollHeight : 21
		animObj[cssDec]=height;
		if (dontAnimate)
		{
			jelm.stop().css(animObj);
		}
		else
		{
			jelm.stop().animate(animObj, 300);
		}
		e.preventDefault();
	}
	$(".panel.collapsable").css({"overflow": "hidden"}).children("h2:first-child").addClass("toggler").bind("mousedown", toggle).trigger("mousedown", true).eq(0).trigger("mousedown", true);


	/* contact panel */

	function ctaToggle(e)
	{
		
	}


	function toggleTab(e, dontAnimate)
	{
		var jelm = $(this).parent();
		var elm = jelm.get(0);				

		elm.closed = (elm.closed == undefined) ? false : !elm.closed;
		var width = elm.closed ? -317 : 0
		jelm.stop().animate( {"right":width}, 250);
		e.preventDefault();
		get_form();
	}
	function get_form () {
		if ($('#contact_form form').length == 0) {
			$.get('/contact/',{},function(data) {
				var frm = data.substring(data.indexOf('<form'),data.indexOf('</form>'))
				$('#contact_form').html('<p>Why not get in touch now and send us a little message?</p>'+frm+'</form>');
				$('#id_Enquiry').attr('cols',25).attr('rows',5);
				$('#contact_form #id_honeypot').parent().css('display','none');
			})
		}
	 }
	 
	var contactTab = $("<a class='tab' href='javascript:;'>Contact</a>").bind("mousedown",toggleTab);
	var closeTab = $("<a class='close' href='javascript:;'>Close</a>").bind("mousedown",toggleTab);
	$("#contact").attr("id","quickcontact").prepend(contactTab).prepend(closeTab);
	
	$("#portfolio-ctas a").bind("click",function(e) { contactTab.trigger("mousedown"); e.preventDefault(); return false } )

})
		
try { document.execCommand("BackgroundImageCache", false, true); } catch(err) {}
