$(function() {
	$('.playlist-panel').hover(function(){
		
	}, function(){
		$(this).hide();
	});
	reload_shadow();
	$('.action-login').click(function(){
		$('.auth-panel').toggle();
	});
	$('.action-playlist').click(function(){
		$('.playlist-panel').toggle();
	});
	$('.min-player').click(function(){
		$('.player-panel').hide();
		$('.max-player').show();
		
		$('.logo').css('margin-top',-26);
		$('.logo2').css('margin-top',4);
	});
	$('.max-player').click(function(){
		$('.player-panel').show();
		$(this).hide();
		$('.logo').css('margin-top',-25);
		$('.logo2').css('margin-top',5);
	});	

	 $("#jquery_jplayer_1").jPlayer({
	 		volume:"0.3",
		  ready: function () {
			   initPlaylist($(this));
		  },
		  ended: function() { // The $.jPlayer.event.ended event
			  	nextPlaylist($(this));
			    //$(this).jPlayer("play"); // Repeat the media
		},
		  timeupdate:function(event){
		        timechange(event.jPlayer.status.currentTime);
			// $("#testMusic").text("Play began at time = " + event.jPlayer.status.currentTime);
		  },
		  pause:function(){
			  deleteMusicCookie();
		  },
		  stop:function(){
		  	deleteMusicCookie();	
		  },
		  cssSelectorAncestor: "", // Remove the ancestor css selector clause
		  cssSelector: {
			  seekBar:'.media-progress-load',
			  playBar:'.media-progress-full',
			  currentTime: '.current',
			  duration:'.limit'   
		      // The other defaults remain unchanged
		    },
		  swfPath: "/assets/plugins/jQuery.jPlayer.2.0.0",
		  supplied: "mp3"
	 });
	$(".media-play-pause").click(function(){		
		$(this).toggleClass('pause');
		if ($(this).hasClass('pause')){
			$.jPlayer.pause();
		  	$(".media-play-pause2").removeClass('pause2');
			$("#jquery_jplayer_1").jPlayer("play");
			deleteMusicCookie();
		}else{
			$("#jquery_jplayer_1").jPlayer("pause");
		}
	});
	$(".scrollable").scrollable();
	

	$(".items img").click(function() {

		// see if same thumb is being clicked
		if ($(this).hasClass("active")) { return; }

		// calclulate large image's URL based on the thumbnail URL (flickr specific)
		var url = $(this).attr("src").replace("_t", "");

		// get handle to element that wraps the image and make it semi-transparent
		var wrap = $("#image_wrap").fadeTo("medium", 0.5);

		// the large image from www.flickr.com
		var img = new Image();


		// call this function after it's loaded
		img.onload = function() {

			// make wrapper fully visible
			wrap.fadeTo("fast", 1);

			// change the image
			wrap.find("img").attr("src", url);

		};

		// begin loading the image from www.flickr.com
		img.src = url;

		// activate item
		$(".items img").removeClass("active");
		$(this).addClass("active");

	// when page loads simulate a "click" on the first image
	});
	
});

function reload_shadow(){
$(':text, :password').each(function(){
	var title = $(this).attr('alt');
	if (title!=''){
		//$(this).val(title);
		var color_origin = '#fff';
		$(this).blur(function(){
			if ($(this).val()==''){
				$(this).val(title);
				$(this).css('color','#b3b3b3');
			}
		})
		$(this).focus(function(){
			if (title==$(this).val())$(this).val('');
			$(this).css('color',color_origin);
		})
				
	}
	$(this).blur();
});	
}

function vote(){
	if ($('.votes:checked').length>0){
		$.post('/ajax/vote/submit',{id_vote:$('#id_vote').val(), vote: $('.votes:checked').val()},function(result){
			resultVote();
		});
	}
}
function resultVote(){
	$('#votes-result').html('<img src="/sys/media/images/ajax-loader.gif"/>');
	$.post('/ajax/vote/result',{id_vote:$('#id_vote').val()}, function(result){
		var obj = eval("("+result+")");
		var html = '';
		for(var i=0; i<obj.votes.length; i++){
			html += obj.votes[i].title+' &mdash; '+obj.votes[i].count+' <br/>';
		}
		$('#voteBtn').remove();
		$('#votes-result').html(html);
	});
}

function action_getup(type, ident, obj){	
	$.post('/ajax/rank/getup',{type:type, ident: ident},function(result){
		$(obj).text(result);
	});
}
	
function action_getdown(type, ident, obj){
	$.post('/ajax/rank/getdown',{type:type, ident: ident},function(result){
		if (result != 'not'){
			$(obj).text(result);
		}
	});
}
function getrank(type, ident, obj){
	$.post('/ajax/rank/getrank',{type:type, ident: ident},function(result){
		if (result != 'not'){
			$(obj).text(result);
		}
	});
}

