﻿/* Author: 

*/

// fullscreen bg
var FullscreenrOptions = {  width: 1000, height: 667, bgID: '.bgimg' };
jQuery.fn.fullscreenr(FullscreenrOptions);


// menu hover
$("#menu > ul").lavaLamp({target:'a'});

//animations
$('#menu').delay(300).animate({width: "80%"},{duration: 2000});
$('#menu > ul').delay(2300).fadeIn();
$('.backLava').delay(3000).animate({width: "40px"},{duration: 1000});
$('#logo').delay(300).animate({height: "87px"},{duration: 2000});
$('#logo > img').delay(2300).fadeIn();
$('#player').delay(2400).fadeIn();

/*
$(".pattern-1").animate({right:'-173px', top:"-104px"},{ duration:2000, easing: 'easeInOutCubic'});
$(".pattern-2").delay(300).animate({right:'-193px', top:"-198px"},{ duration:2000, easing: 'easeInOutCubic'});
$(".pattern-3").delay(600).animate({right:'-116px', top:"-147px"},{ duration:2000, easing: 'easeInOutCubic'});
$(".pattern-4").delay(900).animate({right:'56px', top:"-18px"},{ duration:2000, easing: 'easeInOutCubic'});
$(".pattern-5").delay(1200).animate({right:'40px', top:"-140px"},{ duration:2000, easing: 'easeInOutCubic'});
$(".pattern-6").delay(1500).animate({right:'110px', top:"0"},{ duration:2000, easing: 'easeInOutCubic'});
$(".pattern-7").delay(1800).animate({right:'100px', top:"-140px"},{ duration:2000, easing: 'easeInOutCubic'});
$(".pattern-8").delay(2100).animate({right:'160px', top:"-193px"},{ duration:2000, easing: 'easeInOutCubic'});
$(".pattern-9").delay(2400).animate({right:'220px', top:"-60px"},{ duration:2000, easing: 'easeInOutCubic'});
*/
// background slide
$('#background').cycle({
	    speed: 1000,
	    timeout: 10000,
		slideExpr: '.slide'
});

//lookbook slide
$('#lookbook > ol')
	.after('<div class="nav"><button class="prev">Anterior</button> <button class="next">Próximo</button></div>')
	.cycle({
	    speed: 1000,
	    timeout: 0,
		slideExpr: '.slide',
	    prev:'.prev',
	    next:'.next'
});

// change sections
$("#menu > ul > li > a").click(function() {
	$("#menu > ul > li > a").removeClass("active");
	$(this).addClass("active");
	$(".content").fadeOut();
	var activeTab = $(this).attr("href");
	$(activeTab).delay(500).fadeIn();
	return false;
});



// player
var playItem = 0;

var myPlayList = [
	{name:"La Roux remix",mp3:"http://www.vernier.com.br/music/La-Roux-remix.mp3", ogg:"http://www.vernier.com.br/music/La-Roux-remix.ogg"},
	{name:"Phantogram - Mouthful Of Diamonds",mp3:"http://www.vernier.com.br/music/Phantogram-Mouthful_Of_Diamonds.mp3", ogg:"http://www.vernier.com.br/music/Phantogram-Mouthful_Of_Diamonds.ogg"},
	{name:"Phantogram - When I 39m Small",mp3:"http://www.vernier.com.br/music/Phantogram-When_I_39m_Small.mp3", ogg:"http://www.vernier.com.br/music/Phantogram-When_I_39m_Small.ogg"}
];

// Local copy of jQuery selectors, for performance.
var jpPlayTime = $("#jplayer_play_time");
var jpTotalTime = $("#jplayer_total_time");

$("#jquery_jplayer").jPlayer({
	ready: function() {
		displayPlayList();
		playListInit(true); // Parameter is a boolean for autoplay.
	},
	oggSupport: true
})
.jPlayer("onProgressChange", function(loadPercent, playedPercentRelative, playedPercentAbsolute, playedTime, totalTime) {
	jpPlayTime.text($.jPlayer.convertTime(playedTime));
	jpTotalTime.text($.jPlayer.convertTime(totalTime));
})
.jPlayer("onSoundComplete", function() {
	playListNext();
});

$("#jplayer_previous").click( function() {
	playListPrev();
	$(this).blur();
	return false;
});

$("#jplayer_next").click( function() {
	playListNext();
	$(this).blur();
	return false;
});

function displayPlayList() {
	$("#jplayer_playlist ul").empty();
	for (i=0; i < myPlayList.length; i++) {
		var listItem = (i == myPlayList.length-1) ? "<li class='jplayer_playlist_item_last'>" : "<li>";
		listItem += "<a href='#' id='jplayer_playlist_item_"+i+"' tabindex='1'>"+ myPlayList[i].name +"</a></li>";
		$("#jplayer_playlist ul").append(listItem);
		$("#jplayer_playlist_item_"+i).data( "index", i ).click( function() {
			var index = $(this).data("index");
			if (playItem != index) {
				playListChange( index );
			} else {
				$("#jquery_jplayer").jPlayer("play");
			}
			$(this).blur();
			return false;
		});
	}
}

function playListInit(autoplay) {
	if(autoplay) {
		playListChange( playItem );
	} else {
		playListConfig( playItem );
	}
}

function playListConfig( index ) {
	$("#jplayer_playlist_item_"+playItem).removeClass("jplayer_playlist_current").parent().removeClass("jplayer_playlist_current");
	$("#jplayer_playlist_item_"+index).addClass("jplayer_playlist_current").parent().addClass("jplayer_playlist_current");
	playItem = index;
	$("#jquery_jplayer").jPlayer("setFile", myPlayList[playItem].mp3, myPlayList[playItem].ogg);
}

function playListChange( index ) {
	playListConfig( index );
	$("#jquery_jplayer").jPlayer("play");
}

function playListNext() {
	var index = (playItem+1 < myPlayList.length) ? playItem+1 : 0;
	playListChange( index );
}

function playListPrev() {
	var index = (playItem-1 >= 0) ? playItem-1 : myPlayList.length-1;
	playListChange( index );
}



