$(document).ready(function(){
	var shortify_example = 'Insert your link';
	
	$(function() {
		$("#tabs").tabs({
			fx: { opacity: 'toggle', speed: 'fast' }		
		});
	
		$('#shortify-input').example(shortify_example, { className: 'example' } );
		
		$("#fileUploadstyle").uploadify({
			'uploader': 'uploadify/uploadify.swf',
			'cancelImg': 'uploadify/cancel.png',
			'script': 'http://tldr.me/index.php?act=uploader',
			'multi': true,
			'displayData': 'speed',
			'width': 120,
			'height': 30,
			'fileExt': allowed_ext,
			'fileDesc': file_desc,
			'removeCompleted': false,
			
			'onComplete'	: function(event, ID, fileObj, response, data) {
				$('#fileUploadstyle'+ID).html(response);
				$('.preview-img a').lightBox();
			},
			
			'onAllComplete' : function(event,data) {
				var img_bbcode = document.getElementsByName("img_bbcode");
				var img_link = document.getElementsByName("img_link");
				var thumb_img_bbcode = document.getElementsByName("thumb_img_bbcode");
				var i = 0;
				var img_link_all = '';
				var bb_code_all = '';
				var thumb_bb_code_all = '';
				
				for (var t = img_bbcode.length; i < t; i++) {
					img_link_all += img_link[i].value+"\n";
					bb_code_all += img_bbcode[i].value+"\n";
					thumb_bb_code_all += thumb_img_bbcode[i].value+"\n";
				}
				
				document.getElementById('bbcode_textarea').value = bb_code_all;
				document.getElementById('link_textarea').value = img_link_all;
				document.getElementById('thumb_bbcode_textarea').value = thumb_bb_code_all;
				
				document.getElementById('all_uploads').style.display = 'block';
			}
			
			//'onError'     : function (event,ID,fileObj,errorObj) {
			//	alert(errorObj.type + ' Error: ' + errorObj.info);
			//}
		});
		
		if ($.browser.msie && $.browser.version < 8) {
			if (Math.round(Math.random(1))) {
				alert('OMG it\'s a dinosaur! ...never mind it\'s your Internet Explorer ' + $.browser.version + ".\nPlease upgrade your browser, it is outdated!");
			} else {
				alert('OMG! I just found something thats older than Itsonme! That\'s your Internet Explorer ' + $.browser.version + ".\nPlease upgrade your browser, it is outdated!");
			}
		}
		
	});
	
	$("#shortify-button").click(function() {
		$('#shortify-error-message').fadeOut();
		var shortify_link = $("#shortify-input").val();
		
		if (shortify_example != shortify_link) {
			$.getJSON('index.php?act=shortify&do=shortify&key=' + shortify_link, function(data) {
				if (data['error']) {
					$('#shortify-error-message').html(data['error']);
					$('#shortify-error-message').fadeIn();
				} else {
					$("#shortify-input").val(data['url']);
					$("#shortify-input").focus();
					$("#shortify-input").select();
				}
			})
		}
	});
});
