WebFontConfig = {
	google: { families: [ 'Playfair Display' , 'Josefin+Sans:400' ] }
};
(function() {
	var wf = document.createElement('script');
	wf.src = ('https:' == document.location.protocol ? 'https' : 'http') +
		'://ajax.googleapis.com/ajax/libs/webfont/1/webfont.js';
	wf.type = 'text/javascript';
	wf.async = 'true';
	var s = document.getElementsByTagName('script')[0];
	s.parentNode.insertBefore(wf, s);
})();

var $j=jQuery.noConflict();
var WI = { //home page whats inside
	homeTimeout : false,
	seeMe: function(meth,ev){
		if (!ev.preventDefault()) ev.returnValue = false;
		switch (meth) {
			case 'open':				
				$j(ev.target).parent().children('.hover').show()
				//$j('.hover',ev.target).slideDown();					
				clearTimeout(WI.homeTimeout);					
				break;
			default:				
				$j('.collection .hover').hide();
				$j('.collection .hover .overlay').removeClass('fits').removeClass('protection');
				WI.Timer.setTimer();
				break;				
		}
	},
	overlayHover: function(ev){
		switch (ev.type) {
			case 'mouseenter':						
				var overlay = $j(ev.target).parents('.hover').children('.overlay');					
				if($j(ev.target).hasClass('fits')){
					overlay.stop().show().css({opacity:100}).fadeOut(200,function(){$j(this).removeClass('protection').addClass('fits').fadeIn(200)})
				} else {						
					overlay.stop().show().css({opacity:100}).fadeOut(200,function(){$j(this).removeClass('fits').addClass('protection').fadeIn(200)})
				}
				break;
			default:
				// hide both
				break;
		}			
	},
	Timer : { //home banner
		speed : 3500,
		fade : 1000,
		anim : function(){
			activeFrame = $j('.active-areas .active');
			frames = $j('.active-areas .collection').length;
			frameData = $j.parseJSON(activeFrame.attr('data'));
			
			nextFrame = (frameData.frame==frames)?1:frameData.frame+1;
			if(nextFrame>1){	
				$j('.active-areas .f-'+nextFrame)			
					.fadeIn(WI.Timer.fade,function(){
						$j(this).addClass('active');
						activeFrame.hide().removeClass('active');				
					});
			} else {
				$j('.active-areas .f-'+nextFrame).show().addClass('active');
				activeFrame.fadeOut(
					WI.Timer.fade,
					function(){
						$j(this).removeClass('active');
					}
				);
				$j('.active-areas .f-'+nextFrame).addClass('active');
			}
			WI.Timer.setTimer();
			//var timer = setTimeout(WI.Timer.anim,WI.Timer.speed);
		},
		setTimer : function() {
			WI.homeTimeout = setTimeout(
				WI.Timer.anim,
				WI.Timer.speed
			);	
		}
	}		
}
var TS = { //testimonial scroll
	tFreq : 7000,
	tSpeed : 3000,
	height : 30,
	animateScroll : function(){
		var childVis = $j('.test-banner .shown').index()+1;
		var childCnt = $j('.test-banner .test').length;
		var setPos = (childCnt-1)*TS.height;
		var partner = (childVis<childCnt)?childVis:0;			
		$j('.test-banner .test')
			.eq(childVis-1)
			.removeClass('shown')
			.animate(
				{'top':'-='+TS.height},
				{
					duration: TS.tSpeed,
					complete: function(){
						$j(this).css({'top':setPos});
						TS.timer();
					}
				}
			);
		$j('.test-banner .test')
			.eq(partner)
			.addClass('shown')
			.animate({'top':'-='+TS.height},TS.tSpeed);			
	},
	animateTicker : function(){
		var paneLength = 0;
		$j('.test-banner .test').each(function(){paneLength += $j(this).innerWidth()})
		var pane = $j('.test-banner .test-pane')
		
		pane.css({'width':paneLength+'px','left':'1000px'})
			.animate(
				{
					'left':'-='+(paneLength+1000)
				},
				{
					easing:'linear',
					duration:30000,
					complete: function(){
						TS.animateTicker()						
					}
				}
			)
			
	},
	timer : function(){
		var timeOut = setTimeout(
			TS.animateTicker,
			TS.tFreq
		)
	}
}
var RO = { //Recent Items
	tChange : 6000,
	tFade : 1500,
	animate : function(){
		var childVis= $j('.newest .item:visible').index();
		var childCnt = $j('.newest .item').length;
		if(childVis<childCnt){
			$j('.newest .item').eq(childVis).fadeIn(RO.tFade,function(){$j('.newest .item').eq(childVis-1).hide()});
		} else {
			$j('.newest .item').eq('0').show();
			$j('.newest .item').eq(childVis-1).fadeOut(RO.tFade);
		}
		RO.timer();		
	},
	timer : function() {
		var timeout = setTimeout(
			RO.animate,
			RO.tChange
		);						
	}
}
var Pop = {
	create : function(){
		var popupClose = $j('<div/>')
			.addClass('close')
			.html('Close Popup')
			.click(Pop.remove);
		var popupWr = $j('<div/>')
			.addClass('popup-wrapper')			
			.append(popupClose,'<div class="video-wrapper"><div id="video">Loading...</div></div>');
		var popupBg = $j('<div/>')
			.addClass('popup-bg')
			.append(popupWr);
		var popup = $j('<div/>')
			.addClass('popup')
			.append(popupBg);
		$j('body').append(popup);		
		var margTop = ($j(window).height()-400)/2; 
		popupWr.css({'margin-top':margTop+'px'})
		popup.fadeIn();
		$j.getScript('/js/jwplayer.js',Pop.Video.build); 
		//(Pop.Video.build)();
		
	},
	remove : function(){
		$j('.popup').remove();
	},
	Video : { 
		build: function(){
			jwplayer('video').setup({
				//flashplayer : '/resources/player.swf',
				//autostart: true, 
				//file : '/video.mp4?v='+a,
				file : '/media/video/jille-promo-LO.mp4',
				width: 640,
				height: 360,
				//controlbar: bottom,
				image: '/media/video/jille-promo-cap.jpg',
				plugins: {
				  'hd-2': {
					file: '/media/video/jille-promo-HD.mp4'
				  }
				},
				'modes': [
					 {type: 'html5'},
					 {type: 'flash', src: '/media/player.swf'}
				]            
			});
		}
	}
}
jQuery(document).ready(function(){
	/*$j('.collections div.coll').mouseover(function(){rotateBg(this)});*/	
	TS.animateTicker();	
	RO.timer();	
	$j('.active-areas .collection .open')
		.click(function(ev){WI.seeMe('open',ev)});			
	$j('.active-areas .collection .back').click(function(ev){WI.seeMe('close',ev)})		
	$j('.active-areas .top a')
		.hover(
			WI.overlayHover,
			WI.overlayHover
		)
		.click(function(ev){if (!ev.preventDefault()) ev.returnValue = false;})
		
	$j('.parent h3').click(						  
		function(e){
			var el = $j(this).parent();
			var ul = el.children('ul');
			var height = ul.height();						
			if (el.hasClass('active')) {
				ul.slideUp();
				el.removeClass('active');
			}				
			else {
				ul.slideDown('fast');
				el.addClass('active');
			}
		}
	);
	$j('.AccordionPanelTab').click(
		function(){
			var content = $j(this).parent().children('.AccordionPanelContent');
			content.slideToggle('fast');
		});
	$j('form#quick-order .submit input').click(
		function(e){
			if (!e.preventDefault()) e.returnValue = false;
			invalid = false;
			$j('#quick-order .qty input').removeClass('highlight');			
			$j('.qty input[value!="0"]').each(
				function(){
					var el = $j(this);
					var id = el.attr('id');
					id = id.replace('p-','');
					var countStock = parseInt($j('#s-'+id).text());
					var countQty = parseInt(el.val());
					if (countStock<countQty) {						
						el.addClass('highlight');
						invalid = true;
					}
				}
			);
			if(invalid) {
				alert('We\'re sorry, but your requested quantities exceed stock levels. Please contact us so we can assist you with this order. ');				
			} else { $j('#quick-order').submit(); }
		}
	);
	$j('.header .watch-video').click(Pop.create);
});



