// DEFAULT TEXT DOWNLOAD
function defaultDownloadText(value) {
	if (value == "show") {
		if ($("#url").val() == "") {
			$("#url").val("...Enter the URL then press the Tubeminate button");
		}
	}
	if (value == "clear") {
		if ($("#url").val() == "...Enter the URL then press the Tubeminate button") {
			$("#url").val("");
		}
	}
}

// LOADER ON
function loaderOn(text) {
	$.blockUI({ message: '<h3><img src="imgs/loader.gif" /> '+ text +'</h3>' });
}

// LOADER OFF
function loaderOff() {
	$.unblockUI();
}

function setLogos() {
	$(document).ready(function() {
	       $("input.tubminate-btn").hover(function(event){
	     	 $(this).addClass("tubminate-btn-hover");
	   		},function(){
	    	 $(this).removeClass("tubminate-btn-hover");
	   });
			$("a.s-youtube").hover(function(event){
			 if ($("input.input-online").val() == '...Enter the URL then press the Tubeminate button') {
	     	 	$("input.input-online").attr({value: 'http://www.youtube.com/watch?v=abcdefghi'});
			 }
	   		},function(){
	   		 if ($("input.input-online").val() == 'http://www.youtube.com/watch?v=abcdefghi') {
	    	 	$("input.input-online").attr({value: '...Enter the URL then press the Tubeminate button'});
	   		 }
	   });
			$("a.s-meta").hover(function(event){
			if ($("input.input-online").val() == '...Enter the URL then press the Tubeminate button') {
	     	 	$("input.input-online").attr({value: 'http://www.metacafe.com/watch/2862262/video-title'});
			}
	   		},function(){
	   		if ($("input.input-online").val() == 'http://www.metacafe.com/watch/2862262/video-title') {
	    	 	$("input.input-online").attr({value: '...Enter the URL then press the Tubeminate button'});
	   		}
	   });
			$("a.s-daily").hover(function(event){
			if ($("input.input-online").val() == '...Enter the URL then press the Tubeminate button') {
	     	 	$("input.input-online").attr({value: 'http://www.dailymotion.com/channel/video-title'});
			}
	   		},function(){
	   		if ($("input.input-online").val() == 'http://www.dailymotion.com/channel/video-title') {
	    	 	$("input.input-online").attr({value: '...Enter the URL then press the Tubeminate button'});
	   		}
	   });
			$("a.s-break").hover(function(event){
			if ($("input.input-online").val() == '...Enter the URL then press the Tubeminate button') {
	     	 	$("input.input-online").attr({value: 'http://www.break.com/category/video-title.html'});
			}
	   		},function(){
	   		if ($("input.input-online").val() == 'http://www.break.com/category/video-title.html') {
	    	 	$("input.input-online").attr({value: '...Enter the URL then press the Tubeminate button'});
	   		}
	   });
			$("a.s-vimeo").hover(function(event){
			if ($("input.input-online").val() == '...Enter the URL then press the Tubeminate button') {
	     		 $("input.input-online").attr({value: 'http://vimeo.com/49788888'});
			}
	   		},function(){
	   		if ($("input.input-online").val() == 'http://vimeo.com/49788888') {
	    	 	$("input.input-online").attr({value: '...Enter the URL then press the Tubeminate button'});
	   		}
	   })
			$("a.s-college").hover(function(event){
			if ($("input.input-online").val() == '...Enter the URL then press the Tubeminate button') {
	     	 	$("input.input-online").attr({value: 'http://www.collegehumor.com/video:1919999'});
			}
	   		},function(){
	   		if ($("input.input-online").val() == 'http://www.collegehumor.com/video:1919999') {
	    	 	$("input.input-online").attr({value: '...Enter the URL then press the Tubeminate button'});
	   		}
	   })
			$("a.s-trilu").hover(function(event){
			if ($("input.input-online").val() == '...Enter the URL then press the Tubeminate button') {
	     	 	$("input.input-online").attr({value: 'http://www.trilulilu.ro/user/77419bc0d1cb9c/'});
			}
	   		},function(){
	   		if ($("input.input-online").val() == 'http://www.trilulilu.ro/user/77419bc0d1cb9c/') {
	    	 	$("input.input-online").attr({value: '...Enter the URL then press the Tubeminate button'});
	   		}
	   });
			$("a.s-220").hover(function(event){
			if ($("input.input-online").val() == '...Enter the URL then press the Tubeminate button') {
	     	 	$("input.input-online").attr({value: 'http://www.220.ro/ZkmYrKLk/video-title'});
			}
	   		},function(){
	   		if ($("input.input-online").val() == 'http://www.220.ro/ZkmYrKLk/video-title') {
	    		 $("input.input-online").attr({value: '...Enter the URL then press the Tubeminate button'});
	   		}
	   })
			$("a.s-tare").hover(function(event){
			if ($("input.input-online").val() == '...Enter the URL then press the Tubeminate button') {
	     	 	$("input.input-online").attr({value: 'http://www.tare.ro/user/video-title'});
			}
	   		},function(){
	   		if ($("input.input-online").val() == 'http://www.tare.ro/user/video-title') {
	    	 	$("input.input-online").attr({value: '...Enter the URL then press the Tubeminate button'});
	   		}
	   })
			$("a.s-teava").hover(function(event){
			if ($("input.input-online").val() == '...Enter the URL then press the Tubeminate button') {
	     	 	$("input.input-online").attr({value: 'http://www.peteava.ro/video/material/3954764'});
			}
	   		},function(){
	   		if ($("input.input-online").val() == 'http://www.peteava.ro/video/material/3954764') {
	    	 	$("input.input-online").attr({value: '...Enter the URL then press the Tubeminate button'});
	   		}
	   })
			$("a.s-animoto").hover(function(event){
			if ($("input.input-online").val() == '...Enter the URL then press the Tubeminate button') {
	     	 	$("input.input-online").attr({value: 'http://animoto.com/play/NBE63FM9XdhdfJcvx'});
			}
	   		},function(){
	   		if ($("input.input-online").val() == 'http://animoto.com/play/NBE63FM9XdhdfJcvx') {
	    	 	$("input.input-online").attr({value: '...Enter the URL then press the Tubeminate button'});
	   		}
	   })
			$("a.s-ads").hover(function(event){
			if ($("input.input-online").val() == '...Enter the URL then press the Tubeminate button') {
	     	 	$("input.input-online").attr({value: 'http://adsoftheworld.com/media/tv/title'});
			}
	   		},function(){
	   		if ($("input.input-online").val() == 'http://adsoftheworld.com/media/tv/title') {
	    	 	$("input.input-online").attr({value: '...Enter the URL then press the Tubeminate button'});
	   		}
	   })
			$("a.s-mega").hover(function(event){
			if ($("input.input-online").val() == '...Enter the URL then press the Tubeminate button') {
	     	 	$("input.input-online").attr({value: 'http://www.megavideo.com/?v=NEGMW'});
			}
	   		},function(){
	   		if ($("input.input-online").val() == 'http://www.megavideo.com/?v=NEGMW') {
	    	 	$("input.input-online").attr({value: '...Enter the URL then press the Tubeminate button'});
	   		}
	   })
			$("a.s-blip").hover(function(event){
			if ($("input.input-online").val() == '...Enter the URL then press the Tubeminate button') {
	     	 	$("input.input-online").attr({value: 'http://blip.tv/file/23163xx'});
			}
	   		},function(){
	   		if ($("input.input-online").val() == 'http://blip.tv/file/23163xx') {
	    	 	$("input.input-online").attr({value: '...Enter the URL then press the Tubeminate button'});
	   		}
	   })
			$("a.s-videohu").hover(function(event){
			if ($("input.input-online").val() == '...Enter the URL then press the Tubeminate button') {
	     	 	$("input.input-online").attr({value: 'http://www.videoplayer.hu/videos/play/38326xx'});
			}
	   		},function(){
	   		if ($("input.input-online").val() == 'http://www.videoplayer.hu/videos/play/38326xx') {
	    	 	$("input.input-online").attr({value: '...Enter the URL then press the Tubeminate button'});
	   		}
	   })
	});
}

