



/*
nbs 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
$(function(){
	if($('#slides')){
		$('#slides').slides({
			preload: true,
			generateNextPrev: false,
			play: 6000,
			preloadImage: '/wp-content/themes/nbs/library/images/loading.gif'
		});
	}
	
	if($('#knowledge-slider')){
		$('#knowledge-slider').slides({
			preload: true,
			generateNextPrev: false,
			play: false, //Autoplay slideshow, a positive number will set to true and be the time between slide animation in milliseconds.
			next: 'next',
			prev: 'prev'
		});
	}
	
	 //$("input, textarea, select, button").uniform();
	 $("input:not(:text, :password, .no-uniform), textarea, select, button:not(.no-uniform)").uniform();
	
	if($('#slider1')){
		var slider1 = $('#slider1').bxSlider({
			displaySlideQty: 2,
			moveSlideQty: 1, 
			controls: false,
			startingSlide: 0,
			auto: true, //Make slide transitions occur automatically
			pause: 6000 // In ms, the duration between each slide transition
		});
	}
	 $('#prev1').click(function(){
		slider1.goToPreviousSlide();
		return false;
	  });
	
	  $('#next1').click(function(){
		slider1.goToNextSlide();
		return false;
	  });
	  
	if($('#webisodeSlider')){
            var $currentWebisode = $('div.webisode').eq(0);;
            
            function urldecode(str){return decodeURIComponent((str + '').replace(/\+/g, '%20'));}
            
            function showWebisode($wsContent)
            {
                $('div.webisode').removeClass('webisode_active');
                $currentWebisode.addClass('webisode_active');

                if(($wsContent != null) && ($wsContent.length > 0))
                {
                    var s = urldecode($wsContent.attr('embedsrc'));
                    var t = $wsContent.attr('title');
                    var d = $wsContent.attr('description');
                    if(s && s.length > 0 && t && t.length > 0 && d && d.length > 0)
                    {
                    	$('.jwebisode_embed_display iframe').hide();
                        $('.jwebisode_embed_display').html(s);
                        $('.jwebisode_title_display').html(t);
                        $('.jwebisode_description_display').html(d);
                    }
                } 
            }

            //Show selected webisode
            $('.jwebisode_click').live('click',function(){
                $currentWebisode = $(this).parents('div.webisode');
                showWebisode($currentWebisode.children('var.jwebisode'));
            });
            
            
            var webSlider = $('#webisodeSlider').bxSlider({
                    displaySlideQty: 3,
                    moveSlideQty: 1, 
                    startingSlide: 0,
                    infiniteLoop: true,
                    prevSelector: '#prev1',
                    nextSelector: '#next1',
                    nextImage: '/wp-content/themes/nbs/library/images/knowledge-center/right-arrow.png',
                    prevImage: '/wp-content/themes/nbs/library/images/knowledge-center/left-arrow.png'
            });
            $.nbs = {webSlider: webSlider}; //declare nbs variables
      }
	
}); /* end of as page load scripts */

