jQuery(document).ready(function(){
	jQuery('.disable').click(function(){
		return false;
	});
	
	// forum home - tabbing
	jQuery('.fancy-tab-control a').click(function(){
		if(jQuery(this).parent('li').hasClass('current')) {
			return false; 
		}
		var _desc = jQuery(this).attr('href').substring(1);
		// var _box = jQuery(this).parent('li').parent('ul.fancy-tab-control').parent('div.header').parent('div.splashbox');
		
		// active state
		jQuery('.fancy-tab-control li').removeClass('current');
		jQuery(this).parent('li').addClass('current');
		
		// change content
		jQuery('.fancy-tab-content').children('dd').hide();
		jQuery('.fancy-tab-content').children('dd.' + _desc).fadeIn();
		// alert(_desc);
		
		return false; 
	});
	
});

var _anonymous_modal = null;
var AnonymousModal = new Class({

	Extends:Mooverlay.HTML,

	options:{
		animations:true,
		ajax:{
			url:'/modals/anonymous.php'	
		}
	},

	initialize:function(options) {
		this.parent('tell-friend',options);
		this.addEvent('show',this.onShow.bind(this));
	},

	onShow:function() {
		Loader.fadeOut();
		Cufon.set('fontFamily','FuturaLight');
		Cufon.replace('.modal-stage h2');
		Cufon.now();
		$$('.action-registration-link').addEvent('click',function(event) {
			if(event) event.stop();
			
			var modal = window.retrieve('register-modal');
			if(!modal) {
				// modal.hide();
				_anonymous_modal.close();
				modal = new RegisterModal;
				window.store('register-modal',modal);
				Loader.fadeIn();
				modal.load();
			}
			else {
				modal.show();
			}
		});
	}

});

