
var $j = jQuery.noConflict();

$j(document).ready(function() {
	
	
	
	$j("#callout_portfolio .images li").mouseenter(function() {
		if (!$j("#callout_portfolio").is(".waiting")) {
			//console.debug('grow');
			el_left = $j("#callout_portfolio .work .images li.left");
			el_center = $j("#callout_portfolio .work .images li.center");
			el_right = $j("#callout_portfolio .work .images li.right");
			if ($j(this).hasClass("left")) {
				$j(el_left).stop().animate({
					height: '360',
					width: '360',
					bottom: '0'
				}, 300).css("z-index","10");
				$j(el_center).stop().animate({
					height: '330',
					width: '330',
					left: '150',
					bottom: '15'
				}, 300).css("z-index","5");
				$j(el_right).stop().animate({
					height: '300',
					width: '300',
					bottom: '30'
				}, 300).css("z-index","2");
			} 
			if ($j(this).hasClass("center")) {
				$j(el_center).stop().animate({
					height: '360',
					width: '360',
					left: '120',
					bottom: '0'
				}, 300).css("z-index","10");
				$j(el_left).stop().animate({
					height: '330',
					width: '330',
					bottom: '15'
				}, 300).css("z-index","5");
				$j(el_right).stop().animate({
					height: '330',
					width: '330',
					bottom: '15'
				}, 300).css("z-index","5");
			}
			if ($j(this).hasClass("right")) {
				$j(el_right).stop().animate({
					height: '360',
					width: '360',
					bottom: '0'
				}, 300).css("z-index","10");
				$j(el_center).stop().animate({
					height: '330',
					width: '330',
					left: '120',
					bottom: '15'
				}, 300).css("z-index","5");
				$j(el_left).stop().animate({
					height: '300',
					width: '300',
					bottom: '30'
				}, 300).css("z-index","2");
			}
		}
	});
	
	$j.fn.cycle.transitions.factoria_portfolio = function($cont, $slides, opts){
		opts.fxFn = function(curr, next, opts){
			$j("#callout_portfolio").addClass("waiting");
			$j(curr).find('.images li').each(function(idx, el){
				$j(next).find('.images li').show();
				setTimeout(function(){
					$j(el).slideUp(450, function() {
						if (idx == 1) {
							$j(next).find('.images li').css({"height":"","width":"","left":"","z-index":"","bottom":"-360px"});
							$j(curr).fadeOut(opts.speed);
							$j(next).fadeIn(opts.speed);
							$j(next).find('.images li').each(function(idx, el){

								var curr_classname = el.className;
								if (curr_classname == 'left') { 
									var bot_level = '15px';
								}
								if (curr_classname == 'center') { 
									var bot_level = '0px';
								}
								if (curr_classname == 'right') { 
									var bot_level = '15px';
								}
								//console.debug (curr_classname + ' lvl: ' + bot_level);
								setTimeout(function(){
									$j(el).animate({
										opacity:1,
										bottom: bot_level
									}, 450, function() {
										if (idx == 1) {
											$j("#callout_portfolio").removeClass("waiting");
										}
									});
								}, (200*(2-idx)));

							});
						}
					});
				}, (100*(2-idx)));
			});
			opts.busy=0;
		}
	};


	
	$j('#home_right').cycle({ 
		"fx":"factoria_portfolio",
		timeout: 500000, 
		startingSlide:0,
		speed: 500,
		cleartypeNoBg: true,
		pager: '#callout_portfolio ul.list',
		pause: true,
		pagerEvent: 'mouseover',
		allowPagerClickBubble: true, // allows or prevents click event on pager anchors from bubbling 
		pagerAnchorBuilder: function(idx, slide) { 
			return '#callout_portfolio ul.list li:eq(' + idx + ')';
		},
		updateActivePagerLink: function(pager, currSlideIndex) {
			$j(pager).find('li').removeClass('active').filter('li:eq('+currSlideIndex+')').addClass('active');
		},
		pauseOnPagerHover: true
	});

});

