var i = 4;
var Dom = {
	get: function(el) {
		if (typeof el === 'string') {
			return document.getElementById(el);
		} else {
			return el;
		}
	},
	add: function(el, dest) {
		var el = this.get(el);
		var dest = this.get(dest);
		dest.appendChild(el);
	},
	remove: function(el) {
		var el = this.get(el);
		el.parentNode.removeChild(el);
	}
};

var Event = {
	add: function() {
		if (window.addEventListener) {
			return function(el, type, fn) {
			Dom.get(el).addEventListener(type, fn, false);
			};
		} else if (window.attachEvent) {
			return function(el, type, fn) {
				var f = function() {
					fn.call(Dom.get(el), window.event);
				};
				Dom.get(el).attachEvent('on' + type, f);
			};
		}
	}()
};

function addSlot(num)
{
	if(i < 19)
	{
		for( var n = 0; n < num; n++)
		{
			if(i >= 19)
			return;
			
			var item = document.createElement('li');
			item.innerHTML =	'<input type="file" name="file[]" class="file" /><span>Tags: </span><input type="text" name="tags[]" id="tags_' + ++i + '" class="text" />' + 
							'<input type="checkbox" name="public[]" class="checkbox" id="private_' + i + '" /><label for="private_' + i + '">Private</label>';
			Dom.add(item,'slotList');
		}
	}
}

function toggleLogin(up)
{
	if(!up)
	{
    	$('#login').slideDown('slow'/*,function(){$('#login_user').focus();}*/);
    }
    else
    	$('#login').slideUp('slow');
    
    return false;
};

if (jQuery)
{
	$(document).ready(function() {
	$.fn.toggleInputValue = function() {
		return this.focus(function() {
			if( this.value == this.defaultValue ) {
				this.value = "";
			}
		}).blur(function() {
			if( !this.value.length ) {
				this.value = this.defaultValue;
			}
		});
	};

	$('#login_user').toggleInputValue();
	$('#login_pass').toggleInputValue();
	$('#search').toggleInputValue();
	
	$('#headercolor').ColorPicker({
		onSubmit: function(hsb, hex, rgb) {
			$('#headercolor').val("#" + hex);
		},
		onBeforeShow: function () {
			$(this).ColorPickerSetColor(this.value);
		},
		onChange: function (hsb, hex, rgb) {
			$('#header').css('backgroundColor', '#' + hex);
			$('#headercolor').val("#" + hex);
		}
	})
	});
}