var memberTeamVimeo;
var memberTeamTemplate;
var memberTeamVideos;
var memberTeamAudios;
var memberTeamSelectedItem;
var memberTeamSelectedAudio;
function initMemberTeam(colors,prev,next,files,second){
	changeColors(colors);
	prelaoderVisibility(false);
	$(".title1").css({color:COLOR_1});
	$(".title2").css({color:COLOR_1});
	$(".title1 span").css({color:COLOR_MENU});
	$(".title2 span").css({color:COLOR_MENU});
	memberTeamCredits();
	memberTeamNavControl(prev,next);
	memberTeamCreateFileList(files);
	memberTeamControlCols();
	memberTeamScreenResolution();
	if(second != ""){
		loadSecondImage(second);
	}
	$("#pageContent").stop(true).css({visibility:"visible",opacity:0}).delay(0).animate({opacity:1},300,function(){  
		ahrefControlLinks($("#memberTeamCredits"));
		ahrefControlLinks($("#memberTeamTextCol1"));
		ahrefControlLinks($("#memberTeamTextCol2"));
	});
}
function memberTeamStillFadeIn(){
	//alert("memberTeamStillFadeIn");
	$("#videoStill").css({display:"block",opacity:0}).animate({opacity:1},200);
}
function memberTeamCredits(){
	$("#memberTeamCredits span").css({color:COLOR_1});
	ahrefApplyColorAndRollovers($("#memberTeamCredits"),COLOR_1,COLOR_MENU);
}
function memberTeamNavControl(prev,next){
	/*
	var visibility = ($.address.pathNames()[0] == "curated") ? "visible" : "hidden";
	$("#navRight").css({visibility:visibility});
	$("#navLeft").css({visibility:visibility});
	//asigno eventos para pasar de un memberTeam a otro con navegación lineal
	navRightClickEvent = memberTeamChangeMemberTeam;
	navRightClickParam = next;
	navLeftClickEvent = memberTeamChangeMemberTeam;
	navLeftClickParam = prev;
	*/
}
function memberTeamChangeMemberTeam(url){
	$.address.path(url);
}
function memberTeamCreateFileList(str){
	if(str != ""){
		memberTeamVideos = new Array();
		memberTeamAudios = new Array();
		//src,ext,name,vimeoid;
		var files = str.split(";");
		var file;
		for(var i=0;i<files.length;i++){
			file = files[i].split(",");
			if(file[1].toLowerCase() == "mp3"){
				memberTeamAudios.push({src:file[0],name:file[2]});
			}else{
				memberTeamVideos.push({still:file[0],name:file[2],videoId:file[3]});
			}
		}
		memberTeamSelectedItem = null;
		$("#memberTeamMediaList").css({color:COLOR_1});
		$("#memberTeamMediaList span").css({color:COLOR_1,cursor:"pointer"}).mouseover(function(){
			if($(this).attr("id") != memberTeamSelectedItem){
				$(this).stop(true).animate({color:COLOR_2},150);
			}
		});
		$("#memberTeamMediaList span").mouseout(function(){
			if($(this).attr("id") != memberTeamSelectedItem){
				$(this).stop(true).animate({color:COLOR_1},150);
			}
		});
		$("#memberTeamMediaLisTitle").unbind("mouseover");
		$("#memberTeamMediaLisTitle").unbind("mouseout");
		$("#memberTeamMediaLisTitle").css({cursor:"auto"});
		$("#videoStill").css({cursor:"pointer"});
		$("#videoStill").mouseover(function(){
			$("#videoPlayIcon").stop(true).animate({opacity:0.5});
		});
		$("#videoStill").mouseout(function(){
			$("#videoPlayIcon").stop(true).animate({opacity:1});
		});
		$("#videoStill").click(function(){
			memberTeamAddVideoPlayer();
		});
		if(memberTeamAudios.length > 0){
			memberTeamCreateAudioList();	
		}
		if(memberTeamVideos.length > 0){
			$("#playMediaItem0").mouseover();
			memberTeamChangeVideo(0);
		}else if(memberTeamAudios.length > 0){
			memberTeamOpenAudioList();
		}
	}
}
function loadSecondImage(src){
	var html = '<img src="'+src+'" onload="memberTeamStillFadeIn()"/>';
	$("#videoStill").html(html);
}
function memberTeamChangeVideo(index,target){
	if($(target).css("cursor") == "pointer" || target == undefined || detectMobile()){
		memberTeamVimeo = memberTeamVideos[index].videoId;
		var html = '<img src="'+memberTeamVideos[index].still+'" onload="memberTeamStillFadeIn()"/>';
		html += '<img src="./assets/videoPlayIcon.png" id="videoPlayIcon" />';
		$("#videoStill").html(html);
		$("#videoPlayer").html('');
		if(memberTeamSelectedItem != null){
			var current = "#"+memberTeamSelectedItem;
			memberTeamSelectedItem = null;
			$(current).css({cursor:"pointer"});
			$(current).mouseout();
		}
		memberTeamSelectedItem = "playMediaItem"+index;
		$("#playMediaItem"+index).css({cursor:"auto"});
		//
		$("#videoStill").css({display:"none"});
		$("#audioPlayer").stop(true).css({display:"none"});
		$("#audioList").css({display:"none"});
		$("#jquery_jplayer_1").jPlayer("stop");
		/*
		$("#videoPlayer").stop(true).css({display:"block",opacity:0}).animate({opacity:1},200);
		$("#videoStill").stop(true).css({display:"block",opacity:0}).animate({opacity:1},200);
		$("#audioPlayer").stop(true).css({display:"none"});
		$("#audioList").stop(true).css({display:"none"});
		*/
	}
}
function memberTeamAddVideoPlayer(){
	$("#videoStill").html('');
	var video = memberTeamVimeo;
	video = video.split("http://vimeo.com/").join("");
	video = video.split("http://www.vimeo.com/").join("");
	$("#videoPlayer").html('<iframe id="vimeoplayer" src="http://player.vimeo.com/video/'+video+'?title=0&autoplay=1&amp;byline=0&amp;portrait=0&amp;color=ffffff" width="640" height="360" frameborder="0"></iframe>');
}
function memberTeamCreateAudioList(){
	var top = $("#videoPlayer").position().top+86;
	var left = $("#videoPlayer").position().left;
	$("#audioPlayer").css({top:top,left:left,backgroundColor:COLOR_1});
	//audio player events
	$("div.jp-seek-bar").css({backgroundColor:COLOR_1});
	$("div.jp-play-bar").css({backgroundColor:COLOR_2});
	$("div.jp-audio div.jp-type-single a.jp-play").css({backgroundColor:COLOR_1});
	$("div.jp-audio div.jp-type-single a.jp-pause").css({backgroundColor:COLOR_1});
	$("div.jp-audio div.jp-type-single a.jp-play").mouseover(function(){
		$(this).stop(true).animate({backgroundColor:COLOR_2},300);
	});
	$("div.jp-audio div.jp-type-single a.jp-play").mouseout(function(){
		$(this).stop(true).animate({backgroundColor:COLOR_1},300);
	});
	$("div.jp-audio div.jp-type-single a.jp-pause").mouseover(function(){
		$(this).stop(true).animate({backgroundColor:COLOR_2},300);
	});
	$("div.jp-audio div.jp-type-single a.jp-pause").mouseout(function(){
		$(this).stop(true).animate({backgroundColor:COLOR_1},300);
	});
	$("#jquery_jplayer_1").jPlayer({
		ready: function () {
			
		},
		ended: function (event) {
			//$(this).jPlayer("play");
		},
		swfPath: "js",
		supplied: "mp3, m4a, oga"
	});
	//
	top += 80;
	$("#audioList").css({top:top,left:left,color:COLOR_1});
	var html = '';
	var num;
	for(var i=0;i<memberTeamAudios.length;i++){
		num = (i<9) ? '0'+(i+1) : (i+1);
		html += '<div id="playAudioItem'+i+'" onclick="memberTeamOpenAudio('+i+')">'+num+' '+memberTeamAudios[i].name+'</div>';
	}
	$("#audioList").html(html);	
	memberTeamSelectedAudio = null;
	$("#audioList div").css({cursor:"pointer"});
	$("#audioList div").mouseover(function(){
		if($(this).attr("id") != memberTeamSelectedAudio){
			$(this).stop(true).animate({color:COLOR_2},150);
		}
	});
	$("#audioList div").mouseout(function(){
		if($(this).attr("id") != memberTeamSelectedAudio){
			$(this).stop(true).animate({color:COLOR_1},150);
		}
	});
}
function memberTeamOpenAudioList(index,target){
	if($(target).css("cursor") == "pointer" || target == undefined){
		//alert("memberTeamOpenAudioList="+index);
		if(memberTeamSelectedItem != null){
			var current = "#"+memberTeamSelectedItem;
			memberTeamSelectedItem = null;
			$(current).css({cursor:"pointer"});
			$(current).mouseout();
		}
		memberTeamSelectedItem = "playMediaItem"+index;
		$("#playMediaItem"+index).css({cursor:"auto"});
		//
		$("#videoStill").html('');
		$("#videoPlayer").html('');
		$("#videoStill").css({display:"none"});
		$("#audioPlayer").stop(true).css({display:"none"});
		$("#audioList").css({display:"block"});
		//
		$("#playAudioItem0").mouseover();
		memberTeamOpenAudio(0);
		setTimeout(function(){$("#jquery_jplayer_1").jPlayer("pause")},10);
	}
}
function memberTeamOpenAudio(index){
	if(memberTeamSelectedAudio != null){
		var current = "#"+memberTeamSelectedAudio;
		memberTeamSelectedAudio = null;
		$(current).css({cursor:"pointer"}).mouseout();
	}
	memberTeamSelectedAudio = "playAudioItem"+index;
	$("#"+memberTeamSelectedAudio).css({cursor:"auto"});
	$("#audioPlayer").stop(true).css({display:"block",opacity:0}).delay(100).animate({opacity:1},300);
	//$("#jquery_jplayer_1").jPlayer("setMedia",{mp3:memberTeamAudios[index].src});
	var mp3 = memberTeamAudios[index].src;
	var oga = memberTeamAudios[index].src.split(".mp3").join(".ogg");
	var m4a = memberTeamAudios[index].src.split(".mp3").join(".m4a");
	$("#jquery_jplayer_1").jPlayer("setMedia",{mp3:mp3,oga:oga,m4a:m4a}).jPlayer("play");
}
function addMemberTeamShare(){
	var html = '<div id="memberTeamShare"><span id="memberTeamShareTxt">Share </span><span id="memberTeamEmailButton">Email</span> / '+getSocialNetworkLinks()+'</div>';
	var align = ($("#memberTeamTextCol2").html() == "") ? "right" : "left";
	$("#memberTeamTextCol2").append((align == "right") ? html : html);
	$("#memberTeamShare").css({color:COLOR_1,textAlign:align});
	$("#memberTeamShareTxt").css({color:COLOR_2});
	$("#memberTeamEmailButton").css({cursor:"pointer"});
	$("#memberTeamEmailButton").mouseover(function(){
		$(this).stop(true).animate({color:COLOR_2},150);
	});
	$("#memberTeamEmailButton").mouseout(function(){
		$(this).stop(true).animate({color:COLOR_1},150);
	});
	$("#memberTeamEmailButton").click(function(){
		addEmailForm();
	});
}
function memberTeamControlCols(){
	$("#memberTeamTextCol1").css({color:COLOR_1});
	$("#memberTeamTextCol2").css({color:COLOR_1});
	txtCleanBR($("#memberTeamTextCol1"));
	txtCleanBR($("#memberTeamTextCol2"));
	memberTeamTemplate = 1;
	var bottom = Number(String($("#memberTeamTextCol1").css("bottom")).split("px").join(""));
	//if($("#memberTeamTextCol1").css("bottom") == "50px"){
	if(bottom <= 50){
		memberTeamTemplate = ($("#memberTeamTextCol1").position().left < 100) ? 3 : 2;
		var top;
		if($("#memberTeamTextCol1").height() > $("#memberTeamTextCol2").height()){
			top = $("#memberTeamTextCol1").position().top;
		}else{
			top = $("#memberTeamTextCol2").position().top;
		}
		
		$("#memberTeamTextCol1").css({bottom:"auto",top:top});
		$("#memberTeamTextCol2").css({bottom:"auto",top:top});
		if($("#memberTeamTextCol2").html() == ""){
			$("#memberTeamTextCol2").css({top:(top+$("#memberTeamTextCol1").height()-15)});
		}
	}
	addMemberTeamShare();
	ahrefApplyColorAndRollovers($("#memberTeamTextCol1"),COLOR_1,COLOR_2);
	ahrefApplyColorAndRollovers($("#memberTeamTextCol2"),COLOR_1,COLOR_2);
}
function memberTeamScreenResolution(){
	if(!detectMobile()){
		var resolution = screen.width;
		if(resolution < 1380){
			var margin = 10;
			var offsetX = 1380-resolution-margin;
			var width = resolution;
			var objects;
			var target;
			var left;
			$("#pageContent").css({width:width});
			if(memberTeamTemplate == 1 || memberTeamTemplate == 2){
				objects = ["memberTeamImg","memberTeamTextCol1","memberTeamTextCol2","memberTeamMediaList","videoStill","videoPlayer","audioPlayer"];	
				for(var i=0;i<objects.length;i++){
					target = "#"+objects[i];
					//left = $(target).position().left-offsetX;
					left = Number($(target).css("left").split("px").join(""))-offsetX;
					$(target).css({left:left});
				}
			}
			if(memberTeamTemplate == 3){
				var imgWidth = $("#memberTeamImg").width()-offsetX;
				$("#memberTeamImg").css({width:imgWidth});
				$("#memberTeamImg img").css({marginLeft:-offsetX})
			}
		}
	}
}
