﻿if(current_act == 'playlist/add' || current_act == 'playlist/edit') {
	$().ready(function() {
		$('#pic_type_url').click(function(){
			$('#pic_upload').hide();
			$('#pic_url').show();
		});
		$('#pic_type_upload').click(function(){
			$('#pic_url').hide();
			$('#pic_upload').show();
		});
	});
} else if(current_act == 'playlist/modify_list') {
	$().ready(function() {
		change_place_height();
		$('input[name="up"]').click(function () {
			change_video(this, 'up');
		});
		$('input[name="down"]').click(function () {
			change_video(this,'down');
		});
		$('input[name="del"]').click(function () {
			// 删除专辑列表中的视频
			$(this.parentNode).remove();
		});
		$('[name="remove_videolist"]').click(function() {
			// 清除视频列表
	 		$('#playlist').empty();
		});
	});
} else if(current_act == 'playlist/view') {
	$().ready(function() {
		// 统计专辑点击
		$.getJSON(site_url + "ajax/count_view/playlist/" + plid, function(result) {
			if(result.msg) {
				poc_alert(result.msg);
			}
		});
		// 收藏专辑绑定
		$('#coll_playlist').click(function () {
			$.getJSON(site_url + "ajax/coll_playlist/" + plid, function(result){
				poc_alert(result.msg);
			});
		})
	});
}

// 交换专辑的视频位置
function change_video(cur_video, type) {
	cur_video = $(cur_video.parentNode);
	//console.log($(cur_video).next(), $(cur_video).prev());
	if(type == 'up') {
		if(cur_video.prev().length == 0) {
			alert('已到最顶 ');
		} else {
			cur_video.prev().before(cur_video);
		}
	} else if(type == 'down') {
		if(cur_video.next().length == 0) {
			alert('已到最后 ');			
		} else {
			cur_video.next().after(cur_video);
		}
	}
}

function add_video(vid, title, is_before) {		
	var playlist = $('#playlist');
	var is_exist = false;
	$.each(playlist.find('input[name="vid[]"]'), function(cur_index, cur_element) {
		//console.log(cur_element.value);
		if(cur_element.value == vid) {
			alert('视频已经存在!');
			is_exist = true;
			return false;
		}
	}) ;
	
	if(is_exist) {
		return false;
	}
	
	var video = $('#videohidden').clone(true);
	
	video.removeAttr('id');
	video.find('input[name="vid[]"]').val(vid);
	video.find('[name="title"]').text(title);
	
	if(is_before) {
		playlist.prepend(video);
	} else {	
		playlist.append(video);
	}
	
	video.show();
	change_place_height();
}

// 修改显示专辑的容器的高度
function change_place_height(){
	$('#playlist_place').height(document.getElementById('playlist_place').scrollHeight);
}
