jQuery.fn.cycle.transitions.anythingBox = function($cont, $slides, opts) {
	$cont.css('overflow','hidden');
	
	opts.before.push(function(curr,next,opts) {
		jQuery.fn.cycle.commonReset(curr,next,opts,true,true,true);
	});

	// only adjust speed once!
	if (!opts.speedAdjusted) {
		opts.speed = opts.speed / 2; //shuffle has 2 transitions
		opts.speedAdjusted = true;
	}
	opts.random = 0;

	opts.fxFn = function(curr, next, opts, cb, fwd) {
		jQuery(curr).find('.anything-wrap').each(function(){
			var width = jQuery(this).width();
			var height = jQuery(this).height();
			animateout = jQuery(this).parent().attr('data-out');
			easingout = jQuery(this).parent().attr('data-easingout');
			
			switch(animateout){
				case 'left':
					jQuery(this).animate({'top':0,'left':-width},{ duration:opts.speed, easing:easingout});
					break;
				case 'top':
					jQuery(this).animate({'top':-height,'left':0},{ duration:opts.speed, easing:easingout});
					break;
				case 'right':
					jQuery(this).animate({'top':0,'left':width},{ duration:opts.speed, easing:easingout});
					break;
				case 'bottom':
					jQuery(this).animate({'top':height,'left':0},{ duration:opts.speed, easing:easingout});
					break;
				case 'fade':
					jQuery(this).fadeOut(opts.speed);
					break;
			}
		});

		var wait = setInterval(function(){
			if(!jQuery(curr).find('.anything-wrap').is(":animated")){
				clearInterval(wait);
				jQuery(curr).css(opts.cssAfter);
				jQuery(next).css(opts.cssBefore);
				jQuery(next).find('.anything-wrap').each(function(){
					var width = jQuery(this).width();
					var height = jQuery(this).height();
					animatein = jQuery(this).parent().attr('data-in');
					easingin = jQuery(this).parent().attr('data-easingin');
					jQuery(this).show();
					switch(animatein){
					case 'left':
						jQuery(this).css({'top':0,'left':-width});
						jQuery(this).animate({'top':0,'left':0},{ duration:opts.speed, easing:easingin});
						break;
					case 'top':
						jQuery(this).css({'top':-height,'left':0});
						jQuery(this).animate({'top':0,'left':0},{ duration:opts.speed, easing:easingin});
						break;
					case 'right':
						jQuery(this).css({'top':0,'left':width});
						jQuery(this).animate({'top':0,'left':0},{ duration:opts.speed, easing:easingin});
						break;
					case 'bottom':
						jQuery(this).css({'top':height,'left':0});
						jQuery(this).animate({'top':0,'left':0},{ duration:opts.speed, easing:easingin});
						break;
					case 'fade':
						jQuery(this).css({'top':0,'left':0}).hide();
						jQuery(this).fadeIn(opts.speed);
						break;
					}
				});
			}
		},100);
		if (cb) cb();
	};
};
jQuery.fn.cycle.updateActivePagerLink = function(pager, currSlide, clsName) {
	if(pager.length !=0 && !jQuery(pager).children().eq(currSlide).hasClass(clsName)){
		jQuery(pager).each(function() {
			jQuery(this).children().removeClass(clsName).eq(currSlide).addClass(clsName);
		});
		jQuery(pager).trigger('changeActive',currSlide);
	}
};
function anythingslideInit(item,slideShow){
	var $slider = jQuery(item).find('.slidetext');
	if(slideShow['textAnimate'] == 'anythingBox'||true){
		$slider.find('.anything-box').each(function(){
			$wrap = jQuery(this).find('.anything-wrap');
			if( ! $wrap.hasClass('create')){
				var width = $wrap.width();	
				var height = $wrap.height();
				jQuery(this).css({'overflow':'hidden','width':width,'height':height});
				if(jQuery(this).css('position') !='absolute'){
					jQuery(this).css('position','relative');
				}
				$wrap.css({'position':'absolute','width':width,'height':height}).addClass('create');
			}
		});
	}
	var $slider = jQuery(item).find('.slidetext');
	$slider.sliderVideo({width:slideShow['width'],height:slideShow['height'],poster:slideShow['posterImage'],expressInstall:slideShow['readyswf']});
	$slider.cycle({
		fx:	 slideShow['textAnimate'], 
		/*fx:'anythingBox',*/
		easing:slideShow['textEasing'],
		speed:   slideShow['animationTime'],
		/*speed:3000,*/
		timeout:  slideShow['delay'],
		pager:  jQuery('.slideshownav',item),
		cleartype:1,
		cleartypeNoBg:1,
		prev:jQuery('.slideshowprev',item),
		next:jQuery('.slideshownext',item),
		sync:true,
		manualTrump:false,
		pause:slideShow['pauseOnHover'],
		fastOnEvent:slideShow['animationTime'],
		pagerAnchorBuilder: function(idx, slide) {
			return jQuery('.slideshownav li:eq(' + (idx) + ') a',item);
		},
		before: function(currSlideElement, nextSlideElement, options, forwardFlag){
			var $slide = jQuery(currSlideElement).parent();
			
			if(slideShow['anythingtype'] == 'media'){
				var index = $slide.children().index(nextSlideElement);
				setTimeout(function(){jQuery('#slidelist').cycle(index);}, slideShow['animationTime']);
			}
			var hasPlay = $slide.data('hasPlay');
			var $curr = jQuery(currSlideElement);
			if(typeof hasPlay != 'undefined' && hasPlay!=0){
				var videoList = $curr.data('videoList');
				if(typeof videoList != 'undefined'){
					videoList = String(videoList).split(',');
					var videoObj = $slide.data('video');
					jQuery.each(videoList,function(i,index){
						var video = videoObj.list[index];
						var service = videoObj.services[video.service];
						service.pause(video.id);
					});
					$slide.data('hasPlay',0);
				}
			}
		}
	});
	if(!slideShow['autoPlay']){
		$slider.cycle('pause');
		jQuery(item).find('.slide-button-pause').hide(); 
		jQuery(item).find('.slide-button-play').show();  
	}else{
		jQuery(item).find('.slide-button-play').hide(); 
		jQuery(item).find('.slide-button-pause').show();  
	}
	jQuery(item).find('.slidepause').click(function() {  
		$slider.cycle('pause');
		if(slideShow['anythingtype'] == 'media'){
			jQuery('#slidelist').cycle('pause');
		}
	});
	jQuery(item).find('.slideresume').click(function() { 
		$slider.cycle('resume');
		if(slideShow['anythingtype'] == 'media'){
			jQuery('#slidelist').cycle('resume');
		}
	});
	$slider.bind('videoPlay',function(){
		jQuery(this).data('hasPlay',1);
		$slider.cycle('pause');
		if(slideShow['anythingtype'] == 'media'){
			jQuery('#slidelist').cycle('pause');
		}
	});
	jQuery(item).bind('videoPlay',function(){
		jQuery(item).find('.slide-button-pause').fadeOut(200); 
		jQuery(item).find('.slide-button-play').fadeIn(300);  
	});
	if(slideShow['anythingnav']){
		jQuery(item).css({'position':'relative'});
		jQuery(item).hover(function(){
								jQuery(this).find('.anything-control').fadeIn();
						   },function(){
								jQuery(this).find('.anything-control').fadeOut();
						   });
		jQuery(item).find('.slidepause').click(function(){
			jQuery(item).find('.slide-button-pause').fadeOut(200);									   
			jQuery(item).find('.slide-button-play').fadeIn(300);
		});
		jQuery(item).find('.slideresume').click(function(){
			jQuery(item).find('.slide-button-play').fadeOut(200);									   
			jQuery(item).find('.slide-button-pause').fadeIn(300);
		});
	}
}
function mediaListInit(slideShow){
	jQuery('#slidelist').sliderVideo({width:slideShow['width'],height:slideShow['height'],poster:slideShow['posterImage'],expressInstall:slideShow['readyswf']});
	jQuery('#slidelist').cycle({
		fx:	 slideShow['mediaAnimate'], 
		easing:slideShow['mediaEasing'],
		speed:   slideShow['animationTime'],
		/*speed:5000,*/
		timeout:  slideShow['delay'],
		pager:  jQuery('#slideshow .slideshownav'),
		cleartype:1,
		cleartypeNoBg:1,
		prev:jQuery('#slideshow .slideshowprev'),
		next:jQuery('#slideshow .slideshownext'),
		sync:true,
		fastOnEvent:slideShow['animationTime'],
		pagerAnchorBuilder: function(idx, slide) {
			return '#slideshow .slideshownav li:eq(' + (idx) + ') a';
		},
		before: function(currSlideElement, nextSlideElement, options, forwardFlag){

			var $slide = jQuery('#slidelist');
			var hasPlay = $slide.data('hasPlay');
			if(typeof hasPlay == 'undefined' || hasPlay==0)
				return;
			var curr = jQuery(currSlideElement);
			var videoList = jQuery(curr).data('videoList');
			if(typeof videoList != 'undefined'){
				videoList = String(videoList).split(',');
				var videoObj = $slide.data('video');
				jQuery.each(videoList,function(i,index){
					var video = videoObj.list[index];
					var service = videoObj.services[video.service];
					service.pause(video.id);
				});
				$slide.data('hasPlay',0);
			}
		}
	});
	jQuery("#slidelist").fadeIn("slow");

	jQuery('#slidelist').bind('videoPlay',function(){
		jQuery(this).data('hasPlay',1);
		jQuery('#slidetext').cycle('pause');
		jQuery('#slidelist').cycle('pause');
	});
	if(!slideShow['autoPlay']){
		jQuery('#slidelist').cycle('pause');
	
	}
}
function anyInit(item,slideShow){
	if(slideShow['anythingtype'] == 'media'){
		var length = jQuery('#slidelist img').length;
		jQuery.preload('#slidelist img',{
			threshold:length,
			onFinish:function(){
				jQuery("#slideload").removeClass('preload').html('').fadeOut("fast");
				mediaListInit(slideShow);
				anythingslideInit(item,slideShow);
			}
		});
	}else{
		anythingslideInit(item,slideShow);
	}
	
}
