// JavaScript Document

	$.fn.wait = function(time, type) {
        time = time || 1000;
        type = type || "fx";
        return this.queue(type, function() {
            var self = this;
            setTimeout(function() {
                $(self).dequeue();
            }, time);
        });
    };


	$(function () {
        $('#nav>ul.drawers').each(function(){
			$(this).accordion({
				header: 'h1',
				selectedClass: 'open',
				event: 'click',
				alwaysOpen: 'false',
				active: ".current"
        	});
		});

		$('#rightMenu>ul.drawers').each(function(){
			$(this).accordion({
				header: 'h1',
				selectedClass: 'open',
				event: 'click',
				active: 'false'
        	});
		});
		
		$('#signUpText').val('    Enter your e-mail');
		
		$('#friendsName').val("    Your friend's name");
		$('#friendsEmail').val("    Your friend's e-mail");
		$('#yourName').val("    Your name");
		$('#yourEmail').val("    Your e-mail");
		
		$('#signUpForm').ajaxForm({ 
			target: '#signUpTarget', 
			success: function() { 
				$('#signUpLoad').fadeOut('fast',function(){$('#signUpTarget').fadeIn('fast');});
			} 
		});
		
		$('#shareForm').ajaxForm({ 
			target: '#shareTarget', 
			success: function() { 
				//$('#shareLoad').fadeOut('fast',function(){$('#shareTarget').fadeIn('fast');});
				
				if($('#friendsName').val() == "Your friend's name" || $('#friendsName').val() == "Your friend\\'s name"){$('#friendsName').val("    Your friend's name");}
				if($('#friendsEmail').val() == "Your friend's e-mail" || $('#friendsEmail').val() == "Your friend\\'s e-mail"){$('#friendsEmail').val("    Your friend's e-mail");}
				if($('#yourName').val() == 'Your name'){$('#yourName').val("    Your name");}
				if($('#yourEmail').val() == 'Your e-mail'){$('#yourEmail').val("    Your e-mail");}
			} 
		});
		
		$('.animate').cycle({
			fx:      'fade', 
			speedIn:  2000, 
			speedOut: 2000, 
			delay:   -2000 
		});
		
		if($('#popupNotice').html()){
			$.blockUI({
				message: $('#popupNotice'),
				css: {
					top:  ($(window).height() - $('#popupNotice').height()) /2 + 'px', 
					left: '0px',
					width: '100%',
					cursor: 'auto',
					border: 'none',
					background: '#231f20'
				},
				overlayCSS:  { 
					backgroundColor: '#231f20', 
					opacity:         1 
				},
				timeout: 5000
			}); 
			$('.blockOverlay,#popupNotice').attr('title','Click to close').css({cursor: 'pointer'}).click($.unblockUI);
		}
		
    });
	
	function focusSignUp(){
		if($('#signUpText').val() == '    Enter your e-mail'){
			$('#signUpText').val('');
		}
	}
	
	function blurSignUp(){
		if($('#signUpText').val() == ''){
			$('#signUpText').val('    Enter your e-mail');
		}
	}
	
	function focusFriendsName(){
		if($('#friendsName').val() == "    Your friend's name"){
			$('#friendsName').val('');
		}
	}
	
	function focusFriendsEmail(){
		if($('#friendsEmail').val() == "    Your friend's e-mail"){
			$('#friendsEmail').val('');
		}
	}
		
	function blurFriendsName(){
		if($('#friendsName').val() == ''){
			$('#friendsName').val("    Your friend's name");
		}
	}
	
	function blurFriendsEmail(){
		if($('#friendsEmail').val() == ''){
			$('#friendsEmail').val("    Your friend's e-mail");
		}
	}
	
	function focusYourName(){
		if($('#yourName').val() == "    Your name"){
			$('#yourName').val('');
		}
	}
	
	function focusYourEmail(){
		if($('#yourEmail').val() == "    Your e-mail"){
			$('#yourEmail').val('');
		}
	}
		
	function blurYourName(){
		if($('#yourName').val() == ''){
			$('#yourName').val("    Your name");
		}
	}
	
	function blurYourEmail(){
		if($('#yourEmail').val() == ''){
			$('#yourEmail').val("    Your e-mail");
		}
	}

	function signUpAJAX(){
		
		$('#signUpTarget').fadeOut('fast',function(){$('#signUpLoad').fadeIn('fast');});
		
		$('#signUpForm').submit();
	}
	
	function shareAJAX(){
		
		//$('#shareTarget').fadeOut('fast',function(){$('#shareLoad').fadeIn('fast');});
		
		$('#shareForm').submit();
	}
	
	function playClick(){
		if(navigator.appName.indexOf("Microsoft") != -1) {
			playVideo = window.document['flash/mark'];
		} else {
			playVideo = document['flash/video'];
		}
		
		playVideo.remotePlay();
	}
	
	function controlsOver(){
		if(navigator.appName.indexOf("Microsoft") != -1) {
			showControls = window.document['flash/video'];
		} else {
			showControls = document['flash/video'];
		}
		
		showControls.remoteOver();
	}
	
	function controlsOut(){
		if(navigator.appName.indexOf("Microsoft") != -1) {
			hideControls = window.document['flash/video'];
		} else {
			hideControls = document['flash/video'];
		}
		
		hideControls.remoteOut();
	}