uploaded_images = {
	save_titles: function(){
		var params = $('#uploadedImagesForm').serialize();
		$.ajax({
			url: '/assets/scripts/save_titles.php',
			type: 'POST',
			data: params,
			success: function(data) {
				$('#uploadMsgResult').html(data).show('fast');
				setTimeout(function(){
					$('#uploadMsgResult').hide('fast');
				},3000);
			}
		});
	}
}

function highlight(dat) {
   dat.focus();
   dat.select();
}

function init_form_labels(){
	$('input[title]').each(function() {
		if($(this).val() === '') {
			$(this).val($(this).attr('title'));	
		}
		$(this).focus(function() {
			if($(this).val() == $(this).attr('title')) {
				$(this).val('').addClass('focused');	
			}
		});
		$(this).blur(function() {
			if($(this).val() === '') {
				$(this).val($(this).attr('title')).removeClass('focused');	
			}
		});
	});
	$('textarea[title]').each(function() {
		if($(this).val() === '') {
			$(this).val($(this).attr('title'));	
		}
		$(this).focus(function() {
			if($(this).val() == $(this).attr('title')) {
				$(this).val('').addClass('focused');	
			}
		});
		$(this).blur(function() {
			if($(this).val() === '') {
				$(this).val($(this).attr('title')).removeClass('focused');	
			}
		});
	});
}


$(document).ready(function() {
	
	init_form_labels();
	
	var upload_started = false;
	
	$("#uploadify").uploadify({
		'uploader'       : '/assets/scripts/uploadify.swf',
		'script'         : '/assets/scripts/upload.php',
		'cancelImg'      : '/assets/gfx/cancel.png',
		'folder'         : '/',
		'queueID'        : 'fileQueue',
		'fileExt'		 : "*.jpg;*.gif;*.png", 
		'fileDesc'		 : "JPG, GIF, and PNG Files are Allowed",
		'auto'           : true,
		'multi'          : true,
		'buttonImg'      : '/assets/gfx/upload.png',
		'wmode'          : 'transparent',
		'width'          : 243,
		'height'		 : 85,
		'onFailure'		 : function(){
			alert('Image Upload Failed!');
		},
		'onComplete': function(event, queueID, fileObj, response){


			if(upload_started == false){
				$('#news').slideUp();
//				$('#info').animate({'opacity':'.1'});
//				$('#action_box').animate({'width':'0','opacity':'0'});
//				$('#lcol').css({'display': 'none'});
				$('#rcol').animate({ 'width' : '850px' });
//				$('#uploaded_images').css({'display': 'block'});
				upload_started = true;
			}


			var res = jQuery.parseJSON(response);

			if(res.status == 'ok'){
				$('#uploaded_images').append('<div class="ul upload">'+res.msg+'</div>');
			}else{
				$('#uploaded_images').append('<div class="ul upload_error">'+res.msg+'</div>');
			}
			
			init_form_labels();
				
		}
		
	});

    $('#login-btn').click(function() {
        $('#login').lightbox_me({centered: true, onLoad: function() { $('#login').find('input:first').focus()}});
        return false;
    });

    $('#signup-btn').click(function() {
        $('#sign_up').lightbox_me({centered: true, onLoad: function() { $('#sign_up').find('input:first').focus()}});
        return false;
    });

});