Element.Events.outerClick = {
	
	base : 'click',
	
	condition : function(event){
		event.stopPropagation();
		return false;
	},
	
	onAdd : function(fn){
		this.getDocument().addEvent('click', fn);
	},
	
	onRemove : function(fn){
		this.getDocument().removeEvent('click', fn);
	}
	
};
// 
// var menu = null;
// 
// var CommunityDropDown = new Class({
// 
// 	Implements:[Options,Events],
// 
// 	options:{
// 		offset:-20
// 	},
// 
// 	init:function() {
// 
// 		var result = this.buildMenu();
// 		if(!result) return;
// 
// 		this.animations = false;
// 		this.button = $('community-link');
// 		this.temp = $('community-more');
// 		$$(this.temp).addEvent('click',function(event) {
// 				event.stop();
// 				this.toggle();
// 				// this.hide();
// 		}.bind(this));
// 
// 		window.addEvent('resize',this.adjust);
// 	},
// 
// 	buildMenu:function() {
// 		var html;
// 		
// 		var request = new Request({ 'url':'/json/cmenu.php','async':false,'onSuccess':function(a) { html = a } }).send();
// 		
// 		if(!html) return false;
// 		menu = '<div class="dropdown-menu" id="community-menu">'+html+'</div>';
// 
// 		this.menu = Elements.from(menu);
// 		this.menu.setStyles({
// 				'position':'absolute',
// 				'top':'-9999px',
// 				'display':'none',
// 				'left':'-9999px',
// 				'z-index':5000
// 		});
// 		
// 		this.menu.injectInside('content');
// 		this.menu.addEvent('outerClick',this.hide.bind(this));
// 		
// 		var elms = this.menu.getElements('.video-listing');
// 		$$(elms).addEvent('click',this.onMenuItemClick.bind(this));
// 		
// 		return true;
// 	},
// 
// 	onMenuItemClick:function(event) {
// 		if(event) event.stop();
// 		var item = $(event.target);
// 		if(!item.hasClass('video-listing'))
// 		item = item.getParent('.video-listing');
// 		var link = item.getElement('a');
// 		var href = link.getProperty('href');
// 		if(href) {
// 			window.location = href;	
// 		}
// 	},
// 
// 	toggle:function() {
// 		if(this.isOpen()) {
// 					this.hide();
// 				}
// 				else {
// 					$("videos-menu").setStyles({
// 							'position':'absolute',
// 							'top':'-9999px',
// 							'display':'none',
// 							'left':'-9999px',
// 							'z-index':5000
// 					});
// 					// this.addClass('hover');
// 					this.show();
// 				}
// 	},
// 
// 	show:function() {
// 		if(!this.animations) {
// 			return this.open();
// 		}
// 		
// 		this.menu.setOpacity(0);
// 		this.open();
// 		
// 		new Fx.Tween(this.menu).start('opacity',[0,1]);
// 	},
// 
// 	hide:function() {
// 		if(!this.animations) {
// 			return this.close();
// 		}
// 
// 		new Fx.Tween(this.menu).start('opacity',[1,0]).chain(function() {
// 			this.close();
// 		}.bind(this));
// 	},
// 
// 	open:function() {
// 		this.menu.setStyle('display','block');
// 		this.adjust();
// 	},
// 
// 	close:function() {
// 		this.menu.setStyle('display','none');
// 	},
// 
// 	isOpen:function() {
// 		return this.menu.getStyle('display')!='none';
// 	},
// 
// 	adjust:function() {
// 		// if(this.isOpen()) {
// 			var btn = this.button;
// 			var coords = btn.getCoordinates();
// 			var y = coords.height + parseInt(coords.top);
// 			var x = parseInt(coords.left) + this.options.offset;
// 			
// 			this.menu.setStyles({
// 					'left':x-340,
// 					'top':y
// 			});
// 	
// 			this.fireEvent('position');
// 		// }
// 	},
// 
// 	onOpen:function() {
// 		this.fireEvent('open');
// 	},
// 
// 	onClose:function() {
// 		this.fireEvent('close');
// 	}
// });
// 
// var VideosDropDown = new Class({
// 
// 	Implements:[Options,Events],
// 
// 	options:{
// 		offset:-20
// 	},
// 
// 	init:function() {
// 
// 		var result = this.buildMenu();
// 		if(!result) return;
// 
// 		this.animations = false;
// 		this.button = $('videos-link');
// 		$$(this.button,$('videos-more')).addEvent('click',function(event) {
// 				event.stop();
// 				this.toggle();
// 		}.bind(this));
// 
// 		window.addEvent('resize',this.adjust);
// 	},
// 
// 	buildMenu:function() {
// 		var html;
// 		
// 		var request = new Request({ 'url':'/json/dmenu.php','async':false,'onSuccess':function(a) { html = a } }).send();
// 		
// 		if(!html) return false;
// 		menu = '<div class="dropdown-menu" id="videos-menu">'+html+'</div>';
// 
// 		this.menu = Elements.from(menu);
// 		this.menu.setStyles({
// 				'position':'absolute',
// 				'top':'-9999px',
// 				'display':'none',
// 				'left':'-9999px',
// 				'z-index':5000
// 		});
// 		
// 		this.menu.injectInside('content');
// 		this.menu.addEvent('outerClick',this.hide.bind(this));
// 		
// 		var elms = this.menu.getElements('.video-listing');
// 		$$(elms).addEvent('click',this.onMenuItemClick.bind(this));
// 		
// 		return true;
// 	},
// 
// 	onMenuItemClick:function(event) {
// 		if(event) event.stop();
// 		var item = $(event.target);
// 		if(!item.hasClass('video-listing'))
// 		item = item.getParent('.video-listing');
// 		var link = item.getElement('a');
// 		var href = link.getProperty('href');
// 		if(href) {
// 			window.location = href;	
// 		}
// 	},
// 
// 	toggle:function() {
// 		if(this.isOpen()) {
// 					this.hide();
// 				}
// 				else {
// 					$("community-menu").setStyles({
// 						'position':'absolute',
// 						'top':'-9999px',
// 						'display':'none',
// 						'left':'-9999px',
// 						'z-index':5000
// 					});
// 					this.show();
// 				}
// 	},
// 
// 	show:function() {
// 		if(!this.animations) {
// 			return this.open();
// 		}
// 		
// 		this.menu.setOpacity(0);
// 		this.open();
// 		new Fx.Tween(this.menu).start('opacity',[0,1]);
// 	},
// 
// 	hide:function() {
// 		if(!this.animations) {
// 			return this.close();
// 		}
// 
// 		new Fx.Tween(this.menu).start('opacity',[1,0]).chain(function() {
// 			this.close();
// 		}.bind(this));
// 	},
// 
// 	open:function() {
// 		this.menu.setStyle('display','block');
// 		this.adjust();
// 	},
// 
// 	close:function() {
// 		this.menu.setStyle('display','none');
// 	},
// 
// 	isOpen:function() {
// 		return this.menu.getStyle('display')!='none';
// 	},
// 
// 	adjust:function() {
// 		// if(this.isOpen()) {
// 			var btn = this.button;
// 			var coords = btn.getCoordinates();
// 			var y = coords.height + parseInt(coords.top);
// 			var x = parseInt(coords.left) + this.options.offset;
// 			
// 			this.menu.setStyles({
// 					'left':x - 380,
// 					'top':y
// 			});
// 	
// 			this.fireEvent('position');
// 		// }
// 	},
// 
// 	onOpen:function() {
// 		this.fireEvent('open');
// 	},
// 
// 	onClose:function() {
// 		this.fireEvent('close');
// 	}
// });