var upfile;
var swfu;

function LoadSWF() {
    swfu = new SWFUpload({
		upload_url: "upload.php",
		flash_url : "swfupload.swf",

		// Flash file settings
		file_size_limit : "102400",
		file_types : "*.wav;*.mp3;*.mp2;*.ogg;*.avi;*.mpg;*.mp4;*.3gp;*.mov;*.wmv;*.flv;*.mkv",
		file_types_description : "All Files",
		file_upload_limit : "0",
		file_queue_limit : "1",

		// Event handler settings
		swfupload_loaded_handler : swfUploadLoaded,
		file_queued_handler : fileQueued,
		file_queue_error_handler : fileQueueError,
		file_dialog_complete_handler : fileDialogComplete,
		upload_progress_handler : uploadProgress,
		upload_error_handler : uploadError,
		upload_success_handler : uploadSuccess,
		upload_complete_handler : uploadComplete,
	
		// UI settings
		button_image_url : "imgs/browse-btn.png",
		button_placeholder_id : "btnBrowse",
		button_width: 81,
		button_height: 30,
		button_action: SWFUpload.BUTTON_ACTION.SELECT_FILE,
		button_disable: false,
		button_window_mode : SWFUpload.WINDOW_MODE.TRANSPARENT, 

		// OTHER SETTINGS
		custom_settings : {
			progress_target : "fsUploadProgress",
			upload_successful : false
		},
		
		// Debug settings
		debug: false
	});

}

