(function(){

/* M2V Javascript Updated: Thu 3.6.08 @ 13:21 p.m. Author: Chencheng (sorrycc@gmail.com) —————————————————-*/

Pra.m2v = { // m2v: mv to video
	// 全局变量
	global: {
		// variable
		lazyID:		10,
		currPic:	0,
		styleJSON:	[],
		canSave:	false,
		uploading:	false,
		// for config.xml & flash object
		c: {
			title:		'',
			fontcolor:	'0xFFFFFF',
			fontsize:	14,
			fontpos:	3,
			bgcolor:	'0x000000',
			bgalpha:	25,
			delaytime:	4000,
			turntime:	4000,
			frame:		[154, 'http://storage.pomoho.com/mv/shade/frame/k5.swf'],
			effect:		[711, 'http://storage.pomoho.com/mv/shade/effect/c1.swf'],
			phototype:	0,
			startid:	0,
			bgmusic:	'',
			bgmusic_2:	'',
			photo:		[],
			upload:	[],
			uploaddelid: ''
		},
		// c for reset basic
		c_$: {
			fontcolor:	'0xFFFFFF',
			fontsize:	14,
			fontpos:	3,
			bgcolor:	'0x000000',
			bgalpha:	25,
			delaytime:	4000,
			turntime:	4000
		},
		// url
		picUrl:		'http://60.190.246.238:8001/img/',
		save:		'http://www.pomoho.com/do/mv/savemv.aspx?mvid=-1&userid='+_user.uid+'&content=',
		player:		'http://www.pomoho.com/vid/mveditor.swf',
		baiduMusic:	'http://www.pomoho.com/do/mv/getmusiclist.aspx',
		effect:		'http://www.pomoho.com/do/mv/geteffectlist.aspx?type=1',
		border:		'http://www.pomoho.com/do/mv/geteffectlist.aspx?type=2',
		style:		'http://www.pomoho.com/do/mv/geteffectlist.aspx?type=3',
		effectAll:	'http://www.pomoho.com/do/mv/geteffectlist.aspx?type=4',
		borderAll:	'http://www.pomoho.com/do/mv/geteffectlist.aspx?type=5',
		lazy:		'http://www.pomoho.com/do/mv/geteffectlist.aspx?type=6',
		lazySpecial:'http://www.pomoho.com/do/mv/getlazy.aspx?id=',
		randomMusicID: 'http://www.pomoho.com/do/mv/getRandomMusic.aspx',
		upload:		'http://www.pomoho.com/pmhupload_progress.ashx'
	},
	// Flash通讯接口
	i: {
		refresh:	function(i)		{ if(typeof i != 'undefined') $.extend(Pra.m2v.global.c, {startid:i+1}); var f = window['m2vPlayer'] || document['m2vPlayer']; f.resetAlbum(Pra.m2v.global.c); },
		picAdd:		function(s)		{ if(s) Pra.m2v.global.c.photo.push(s); Pra.m2v.i.refresh(); },
		picRemove:	function(s)		{
			var arr = [], photo = Pra.m2v.global.c.photo;
			for (var i=0,il=photo.length; i<il; i++) {
				if (i != s) arr.push(photo[i]);
			}
			Pra.m2v.global.c.photo = arr;
			Pra.m2v.i.refresh();
		},
		picText:	function(i,s)	{ Pra.m2v.global.c.photo[i][1] = s; Pra.m2v.i.refresh(i); },
		picStyle:	function(i,s,n)	{ Pra.m2v.global.c.photo[i][2] = s; Pra.m2v.global.c.photo[i][4] = n; Pra.m2v.i.refresh(i); },
		addMusic:	function(s) 	{ $.extend(Pra.m2v.global.c, {bgmusic:s}); Pra.m2v.i.refresh(); },
		pause:		function()		{ var f = window['m2vPlayer'] || document['m2vPlayer']; f.pausemusic(); },
		play:		function()		{ var f = window['m2vPlayer'] || document['m2vPlayer']; f.restartmusic(); },
		fontColor:	function(s) 	{ if(s) $.extend(Pra.m2v.global.c, {fontcolor:'0x'+s}); Pra.m2v.i.refresh(); },
		fontSize:	function(s)		{ if(s) $.extend(Pra.m2v.global.c, {fontsize:s}); Pra.m2v.i.refresh(); },
		fontPos:	function(s)		{ if(s) $.extend(Pra.m2v.global.c, {fontpos:s}); Pra.m2v.i.refresh(); },
		bgColor:	function(s)		{ if(s) $.extend(Pra.m2v.global.c, {bgcolor:'0x'+s}); Pra.m2v.i.refresh(); },
		bgAlpha:	function(s)		{ if(s) $.extend(Pra.m2v.global.c, {bgalpha:s}); Pra.m2v.i.refresh(); },
		delay:		function(s)		{ if(s) $.extend(Pra.m2v.global.c, {delaytime:s}); Pra.m2v.i.refresh(); },
		turn:		function(s)		{ if(s) $.extend(Pra.m2v.global.c, {turntime:s}); Pra.m2v.i.refresh(); },
		frame:		function(s) 	{ if(s) $.extend(Pra.m2v.global.c, {frame:s}); Pra.m2v.i.refresh(); },
		effect:		function(s) 	{ if(s) $.extend(Pra.m2v.global.c, {effect:s}); Pra.m2v.i.refresh(); },
		setBasic:	function()		{ $.extend(Pra.m2v.global.c, Pra.m2v.global.c_$); Pra.m2v.i.refresh(); }
	},
	// DOMLoaded的初始化
	init: function() {
					//_user.uid = 9304234;

		// 写入Player 会无效，bug？
		//$('#Show').html(Pra.flash({url:Pra.m2v.global.player,w:400,h:300,wmode:'opaque',back:true,name:'m2vPlayer'}));
		if (_user.uid == 0) {
			//location = 'http://www.pomoho.com/ui/login.aspx?AfterLoginReturnURL=/ui/editmv.aspx';

		}
		$('#Music .option div').eq(0).hide();
		$('#music_by_hot').attr('checked', true);
		// 效果预览
		$('#Handle .s1').bind('click', this.preview);
		$('#ShowType a').click(function(){ this.blur(); return false; });

	    if ($('#Main').attr('class') == 'edit') {
		var mvid = $('#Main').attr('rel').replace(/.+mvid=(\d+)&.+/, '$1');};
        //ZJW
       //$('#meatf .confirmBtn').click(function(){ alert('点中了'); return false; });

		// tab切换
		$('#Col_1, #Col_2').tab();
		$('#Col_1 .tab li a')
			.eq(0).click(function(){  })
			.end().eq(1).click(function(){ $('#PicUploading').css('display','none'); });
		$('#Col_1 .tab li a').eq(0).click(function(){
			if ($('#MusicLoading').css('display') == 'block') {
				$('#MusicLoading').hide();
			}
			if (Pra.m2v.global.uploading) {
				$('#PicUploading').show();
			}
		}).end().eq(1).click(function(){
			if (/none/.test($('#Music').attr('class'))) {
				$('#Music').hide();
				$('#MusicLoading').show();
			}
		});
		// 添加图片
		$('#Pic label').click(function(){
			var id = $(this).find('input').attr('id').replace(/_(\w)/g, function(a, b){return b.toUpperCase()}).replace('pic', 'Pic');
			$('#Pic .detail a').hide();
			$('#'+id).css('display','block');
			$(this).blur();
		});
		     //弹出album Dialog
				$('#PicFromAlbum').click(function(){$("#tablist li").removeClass("currenta");$("#tablist li:eq(0)").addClass("currenta");
				Pra.loadScript(" http://www.pomoho.com/do/mv/getphotolist.aspx?typeid=2&albumid=-111&albumvideoid="+mvid+"&curpage=1&userid="+_user.uid+"");
				Pra.loadScript("http://www.pomoho.com/do/mv/getphotolist.aspx?typeid=1&albumvideoid="+mvid+"&userid="+_user.uid+"");
				$('.meat1').css('display','block'); $('.meat2 ,.meat3').hide();
				$('.meat select').hide();
				$('#PicSelect').show(10, function(){ $('#PicSelect').find('.file').val('').end().dialog({overlay:true,bgColor:'black',opacity:0.5}); }); 
				
			
				if($.browser.msie) { $('#PicSelect').find('.file').each(function(){ this.outerHTML = this.outerHTML; }); /*setTimeout(function(){ $('#PicSelect .file').change(function(){ alert('d') }); }, 1000);*/ } this.blur();return false;});
						
		// 弹出PicSelect Dialog
		$('#PicFromLocal').click(function(){$("#tablist li").removeClass("currenta");$("#tablist li:eq(2)").addClass("currenta");$('.meat3').css('display','block');$('.meat1,.meat2').hide();$('.meat select').hide();$('#PicSelect').show(10, function(){ $('#PicSelect').find('.file').val('').end().dialog({overlay:true,bgColor:'black',opacity:0.5}); }); if($.browser.msie) { $('#PicSelect').find('.file').each(function(){ this.outerHTML = this.outerHTML; }); /*setTimeout(function(){ $('#PicSelect .file').change(function(){ alert('d') }); }, 1000);*/ } this.blur(); return false; });
		
		
		// 弹出PicSelectFromNet Dialog
		$('#PicFromNet').click(function(){$("#tablist li").removeClass("currenta");$("#tablist li:eq(1)").addClass("currenta");$('.meat2').css('display','block');$('.meat1,.meat3').hide();$('.meat select').hide(); $('#PicSelect').show(10, function(){ $('#PicSelect').find('.txt').val('http://').end().dialog({overlay:true,bgColor:'black',opacity:0.5}); }); this.blur(); return false; });
		// PicSelect Dialog里的file输入框事件
		$('#PicSelect .file').change(function(){
			if (!/.+\.(jpg|gif|jpeg|png)$/i.test($(this).val())) {
				$(this).addClass('error');
				alert('提示：文件格式不正确，请选择JPG、GIF或PNG格式的图片文件！');
				$(this).focus();
			} else {
				$(this).removeClass('error');
			}
		});
		
		// PicSelectFromNet Dialog里的text输入框事件
		$('#PicSelect .txt').click(function(){
			if ($(this).val() == 'http://') {
				$(this).val('');
			}
		}).blur(function(){
			if ($(this).val() == '') {
				$(this).val('http://');
			} else if (!/^http:\/\/.*\.(jpg|gif|jpeg|png)$/i.test($(this).val()) && $(this).val() != 'http://') {
				$(this).css('background','red');
				alert('提示：文件格式不正确，请选择JPG、GIF或PNG格式的图片文件！');
			} else {
				$(this).css('background','transparent');
			}
		});
		// 点击PicSelect, PicSelectFromNet里的取消
		$('#PicSelect, #PicSelectFromNet').each(function(){
			$(this).find('.handle .s2').click(function(){
				var files = $(this).parent().prev()[0];
				var clone = $(files).find('div').clone(true);
				clone.each(function(){
					$(this).find('.file').val('').removeClass('error');
					$(this).find('.txt').val('http://').removeClass('error');
				});
				clone.appendTo(files);
				$(this).css('display', 'none');
				return false;
			});
		});
		// 点击PicSelect里的确定上传本地图片
		$('.meat3 .s1').bind('click', Pra.m2v.uploadClick);
		// 点击PicSelectFromNet里的确定上传网络图片
		$('.meat2 .s1').click(function(){
			Pra.m2v.uploadClick({
				type: 'net',
				input: '.meat2 .txt',
				hide: '#PicSelect',
				alert: '您还没有输入一张有效图片地址，请输入地址或上传本地图片！',
				callback: function(){
					$('.meat select').show();
					Pra.m2v.global.uploading = true;
					window.PMHNetUpload = new Pra.m2v.upload({
							type: 'net',
							form: '#PicSelectFromNet form',
							callback: function(){
								$('#PicUploading').hide();
								$('#Pic').removeClass('none');
								
								$('#PhotoList .s1').unbind('click').bind('click', Pra.m2v.mPhotoStyleBind);
								$('#PhotoList .txt, #PhotoList .s2').unbind('click').bind('click', Pra.m2v.mPhotoTextBind);
								$('#PhotoList .p a').unbind('click').bind('click', Pra.m2v.mPhotoPhotoBind);
								$('#PhotoList .h_close').unbind('click').bind('click', Pra.m2v.mPhotoClose);
								Pra.m2v.mPhotoSort();
							}
						});
				}
			});
			return false;
		});
		// Music里面的label切换
		$('#Music label').click(function(){
			var id = $(this).find('input').attr('id').replace(/_(\w)/g, function(a, b){return b.toUpperCase()}).replace('music', 'Music');
			$('#Music .detail').hide();
			$('#'+id).css('display','block');
			$(this).blur();
		});
		// file改变时上传音乐文件
		$('#MusicFromLocal .file').change(function(){
			Pra.m2v.uploadMusicClick();
		});
		$('#MusicFromLocal .btn').click(function(){
			Pra.m2v.uploadMusicClick();
		});
		// 添加网络音乐地址
		$('#MusicFromNet .btn').click(function(){
			if (!/^http:\/\/.*\.mp3$/i.test($.trim($('#MusicFromNet .txt').val()))) {
				alert('提示：请输入正确的音乐地址！');
				$('#MusicFromNet .txt').addClass('error').focus();
			} else {
				$('#MusicFromNet .txt').removeClass('error');
				Pra.m2v.i.addMusic($('#MusicFromNet .txt').val());
				Pra.m2v.global.c.bgmusic_2 = $('#MusicFromNet .txt').val();
				$('#MusicFromNet .txt').val('http://'); // clear input
				$('#Music').addClass('none');
				$('#MusicLoading').show();
			}
		});
		// 热门音乐，弹出对话框
		$('#MusicByHot a').click(function() {
			$('#TopMusicFromBaidu').show(10, function(){ $('#TopMusicFromBaidu').dialog({overlay:true,bgColor:'black',opacity:0.5}); });
			if ( $('#TopMusicFromBaidu .dialog_loading').css('display') != 'none') Pra.loadScript(Pra.m2v.global.baiduMusic);
			this.blur();
			return false;
		});
		// 音乐的暂停和播放
		$('#MusicLoading .s1').bind('click', Pra.m2v.pauseMusic);
		$('#MusicLoading .s2').click(function(){
			$('#MusicRemove').show().dialog({overlay:true,bgColor:'black',opacity:0.5});
			this.blur();
			return false;
		});
		$('#MusicRemove .s1').click(function(){
			Pra.m2v.i.addMusic('');
			Pra.m2v.global.c.bgmusic_2 = '';
			$('#Music').removeClass('none');
			$('#MusicLoading').hide();
			$('#MusicRemove').hide();
			Pra.ui.overlay();
		});
		$('#MusicRemove .s2').click(function(){
			$('#MusicRemove').hide();
			Pra.ui.overlay();
		});
		// 基本设置里的
		$('#SetText .s1 .color').color(function(s){ Pra.m2v.i.fontColor(s.replace('#', '')); });
		$('#SetText .s2 .color').color(function(s){ Pra.m2v.i.bgColor(s.replace('#', '')); });
		var selectArr = ['fontSize','fontPos','bgAlpha','turn','delay'];
		$('#Set select').each(function(i){
			$(this).change(function(){ Pra.m2v.i[selectArr[i]]($(this).val()); });
		});
		$('#SetText .clear').click(function() {
			if (confirm('您确定要取消所有文字输入么？这个操作不能恢复哦！')) {
				for (var i=0,l=Pra.m2v.global.c.photo.length; i<l; i++) {
					Pra.m2v.global.c.photo[i][1] = '请输入说明';
				}
				$('#PhotoList .mPhoto').not('.blank').each(function() {
					$(this).find('.txt').val('请输入说明');
				});
				// Pra.m2v.setBasic();
				// Pra.m2v.i.setBasic();
				Pra.m2v.i.refresh();
			}
			this.blur();
			return false;
		});		
		Pra.loadScript(Pra.m2v.global.randomMusicID);
		// 特效、边框、懒人的事件
		$('#Col_2 .tab li a')
			.eq(1).click(function(){ if (!/loaded/.test($('#Effect').attr('class'))) Pra.loadScript(Pra.m2v.global.effect); })
			.end().eq(2).click(function(){ if (!/loaded/.test($('#Border').attr('class'))) Pra.loadScript(Pra.m2v.global.border); })
			.end().eq(3).click(function(){ if (!/loaded/.test($('#Lazy').attr('class'))) Pra.loadScript(Pra.m2v.global.lazy); });
		// Dialog里的Close事件
		$('#PicSelect, #PicSelectFromNet, #TopMusicFromBaidu, #PicStyleSelect, #PicTextInput, #EffectAll, #BorderAll, #MusicRemove, #LastStep, #PicDelete, #Alert').each(function(){
			$(this).find('.close').click(function() {
				$('.meat select').show();
				$(this).parent().parent().hide();
				
				Pra.ui.overlay({close:true});
				this.blur();
				return false;
				
			});
		});
		// 拖动图片 -> 文字说明输入框
		$('#PicTextInput')
			.find('.s1').click(function(){ Pra.m2v.picTextInputSubmit(); })
			.next().click(function(){
				$('#PicTextInput').hide();
				Pra.ui.overlay();
			});
		// 图片过渡效果列表
		Pra.loadScript(Pra.m2v.global.style);
		$('#Layout_3 .tab li a').click(function(){ alert('........\n.......\n......\n.....\n....\n...\n..\n.\n\n没事别瞎点'); this.blur(); return false; });
		// 保存
		$('#Handle a.s2, #Save a').bind('click', Pra.m2v.save);
		$('#LastStep .s1').click(function(){
			if ($('#LastStep .txt').val() == '') {
				alert('请输入相册视频的标题！');
				$('#LastStep .txt').focus();
				return;
			}
			var c = Pra.m2v.global.c, s = '',ci=$("input[@name=items][@checked]").val();
			s += '<config>';
			s += '<a t="'+escape($('#LastStep .txt').val().replace(/\"/g, '&qt;').replace(/</g, '&lt;').replace(/>/g, '&gt;'))+'" fc="'+c.fontcolor.replace('0x','')+'" fs="'+c.fontsize+'" fp="'+c.fontpos+'" bc="'+c.bgcolor.replace('0x','')+'" ba="'+c.bgalpha+'" dt="'+c.delaytime+'" tt="'+c.turntime+'" f="'+c.frame[0]+'" e="'+c.effect[0]+'" bm="'+c.bgmusic_2+'" ci="'+ci+'" did="'+Pra.m2v.global.c.uploaddelid+'"/>';
			s += '<c>';
			for (var i=0,il=c.photo.length; i<il; i++) {
				s += '<p id="'+c.photo[i][3]+'" s="'+c.photo[i][4]+'" t="'+escape(c.photo[i][1].replace(/\"/g, '&qt;').replace(/</g, '&lt;').replace(/>/g, '&gt;'))+'" />';
				//  src="'+c.photo[i][5].replace(Pra.m2v.global.picUrl,'')+'"
			}
			s += '</c><ul ids="';
			for (var i=0,il=c.upload.length; i<il; i++) {
				s += c.upload[i][0]+',';
			}
			s += '" /></config>';
			// 提交保存请求
			var url = Pra.m2v.global.save+s, mvid = -1;
			if ($('#Main').attr('class') == 'edit') {
				mvid = $('#Main').attr('rel').replace(/.+mvid=(\d+)&.+/, '$1');
				url = url.replace(/mvid=-1&/, 'mvid='+mvid+'&');
			}
			//Pra.loadScript(url);
			document.getElementById("txtpost").value = s;
			document.getElementById("formpost").action = url;
			document.getElementById("formpost").submit();

			this.blur();
			$('#LastStep .txt, #LastStep .s1, #LastStep .s2').attr('disabled', true);
			$('#LastStep .s1').val('保存中...');
		});
		$('#LastStep .s2').click(function(){
			$('#LastStep').hide();
			Pra.ui.overlay();
			if ($('#Handle .s1').text() != '效果预览') {
				$('#Show, #Handle').css({zIndex: 0});
				$('#Handle .s1').text('效果预览').blur().unbind('click').bind('click', Pra.m2v.preview);
				Pra.ui.overlay();
			}
		});
		// 编辑模式
		if ($('#Main').attr('class') == 'edit' && $('#Main').attr('rel')) {
			Pra.loadScript($('#Main').attr('rel'));
		}
	},
	alert: function(s) {
		$('#Alert').find('p').text(s).end().show().dialog({overlay:true,bgColor:'black',opacity:0.5});
	},
	save: function() {
		if ($('#Handle .s1').text() == '继续编辑') {
			$('#Show, #Handle').css({zIndex: 0});
		}
		if (!Pra.m2v.global.canSave) {
			Pra.m2v.alert('至少一张相片才能保存');
			return false;
		}
		$('#LastStep .txt, #LastStep .s1, #LastStep .s2').removeAttr('disabled');
		$('#LastStep .s1').val('保存相册视频');
		$('#LastStep').show().dialog({overlay:true,bgColor:'black',opacity:0.5}).find('.txt').focus();
		if (Pra.m2v.global.c.title != '') {
			$('#LastStep .txt').val(Pra.m2v.global.c.title);
		}
		this.blur();
		return false;
	},
	edit: function(j) {
		Pra.m2v.global.canSave = true;
		$.extend(Pra.m2v.global.c, j);
		setTimeout(function(){ Pra.m2v.i.refresh() }, 100);
		
		if (Pra.m2v.global.c.bgmusic != '') {
			$('#Music').addClass('none'); // music
		}
		$('#SetText .s1 a').css('background', '#'+j.fontcolor.replace('0x','')); // set
		$('#SetText .s2 a').css('background', '#'+j.bgcolor.replace('0x',''));
		var arr = [{12:0, 14:1, 16:2, 18:3, 20:4}, {1:0, 3:1, 4:2, 2:3}, {0:0, 25:1, 50:2, 75:3, 100:4}, {2000:0, 4000:1, 6000:2}, {2000:0, 4000:1, 6000:2}],
			val = [j.fontsize, j.fontpos, j.bgalpha, j.turntime, j.delaytime];
		$('#SetText .s3 select, #SetText .s4 select, #SetText .s5 select, #SetSwitch .s1, #SetSwitch .s2')
			.each(function(i){
				if (arr[i][val[i]] == 'undefine') { return; }
				$(this).find('option')
					.each(function(){ $(this).removeAttr('selected') })
					.eq(parseInt(arr[i][val[i]])).attr('selected', true);
		});
		
		for (var i=0,il=j.photo.length; i<il; i++) { // mphoto
			var text = (j.photo[i][1]=='')?'请输入说明':j.photo[i][1];
			$('<div id="mphoto_'+Math.abs(j.photo[i][3])+'" class="mPhoto"><div class="t">拖动图片</div><div class="p"><a href="javascript:;"><img src="'+j.photo[i][5]+'" width="126" /></a></div><div class="h"><div class="h_txt"><input type="text" value="'+text+'" class="txt" /></div><div class="h_btn"><a href="" class="s1" title="样式">样式</a> <a href="" class="s2" title="文字">文字</a></div><a href="" title="关闭" class="h_close">关闭</a></div></div>').appendTo('#PhotoList');
		}
		if (!$('#Save')[0]) $('#PhotoList').after('<div id="Save"><a href="" title="保存视频">保存视频</a></div>');
		// setTimeout(function(){ $('#PhotoList .mPhoto img').resizeImage({width:126,height:123}) }, 100);
		var plength = 20-j.photo.length;

		$('#currentTit').html('一个相册视频最多可包含<span>20</span>张图片，您还可以上传<span>'+plength+'</span>张图片');
		$('#PhotoList .s1').unbind('click').bind('click', Pra.m2v.mPhotoStyleBind);
		$('#PhotoList .txt, #PhotoList .s2').unbind('click').bind('click', Pra.m2v.mPhotoTextBind);
		$('#PhotoList .p a').unbind('click').bind('click', Pra.m2v.mPhotoPhotoBind);
		$('#PhotoList .h_close').unbind('click').bind('click', Pra.m2v.mPhotoClose);;
		Pra.m2v.mPhotoSort();
	},
	// 预览
	preview: function() {
		// 添加一个遮罩层
		$('#Show, #Handle').css({zIndex: 10001});
		Pra.ui.overlay({bgColor:'black', opacity:0.5});
		$('#Handle .s1').text('继续编辑').unbind('click').click(function(){
			Pra.ui.overlay({close:true});
			$('#Show, #Handle').css({zIndex: 0});
			$(this).text('效果预览').blur().unbind('click').bind('click', Pra.m2v.preview);
			return false;
		});
		this.blur();
		return false;
	},
	// 音乐的暂停和播放
	pauseMusic: function() {
		Pra.m2v.i.pause();
		$(this).text('播放音乐').unbind('click').click(function(){
			Pra.m2v.i.play();
			$(this).text('暂停音乐').blur().unbind('click').bind('click', Pra.m2v.pauseMusic);
			return false;
		});
		this.blur();
		return false;
	},
	// 本地/网络图片上传
	uploadClick: function(options) {
		var o = {
			type: 'local',
			input: '#PicSelect .file',
			hide: '#PicSelect',
			addNone: '#Pic',
			alert: '没有选择任何图片，您可以点击【浏览...】按钮选择多张图片，然后一起上传。',
			callback: function() {
				$('.meat select').show();
				Pra.m2v.global.uploading = true;
				window.PMHUpload = new Pra.m2v.upload({
						callback: function(){
							$('#PicUploading').hide();
							
							$('#Pic').removeClass('none');
							$('#PhotoList .s1').unbind('click').bind('click', Pra.m2v.mPhotoStyleBind);
							$('#PhotoList .txt, #PhotoList .s2').unbind('click').bind('click', Pra.m2v.mPhotoTextBind);
							$('#PhotoList .p a').unbind('click').bind('click', Pra.m2v.mPhotoPhotoBind);
							$('#PhotoList .h_close').unbind('click').bind('click', Pra.m2v.mPhotoClose);
							Pra.m2v.mPhotoSort();
						}
					});
			}
		};
		if (options) $.extend(o, options);
		
		var mPhotoLength = $('#PhotoList .mPhoto').length;
		
		var pics = [];
		$(o.input).each(function(){
			var val = $(this).val();
			if (!/error/.test(this.className) && val != '' && val != 'http://' && /.+\.(jpg|gif|jpeg|png)$/i.test(val))
				pics.push(val);
		});
		if (pics.length > 0) {
			if (parseInt(pics.length + Pra.m2v.global.c.photo.length) >= 21) {
				alert('最多只能添加20张相片,如果想继续添加,请先删除你不想保留的相片!');
			} else {
				$(o.hide).hide();
				$(o.addNone).addClass('none');
				Pra.ui.overlay();
				$('#PicUploading').show();
				o.callback();
			}
		} else {
			alert(o.alert);
		}
		return false;
	},
	// 上传音乐一
	uploadMusicClick: function() {
		var file = $('#MusicFromLocal .file');
		if (!/.+\.mp3$/i.test(file.val())) {
			file.addClass('error');
			alert('提示：文件格式不正确，请选择MP3格式的音乐文件！');
			file.focus();
		} else {
			file.removeClass('error');
			Pra.m2v.uploadMusic();
		}
	},
	// 上传音乐二
	uploadMusic: function() {
		$('#Music').addClass('none');
		$('#MusicUploading').show();
		window.PMHUpload = new Pra.m2v.upload({
				form: '#MusicFromLocal form',
				mp3: true,
				callback: function(){
					$('#MusicUploading').hide();
					// $('#Music').removeClass('none');
				}
			});
			
		// clear input: can't do this, for it calls a bug
		// $('#MusicFromLocal .file').val('');
		// if ($.browser.msie) $('#MusicFromLocal .file')[0].outerHTML = $('#MusicFromLocal .file')[0].outerHTML;
	},
	// 载入百度热门音乐
	loadBaiduMusic: function(json) {
		var t = '', c = []; // String(title, content)
		for (var i=0,l=json.length; i<l; i++) {
			t += '<li><a href="">'+json[i].t+'</a></li>';
			c.push('<ul class="s">');
			for (var j=0,le=json[i].c.length; j<le; j++) {
				c.push('<li><a href="" rel="'+json[i].c[j][1]+'">'+json[i].c[j][0]+'</a></li>');
			}
			c.push('</ul>');
		}
		$('#TopMusicFromBaidu .dialog_loading').hide();
		$('#TopMusicFromBaidu .meat').append('<div class="tab_music"><ul></ul></div><div class="tablet"></div>');
		$('#TopMusicFromBaidu .tab_music ul').html(t);
		$('#TopMusicFromBaidu .tablet').html(c.join(''));
		$('#TopMusicFromBaidu .tab_music li:first, #TopMusicFromBaidu .tablet ul:first').addClass('current');
		$('#TopMusicFromBaidu').updateDialog();
		$('#TopMusicFromBaidu').tab({tab:'.tab_music'});
		$('#TopMusicFromBaidu').find('.tablet li a').click(function(){
			Pra.m2v.i.addMusic($(this).attr('rel'));
			Pra.m2v.global.c.bgmusic_2 = $(this).attr('rel');
			$('#TopMusicFromBaidu').hide();
			Pra.ui.overlay();
			$('#Music').addClass('none');
			$('#MusicLoading').show();
			this.blur();
			return false;
		});
	},
	
	
	
	//载入相册
	loadPhotoAlbum:function(photoAlbum){
		var AlbumName="",AlbumOption="<option value=-111>所有相册图片</option>";
			  for(var i=0;i<photoAlbum.length;i++){
				  
				  AlbumOption+="<option value="+photoAlbum[i][0]+">"+photoAlbum[i][1]+"</option>";
			  }
			  AlbumName="<select name='select' class='album' onchange=Pra.m2v.selAlbumChange(); id='Select'>"+AlbumOption+"</select>";
			  $('#albumCon').html(AlbumName);
			 
			 
	},
	   
    selAlbumChange:function()
	{
	    var selValue = $("#Select").val();
		var mvid = -1;
		if ($('#Main').attr('class') == 'edit') {
		  mvid = $('#Main').attr('rel').replace(/.+mvid=(\d+)&.+/, '$1');
		}
	    Pra.loadScript(" http://www.pomoho.com/do/mv/getphotolist.aspx?typeid=2&albumvideoid="+mvid+"&albumid="+selValue+"&curpage=1&userid="+_user.uid);
	},

     //载入图片 ZJW
	 loadPhotos:function(photolist){
	    var photo="";c = [];
	    for(var i=0;i<photolist.length;i++){
	  
	   
        for (var j=0,le=photolist[i].c.length; j<le; j++) {
			  photo+="<ul class='albumList'>";
				  photo+="<li><span class='myphoto'><img id=img_"+photolist[i].c[j][0]+" src="+photolist[i].c[j][2]+" +width='100' height='75' title='"+photolist[i].c[j][1]+"' onload=javascript:photoSize(this.id);></span>";
				  if(photolist[i].c[j][3]>0)
				  {
				      photo+="<span class='myphotoCheck'><input type='checkbox' name='photo' value='checkbox' id="+photolist[i].c[j][0]+" checked/></span></li>";
				  }
				  else
				  {
				      photo+="<span class='myphotoCheck'><input type='checkbox' name='photo' value='checkbox' id="+photolist[i].c[j][0]+"/></span></li>";
				  }
			  photo+="</ul>";
			   }


			 }
	    
			  photo+=" <p class=\"btnPara\">";
			  photo+="<input type=\"button\" name=\"Submit\" value=\"全选\" class=\"confirmBtn\" id=\"AllSelect\" onclick=\"Pra.m2v.Allselect();\"/>";
			  photo+=" <input type=\"button\" id=\"confirmBtn\" name=\"Submit\" value=\"确定\" onclick=\"Pra.m2v.confirmBtn();\" class=\"confirmBtn\"/>";
			  photo+=" </p>";
			  $('#meatf').html(photo+photolist[0].p);
			  
	}, 


   confirmBtn: function(){
			var checkBoxId=[];
			var ImgUrl=[];
            var count=0,icount=0,iicount=0;
			var checkBox=document.getElementsByName("photo");
            $('.meat select').show();

	        




	           for(var i=0;i<checkBox.length;i++){
				//获取选中复选框的id
			     if(checkBox[i].checked)
						{  
						   
			    	       for(var it=0;it<Pra.m2v.global.c.photo.length;it++) {
						   if ( parseInt(checkBox[i].id)== Math.abs(Pra.m2v.global.c.photo[it][3])) {
							         iicount++;
						      }
						   }
						   icount++;
						}
	              }		
				 icount = icount-iicount;
				 leadPhoto = 20-Pra.m2v.global.c.photo.length-icount;
			   
				 if(Pra.m2v.global.c.photo.length+icount>20)
	             {
					alert('最多只能添加20张相片,如果想继续添加,请先删除你不想保留的相片');
					Pra.ui.overlay({close:true});
			        $('#PicSelect').hide();
					return false;
			     }
				 else
	             {
				     $('#currentTit').html('一个相册视频最多可包含<span>20</span>张图片，您还可以上传<span>'+leadPhoto+'</span>张图片');
				 }










				


			for(var i=0;i<checkBox.length;i++){
			//获取选中复选框的id
			if(checkBox[i].checked)
			{   count++;

			//获取对应图片src
			        
                    var photos=Pra.m2v.global.c.photo;
			    	for (var ii=0,il=photos.length; ii<il; ii++) {
						if ( parseInt(checkBox[i].id)== Math.abs(photos[ii][3])) {
							 $('#PhotoList .s1').unbind('click').bind('click', Pra.m2v.mPhotoStyleBind);
							 $('#PhotoList .txt, #PhotoList .s2').unbind('click').bind('click', Pra.m2v.mPhotoTextBind);
							 $('#PhotoList .p a').unbind('click').bind('click', Pra.m2v.mPhotoPhotoBind);
							 $('#PhotoList .h_close').unbind('click').bind('click', Pra.m2v.mPhotoClose);
							 Pra.m2v.mPhotoSort();
							 Pra.ui.overlay({close:true});
							 $('#PicSelect').hide();
							 return false;
						}
					}
			


			    var style = Pra.m2v.global.styleJSON[Math.floor((Math.random() * Pra.m2v.global.styleJSON.length))];
                var imgId = "img_"+parseInt(checkBox[i].id);
			
			    var imgsrc=document.getElementById(imgId).getAttribute("src");

				Pra.m2v.i.picAdd([imgsrc.replace('/s_','/m_'), '输入文字说明', style[2], "-"+parseInt(checkBox[i].id), style[0],imgsrc.replace('/s_','/m_')]);
				Pra.m2v.i.refresh();
				$('<div id="mphoto_'+imgId+'" class="mPhoto"><div class="t">拖动图片</div><div class="p"><a href="javascript:;"><img src="'+imgsrc+'" width="126" /></a></div><div class="h"><div class="h_txt"><input type="text" value="请输入说明" class="txt" /></div><div class="h_btn"><a href="javascript:;" class="s1" title="样式">样式</a> <a href="javascript:;" class="s2" title="文字">文字</a></div><a href="javascript:;" title="关闭" class="h_close">关闭</a></div></div>').appendTo('#PhotoList');
				Pra.m2v.global.c.upload.push([parseInt(checkBox[i].id), imgsrc]);
				if (!Pra.m2v.global.canSave) {
						Pra.m2v.global.canSave = true;
						if (!$('#Save')[0]) $('#PhotoList').after('<div id="Save"><a href="" title="保存视频">保存视频</a></div>');
						$('#Save a').bind('click', Pra.m2v.save);
					}
				
			 }
		   }
		   if(count==0)
	        {
			   alert('请选择一张图片!');
			   return false;
			}
								
			

		     $('#PhotoList .s1').unbind('click').bind('click', Pra.m2v.mPhotoStyleBind);
			 $('#PhotoList .txt, #PhotoList .s2').unbind('click').bind('click', Pra.m2v.mPhotoTextBind);
			 $('#PhotoList .p a').unbind('click').bind('click', Pra.m2v.mPhotoPhotoBind);
			 $('#PhotoList .h_close').unbind('click').bind('click', Pra.m2v.mPhotoClose);
			 Pra.m2v.mPhotoSort();
			 Pra.ui.overlay({close:true});
			 $('#PicSelect').hide();
			 return false;

		},

	  
	Allselect: function (){
			var photos=document.getElementsByName("photo");
			for(var i=0;i<photos.length;i++){
			if(photos[i].type=="checkbox"&&photos[i].name=="photo"){
			photos[i].checked=true;
			           }
			     }
			} ,
	// 重新设置基本设置
	setBasic: function(options) {
		var o = {
			s1: '#FFFFFF',
			s2: '#000000'
		};
		if (options) $.extend(o, options);
		
		$('#SetText .s1 a').css('background', o.s1);
		$('#SetText .s2 a').css('background', o.s2);
		$('#SetText .s3 select, #SetText .s4 select, #SetText .s5 select, #SetSwitch .s1, #SetSwitch .s2')
			.each(function(){
				$(this).find('option')
					.each(function(){ $(this).removeAttr('selected') })
					.eq(1).attr('selected', true);
			});
	},
	// 载入特效
	loadEffect: function(j) {
		switch (j.type) {
			case 'effect':
				$('#Effect').m2vLoadEffect(j.items, {type:'effect', callback:function(){$('#Effect').tab({tab:'.type_tab', tablet:'.type_tablet'});$('#Effect').m2vEnableAll({type:'effect'});/**/}});
				break;
			case 'border':
				$('#Border').m2vLoadEffect(j.items, {type:'border', callback:function(){$('#Border').tab({tab:'.type_tab', tablet:'.type_tablet'});$('#Border').m2vEnableAll({type:'border'});/**/}});
				break;
			case 'style':
				Pra.m2v.global.styleJSON = j.items;
				var c = '';
				for (var m=0,ml=j.items.length; m<ml; m++) {
					c += '<li id="'+j.items[m][0]+'" rel="'+j.items[m][2]+'"><div><a href=""><img src="'+j.items[m][1]+'" alt="'+j.items[m][3]+'" /></a></div><p><a href="">'+j.items[m][3]+'</a></p></li>';
				}
				$('#PicStyleSelect ul').html(c);
				$('#PicStyleSelect ul a').click(function(){
					$('#PicStyleSelect').hide();
					Pra.ui.overlay();
					var el = $(this).parent().parent();
					Pra.m2v.i.picStyle(Pra.m2v.global.currPic-1, el.attr('rel'), el.attr('id'));
					this.blur();
					return false;
				});
				break;
			case 'effectAll':
				$('#EffectAll').m2vLoadEffectAll(j.items, {type:'effect'});
				break;
			case 'borderAll':
				$('#BorderAll').m2vLoadEffectAll(j.items, {type:'border'});
				break;
			case 'lazy':
				var c = '';
				for (var m=0,ml=j.items.length; m<ml; m++) {
					c += '<li id="lazy_'+j.items[m][0]+'"><a href=""><img src="'+j.items[m][1]+'" /></a></li>';
				}
				$('#Lazy')
					.addClass('loaded')
					.html('<p>请选择一个主题，我们将为您自动搭配出一个美丽的相册视频哦！一键到位！</p><div class="type_tablet"><ul class="s current">'+c+'</ul></div>')
					.find('ul li a').click(function(){
							var id = $(this).parent().attr('id').replace('lazy_', '');
							if (true/*Pra.m2v.global.lazyID != id*/) {
								Pra.m2v.global.lazyID = id;
								Pra.loadScript(Pra.m2v.global.lazySpecial + id);
							}
							this.blur();
							return false;
						});
				break;
			default:
				break;
		}
	},
	// 载入指定lazy主题
	loadLazy: function(j) {
		$.extend(Pra.m2v.global.c, {effect:j.ef,frame:j.bd,bgmusic:j.ms,bgmusic_2:j.ms,bgcolor:'0x'+j.bc,fontcolor:'0x'+j.fc,fontsize:j.fs,fontpos:j.fp,bgalpha:j.ba,turntime:j.tt,delaytime:j.dt});
		Pra.m2v.i.refresh();
		$('#SetText .s1 a').css('background', '#'+j.fc);
		$('#SetText .s2 a').css('background', '#'+j.bc);
		var arr = [{12:0, 14:1, 16:2, 18:3, 20:4}, {1:0, 3:1, 4:2, 2:3}, {0:0, 25:1, 50:2, 75:3, 100:4}, {2000:0, 4000:1, 6000:2}, {2000:0, 4000:1, 6000:2}],
			val = [j.fs, j.fp, j.ba, j.tt, j.dt];
		$('#SetText .s3 select, #SetText .s4 select, #SetText .s5 select, #SetSwitch .s1, #SetSwitch .s2')
			.each(function(i){
				if (arr[i][val[i]] == 'undefine') { return; }
				$(this).find('option')
					.each(function(){ $(this).removeAttr('selected') })
					.eq(parseInt(arr[i][val[i]])).attr('selected', true);
		});
		if (/\.mp3/.test(j.ms) && !/none/.test($('#Music').attr('class'))) { // show musicLoading div
			if ($('#Music').css('display') == 'block') {
				$('#MusicLoading').show();
			}
			$('#Music').addClass('none');
		}
	},
	// mPhoto 重新排序以及drag初始化
	mPhotoSort: function() {
		// $('#PhotoList .mPhoto').each(function(i){ $(this).attr('id', 'mPhoto_'+(i+1)); }); // reset mPhoto id
		Pra.m2v.mPhotoBlankReset();
		$('#PhotoList').sort({
			items: '> .mPhoto',
			handle: '.t',
			helper: function(e, m){
				return $('<div>').addClass('mPhoto').css({background:'#fff',border:'2px dashed #aaa',width:132,height:194,height:m.element.clientHeight-2})[0]
			},
			opacity: 0.7,
			callback: function() {
				// 计算
				var arr = [],
					photo = Pra.m2v.global.c.photo;
				$('#PhotoList .mPhoto').not('.blank').each(function(){
					var id = $(this).attr('id').replace('mphoto_', '');
					for (var i=0,il=photo.length; i<il; i++) {
						if (id == Math.abs(photo[i][3])) {
							arr.push(photo[i]);
						}
					}
				});
				if (arr.length >0 ) {
					Pra.m2v.global.c.photo = arr;
					delete arr;
				}
				Pra.m2v.i.refresh();
				Pra.m2v.mPhotoSort(); // 重新计算blank层
			}
		});
	},
	// 获取 mPhoto ID
	mPhotoID: function(id) {
		var tmp = 0;
		$('#PhotoList .mPhoto').not('.blank').each(function(i){
			if ($(this).attr('id') == id) {
				tmp = i+1;
			}
		});
		return tmp;
	},
	// mPhoto 空DIV重置
	mPhotoBlankReset: function() {
		if ($('#PhotoList .blank')[0]) $('#PhotoList .blank').remove();
		for (var i=0; i<$('#PhotoList .mPhoto').length; i++)
			if ((i+2)%7 == 0) { $('#PhotoList .mPhoto').eq(i).after('<div class="mPhoto blank">'); }
		if (($('#PhotoList .mPhoto').length)%7 != 0) $('#PhotoList').append('<div class="mPhoto blank">');
	},
	mPhotoClose: function(e) {
		var el = $(this).parent().parent(),
			e = e || window.event,
			id = Pra.m2v.mPhotoID(el.attr('id'));
		Pra.m2v.global.c.uploaddelid+=el.attr('id').replace('mphoto_img_','')+',';
		//alert(Pra.m2v.global.c.uploaddelid);
		$('#PicDelete')
			.show().css('top', e.clientY+document.documentElement.scrollTop-100).dialog({overlay:true,bgColor:'black',opacity:0.5})
			.find('.s1').unbind('click').click(function(){
				Pra.m2v.i.picRemove(id-1);
				$('#PhotoList .mPhoto').not('.blank').eq(id-1).remove();
				$('#PicDelete').hide();
				Pra.ui.overlay();
				if ($('#PhotoList .mPhoto').not('.blank').length == 0) {
					Pra.m2v.global.canSave = false;
				}
			})
			.end().find('.s2').unbind('click').click(function(){
				$('#PicDelete').hide();
				Pra.ui.overlay();
			});
		this.blur();
		var plength = 20-Pra.m2v.global.c.photo.length+1;
	    $('#currentTit').html('一个相册视频最多可包含<span>20</span>张图片，您还可以上传<span>'+plength+'</span>张图片');
		return false;
	},
	mPhotoPhotoBind: function() {
		Pra.m2v.i.refresh(Pra.m2v.mPhotoID($(this).parent().parent().attr('id'))-1);
		this.blur();
		return false;
	},
	// mPhoto style事件绑定
	//modify by zhuhua on 2008-03-19
	mPhotoStyleBind: function(e) {
		var el = $(this).parent().parent().parent(),
			id = Pra.m2v.mPhotoID(el.attr('id')),
			e = e || window.event;
		var styleID = Pra.m2v.global.c.photo[id-1][4];
		$('#PicStyleSelect ul li').each(function(){
			if( $(this).attr('id')==styleID ){
				$(this).find('div a img').css('border','1px solid #FF5A00');
			} else {
				$(this).find('div a img').css('border','1px solid #ccc');
			}
		});

		Pra.m2v.global.currPic = Pra.m2v.mPhotoID(el.attr('id'));
		
		$('#PicStyleSelect').show().css('top', e.clientY+document.documentElement.scrollTop-310).dialog({overlay:true,bgColor:'black',opacity:0.5})
		.find('h2 strong').text(id);

		this.blur();
		return false;
	},
	// mPhoto text事件绑定
	mPhotoTextBind: function(e) {
		var el = $(this).parent().parent().parent(),
			id = Pra.m2v.mPhotoID(el.attr('id')),
			val = el.find('.txt').val() == '请输入说明' ? '' : el.find('.txt').val(),
			e = e || window.event;
		$('#PicTextInput')
			.show().css('top', e.clientY+document.documentElement.scrollTop-100).dialog({overlay:true,bgColor:'black',opacity:0.5})
			.find('h2 strong').text(id)
			.end().find('.txt').val(val).focus();
		return false;
	},
	// 图片文字输入 -> 提交
	picTextInputSubmit: function() {
		var id = $('#PicTextInput h2 strong').text(),
			val = $('#PicTextInput .txt').val();
		if (val == '') {
			alert('请输入此图片的文字说明！');
			$('#PicTextInput .txt').focus();
			return;
		} else if (val.count() > 60) {
			alert('对不起,文字说明不能超过30个！');
			$('#PicTextInput .txt').focus();
			return;
		}
		$('#PhotoList .mPhoto').not('.blank').eq(id-1).find('.txt').val(val).focus();
		Pra.m2v.i.picText(id-1, val);
		$('#PicTextInput').hide();
		Pra.ui.overlay();
	},
	saveCallback: function(j) {
		if (j.id <= 0) {
			alert('保存错误，请稍后重试！');
		} else {
			window.location = 'http://www.pomoho.com/my/mvok.aspx?mvid='+j.id;
		}
	}
};

$.extend(Pra.pg, {
	m2vLoadEffect: function(j, options) {
		var o = {};
		$.extend(o, options);
		var t = '', c = '', tmp, type = (o.type=='effect')?'特效':'边框';
		for (var m=0,ml=j.length; m<ml; m++) {
			t += '<li><a href="" title="'+j[m].t+'">'+j[m].t+'</a></li>';
			c += '<ul class="s">';
			c += '<li class="cancel"><a href=""><img src="http://static.pomoho.com/images/m2v/cancel.png" alt="取消'+type+'" /></a></li>';
			for (var n=0,nl=j[m].c.length; n<nl; n++) {
				tmp = j[m].c[n];
				c += '<li id="'+o.type+'_'+tmp[0]+'" rel="'+tmp[2]+'"><a href=""><img src="'+tmp[1]+'" /></a></li>';
			}
			c += '</ul>';
		}
		$(this)
			.addClass('loaded')
			.html('<div class="type_tab"><strong>'+type+'分类：</strong><ul>'+t+'</ul><a href="" title="查看全部" class="all">查看全部</a></div><div class="type_tablet">'+c+'</div>')
			.find('.type_tab li:first').addClass('current')
			.end().find('.type_tablet ul:first').addClass('current');
		if (o.callback) o.callback();
		$(this).find('.cancel a').click(function(){
			//modify
			if (o.type == 'effect') {
				$('#effect_'+Pra.m2v.global.c.effect[0]+' a img').css('border','1px solid #ccc');
				$('#effectall_'+Pra.m2v.global.c.effect[0]+' a img').css('border','1px solid #ccc');
				Pra.m2v.i.effect([-1,'']);
			} else if (o.type == 'border') {
				$('#border_'+Pra.m2v.global.c.frame[0]+' a img').css('border','1px solid #ccc');
				$('#borderall_'+Pra.m2v.global.c.frame[0]+' a img').css('border','1px solid #ccc');
				Pra.m2v.i.frame([-1,'']);
			}
			this.blur();
			return false;
		}).end().find('.type_tablet li').not('.cancel').find('a').click(function(){
			var el = $(this).parent();
			//modify
			if (o.type == 'effect') {
				$('#effect_'+Pra.m2v.global.c.effect[0]+' a img').css('border','1px solid #ccc');
				$('#effectall_'+Pra.m2v.global.c.effect[0]+' a img').css('border','1px solid #ccc');
				Pra.m2v.i.effect([el.attr('id').replace('effect_',''),el.attr('rel')]);
				$('#effect_'+Pra.m2v.global.c.effect[0]+' a img').css('border','1px solid #FF5A00');
				$('#effectall_'+Pra.m2v.global.c.effect[0]+' a img').css('border','1px solid #FF5A00');
			} else if (o.type == 'border') {
				$('#border_'+Pra.m2v.global.c.frame[0]+' a img').css('border','1px solid #ccc');
				$('#borderall_'+Pra.m2v.global.c.frame[0]+' a img').css('border','1px solid #ccc');
				Pra.m2v.i.frame([el.attr('id').replace('border_',''),el.attr('rel')]);
				$('#border_'+Pra.m2v.global.c.frame[0]+' a img').css('border','1px solid #FF5A00');
				$('#borderall_'+Pra.m2v.global.c.frame[0]+' a img').css('border','1px solid #FF5A00');
			}
			this.blur();
			return false;
		});
	},
	m2vEnableAll: function(options) {
		var o = {};
		if (options) $.extend(o, options);
		
		return $(this).find('.all').click(function(){
			if (o.type == 'effect') {
				$('#EffectAll').show().dialog({overlay:true,bgColor:'black',opacity:0.5});
				if (!/loaded/.test($('#EffectAll').attr('class'))) Pra.loadScript(Pra.m2v.global.effectAll);
			} else if (o.type == 'border') {
				$('#BorderAll').show().dialog({overlay:true,bgColor:'black',opacity:0.5});
				if (!/loaded/.test($('#BorderAll').attr('class'))) Pra.loadScript(Pra.m2v.global.borderAll);
			}
			this.blur();
			return false;
		});
	},
	//modify
	m2vLoadEffectAll: function(j, options) {
		var o = {};
		if (options) $.extend(o, options);
		
		var c = '', type = (o.type=='effect')?'特效':'边框';
		c += '<li class="cancel"><div><a href=""><img src="http://static.pomoho.com/images/m2v/cancel.png" alt="取消'+type+'" /></a></div></li>';
		for (var m=0,ml=j.length; m<ml; m++) {
			c += '<li id="'+o.type+'all_'+j[m][0]+'" rel="'+j[m][2]+'"><div><a href=""><img src="'+j[m][1]+'" alt="" /></a></div></li>';
		}
		$(this)
			.addClass('loaded')
			.find('.meat').html('<ul>'+c+'</ul>')
			.end().updateDialog();
		//modify
		if (o.type == 'effect') {
			$('#effectall_'+Pra.m2v.global.c.effect[0]+' a img').css('border','1px solid #FF5A00');
		} else {
			$('#borderall_'+Pra.m2v.global.c.frame[0]+' a img').css('border','1px solid #FF5A00');
		}
		
		$(this).find('.cancel a').click(function(){
			//modify
			if (o.type == 'effect') {				
				$('#effect_'+Pra.m2v.global.c.effect[0]+' a img').css('border','1px solid #ccc');
				$('#effectall_'+Pra.m2v.global.c.effect[0]+' a img').css('border','1px solid #ccc');
				Pra.m2v.i.effect([-1,'']);
				$('#EffectAll').hide();
			} else {
				$('#border_'+Pra.m2v.global.c.frame[0]+' a img').css('border','1px solid #ccc');
				$('#borderall_'+Pra.m2v.global.c.frame[0]+' a img').css('border','1px solid #ccc');
				Pra.m2v.i.frame([-1,'']);
				$('#BorderAll').hide();
			}
			Pra.ui.overlay();
			this.blur();
			return false;
		}).end().find('li').not('.cancel').find('a').click(function(){
			//modify
			var el = $(this).parent().parent();
			if (o.type == 'effect') {				
				$('#effect_'+Pra.m2v.global.c.effect[0]+' a img').css('border','1px solid #ccc');
				$('#effectall_'+Pra.m2v.global.c.effect[0]+' a img').css('border','1px solid #ccc');
				Pra.m2v.i.effect([el.attr('id').replace('effectall_',''),el.attr('rel')]);
				$('#effect_'+Pra.m2v.global.c.effect[0]+' a img').css('border','1px solid #FF5A00');
				$('#effectall_'+Pra.m2v.global.c.effect[0]+' a img').css('border','1px solid #FF5A00');
				$('#EffectAll').hide();
			} else {
				$('#border_'+Pra.m2v.global.c.frame[0]+' a img').css('border','1px solid #ccc');
				$('#borderall_'+Pra.m2v.global.c.frame[0]+' a img').css('border','1px solid #ccc');
				Pra.m2v.i.frame([el.attr('id').replace('borderall_',''),el.attr('rel')]);
				$('#border_'+Pra.m2v.global.c.frame[0]+' a img').css('border','1px solid #FF5A00');
				$('#borderall_'+Pra.m2v.global.c.frame[0]+' a img').css('border','1px solid #FF5A00');
				$('#BorderAll').hide();
			}
			Pra.ui.overlay();
			this.blur();
			return false;
		});
	}
});

/**
 * 上传类
 * @method upload
 * @param {Object} options
 */
Pra.m2v.upload = function(options) {
	this.url = Pra.m2v.global.upload;
	this.timer = null;
	this.cur = 0;
	this.forms = [];
	
	var o = {
		type: '',
		mp3: false,
		form: '#PicSelect .files form'
	};
	if (options) $.extend(o, options);
	o.bar = o.mp3 ? 'Music' : 'Pic';
	this.options = o;
	
	var self = this;
	
	$(o.form).each(function(){
		var val = $(this).find('.file')[0] ? $(this).find('.file').val() : $(this).find('.txt').val();
		if (o.mp3) {
			var fileCheck = /.+\.(mp3)$/i.test(val);
		} else {
			var fileCheck = /.+\.(jpg|gif|jpeg|png)$/i.test(val);
		}
		if (fileCheck && val != '' && val != 'http://') {
			self.forms.push(this);
		}
	});
	this.start();
};

$.extend(Pra.m2v.upload.prototype, {
	start: function() {
		var self = this;
		if (this.options.type == 'net') {
			Pra.loadScript(this.url+'?action=getnetuploadguid&callback=PMHNetUpload.getUploadGUIDCallBack');
		}
		else {
			Pra.loadScript(this.url+'?action=getguid&callback=PMHUpload.getUploadGUIDCallBack');
		}
		if (!this.options.mp3) {
			$('#PicUploading')
				.find('.ing a').unbind('click').click(function(){ self.next(); this.blur(); return false; })
				.end().find('.ifinish a').unbind('click').click(function(){ self.restart(); this.blur(); return false; });
		} else {
			$('#MusicUploading')
				.find('.ifinish a').unbind('click').click(function(){ self.restart(); this.blur(); return false; });
		}
	},
	getUploadGUIDCallBack: function(id) { // use PMHUpload or PMHNetUpload as className
		this.uid = id;
		$(this.forms[this.cur]).find('input[@name=uploadid]').val(id).end().submit();
		if (this.timer != null) {
			clearInterval(this.timer);
		}
		var self = this;
		// updateBar
		this.timer = setInterval(function() {
			if (self.options.type == 'net') {
				Pra.loadScript(self.url+'?action=getinfo&uploadid='+self.uid+'&callback=PMHNetUpload.updateProgressCallBack');
			} else {
				Pra.loadScript(self.url+'?action=getinfo&uploadid='+self.uid+'&callback=PMHUpload.updateProgressCallBack');
			}
		}, 1000);
	},
	updateProgressCallBack: function(s) {
		var o = this.options;
		switch (s.state.toLowerCase()) {
			case 'uploading':
				if (s.percent > 0) {
					$('#'+o.bar+'Uploading .ing span').text(this.cur+1);
					$('#'+o.bar+'Uploading .uploadbar span').text(s.percent+'%').css('width',s.percent+'%');
					$('#'+o.bar+'Uploading .info .s1').text(Math.round(s.totalSize*s.percent/10240)/10+'K/'+Math.round(s.totalSize/102)/10+'K');
					$('#'+o.bar+'Uploading .info .s2 span').text(s.leftTime);
					$('#'+o.bar+'Uploading .info .s3 span').text(Math.round(s.speed/1024*10)/10+'K/s');
				}
				break;
			case 'uploaded':
				$('#'+o.bar+'Uploading .ing span').text(this.cur+1);
				$('#'+o.bar+'Uploading .uploadbar span').text('100%').css('width','100%');
				$('#'+o.bar+'Uploading .info .s1').text(Math.round(s.totalSize*s.percent/10240)/10+'K/'+Math.round(s.totalSize/102)/10+'K');
				$('#'+o.bar+'Uploading .info .s2 span').text('0分0秒');
				$('#'+o.bar+'Uploading .info .s3 span').text('0K/s');
				if (!o.mp3) {
					var style = Pra.m2v.global.styleJSON[Math.floor((Math.random() * Pra.m2v.global.styleJSON.length))];
					Pra.m2v.i.picAdd([s.tempURL, '输入文字说明', style[2], -s.uploadFileID, style[0], s.url]);
					$('<div id="mphoto_'+s.uploadFileID+'" class="mPhoto"><div class="t">拖动图片</div><div class="p"><a href="javascript:;"><img src="'+s.tempURL+'" width="126" /></a></div><div class="h"><div class="h_txt"><input type="text" value="请输入说明" class="txt" /></div><div class="h_btn"><a href="javascript:;" class="s1" title="样式">样式</a> <a href="javascript:;" class="s2" title="文字">文字</a></div><a href="javascript:;" title="关闭" class="h_close">关闭</a></div></div>').appendTo('#PhotoList');
					if (!Pra.m2v.global.canSave) {
						Pra.m2v.global.canSave = true;
						if (!$('#Save')[0]) $('#PhotoList').after('<div id="Save"><a href="" title="保存视频">保存视频</a></div>');
						$('#Save a').bind('click', Pra.m2v.save);
					}
					// 设置图片宽高
					// setTimeout(function(){ $('#mphoto_'+s.uploadFileID+' img').resizeImage({width:126,height:123}) }, 100);
				} else {
					Pra.m2v.i.addMusic(s.tempURL);
					Pra.m2v.global.c.bgmusic_2 = s.url;
					$('#MusicLoading').show();
					$('#MusicFromLocal .file').val('');
					if ($.browser.msie) $('#MusicFromLocal .file')[0].outerHTML = $('#MusicFromLocal .file')[0].outerHTML;
				}
				Pra.m2v.global.c.upload.push([s.uploadFileID, s.url]);
				var plength = 20-Pra.m2v.global.c.photo.length;
				$('#currentTit').html('一个相册视频最多可包含<span>20</span>张图片，您还可以上传<span>'+plength+'</span>张图片');
				Pra.m2v.global.uploading = false;
				this.next();
				break;
			case 'canceled':
				this.next();
				break;
			case 'error':
				this.next();
				break;
			default:
				break;
		}
	},
	next: function() {
		this.cur ++;
		if (this.cur < this.forms.length)
			this.start();
		else {
			var o = this.options;
			if (o.callback) o.callback();
			clearInterval(this.timer);
		}
	},
	restart: function() {
		clearInterval(this.timer);
		var o = this.options;
		if (o.callback) o.callback();
		if (o.mp3) {
			$('#Music').removeClass('none');
		}
	}
});

String.prototype.count = function() {
	var output = 0;
	for(var i=0, length=this.length; i<length; i++) {
		letter = this.charAt(i);
		if(!/[u00-uFF]/.test(letter)) {
			output += 2;
		} else {
			output ++;
		}
	}
	return output;
};

})();
/*ransiwei 2009.4.15 相册视频遮罩对话框的菜单切换*/
//function tab(id){
//var links=document.getElementById("tablist").getElementsByTagName("a");
//var li=document.getElementById("tablist").getElementsByTagName("li");
//var meat=document.documentElement.className=='meat';
//for(var i=0;i<links.length;i++){
//li[i].className="";
//meat[i].style.display="none";
//if(id==i){
//li[id].className="currenta";
//meat[id].style.display="block";
//}
//}
//}

$(document).ready(function(){
	$("#tablist li").bind('click',function(){
	$("#tablist li").removeClass("currenta");
	$(this).addClass("currenta");
	}
	)
	$("#tablist li:eq(0)").bind('click',function(){
												 $('.meat1').css('display','block');
										   $('.meat2,.meat3').hide();
										  
										   Pra.loadScript(" http://www.pomoho.com/do/mv/getphotolist.aspx?typeid=2&albumvideoid="+mvid+"&albumid=-111&curpage=1&userid="+_user.uid+"");
										   Pra.loadScript("http://www.pomoho.com/do/mv/getphotolist.aspx?typeid=1&albumvideoid="+mvid+"&userid="+_user.uid+"");

										   })
	$("#tablist li:eq(1)").bind('click',function(){
											$('.meat2').css('display','block');
										   $('.meat1,.meat3').hide();
	                                      $('.meat2').find('.txt').val('http://');
										   })
		$("#tablist li:eq(2)").bind('click',function(){
											$('.meat3').css('display','block');
										   $('.meat1,.meat2').hide();
										    $('.meat3').find('.file').val('');
										   })

});

//图片自适应大小
function photoSize(imgid){
	var initWidth=100;//初始化最大宽度
	var initHeight=75;
	 var Imgwidth=$('#'+imgid).width();
	 var Imgheight=$('#'+imgid).height();						  
			if(Imgwidth>initWidth){
					$('#'+imgid).width(initWidth);
								$('#'+imgid).height(initWidth*Imgheight/Imgwidth);
							}
								if(Imgheight>initHeight){
								$('#'+imgid).height(initHeight);
									$('#'+imgid).width(initHeight*Imgwidth/Imgheight)
							}
};
//photoSize:function(){
//	var initWidth=100;//初始化最大宽度
//	var initHeight=75;
//	 var Imgwidth=$(this).width();
//	 var Imgheight=$(this).height();						  
//			if(Imgwidth>initWidth){
//					$(this).width(initWidth);
//								$(this).height(initWidth*Imgheight/Imgwidth);
//								}
//								if(Imgheight>initHeight){
//									$(this).height(initHeight);
//									$(this).width(initHeight*Imgwidth/Imgheight)
//								}
//}
