j(document).ready(function(){
    j('.acc_container').hide(); 
	j('.acc_trigger:first').addClass('active').next().show(); //Add "active" class to first trigger, then show/open the immediate next container
	j(".acc_trigger").click(function(){
		j(this).toggleClass("active").next().slideToggle("fast");
		return false; //Prevent the browser jump to the link anchor
	});
             j("a.fb").fancybox({
             type: 'iframe'
        });
        j("#inline").fancybox();
       j('a.fbclose').click(function(){ 
            parent.top.j('#fancybox-close').trigger('click'); 
        }); 

    j("button[id=calc]").bind("click", recalc);
    
    j("#home-callout").tabs({fx:{opacity: "toggle"}}).tabs("rotate", 5000, true); 
    //call below pauses the rotation when hovering the banner
    j("#home-callout").hover(function() {  
    	j("#home-callout").tabs("rotate",0,true);
    },function() {  
    	j("#home-callout").tabs("rotate",5000,true);  
    });
    
    j('.so_name').attr('placeholder', 'Name');
    j('.so_name').blur();
    j('.so_email').attr('placeholder', 'E-mail');
 
});

function recalc(){
    var t_sand = 0;
    var t_road = 0;

    if (j("input:radio[name=paving]:checked").val() == 'Pathway') 
    { 
        t_sand = 0.03;
        t_road = 0.05;
    } 
    else if (j("input:radio[name=paving]:checked").val() == 'Driveway') 
    {
        t_sand = 0.04;
        t_road = 0.075;
    }
    // Calculate the Road Base
    j("[id=road]").calc(
        // the equation to use for the calculation
        "length * width * type * 1.9",
        // define the variables used in the equation, these can be a jQuery object
        {
            length: j("input[id=num_length]"),
            width: j("input[id=num_width]"),
            type: t_road 
        },
        // define the formatting callback, the results of the calculation are passed to this function
        function (s){
            // return the number 
            return s.toFixed(2);
        },
        // define the finish callback, this runs after the calculation has been complete
        function ($this){
            var sum = $this.sum();
            
            j("#road").text(
                // round the results to 2 digits
                sum.toFixed(2)
            );
        }
    );
    // Calculate the Bedding Sand
    j("[id=bedding]").calc(
        "length * width * type * 1.5",
        {
            length: j("input[id=num_length]"),
            width: j("input[id=num_width]"),
            type: t_sand
        },
        function (s){
            return s.toFixed(2);
        },
        function ($this){
            var sum = $this.sum();
            
            j("#bedding").text(
                sum.toFixed(2)
            );
        }
    );
    // Calculate the Gap Sand
    j("[id=gap]").calc(
        "length * width / div",
        {
            length: j("input[id=num_length]"),
            width: j("input[id=num_width]"),
            div: 6
        },
        function (s){
            return s.toFixed(2);
        },
        function ($this){
            var sum = $this.sum();
            
            j("#gap").text(
                sum.toFixed(2)
            );
        }
    );
    j("li.results").css("display", "block");
}
