var BASE = "", // http://www.mhcoelho.com/
	MOVING = false,
	AUTO = true,
	SLIDE_TIMER = 5000, // 1000 = 1seg
	ANIMATION = 500, // 1000 = 1seg
	FEATURED = {
		ipad:[
			{title:'Research&amp;Design', subtitle:'lead design', src:'rd_01.jpg'},
			{title:'WLP prototype', subtitle:'lead design', src:'wlp_01.jpg'},
			{title:'WLP prototype', subtitle:'lead design', src:'wlp_02.jpg'},
			{title:'WLP prototype', subtitle:'lead design', src:'wlp_03.jpg'},
			{title:'WLP prototype', subtitle:'lead design', src:'wlp_04.jpg'},
			{title:'WLP prototype', subtitle:'lead design', src:'wlp_05.jpg'},
			{title:'Best Bank website', subtitle:'lead design', src:'best_01.jpg'},
			{title:'Best Bank website', subtitle:'lead design', src:'best_02.jpg'},
			{title:'Best Bank website', subtitle:'lead design', src:'best_03.jpg'},
			{title:'Best Bank landing page', subtitle:'front-end design', src:'best_landing_01.jpg'},
			{title:'Best Bank landing page', subtitle:'front-end design', src:'best_isavings_01.jpg'},
			{title:'Best Trading Challenge', subtitle:'lead design', src:'best_trading_challenge_01.jpg'},
			{title:'Best virtual gallery', subtitle:'creative direction', src:'best_af_01.jpg'},
			{title:'Tranquilidade login', subtitle:'lead design', src:'tranquilidade_login_01.jpg'},
			{title:'Tranquilidade website', subtitle:'lead design', src:'tranquilidade_web_01.jpg'},
			{title:'Tranquilidade website', subtitle:'lead design', src:'tranquilidade_web_02.jpg'},
			{title:'Tranquilidade website', subtitle:'lead design', src:'tranquilidade_web_03.jpg'},
			{title:'Alico product website', subtitle:'lead design', src:'alico_01.jpg'},
			{title:'Alico product website', subtitle:'lead design', src:'alico_02.jpg'},
			{title:'Asus product website', subtitle:'lead design', src:'asus_01.jpg'},
			{title:'Asus product website', subtitle:'lead design', src:'asus_02.jpg'},
			{title:'Bestlife website', subtitle:'lead design', src:'bestlife_01.jpg'},
			{title:'Bestlife website', subtitle:'lead design', src:'bestlife_02.jpg'},
			{title:'Logo insurances website', subtitle:'lead design', src:'logo_01.jpg'},
			{title:'Logo insurances website', subtitle:'lead design', src:'logo_02.jpg'},
			{title:'Real Madrid Mobile', subtitle:'front-end design', src:'real_madrid_01.jpg'},
			{title:'Lifecooler iOS app', subtitle:'creative direction', src:'lifecooler_01.jpg'},
			{title:'Microsoft Dynamics', subtitle:'lead design', src:'microsoft_dynamics_01.jpg'}
		],
		iphone:[
			{title:'eBudget app', subtitle:'lead design and creative direction', src:'ebudget_01.jpg'},
			{title:'eBudget app', subtitle:'lead design and creative direction', src:'ebudget_02.jpg'},
			{title:'eBudget app', subtitle:'lead design and creative direction', src:'ebudget_03.jpg'},
			{title:'Best mobile website', subtitle:'lead design and creative direction', src:'best_mobile_01.jpg'},
			{title:'Best mobile website', subtitle:'lead design and creative direction', src:'best_mobile_02.jpg'},
			{title:'Best mobile website', subtitle:'lead design and creative direction', src:'best_mobile_03.jpg'},
			{title:'Best mobile website', subtitle:'lead design and creative direction', src:'best_mobile_04.jpg'},
			{title:'Tranquilidade mobile website', subtitle:'lead design', src:'tranquilidade_mobile_01.jpg'},
			{title:'Tranquilidade mobile website', subtitle:'lead design', src:'tranquilidade_mobile_02.jpg'},
			{title:'Tranquilidade mobile website', subtitle:'lead design', src:'tranquilidade_mobile_03.jpg'},
			{title:'eNature app', subtitle:'creative direction', src:'enature_01.jpg'},
			{title:'eNature app', subtitle:'creative direction', src:'enature_02.jpg'},
			{title:'eNature app', subtitle:'creative direction', src:'enature_03.jpg'},
			{title:'eNature app', subtitle:'creative direction', src:'enature_04.jpg'},
			{title:'J&B app', subtitle:'lead design', src:'diageo_01.jpg'}
		]
	};


$(function(){
	$('.bt').children('span').animate({opacity:0},0);
	$('.bt').hover(
		function(){
			$(this).children('span:eq(0)').stop(true).animate({
				opacity: 1
			},100);
		},
		function(){
			$(this).children('span:eq(0)').stop(true).animate({
				opacity: 0
			},100);
		}
	);
	
	$('a.bt.bt_prev').click(function(e){
		clearTimeout(AUTO);
		AUTO = false;
		move();
		e.preventDefault();
	});
	
	$('a.bt.bt_next').click(function(e){
		clearTimeout(AUTO);
		AUTO = false;
		move(true);
		e.preventDefault();
	});
	
	config();
});


  
function config($el){
	var $ipad = $('#ipad'),
		$iphone = $('#iphone');
	
	$ipad.data('position', 0);
	
	for(k in FEATURED){
		var $el = $('#' + k);
		$el.data('position', FEATURED[k].length - 1)
			.data('total', FEATURED[k].length);
		for(i = 0; i < FEATURED[k].length;i++){
			var f = FEATURED[k][i];
			$el.append('<div class="s_item" style="background-image:url(' + BASE + 'imgs/featured/' + f.src + ');"></div>');
		}
		$el.children('.s_item').animate({opacity:0},0);
	}
	move(true); // start
}

function move(forward){
	if(MOVING){return false;}
	MOVING = true;
	$('#ipad, #iphone').each(function(){
		var $el = $(this),
			id = $el.attr('id'),
			data = FEATURED[id],
			$title = $('#controller_' + id + ' h2'),
			$subtitle = $('#controller_' + id + ' span'),
			$cur = $el.children('.s_item:eq(' + $el.data('position') + ')'),
			next = (forward?
				($el.data('position') + 1) % $el.data('total')
				:
				($el.data('position')?$el.data('position'):$el.data('total')) - 1
				),
			$next = $el.children('.s_item:eq(' + next + ')');
			
		$title.text(data[next].title); //change title
		$subtitle.text(data[next].subtitle); //change subtitle
		$el.children('.s_item.on').removeClass('on');
		$next.addClass('on').animate({opacity:1},ANIMATION,function(){
			MOVING = false;
			$cur.animate({opacity:0},0);
		});
		if(AUTO){
			AUTO = setTimeout("move(true)",SLIDE_TIMER);
		}
		$el.data('position',next);
	});
	
	return true;
}
