$(document).ready(function(){

		
	$("#loginTopLink").click(function(){
		$('#loginBar').slideDown();
	});
	

	$("#formLogin").submit(function(){
		
		channel = $("#fld-username").val();
		password = $("#fld-password").val();
		
		$.post('js/login.php',{channel:channel,password:password}, function(data) {
			if(data)
			{
				if(data=='1')
				{	
					if($("#fldChannelPage").val()==1)
					{
						redirectEditPage();
					}
					
					
					$("#channel-ready").slideUp();
					$("#channel-teaser-container").slideDown();
				
					$("#iframeBox").html("<iframe name=\"edit_iframe\" id=\"edit_iframe\" src=\"edit.php\" scrolling=\"no\" frameborder=\"0\"></iframe>");
					$("#header").slideUp();
					$("#iframeBox").slideDown();
					//$('body').scrollTo( $('#iframeBox'), 500);
					$("#content1").slideUp();
					$("#logoutLink").slideDown();
					$('#loginBar').slideUp();
					
					$('#button-cover').fadeIn();
					$('#createChannelLink').hide();
					
				}else{
					alert('Wrong username or password.');
				}
			}
		});
		
		return false;
		
	});
	
	$("#logoutLink").click(function(){										

		$('#subCheckInfo').html('');
	    $('#backgroundCheckInfo').html('');
		$('#linkCheckInfo').html('');
  		$('#titleCheckInfo').html('');
		$('#nameCheckInfo').html('');
	    $('#emailCheckInfo').html('');
		$('#passCheckInfo').html('');
		$('#passCheck2Info').html('');
		
		$.post('js/login.php',{logout:'1'}, function(data) {
			if(data=='1')
			{				
				$("#header").slideDown();
				$("#iframeBox").slideUp();
				$("#content1").slideDown();
				$("#logoutLink").slideUp();
				$("#logoutLink").hide();
				
				$("#fld-username").val("");
				$("#fld-password").val("");
				
				$("#content1").animate({height: '290px'},1,function(){});
				
				$('#button-cover').fadeOut();
				$('#createChannelLink').show();
				
			}
		});	
	});
	

});
