$(document).ready(function(){
	try{
		var homepageFeatureSlider = $(".page-homepage #feature");
		var direction = 'left';
		
		if(homepageFeatureSlider.length){
			var sliderWidth = homepageFeatureSlider.children(":first").width();
		}
	}catch(e){}
	
	try{
		if($("#unit-media-gallery").children().length > 1){
			var direction = 'left';
			var mediaGallery = $("#unit-media-gallery");
			var sliderWidth = $("#unit-media-gallery").children(":first").width();
			mediaGallery.cycle({
				fx: "scrollLeft",
				timeout: 0,
				fx: 'custom',
				easing: "swing",
				cssBefore: {
					left: direction == 'left' ? sliderWidth : -sliderWidth,
					display: 'block'
				},
				animIn: {
					left: 0
				},
				animOut: {
					left: direction == 'left' ? -sliderWidth : sliderWidth
				},
				before: function(currSlideElement, nextSlideElement, options, forwardFlag){
					options['animOut']['left'] = direction == 'left' ? -sliderWidth : sliderWidth;
					options['cssBefore']['left'] = direction == 'left' ? sliderWidth : -sliderWidth;
				},
				after: function (curr,next,opts) {
					direction = "left";
				}
			});
			
			$("#prev").click(function(e){
				e.preventDefault();
				direction = 'right';
				mediaGallery.cycle('prev');
			});
			$("#next").click(function(e){
				e.preventDefault();
				direction = 'left';
				mediaGallery.cycle('next');
			});
		}
	}catch(e) {
		console.log(e);
	}
	
	try{
		$("#unit-image-gallery li a").colorbox();
	}catch(e) {console.log(e)}
	
	try{
		$("#unit-video-gallery li a").colorbox();
	}catch(e) {console.log(e)}
});
