$(document).ready(function(){
	
	$('.read_more').click(function(){
		$(this).next('.rest_of_text').slideToggle();
	});
	
	function blog_ready() {
			
		var speed = 500;
		
		$('#alw_login').data('html',$('#alw_login').html());
		
		$('#alw_register').data('html',$('#alw_register').html());
		
		$('#alw_lostPassword').data('html',$('#alw_lostPassword').html());
		
		
		
		$('.show_login').bind('click',function() {

		
		//$('.show_login').click(function(){
			
			$('.show_register').css('font-style','normal');
			
			$(this).css('font-style','italic');
			
			$('#alw_login').slideToggle(speed,function(){
				
				if ($(this).css('display') == 'none') $('.show_login').css('font-style','normal');
				
				reset_form();
			
			});
			
			$('#alw_register').slideUp(speed,function(){
				
				$('#alw_register').html($('#alw_register').data('html'));
				
			});
			
			$('#alw_lostPassword').slideUp(speed,function(){
				
				$('#alw_lostPassword').html($('#alw_lostPassword').data('html'));
				
				
				$('.show_lost_password').click(function(){
			
					$('.show_register').css('font-style','normal');
					
					$('.show_login').css('font-style','normal');
					
					$('#alw_lostPassword').slideDown(speed,function(){
						
						reset_form();
					
					});
					
					$('#alw_login').slideUp(speed,function(){
						
						$('#alw_login').html($('#alw_login').data('html'));
					
					});
					
					$('#alw_register').slideUp(speed,function(){
						
						$('#alw_register').html($('#alw_register').data('html'));
					
					});
					
				});
				
				
			});
			
		});
		
		rExp = /#login/gi;

		if (window.location.href.search(rExp)>0) $('.show_login').trigger('click');
		
		$('.show_register').click(function(){
			
			$('.show_login').css('font-style','normal');
			
			$(this).css('font-style','italic');
			
			$('#alw_register').slideToggle(speed,function(){
				
				if ($('#alw_register').css('display') == 'none') $('.show_register').css('font-style','normal');
				
				reset_form();
			
			});
			
			$('#alw_login').slideUp(speed,function(){
				
				$('#alw_login').html($('#alw_login').data('html'));
			
			});
			
			$('#alw_lostPassword').slideUp(speed,function(){
				
				$('#alw_lostPassword').html($('#alw_lostPassword').data('html'));
			
			});
			
		});
		
		
		

		function reset_form () {
			
			$('#register_login input[type!=button]').unbind('focus');
			
			$('#register_login input[type!=button]').focus(function(){
			
				$(this).data('set',true);
				
				if (!$(this).data('focused')) {
					$(this).data('focused',true);
					$(this).attr('value','');
				}
				
				if ($(this).attr('id') == 'password__') $('#register_login #password_label').css('display','none');
				
				//$(this).focus();
			});
			
			
			$('#register_login input').each(function(){
				$(this).data('focused',false);
			});
			
			$('#register_login input[type!=button]').each(function(){
				$(this).data('set',false);
				$(this).data('value',$(this).attr('value'));
			});
			
			$('#register_login #password_label').unbind('click');
			
			$('#register_login #password_label').click(function() {
				$(this).remove();
				$('#password__').focus();
			});
			
			// checkboxes
			
			$('a.pretty_checkbox').unbind('click');
			
			$('a.pretty_checkbox').click(function(){
				
				checkbox = $('#'+$(this).attr('id')+'_checkbox');
				
				if (checkbox.attr('checked')) {
					$(this).css('background-image','url('+template_directory+'/images/checkbox.gif)');
					checkbox.attr('checked',false);
				}
				
				else {
					$(this).css('background-image','url('+template_directory+'/images/checkbox_checked.jpg)');
					checkbox.attr('checked',true);
				}	
				
				if ($(this).attr('id') == 'receive_newsletter') {
					$('#newsletter_form').slideToggle();
				}
				
				if ($(this).attr('id') == 'receive_newsletter_') {
					$('#newsletter_form_').slideToggle();
				}
				
			});
			
			alw_init();
			
		}
		
		reset_form ();
		
		// User options
		$('.show_userops').click(function(){
			$('.user_ops').slideToggle();
		});
		
		// comments
		//window.location.href
		//myString = new String("Go to DevGuru.com")
		rExp = /#comment/gi;

		if (window.location.href.search(rExp)>0 || is_single) $('.comments_div').css('display','block');
		
		//$('.commentlist li:last').css({'border':'none','margin-bottom':'0px','padding-bottom':'0px'});
		$('.comments_roller').each(function(){
			
			$(this).data('rolled',true);
			
			if (window.location.href.search(rExp)>0 || is_single) {
			
				$(this).data('rolled',false);
				
				$(this).parent().css('font-style','italic');
			}
			
		});
		
		$('.comments_roller').click(function(){
			
			if ($(this).data('rolled')) {
				
				$(this).data('rolled',false);
				
				$(this).parent().css('font-style','italic');
				
			} else {
				
				$(this).data('rolled',true);
				
				$(this).parent().css('font-style','normal');
				
			}
			
			$(this).parent().siblings('.comments_div').slideToggle();
		});
		
		$('.register_in_blog').click(function(){
			
			$.scrollTo('#register_login',500);
			
			$('.show_login').css('font-style','normal');
			
			$('.show_register').css('font-style','italic');
			
			
			$('#alw_register').slideDown(speed,function(){
				
				reset_form();
			
			});
			
			$('#alw_login').slideUp(speed,function(){
				
				$('#alw_login').html($('#alw_login').data('html'));
			
			});
			
			$('#alw_lostPassword').slideUp(speed,function(){
				
				$('#alw_lostPassword').html($('#alw_lostPassword').data('html'));
			
			});
		});

 		$('.comment_text').each(function() {
 			$(this).children('p').last().css('margin-bottom','0px');
 		});
 		
 		var admin_on = false;
 		
 		$('#content').data('html',$('#content').html());
 		
 		$('.go_admin').click(function(){
 			if (!admin_on) {
				
				//$('#content').html('<div class="separator"></div><h2 style="color:black;">#'+$('.show_userops').html()+'</h2><iframe id="admin_iframe" src="'+template_directory+'../../../../wp-admin/profile.php?only_profile=true&lang='+lang+'"></iframe>');
				$('#content').html('<div class="separator"></div><iframe scrolling="no" id="admin_iframe" src="'+template_directory+'../../../../wp-admin/profile.php?only_profile=true&lang='+lang+'"></iframe><hr style="display:block;" class="big_hr"/>');
					
				
 				admin_on = true;
 				
 				delete_on = false;
 				
 			} else {
 			
 				$('#content').html($('#content').data('html'));
 				
 				admin_on = false;
 			
 			}
 		});
 		
 		var delete_on = false;
 		$('.delete_account').click(function(){
 			if (!delete_on) {
				
				//$('#content').html('<div class="separator"></div><h2 style="color:black;">#'+$('.show_userops').html()+'</h2><iframe id="admin_iframe" src="'+template_directory+'../../../../wp-admin/profile.php?only_profile=true&lang='+lang+'"></iframe>');
				$('#content').html('<div class="separator"></div><iframe style="height:200px;" scrolling="no" id="admin_iframe" src="'+template_directory+'../../../../wp-admin/admin.php?page=user_self_delete_user&only_profile=true&lang='+lang+'"></iframe><hr style="display:block;" class="big_hr"/>');
					
 				delete_on = true;
 				
 				admin_on = false;
 				
 			} else {
 			
 				$('#content').html($('#content').data('html'));
 				
 				delete_on = false;
 			
 			}
 		});
 	}
 	
 	blog_ready();
});