function uploadDone() {
	loaderOn('Creating preview...');
	$.ajax({
	    url: 'ajax.php?function=createpreview',
	    type: 'GET',
	    cache: false,
	    dataType: 'html',
	    data: 'original='+upfile,
	    error: function(){
	        alert('Error creating a preview.');
	    },
	    success: function(response){
			if (response == "ok") {
				location.href = 'free-convert-and-download-your-video.html';
			}
	    }
	});
}

function downloadFromSite() {
	loaderOn('Downloading your video...');
	$.ajax({
	    url: 'ajax.php?function=downloadvideo',
	    type: 'GET',
	    cache: false,
	    dataType: 'html',
	    data: 'url=' + $.URLEncode($('#url').val()),
	    error: function(){
	        alert('Error downloading your video. Please verify the video link.');
	    },
	    success: function(response){
			if (response == "ok") {
				location.href = 'free-convert-and-download-your-video.html';
			} else {
				loaderOff();
				alert('Error downloading your video. Please verify the video link.');
			}
	    }
	});
}

function convertVideo() {
	loaderOn('Converting your video...');
	$.ajax({
	    url: 'ajax.php?function=convertvideo',
	    type: 'GET',
	    cache: false,
	    dataType: 'html',
	    data: 'start=' + $('#start').val() + '&duration=' + $('#duration').val() + '&size=' + $('#size').val() + '&format=' + $('#format').val() + '&vq=' + $('#vq').val() + '&aq=' + $('#aq').val(),
	    error: function(){
	        alert('Error converting the video.');
	    },
	    success: function(response){
	    	loaderOff();
	    	$('#link').attr("href", 'http://www.tubeminator.com/download-video-' + response);
			$('#link').html('http://www.tubeminator.com/download-video-' + response);
			$('#final-link').fadeIn();
	    }
	});
}

function secToStr(seconds) {
	var output = "00:00";
	seconds = seconds.toFixed();
	sec = seconds % 60;
	min = (seconds-sec)/60;
	if (min < 10) min = '0' + min;
	if (sec < 10) sec = '0' + sec;
	output = min + ":" + sec;
	return output;
}

function sendEvent(swf,typ,prm) { 
	thisMovie(swf).sendEvent(typ,prm);
}

function getUpdate(typ,pr1,pr2,swf) { }

function thisMovie(swf) {
	if(navigator.appName.indexOf("Microsoft") != -1) {
		return window[swf];
	} else {
		return document[swf];
	}
}