$(document).ready(function(){
    
    $("div.puffWrapper.gron ul").addClass("oppet");
    
    $("div.puffWrapper.bla.acc div.accordion").addClass("large");

	Cufon.replace('h3, .cufon', {fontFamily : 'Chalet'});
	
	$("div.puffWrapper a.readMore").click(function(){
		
		var theParent = $(this).parent();
		var oldHeight = 202;
		var theWrapper = $(theParent).parent();
		if($(theWrapper).hasClass("acc")){
			return false;
		}
		var theBody = $(theWrapper).find(".puffBody");
		var theContent = $(theBody).find(".puffContent");

		var theHeight = $(theContent).height();
		$(theBody).toggleClass("collapsed");
		
		if($(theBody).hasClass("collapsed")){
			$(theBody).animate({"height": oldHeight + "px"});
		}
		else{
			$(theBody).animate({"height":theHeight+"px"});
		}
		
		$(this).toggleClass("open");
		
		return false;
	});

	$("div.puffWrapper.acc a.readMore").click(function(){
		
		var theParent = $(this).parent();
		var oldHeight = 202;
		var theWrapper = $(theParent).parent();
		var theBody = $(theWrapper).find(".puffBody");
		var theContent = $(theBody).find(".puffContent");

		var theHeight = $(theContent).height();
		$(theBody).toggleClass("collapsed").toggleClass("ie6");
		
		if($(theBody).hasClass("collapsed")){
			//$(theBody).animate({"height": oldHeight + "px"});
			$(theBody).css({"height": oldHeight + "px"});
		}
		else{
			//$(theBody).animate({"height":theHeight+"px"});
			$(theBody).css({"height" : "100%"});
		}
		
		$(this).toggleClass("open");
		
		return false;
	});
	
	$("ul").each(function(){
		$(this).find("li:last").addClass("last");
	})
	$(".accordion").each(function(){
		$(this).find("h4:last").addClass("last");
	})
	$(".accordion h4").click(function(){
		var theParent = $(this).parent();
		var oldHeight = 202;
		var theWrapper = $(theParent).parent();
		var theBody = $(theWrapper).parent()
		var theMainWrapper = $(theBody).parent();
		var readMore = $(theMainWrapper).find("a.readMore");
		$(readMore).addClass("open");
		//var theBody = $(thePuffWrapper).find(".puffBody");
		var theContent = $(theBody).find(".puffContent");
		$(theBody).css({"height" : "100%"}).removeClass("collapsed");
	});
	//$(".accordion h3:last").addClass("last");
	//$(document).pngFix();
	$(".accordion").accordion({autoHeight : false, collapsible : true, active : false});
});