mediaRequests= function (){
	var dlRequest;
	var cgpop;
	var mediaid;
	var iscut;
	//var cor_ajaxs=new Array();
	var cor_intevals=new Array();
	//var cor_bars=new Array();
	var hds_sets=new Array(); // presets
	hds_sets[0]=new Array(1,1,0);
	hds_sets[1]=new Array(4,5,5);
	hds_sets[2]=new Array(4,5,5);
	hds_sets[3]=new Array(2,0,3);
	hds_sets[4]=new Array(6,2,8);
	hds_sets[5]=new Array(5,5,8);
	hds_sets[6]=new Array(6,2,8);
	hds_sets[7]=new Array(6,2,8);
	var defSize=new Array(0,0,0); // default width and height and ratio
	this.hds_setSetts= function(){ // preset dropdown selected
		var tem71=el("hds_type").selectedIndex;
		var i=0;
		while(true){
			if(el("hds_type_"+i)){
				el("hds_type_"+i).style.display= (i==tem71) ? "inline" : "none";
			}else{
				break;
			}
			i++;
		}
		el("hds_size").selectedIndex=hds_sets[tem71][0];
		el("hds_fps").selectedIndex=hds_sets[tem71][1];
		el("hds_kbt").selectedIndex=hds_sets[tem71][2];
	}
	this.hds_setCustom= function(){ // custom size checkbox is pressed
		if(defSize[0]==0 && defSize[1]==0 && defSize[2]==0){
			defSize[0]=el("hdcustom_w").value;
			defSize[1]=el("hdcustom_h").value;
			defSize[2]=defSize[0]/defSize[1];
		}
		if(el("hdcustom").checked){
			el("hdcustom_w").readOnly=false;
			el("hdcustom_h").readOnly=false;
		}else{
			el("hdcustom_w").readOnly=true;
			el("hdcustom_h").readOnly=true;
		}
	}
	this.hds_typeSize= function(which){ // when custom size field is being typed
		if(el("hdcustom").checked){
			var order=new Array('w','h');
			if(which==1) order=new Array('h','w');
			var vals=parseInt(el("hdcustom_"+order[0]).value);
			if(isNaN(vals)) vals=0;
			el("hdcustom_"+order[0]).value=vals;
			if(el("hdcustom_lock").checked){
				var vals2= (which==1) ? parseInt(vals*defSize[2]) : parseInt(vals/defSize[2]);
				el("hdcustom_"+order[1]).value=vals2;
			}
		}
	}
	this.hds_setCustomLock= function(){ // custom lock pressed
		this.hds_typeSize(0);
	}
	this.hds_submit= function(mediaid, iscut, orig){ // form submitted
//		cgpop.close();
		var ajaxConv = new ajax();
		ajaxConv.init();
		var track=new Date().getTime();
		if(orig!=1){
			var temSize=el("hds_size").value;
			if(el("hdcustom") && el("hdcustom_w") && el("hdcustom_h")){
				if(el("hdcustom").checked){
					if(el("hdcustom_w").value>0 && el("hdcustom_h").value>0){
						temSize=parseInt(el("hdcustom_w").value)+"x"+parseInt(el("hdcustom_h").value);
					}
				}
			}
		}
		var params= (iscut) ? 'op=convert_cut&cutid='+mediaid+'&ctp=1' : 'op=convert_hd&mediaid='+mediaid;
		if(orig!=1){
			params+='&hdtype='+el("hds_type").value+'&hdsize='+temSize+'&hdfps='+el("hds_fps").value+'&hdkbt='+el("hds_kbt").value+'&track='+track;
			var tem71=el("hds_type").selectedIndex;
			if(el("hds_type_"+tem71)){
				params+='&hdtype_vcodec='+el("hds_type_"+tem71).value;
			}
		}else{
			params+="&orig=1&track="+track;
			el("prepOrigBut").style.display="none";
			el("prepOrigText").style.display="inline";
		}
		if(iscut){
			ajaxConv.load('GET', url_root+'/ajax-cut.php?'+params, true);
		}else{
			ajaxConv.load('GET', url_root+'/ajax-media.php?'+params, true);
		}
		setTimeout("mediaRequests.checkHDId("+mediaid+", "+track+", "+iscut+");", 1000);
		setTimeout("mediaRequests.openedDownload();", 1000);
	}
	this.checkHDId= function(media1, track1, iscut){
		var ajaxConv = new ajax();
		ajaxConv.init();
		ajaxConv.success = function (){
			var values=eval(ajaxConv.getResponseText());
			if(values){
				if(values[0]==1){
					dBar.addItem(values[1], values[2], values[3], values[4], values[5], values[6], values[7]);
				}else{
					setTimeout("mediaRequests.checkHDId("+media1+", "+track1+", "+iscut+");", 1000);
				}
			}
		}
		var params='op=media_get_new_bar_id&type=';
		params+= (iscut) ? "hdcut" : "hdmedia";
		params+='&mediaid='+media1+'&track='+track1;
		ajaxConv.load('GET', url_root+'/ajax-bar.php?'+params, true);
	}
	this.remove= function(n1){
		if(confirm("Are you sure you want to proceed?")){
			var ajax2 = new ajax();
			ajax2.init();
			ajax2.success = function (){
				//var values=eval(ajax2.getResponseText());
				//alert(values);
			}
			el('sub_'+n1).innerHTML="<i>Removed</i>";
			var params='op=media_download_request_remove&reqid='+n1;
			ajax2.load('GET', url_root+'/ajax-media.php?'+params,true);
		}
	}
	this.preview= function(n1){ // preview
		var ajax2 = new ajax();
		ajax2.init();
		ajax2.success = function (){
			var values=eval(ajax2.getResponseText());
			if(values.length>0){
				if(mediaRequests.dlRequest!=n1){ // different video opened
					drawPlayer(values[0], values[2], 0, values[1], "flash_player", 3, 1);
					mediaRequests.dlRequest=n1;
				}
				el('cl-submitted-mid').innerHTML=values[3];
			}
			if(tb_init) tb_init("a.thickbox, area.thickbox, input.thickbox");
		}
		if(el('sub_prev_main').style.display!="block") el('sub_prev_main').style.display="block";
		el('cl-submitted-mid').innerHTML="<i>Loading ...</i>";
		if(this.dlRequest!=n1){ // different video opened
			el('flash_player').innerHTML=" ";
		}
		var params='op=media_download_requests&reqid='+n1;
		ajax2.load('GET', url_root+'/ajax-media.php?'+params,true);
	}
	this.openDownload= function(handle, n1){ // open export download window
		mediaid=n1;
		iscut=0;
		cgpop=cgspopup(handle, "/ajax-thickbox.php?op=show_downloadmedia_page&mediaid="+n1, null, mediaRequests.openedDownload1);
	}
	this.openExport= function(handle, n1){ // open export download window
		mediaid=n1;
		iscut=0;
		cgpop=cgspopup(handle, "/ajax-thickbox.php?op=show_exporthdmedia_page&mediaid="+n1, null, mediaRequests.openedDownload);
	}
/*	this.openClipper= function(n1){ // open export download window
		mediaid=n1;
		iscut=0;
		var url=url_root+'/ajax-submit-media.php?op=media_item&media='+n1+'&studio='+window.submitMedia.studio + '&project=' + window.submitMedia.project + '&clip=2';
		cgpop=cgspopup(null, url, null, mediaRequests.openedClipper);
	}*/
	this.openDownloadCut= function(handle, n1){ // open export download window
		mediaid=n1;
		iscut=1;
		cgpop=cgspopup(handle, "/ajax-thickbox.php?op=show_exporthd_page&cutid="+n1, null, mediaRequests.openedDownload);
	}
/*	this.openedClipper= function(){
		$('a#media-item').click(function() {
			cgpop.close();
//			tb_remove(); //close iframe window
		});
		$('a#create-clip').click(function() {
			var title=el('clip_form').title.value
			var description=el('clip_form').description.value
			var tags=el('clip_form').tags.value
			if(title==''){
				alert('Title required.')
				return;
			}
			if(clipVideo.clipin == clipVideo.clipout){
				alert('Use In and Out buttons to create a Clip.')
				return;
			}
			el("clipNotify").innerHTML="Clipping ... ";
			var ajax2 = new ajax();
			ajax2.init();
			ajax2.success = function (){
				var values=eval(ajax2.getResponseText());
				if(values!=null){
					updateProgress("uploadmedia", values[1], "clipNotify");
					$('a#open-clip').click(function() {
						cgpop.close();
						if(window.submitMedia.page_id!='editor'){
							document.location.href=values[4];
						}else{
							window.submitMedia.media = values[0];
							window.submitMedia.media_name = values[3];
							var url = url_root + '/ajax-submit-media.php?op=media_item&page_id=editor&media=' + window.submitMedia.media + '&project=' + window.submitMedia.project;
							$.get(url, function(html) {
								if (!html) {
									return;
								}
								$('div#admin-media-manager-right').html(html);
								window.submitMedia._attachMediaItemEvents();
								window.submitMedia._attachThumbnailEvent();
							}, 'text');
						}
						return false;
					});
					el("create-clip").style.display="none";
					el("open-clip").style.display="inline";
				}
			}
			var params='op=create_clip&mediaid='+mediaid+'&in='+clipVideo.clipin+'&out='+clipVideo.clipout+'&title='+title+'&description='+description+'&tags='+tags+'&projid='+window.submitMedia.project;
			alert(params);
			//ajax2.load('GET', url_root+'/ajax.php?'+params,true);
			//return false;
		});
	}*/
	this.openedDownload1= function(){
		mediaRequests.openedDownload(1);
	}
	this.openedDownload= function(showType){ // once window is opened
		if(el("expPop_Right")){
			el("expPop_Right").innerHTML="Loading Downloads ...";
			var ajax2 = new ajax();
			ajax2.init();
			ajax2.success = function (){
				var values=eval(ajax2.getResponseText());
				el("expPop_Right").innerHTML= (values==null) ? "No Downloads Found" : values[0];
				if(values!=null) eval(values[1]);
			}
			if(iscut){
				var params='op=cuthd_downloads_list&cutid='+mediaid;
				ajax2.load('GET', url_root+'/ajax-cut.php?'+params,true);
			}else{
				var params='op=media_downloads_list&mediaid='+mediaid;
				if(showType!=undefined) params+="&showType="+showType;
				ajax2.load('GET', url_root+'/ajax-media.php?'+params,true);
			}
		}else{ // retry
//			setTimeout("mediaRequests.openedDownload();", 2000);
		}
	}
	this.payMedia= function(projid,mediaid){
		if(confirm("Are you sure you want to submit full payment?")){
			el('btn_'+projid+'_'+mediaid).innerHTML="<i>Processing ...</i>";
			var ajax2 = new ajax();
			ajax2.init();
			ajax2.success = function (){
				var values=eval(ajax2.getResponseText());
				if(values=='y'){
					el('btn_'+projid+'_'+mediaid).innerHTML="<i>Payment is Successful</i>";
					alert("Payment is Successful");
				}else{
					el('btn_'+projid+'_'+mediaid).innerHTML="<i>Payment Failed</i>";
					alert(values);
				}
				//mediaRequests.preview(mediaRequests.dlRequest);
			}
			var params='op=pay_for_cut&projid='+projid+'&mediaid='+mediaid;
			ajax2.load('GET', url_root+'/ajax-cut.php?'+params,true);
		}
	}
/*	this.convRun= function(projid,mediaid,t_title,t_type,t_size,n_fps,n_kbt){
		var ajaxConv = new ajax();
		ajaxConv.init();
		tb_remove(); //close iframe window
		ajaxConv.success = function (){
			var values=eval(ajaxConv.getResponseText());
			el('btn_'+projid+'_'+mediaid).innerHTML="<i>Completed</i>";
			mediaRequests.preview(mediaRequests.dlRequest);
		}
		el('btn_'+projid+'_'+mediaid).innerHTML="<i>Exporting ...</i>";
		var params='op=convert_hd&projid='+projid+'&mediaid='+mediaid+'&hdtype='+t_type+'&hdsize='+t_size+'&hdfps='+n_fps+'&hdkbt='+n_kbt;
		ajaxConv.load('GET', url_root+'/ajax-media.php?'+params, true);
	}*/
	this.removeFile= function(projid,mediaid){
		if(confirm("Are you sure you want to remove?")){
			var ajax2 = new ajax();
			ajax2.init();
			ajax2.success = function (){
				mediaRequests.preview(mediaRequests.dlRequest);
			}
			var params='op=remove_file&projid='+projid+'&mediaid='+mediaid;
			ajax2.load('GET', url_root+'/ajax-media.php?'+params,true);
		}
	}
}
var mediaRequests = new mediaRequests();