// VideosDropDown = new VideosDropDown;
// CommunityDropDown = new CommunityDropDown;
// StoreDropDown = new StoreDropDown;

window.addEvent('domready',function() {

//webkit browsers
if(Browser.Engine.webkit) {
	$(document.body).addClass('webkit');
}

//FF2
if(Browser.Engine.gecko) {
	var n = new String(navigator.userAgent).toLowerCase();
	if(n.contains('firefox/2')) {
		$(document.body).addClass('ff2');
	}
	else if(n.contains('firefox/3.0')) {
		$(document.body).addClass('ff3');
	}
}

// VideosDropDown.init();
// CommunityDropDown.init();
// StoreDropDown.init();

var header = document.getElement('h1');
if(header) {
	header.setStyle('cursor','pointer');
	header.addEvent('click',function(event) {
		event.stop();
		window.location = '/';
	});
}

//setup the register events
$$('.action-registration-link').addEvent('click',function(event) {
	if(event) event.stop();

	var modal = window.retrieve('register-modal');
	if(!modal) {
		modal = new RegisterModal;
		window.store('register-modal',modal);
		Loader.fadeIn();
		modal.load();
	}
	else {
		modal.show();
	}

});

// $$('.bio','.author').addEvent('click',function(event) {
// 
// 	if(event) event.stop();
// 	var target = $(event.target);
// 	if(target) {
// 		var tag = target.get('tag').toLowerCase();
// 		if(tag!='li')
// 		target = target.getParent('.bio');
// 		var child = target.getElement('.action-bio-link');
// 		if(child) {
// 			var dull = {};
// 			dull.stop = $empty;
// 			dull.target = child;
// 			child.fireEvent('click',[dull]);
// 		}
// 	}
// });

$$('.tell-a-friend').addEvent('click',function(event) {
	if(event) event.stop();

	var target = $(event.target);
	var modal = target.retrieve('modal');
	if(!modal) {
		modal = new FriendModal;
		target.store('modal',modal);
		Loader.fadeIn();
		modal.load();
	}
	else {
		// target.store('modal',modal);
		// Loader.fadeIn();
		modal.load();
		// modal.show();
	}
	
	$("community-menu").setStyles({
		'position':'absolute',
		'top':'-9999px',
		'display':'none',
		'left':'-9999px',
		'z-index':5000
	});
	
	$("videos-menu").setStyles({
		'position':'absolute',
		'top':'-9999px',
		'display':'none',
		'left':'-9999px',
		'z-index':5000
	});
	return false;
});

$$('.contact-us-action').addEvent('click',function(event) {
	if(event) event.stop();
	// alert('fsdfd');
	var target = $(event.target);
	var modal = target.retrieve('modal');
	if(!modal) {
		modal = new ContactModal;
		target.store('modal',modal);
		Loader.fadeIn();
		modal.load();
	}
	else {
		// target.store('modal',modal);
		// Loader.fadeIn();
		modal.load();
		// modal.show();
	}
	
	$("community-menu").setStyles({
		'position':'absolute',
		'top':'-9999px',
		'display':'none',
		'left':'-9999px',
		'z-index':5000
	});
	
	$("videos-menu").setStyles({
		'position':'absolute',
		'top':'-9999px',
		'display':'none',
		'left':'-9999px',
		'z-index':5000
	});
	return false;
});

$$('.forgot-password-action').addEvent('click',function(event) {
	if(event) event.stop();

	var target = $(event.target);
	var modal = target.retrieve('modal');
	if(!modal) {
		modal = new ForgotPassword;
		target.store('modal',modal);
		Loader.fadeIn();
		modal.load();
	}
	else {
		// target.store('modal',modal);
		// 		Loader.fadeIn();
		modal.load();
	}

	$("community-menu").setStyles({
		'position':'absolute',
		'top':'-9999px',
		'display':'none',
		'left':'-9999px',
		'z-index':5000
	});
	
	$("videos-menu").setStyles({
		'position':'absolute',
		'top':'-9999px',
		'display':'none',
		'left':'-9999px',
		'z-index':5000
	});
});

$$('.action-bio-link').addEvent('click',function(event) {
	if(event) event.stop();
	var target = $(event.target);
	var person = this.getProperty('data-person');
	var modal = target.retrieve('modal');
	if(!modal) {
		modal = new BioModal(person);
		target.store('modal',modal);
		modal.load();
	}
	else {
		modal.show();	
	}
	
	$("community-menu").setStyles({
		'position':'absolute',
		'top':'-9999px',
		'display':'none',
		'left':'-9999px',
		'z-index':5000
	});
	
	$("videos-menu").setStyles({
		'position':'absolute',
		'top':'-9999px',
		'display':'none',
		'left':'-9999px',
		'z-index':5000
	});
	return false;
});



$$('.action-login').addEvent('click',function(event) {
	if(event) event.stop();

	var target = $(event.target);
	var modal = target.retrieve('modal');
	if(!modal) {
		// _anonymous_modal.hide();
		// unset();
		_anonymous_modal = new AnonymousModal;
		target.store('modal',_anonymous_modal);
		Loader.fadeIn();
		_anonymous_modal.load();
	}
	else {
		_anonymous_modal.show();
	}
	
	$("community-menu").setStyles({
		'position':'absolute',
		'top':'-9999px',
		'display':'none',
		'left':'-9999px',
		'z-index':5000
	});
	
	$("videos-menu").setStyles({
		'position':'absolute',
		'top':'-9999px',
		'display':'none',
		'left':'-9999px',
		'z-index':5000
	});
});

// $('tell-a-friend').addEvent('click',function(event) {
// 	if(event) event.stop();
// 
// 	var target = $(event.target);
// 	var modal = target.retrieve('modal');
// 	if(!modal) {
// 		modal = new FriendModal;
// 		target.store('modal',modal);
// 		Loader.fadeIn();
// 		modal.load();
// 	}
// 	else {
// 		modal.show();
// 	}
// });


// 
var login = $('form-login');
if(login) {
	var username = $('input-login-username');
	var password = $('input-login-password');
	if(username && password) {
		username.focusToggle();
		password.focusToggle();
	}
}

Cufon.set('fontFamily','FuturaLight');
Cufon.replace('.custom-heading');

Cufon.set('fontFamily','FuturaCond');
Cufon.replace('#content h4');
Cufon.now();

});
