(function($){
	$(function(){

		var lightbox = {
			'wrappers': {
				'cover': $('<div>').addClass('lightbox-cover').css({
					'position': 'absolute',
					'top': '0',
					'left': '0',
					'width': $(window).width(),
					'height': $('html').height(),
					'background': '#000',
					'z-index': 1000
				}),
				'content': $('<div>').addClass('lightbox-content').css({
					'position': 'absolute',
					'top': '100px',
					'left': '50%',
					'margin-left': -200,
					'width': 400,
					'background': '#FFF',
					'border': '5px solid #000',
					'padding': '5px',
					'z-index': 1001
				})
				
			},
			'show': function(html){
				this.wrappers.cover.css({'opacity': 0, 'display': 'block'}).animate({'opacity': 0.7}, 'fast');
				this.wrappers.content.html(html).fadeIn('fast');
				$('.lightbox-close', this.wrappers.content).click(function(){
					lightbox.hide();
				});
			},
			'hide': function(){
				this.wrappers.cover.fadeOut('fast');
				this.wrappers.content.fadeOut('fast');
			},
			'init': function() {
				this.wrappers.cover.hide().click(function(){
					lightbox.hide();
				});
				this.wrappers.content.hide();
				$('body').append(this.wrappers.cover).append(this.wrappers.content);
				//console.log()
			}
		};
		lightbox.init();
		
		$(".link-select input").hide();
		$(".link-select select").change(function(){
			
			if( $(this.options[this.selectedIndex]).hasClass('password-protect') ) {
				lightbox.show(
					'<form class="login" action="'+ wp_home +'/wp-login.php" method="post">'+
						'<h2>Please Login</h2>'+
						'<label><span>Username</span> <input type="text" name="log" class="input-text" /> </label>'+
						'<label><span>Password</span> <input type="password" name="pwd" class="input-text" /></label>'+
						'<div><input type="submit" value="Login" class="submit" /> <input type="reset" value="Cancel" class="lightbox-close" /></div><div class="clear"></div>'+
					'</form>');
			} else {
				if(this.value) {
					this.form.submit();
				}
			}
		});
	});
})(jQuery);
