//change className of html from .noJS to .hasJS.
(function(el){el.className=el.className.replace("noJS", "hasJS")})(document.documentElement);

//Initial bind
$(document).ready(function () {
	/* :: iframe lightbox :: */
	if (typeof $.fn.fancybox == "function") {
		$banner = $(".banner .lightbox");
		if($banner.length > 0){
			$banner.fancybox({
				'width'				: '35%',
				'height'			: '65%',
				'autoScale'     	: false,
				'transitionIn'		: 'none',
				'transitionOut'		: 'none',
				'type'				: 'iframe',
				'titleShow'			: 'false'
			});
		}
	}
});
$(window).load(function(){
	$.easing.bounce = function (x, t, b, c, d) {
		var s = 1.70158; 
		if ((t/=d/2) < 1) return c/2*(t*t*(((s*=(1.525))+1)*t - s)) + b;
		return c/2*((t-=2)*t*(((s*=(1.525))+1)*t + s) + 2) + b;
	}


	
	$scrollable = $(".scrollable");
	if ($scrollable.length>0) {
		$scrollable.each(function(){
			$el = $(this);
			var $panels = $el.find(".panels");
			$panels.find(".panel:first").addClass("firstPanel");
			var hasPaging = $el.hasClass("has-paging")
			var conf = {
				easing:		'bounce'
				,speed:		500
				,autoplay: 	false
				,paging: 	hasPaging
				,interval: 	5000
				,loop: 		true
				,width: 	null
				,height: 	null
			}
			
			var meta = $el.metadata();			
			conf = $.extend(conf, meta);
			if (!conf.width){
				conf.width = $el.width();
				
			}
			if (!conf.height){
				conf.height = $panels.height();
			}
			
			$el.height(conf.height).width(conf.width);

			$panel = $el.find(".panel")
			$panelPadding = $panel.width() - $panel.innerWidth();
			if($.browser.msie){
				$panelPadding = $panelPadding + 1; /* IE8 Fix: 1px float panel roundup bug */
			}
			$panel.width(conf.width + $panelPadding + 1);

			var api = $el.scrollable({items:'.panels', circular: conf.loop, speed: conf.speed, easing: conf.easing });

			if(!conf.keyboard){
				$el.data("scrollable").getConf().keyboard = false;
			}
			
			if (conf.paging){
				api.navigator({ navi:".panel-nav", naviItem:'a', activeClass:'current', indexed:true})
			}
			
			if(conf.autoplay){
				api.autoscroll({ autoplay:true, interval: conf.interval, api:true })
			}
		});
	}
});
