/*
Bones Scripts File
Author: Eddie Machado

This file should contain any js scripts you want to add to the site.
Instead of calling it in the header or throwing it inside wp-head()
this file will be called automatically in the footer so as not to 
slow the page load.

*/

// Modernizr.load loading the right scripts only if you need them
Modernizr.load([
	{
    // Let's see if we need to load selectivizr
    test : Modernizr.borderradius,
    // Modernizr.load loads selectivizr for IE6-8
    nope : ['selectivizr-min.js']
	}
]);

/* imgsizer (flexible images for fluid sites) */
var imgSizer={Config:{imgCache:[],spacer:"/path/to/your/spacer.gif"},collate:function(aScope){var isOldIE=(document.all&&!window.opera&&!window.XDomainRequest)?1:0;if(isOldIE&&document.getElementsByTagName){var c=imgSizer;var imgCache=c.Config.imgCache;var images=(aScope&&aScope.length)?aScope:document.getElementsByTagName("img");for(var i=0;i<images.length;i++){images[i].origWidth=images[i].offsetWidth;images[i].origHeight=images[i].offsetHeight;imgCache.push(images[i]);c.ieAlpha(images[i]);images[i].style.width="100%";}
if(imgCache.length){c.resize(function(){for(var i=0;i<imgCache.length;i++){var ratio=(imgCache[i].offsetWidth/imgCache[i].origWidth);imgCache[i].style.height=(imgCache[i].origHeight*ratio)+"px";}});}}},ieAlpha:function(img){var c=imgSizer;if(img.oldSrc){img.src=img.oldSrc;}
var src=img.src;img.style.width=img.offsetWidth+"px";img.style.height=img.offsetHeight+"px";img.style.filter="progid:DXImageTransform.Microsoft.AlphaImageLoader(src='"+src+"', sizingMethod='scale')"
img.oldSrc=src;img.src=c.Config.spacer;},resize:function(func){var oldonresize=window.onresize;if(typeof window.onresize!='function'){window.onresize=func;}else{window.onresize=function(){if(oldonresize){oldonresize();}
func();}}}}

// as the page loads, cal these scripts
jQuery(document).ready(function() {

    var max = null;
    jQuery("#testimonials div").each(function() {
        if ( !max || max.outerHeight(true) < jQuery(this).outerHeight(true) )
        max = jQuery(this);
    });
    
    

    if(jQuery('#testimonials').length > 0) {
        jQuery("#testimonials").css('height', max.height()+"px");
        
        jQuery('#testimonials').cycle({ 
            fx:    'fade', 
            pause:  1,

            timeout: 22000,
            speed: 800
            //after: onAfter
        });
    }

	
	
	// add all your scripts here

 
}); /* end of as page load scripts */

jQuery(window).load(function() {
    if(jQuery("#sticky").length > 0) {
        jQuery('#sticky').stickySidebar();
    }
});


function gform_product_total(formId, total){
    //only apply logic to form ID 165
    if(formId != 2)
      return total;
    
    var quantity = jQuery(".ginput_quantity").val();
    
    if(quantity > 5 && quantity <= 17) {
        jQuery(".ginput_product_price").html("$16.99");
        total = quantity * 16.99;
    } else if(quantity > 17 && quantity <=23) {
        jQuery(".ginput_product_price").html("$16.75");
        total = quantity * 16.75;
    } else if(quantity > 23) {
        jQuery(".ginput_product_price").html("$15.95");
        total = quantity * 15.95;
    }
        
    return total;
}


function onAfter(curr, next, opts, fwd) {
    var index = opts.currSlide;
    jQuery('#prev,#prev2,#prev3,#prev4,#prev5')[index == 0 ? 'hide' : 'show']();
    jQuery('#next,#next2,#next3,#next4,#next5')[index == opts.slideCount - 1 ? 'hide' : 'show']();
    //get the height of the current slide
    var $ht = jQuery(this).height();
    //set the container's height to that of the current slide
    jQuery(this).parent().animate({height: $ht});
}

