$(document).ready(function(){
	
	$("#loginArea").hide();
	$("#loginContainer, #wrapper #userNav li").addClass('jsActivated');
	$(".searchForm label, .af-form-wrapper label.previewLabel, .joinNow label").addClass("visible");
	//$("a[rel^='prettyPhoto']").prettyPhoto();
	$("a#video").fancybox({
				'titleShow'     : false,
				'transitionIn'	: 'elastic',
				'transitionOut'	: 'elastic'
			});
	$("#slider").easySlider({
		auto: true, 
		continuous: true,
		controlsShow:false,
		speed:500,
		pause:5000,
		continuous:true
		});	
	$("#userNav .login").click(function(){
		$("#loginArea").slideToggle('slow');
		});	
	$(".searchForm input.textBox, .af-form-wrapper input.textBox,  .joinNow input.textBox").each(function(){
		identity = $(this).attr("id");
		selector = '#'+$(this).attr("id");
		hidelabel(selector, identity);
		value = $(selector).val();
		    if(value!=""){ 
				$("label[for="+identity+"]").hide();
			}
	});
	$('.hidden').hide();
	$('p.showTrigger a').click(function(){
		$('.hidden').fadeIn(500);
		$('.hidden').removeClass('.hidden');
		$('p.showTrigger').fadeOut(100);
	});	
});	

function hidelabel (selector, identity){
	value = $(selector).val();
	$(selector).bind("focus", function(){	
		value = $(selector).val();
		if(value==""){ 
			$("label[for="+identity+"]").hide();
		}
	 });
	$(selector).bind("blur", function(){
		value = $(selector).val();
		if(value==""){ 
			$("label[for="+identity+"]").show();
		}
		else{
			$("label[for="+identity+"]").hide();
			}
	 });		
}

jQuery.fn.center = function () {
	this.css("position","fixed");
	this.css("top", ( $(window).height() - this.outerHeight() ) / 2 + "px");
	this.css("left", ( $(window).width() - this.outerWidth() ) / 2 + "px");
    return this;
}

jQuery.jwbox = {
	lightbox	:	null,
	player	: null,
	toggle	: function(context) {
		if (!$.jwbox.lightbox) {
				$.jwbox.lightbox = $(".jwbox_hidden", context);
				$.jwbox.center();
				$("#jwbox_background").fadeIn("fast");
				$.jwbox.lightbox.css("display","block")
				$.jwbox.center();
				$("#jwbox_background").fadeTo(0, 0.8);
				$("object", context).each(function(){
					$.jwbox.player = document.getElementById(this.id);
				});
		} else if ((context.className == 'jwbox_content')) {
		} else {
			try {
				$.jwbox.player.sendEvent("STOP");
				$.jwbox.player = null;
			} catch (err) {
			}
			$.jwbox.lightbox.css("display","none");
			$.jwbox.lightbox = null;
			$("#jwbox_background").fadeOut("fast");
		}
	},
	center	: function() {
		if ($.jwbox.lightbox) {
			$.jwbox.lightbox.center();
		}
	}
}

$(document).keyup(function(event){
    if (event.keyCode == 27 && $.jwbox.lightbox) {
		$.jwbox.toggle($("#jwbox_background"));
    }
});

$(document).ready(function () {
	$("body").append('<div id="jwbox_background">&nbsp;</div>');
	$(".jwbox").click(function () {$.jwbox.toggle(this); return false;});
	$(".jwbox_content").append('<div class="jwbox_close">close</div>');
	$("#jwbox_background").click(function () {$.jwbox.toggle(this); return false;});
	$(".jwbox_content").click(function () {$.jwbox.toggle(this); return false;});
	$(".jwbox_close").click(function () {$.jwbox.toggle(this); return false;});
	$("p.downloadVideo a, a.getFreeCoaching").click(function () {
		window.location.replace($(this).attr('href'));
										   });
	$("p.downloadChart a").click(function () {
		window.open($(this).attr('href'),'_blank');
										   });
	$(window).resize(function() {$.jwbox.center();});
});


$(document).ready(function() {

$(".gettingStarted a#register").fancybox();
	
});



