// For the pop-up
$(document).ready(function(){
  
	// uncheck the checkbox
	$('form input.do_not_display').prop('checked', false);
  
  
	function showPopUp() {
   	
   	
   	$('#window').fadeIn('fast').css({
   		'width':'900px',
   		'height':'590px'
   	});

	 $('#window').css({
			 position:'absolute',
			 left: ($(window).width() - $('#window').outerWidth())/2,
			 top: ($(window).height() - $('#window').outerHeight())/2
			});
	
   	$('body').append('<div id="fade"></div>');
   	$('#fade').fadeIn();
	
	$('#fade').click(function() {
			var cookieName = "close-popup";
			var cookieOptions = {expires: 1, path: '/'}
			$.cookie(cookieName, true, cookieOptions);
				$(this).fadeOut(function(){
				$(this).remove();
			});
	
			$('#window').fadeOut('fast');
			$('iframe').attr('src', '');
			
			return false;	
		});
   }
   
   // close button
   $('a #close').click(function() {
   		var cookieName = "close-popup";
   		var cookieOptions = {expires: 1, path: '/'}
		$.cookie(cookieName, true, cookieOptions);
   			$('#fade').fadeOut(function(){
   			$('#fade').remove();
   		});

		$('#window').fadeOut('fast');
		$('iframe').attr('src', '');
		
		return false;
   });

   // adds a cookie if the user does not want to see the pop-up
   $('form input.do_not_display').change(function() {
   		var cookieName = "popup";
   		var cookieOptions = {expires: 365, path: '/'}

   		if(this.checked) {
   			console.log('checked');
   			$.cookie(cookieName, true, cookieOptions);
   		} else {
   			console.log('unchecked');
   			$.cookie(cookieName, null);
   		}
   });
	
	// sets default values for the form
	$('#username').defaultValue();
	$('#register #username').defaultValue();
	$('#password').defaultValue();
	
	if ($.cookie('popup')==null && $.cookie('close-popup')==null) {
	  	showPopUp();
	}
	$(document).ready(function(){
   	
   	$("#feature_content").click(function(){
   		var iframe = "<iframe />";

    	var url = "http://www.youtube.com/embed/xOWa8aV9ojY?autoplay=1&autohide=1&modestbranding=1&rel=0&hd=1";

    	var width = 600;
    	var height = 335;
    	var frameborder = 0;

    	 $(iframe, {
            name: 'videoframe',
            id: 'videoframe',
            src: url,
            width: '600',
            height: '335',
            frameborder: 0,
			class: 'youtube-player',
			type: 'text/html',
            allowfullscreen: true
        }).css({'position': 'absolute', 'top': '11px', 'left': '11px'}).appendTo(this);

    	$(this).find('img').fadeOut(function() { $(this).remove();});
   
  		});

 	});
	 
	// password
	function CheckForm() {
		if (document.login.username.value == "") {
			alert("Please enter your username.");
			document.login.username.focus();
			return false;
		}
		if (document.login.Password.value == "") {
			alert("Please enter your password.");
			document.login.Password.focus();
			return false;
		}
			return true;
	}
	
	function CheckJoin() {
		if (document.joinForm.loggedin.value == "false") {
			alert("Please log in first.");
			return false;
		}
		if (document.joinForm.classCode.value == "") {
			alert("Please enter a valid class code.");
			document.joinForm.classCode.focus();
			return false;
		}
	return true;
	}
	
	$('a#lost').click(function () {
		console.log('clicked');
		if (document.login.username.value == "") {
			alert("Please enter your email address. We will send your password to the address entered.");
			document.login.username.focus();
		} else {
			var pwlink = "lostpassword.cfm?em="+document.login.username.value;
			location.href=(pwlink);
		}
	});
 });

