$(document).ready(function() {
	
	var isShortcutDisabled = false;
    
	$("input, textarea").focus(function () {
		   isShortcutDisabled = true; 
		});
		
	$("input").blur(function () {
		   isShortcutDisabled = false;
		});	
		
	$(document).bind('keydown', 'g',function (evt){
		if(!isShortcutDisabled){
			$('.mainContent').animate({opacity: '0.5'}, 200);
			$url = '';
			$.get('http://www.kotusozluk.com/noload/guzelinden.get.php', function(data){
				$('ul.leftTopicList li a').removeClass('active');
				$('.mainContent').load(data + '&type=ajax', function(data2){
					$('.mainContent').animate({opacity: '1.0'}, 100);
					var scrollElem = $('.mainContent').closest('body');
					scrollElem.animate({scrollTop: 0}, 400);
					window.history.pushState(data2, "Title", data);
				});
				ie8SafePreventEvent(e);
			});
			
		}
	});
	
	$(document).bind('keydown', 'b',function (evt){
		if(!isShortcutDisabled){
			$('.leftTopics').animate({opacity: '0.5'}, 200);
			var $url = 'http://www.kotusozluk.com/bugun/';
			$('.left').load($url + '&type=ajax' ,function(){
				var imageH = $(window).height() - 87;
				$('.leftTopics').css("height", imageH);
				$('.leftTopics').animate({opacity: '1.0'}, 100);
			});	
		}
	});
	$(document).bind('keydown', 'k',function (evt){
		if(!isShortcutDisabled){
			$('.leftTopics').animate({opacity: '0.5'}, 200);
			var $url = 'http://www.kotusozluk.com/karisik/';
			$('.left').load($url + '&type=ajax' ,function(){
				var imageH = $(window).height() - 87;
				$('.leftTopics').css("height", imageH);
				$('.leftTopics').animate({opacity: '1.0'}, 100);
			});	
		}
	});
	$(document).bind('keydown', 's',function (evt){
		if(!isShortcutDisabled){
			$('.leftTopics').animate({opacity: '0.5'}, 200);
			var $url = 'http://www.kotusozluk.com/sonra/';
			$('.left').load($url + '&type=ajax' ,function(){
				var imageH = $(window).height() - 87;
				$('.leftTopics').css("height", imageH);
				$('.leftTopics').animate({opacity: '1.0'}, 100);
			});	
		}
	});
	$(document).bind('keydown', 'n',function (evt){
		if(!isShortcutDisabled){
			$('.leftTopics').animate({opacity: '0.5'}, 200);
			var $url = 'http://www.kotusozluk.com/neleroluyor/';
			$('.left').load($url + '&type=ajax' ,function(){
				var imageH = $(window).height() - 87;
				$('.leftTopics').css("height", imageH);
				$('.leftTopics').animate({opacity: '1.0'}, 100);
			});	
		}
	});
	
	$(document).bind('keydown', 'u',function (evt){
		if(!isShortcutDisabled){
			$('.leftTopics').animate({opacity: '0.5'}, 200);
			var $url = 'http://www.kotusozluk.com/ukte/';
			$('.left').load($url + '&type=ajax' ,function(){
				var imageH = $(window).height() - 87;
				$('.leftTopics').css("height", imageH);
				$('.leftTopics').animate({opacity: '1.0'}, 100);
			});	
		}
	});
	
	$(document).bind('keydown', 'm',function (evt){
		if(!isShortcutDisabled){
			window.location = 'http://www.kotusozluk.com/mesajlar/';
		}
	});
	
	
	
	$(document).bind('keydown', 't',function (evt){
		if(!isShortcutDisabled){
			window.location = 'http://www.kotusozluk.com/twit/';
		}
	});
	
	$(document).bind('keydown', 'h',function (evt){
		if(!isShortcutDisabled){
			window.location = 'http://www.kotusozluk.com/';
		}
	});
	
	
	
	$(document).bind('keyup', 'a',function (evt){
		if(!isShortcutDisabled){
			
			if($('.searchBox').val() == 'ara / getir'){
				$('.searchBox').val('');
				$('.searchBox').addClass('active');
			}
			$('.searchBox').focus();
		}
	});
	
$title = document.title;
		$url = 'http://www.kotusozluk.com/index.php?type=post&section=userAction&action=check';
			$.get($url, function(data){
				var myarray = data.split(".");
				//alert(myarray[0] + '\n' + myarray[1] + '\n' + myarray[2]);
				if(myarray[0] > 0){
					$('li#message input').addClass('new');
					$('li#message .infoNumber').css('display', 'block');
					$('li#message .infoNumber').html(myarray[0]);
				} else { $('li#message .infoNumber').css('display', 'none'); }
				if(myarray[1] > 0){
					$('li#notification input').addClass('new');
					$('li#notification .infoNumber').css('display', 'block');
					$('li#notification .infoNumber').html(myarray[1]);
				} else { $('li#notification .infoNumber').css('display', 'none');}			
				if(myarray[2] > 0){
					$('li#news input').addClass('new');
					$('li#news .infoNumber').css('display', 'block');
					$('li#news .infoNumber').html(myarray[2]);
				} else { $('li#news .infoNumber').css('display', 'none'); }
				
				var total = Number(myarray[0]) + Number(myarray[1]) + Number(myarray[2]);
				if(total > 0) { document.title = '(' + total + ') ' + $title; } else { document.title = $title; }
					
			});
	function sedat() { 			$('.inPagePopup .innerContent').html('');
			$('.inPagePopup').css('display', 'none');}
	
	setInterval(function(){
		
		$url = 'http://www.kotusozluk.com/index.php?type=post&section=userAction&action=check';
			$.get($url, function(data){
				var myarray = data.split(".");
				//alert(myarray[0] + '\n' + myarray[1] + '\n' + myarray[2]);
				if(myarray[0] > 0){
					$('li#message input').addClass('new');
					$('li#message .infoNumber').css('display', 'block');
					$('li#message .infoNumber').html(myarray[0]);
				} else { $('li#message .infoNumber').css('display', 'none'); }
				if(myarray[1] > 0){
					$('li#notification input').addClass('new');
					$('li#notification .infoNumber').css('display', 'block');
					$('li#notification .infoNumber').html(myarray[1]);
				} else { $('li#notification .infoNumber').css('display', 'none');}			
				if(myarray[2] > 0){
					$('li#news input').addClass('new');
					$('li#news .infoNumber').css('display', 'block');
					$('li#news .infoNumber').html(myarray[2]);
				} else { $('li#news .infoNumber').css('display', 'none'); }
				
				var total = Number(myarray[0]) + Number(myarray[1]) + Number(myarray[2]);
				if(total > 0) { document.title = '(' + total + ') ' + $title; } else { document.title = $title; }
					
			});
		},10000);	

    var bgOffset = 0;
    var bgInterval;
	$('#logo').click(function() {
        window.location = '/';
    });
	 $('#logo').mouseenter(function() {
        bgInterval = setInterval(shiftImage, 90);

        function shiftImage() {
            bgOffset-=250;
            if(Math.abs(bgOffset) >= 6500) {
                bgOffset = 0;
            }
            $('#logo').css('background-position', bgOffset);
        }
    });

    $('#logo').mouseleave(function() {
        clearInterval(bgInterval);
        $('#logo').css('background-position', '0');
    });
	/*	 */
	var $sozluk_url = 'http://www.kotusozluk.com/';
	/*  */
	
	$('#moDatePicker').live('click', function(){ $(this).simpleDatepicker(); });
	var imageH = $(window).height() - 87;
	$('.leftTopics').css("height", imageH);
	

	
	
	$('.inPagePopup').drag(function(event,dd){
                $( this ).css({
                        top: dd.offsetY,
                        left: dd.offsetX,
						margin: 0
                        });
                });	
				
	
	$('.searchBox').live('click', function(){
		var $isEntry = $(this).val().match(/^#$/gi);
		if($(this).val() == 'ara / getir'){
			$(this).val('');
			$(this).addClass('active');
		}else if($(this).val().length > 0 && $isEntry == null){
			$(this).addClass('openPopup');
			$('.searchButton').addClass('openPopup');
			var $word = encodeURI($(this).val());
			var $url = 'http://www.kotusozluk.com/noload/search.popup.php/?word=' + $word;
			
			
			$('.searchPopup').load($url);
			$('.searchPopup').slideDown("fast");
			
		}
		else {
			$(this).removeClass('openPopup');
			$('.searchButton').removeClass('openPopup');
			$('.searchPopup').html('');
			$('.searchPopup').slideUp("fast");
		}
	});
	
	$('.searchBox').live('keyup', function(e){
		if(e.keyCode == 40){
			var $selected = $('li.searchSelected');
			if ($selected.length == 0 ) $selected = $('li.searchResult:last');
			$selected.removeClass('searchSelected');
			var $next = $selected.next();
			var $next = $next.hasClass('searchTitle') ? $next.next() : $next;
			var $next =  $next.length ? $next.addClass('searchSelected') : $('li.searchResult:first').addClass('searchSelected');
		}		
		else if(e.keyCode == 38){
			var $selected = $('li.searchSelected');
			if ($selected.length == 0 ) $selected = $('li.searchResult:first');
			$selected.removeClass('searchSelected');
			var $previous = $selected.prev();
			var $previous = $previous.hasClass('searchTitle') ? $previous.prev() : $previous;
			var $previous = $previous.length ? $previous.addClass('searchSelected') : $('li.searchResult:last').addClass('searchSelected');			
		}
		else if(e.keyCode == 13){
			var $section = $('.searchBox').attr('section');
			var $name = $('li.searchSelected a').html();
			var $name2 = $('.searchBox').val();
			var $isEntry = $name2.match(/^#([0-9]+)$/gi);
			if($isEntry != null){
				
				var url = 'http://www.kotusozluk.com/entry/' + $('.searchBox').val().replace('#', '') + '/';

				/*if($section == 'main'){
					$('.mainContent').load(url + '&type=ajax', function(data){
						$(e.document).scrollTop();
						window.history.pushState(data, "Title", url);
						});
					searchBoxClose();
				}
				else {*/
					window.location = url;
				//}
			}
			else if($name2 != $name){
				var url = 'http://www.kotusozluk.com/nedir/' + $('.searchBox').val().replace(/ /g, '+') + '/';
				if($section == 'main'){
					$('.mainContent').load(url + '&type=ajax', function(data){
						var scrollElem = $('.mainContent').closest('body');
						scrollElem.animate({scrollTop: 0}, 400);
						window.history.pushState(data, "Title", url);
						});
					searchBoxClose();
				}
				else {
					window.location = url;
				}
			}
			else {
				var url = $('li.searchSelected a').attr('href');
				if($('li.searchSelected a').hasClass('topic') && $section == 'main'){
						$('.mainContent').load(url + '&type=ajax', function(data){
							var scrollElem = $('.mainContent').closest('body');
							scrollElem.animate({scrollTop: 0}, 400);
							window.history.pushState(data, "Title", url);
							});
						searchBoxClose();
				}
				else {
					var url = $('li.searchSelected a').attr('href');
					window.location = url;
				}
			}
		}
		else if($(this).val().length > 0){
			$(this).addClass('openPopup');
			$('.searchButton').addClass('openPopup');
			
			var $url = 'http://www.kotusozluk.com/noload/search.popup.php/?word=' + $(this).val().replace(/ /g, '+');
			
			$('.searchPopup').load($url, function(){
				$('li.searchResult:first').addClass('searchSelected');
			});
			$('.searchPopup').slideDown("fast");
			
		}
		else {
			$(this).removeClass('openPopup');
			$('.searchButton').removeClass('openPopup');
			$('.searchPopup').html('');
			$('.searchPopup').slideUp("fast");
		}
	});
	
	$('li.searchResult').live('mouseover', function(){
		$('li.searchSelected').removeClass('searchSelected'),
		$(this).addClass('searchSelected');
	});
	
	$('li.searchResult').live('click', function(e){
		var $section = $('.searchBox').attr('section');
		if($(this).find('a').hasClass('topic') && $section == 'main'){
			if(e.which == 1){
				var url = $(this).find('a').attr('href');
				$('ul.leftTopicList li a').removeClass('active');
				$('.mainContent').load(url + '&type=ajax', function(data){
					var scrollElem = $('.mainContent').closest('body');
					scrollElem.animate({scrollTop: 0}, 400);
					window.history.pushState(data, "Title", url);
					}
				);
				return false;
			}
		}
		else {
			var url = $(this).find('a').attr('href');
			window.location = url;			
		}
	});
	
	var searchBoxClose = function(){
		$('.searchBox').removeClass('openPopup');
		$('.searchBox').removeClass('active');
		$('.searchButton').removeClass('openPopup');
		$('.searchPopup').html('');
		$('.searchPopup').slideUp("fast");
		$('.searchBox').val('ara / getir');
		$('.searchBox').blur();
		$('#searchButton').attr('noform', 'true');
	};
	
	$('.searchClose').live('click', function(){
		searchBoxClose();
	});
	
	/*$('.searchBox').blur(function(){
		$(this).removeClass('openPopup');
		$('.searchButton').removeClass('openPopup');
		$('.searchPopup').html('');
		$('.searchPopup').slideUp("fast");
	});*/
	
	$('.searchButtonDetail, .searchDetailLink').live('click', function(){
		$('#searchButton').attr('noform', 'false');
		var $word = $('.searchBox').val();
		if($word == '' || $word == 'ara / getir'){
			$word = '';
		}
		searchBoxClose();
		$('#searchButton').attr('noform', 'false');
		$('.searchButton').addClass('openPopup');
		$('.searchBox').addClass('openPopup');

		
		var $url = 'http://www.kotusozluk.com/noload/search.popup.php/?action=adv&word=' + $word.replace(/ /g, '+');

		$('.searchPopup').load($url, function(){
			$('#sbDatePicker').simpleDatepicker();
		});
		$('.searchPopup').slideDown("fast");
		
	});
	
	$('#searchButton').click(function(){
		if($(this).attr('noform') == 'false'){
			var $section = $('.searchBox').attr('section');
			var $data = '&' + $('#searchBoxForm').serialize();
			var $url = $('#searchBoxForm').attr('href') + $data + '&type=ajax';
			$('.left').html('<center><img src="http://www.kotusozluk.com/theme/kotusozluk/images/yukleniyor.gif"></center>');
			$('.left').load($url, function(){
				var imageH = $(window).height() - 87;
				$('.leftTopics').css("height", imageH);
			});
		} else {
			var $data = '&q=' + $('.searchBox').val();
			var $url = 'http://www.kotusozluk.com/ara/' + $data + '&type=ajax';
			$('.left').html('<center><img src="http://www.kotusozluk.com/theme/kotusozluk/images/yukleniyor.gif"></center>');
			$('.left').load($url, function(){
				var imageH = $(window).height() - 87;
				$('.leftTopics').css("height", imageH);
			});
		}
	});
	
	/*$('.searchButtonDetail').blur(function(){
		$('.searchButton').removeClass('openPopup');
		$('.searchButton').removeClass('openPopup');
		$('.searchPopup').html('');
		$('.searchPopup').slideUp("fast");		
	});*/
	
	
	$('.headerButtons li').click(function(){
		if($(this).hasClass('active')){
			$('.headerPopup').slideUp("fast");
			$('.headerButtons li').removeClass('active');
		}
		else {
			$('.headerPopup').slideUp("fast");
			$('.headerButtons li').removeClass('active');
			$(this).addClass('active');		
			if($(this).attr('id') == 'message'){
				$url = 'http://www.kotusozluk.com/index.php?type=post&section=userAction&action=showMessage';
				$('.headerPopup').load($url);
				$('.headerPopup').slideDown("fast");
				$('li#message .infoNumber').css('display', 'none');	
				document.title = $title;				
				}
			else if($(this).attr('id') == 'notification'){
				$url = 'http://www.kotusozluk.com/index.php?type=post&section=userAction&action=showNotification';
				$('.headerPopup').load($url);
				$('.headerPopup').slideDown("fast");
				$('li#notification .infoNumber').css('display', 'none');
				document.title = $title;
			}	
			else if($(this).attr('id') == 'news'){
				$url = 'http://www.kotusozluk.com/index.php?type=post&section=userAction&action=showNews';
				$('.headerPopup').load($url);
				$('.headerPopup').slideDown("fast");
				$('li#news .infoNumber').css('display', 'none');
				document.title = $title;
			}	
			else if($(this).attr('id') == 'bin'){
				$url = $(this).find('input').attr('href');
				window.location = $url;
			}
			else if($(this).attr('id') == 'modstyle'){
				$url = 'http://www.kotusozluk.com/index.php?type=post&section=userAction&action=modstyle';
				$.get($url, function(data){
					   $.toast({
					        message:data,
					        displayTime:2000,
					        inTime:100,
					        outTime:400
					      });;
				});
			}
		}
		
		return false;
	});
	
	$('.homeStatusTop').live('click', function(){
		$(this).css('display', 'none');
		$('#homeStatusWrite').css('display', 'block');
		$('#homeStatusWrite #entryWriteContent').focus();
	});
	
	$('.homeStatus #entryWriteContent').live('keyup keydown', function(){
		var $remaining = 200-$(this).val().length;
		$('.homeStatusCharacter').html('kalan karakter: ' + $remaining);
		if($remaining == 0){
			$text = $(this).val().substr(0, 200);
			$(this).val($text);
		}
	})
	
			$('#buttonUpload').live('click', function(){
				var gallery = $(this).attr('gallery_name');

				if(!gallery || gallery == 'undefined' || gallery == ''){
					$('.uploadPopupMain').html('<iframe src="http://www.kotusozluk.com/images/upload/index.php" border="0" style="border: none; width: 100%; height: 100%"></iframe>');				
				}
				else if(gallery != ''){
					$('.uploadPopupMain').html('<iframe src="http://www.kotusozluk.com/images/upload/index.php?baslik=' + gallery +'" border="0" style="border: none; width: 100%; height: 100%"></iframe>');
				}
				
				$('body').css('overflow', 'hidden');
				$height = window.innerHeight;
				$height = $height - 60;
				$('.uploadPopup').css('height', $height);
				$('.uploadPopup iframe').css('height', $height-50);
				$('.uploadBackground').fadeIn(400);
				$('.uploadPopup').fadeIn(400);
			});
			
			$('#uploadClose').live('click',function(){
				$('.uploadPopupMain').html('');
				$('body').css('overflow', 'auto');
				$('.uploadBackground').fadeOut(400);
				$('.uploadPopup').fadeOut(400);
			});			
				
	
	$('.mainEntryWriteButtons input').live('click', function(){
		
		
		/* ENTRi YAZMA BUTONLARI */
		var textarea = document.getElementById("entryWriteContent"); 
		var len = textarea.value.length; 
		var start = textarea.selectionStart; 
		var end = textarea.selectionEnd; 
		if(end-start == 0){
			if($(this).val() == '(bkz: )'){
				$('.mainEntryWriteAction').html('<input type="text" size="20" id="mainEntryWriteActionSubmitField"><input type="hidden" value="bkz" id="mainEntryWriteActionSubmitHidden" /><input type="submit" class="button" value="ekle" id="mainEntryWriteActionSubmit" />');
			}
			else if($(this).val() == '(gbkz: )'){
				$('.mainEntryWriteAction').html('<input type="text" size="20" id="mainEntryWriteActionSubmitField" value=""><input type="hidden" value="gbkz" id="mainEntryWriteActionSubmitHidden" /><input type="submit" class="button" value="ekle" id="mainEntryWriteActionSubmit" />');
			}
			else if($(this).val() == '(abkz: )'){
				$('.mainEntryWriteAction').html('<input type="text" size="20" id="mainEntryWriteActionSubmitField" value=""><input type="hidden" value="abkz" id="mainEntryWriteActionSubmitHidden" /><input type="submit" class="button" value="ekle" id="mainEntryWriteActionSubmit" />');	
			}
			else if($(this).val() == '(v: )'){
				textarea.value += ' (v: )';
			}
			else if($(this).val() == '--spoiler--'){
				textarea.value += '\n---(gbkz: spoiler)---\n\n \n\n---(gbkz: spoiler)---\n';
			}
			else if($(this).val() == '(link: )'){
				$('.mainEntryWriteAction').html('url:<input type="text" size="20" id="mainEntryWriteActionSubmitField" value="http://">yazi:<input type="text" size="20" id="mainEntryWriteActionSubmitField2" value=""><input type="hidden" value="link" id="mainEntryWriteActionSubmitHidden" /><input type="submit" class="button" value="ekle" id="mainEntryWriteActionSubmit" />');	
			}
		}
		else {
			var sel = textarea.value.substring(start, end); 
			if($(this).val() == '(bkz: )'){
				var replace = '(bkz: ' + sel + ')'; 
				textarea.value =  textarea.value.substring(0,start) + replace + textarea.value.substring(end,len); 		
			}
			else if($(this).val() == '(gbkz: )'){
				var replace = '(gbkz: ' + sel + ')'; 
				textarea.value =  textarea.value.substring(0,start) + replace + textarea.value.substring(end,len); 		
			}
			else if($(this).val() == '(abkz: )'){
				var replace = '(abkz: ' + sel + ')'; 
				textarea.value =  textarea.value.substring(0,start) + replace + textarea.value.substring(end,len); 		
			}
			else if($(this).val() == '(v: )'){
				var replace = '(v: ' + sel + ')'; 
				textarea.value =  textarea.value.substring(0,start) + replace + textarea.value.substring(end,len); 		
			}
			else if($(this).val() == '--spoiler--'){
				var replace = '\n---(gbkz: spoiler)---\n\n' + sel + '\n\n---(gbkz: spoiler)---\n'; 
				textarea.value =  textarea.value.substring(0,start) + replace + textarea.value.substring(end,len); 		
			}
		}
	});
	
	$('#mainEntryWriteActionSubmit').live('click', function(){
		var textarea = document.getElementById("entryWriteContent"); 
		var field = $('#mainEntryWriteActionSubmitField').val();
		var field2 = $('#mainEntryWriteActionSubmitField2').val();
		if($('#mainEntryWriteActionSubmitHidden').val() == 'bkz')
			textarea.value += ' (bkz: ' + (field == '' ? '' : field) + ')';
		else if($('#mainEntryWriteActionSubmitHidden').val() == 'gbkz')
			textarea.value += ' (gbkz: ' + (field == '' ? '' : field) + ')';
		else if($('#mainEntryWriteActionSubmitHidden').val() == 'abkz')
			textarea.value += ' (abkz: ' + (field == '' ? '' : field) + ')';	
		else if($('#mainEntryWriteActionSubmitHidden').val() == 'link')
			textarea.value += ' (link: ' + (field == '' ? '' : field) + ' ' + (field2 == '' ? '' : field2) + ')';	
		
		$('.mainEntryWriteAction').html('');
		

	});

	
	$('ul.leftTopicList li a').live('click', function(e){
		$liid = $(this).attr('id');
		if($liid == 'test'){
			alert('test');
		}
		if(e.which == 1 && $liid != 'reklam'){
			var scrollElem = $('.mainContent').closest('body');
			var url = $(this).attr('href');
			$('ul.leftTopicList li a').removeClass('active');
			$(this).addClass('active');
			$('.mainContent').load(url + '&type=ajax', function(data){
				scrollElem.animate({scrollTop: 0}, 400);
				window.history.pushState(data, "Title", url);
				}
			);
			ie8SafePreventEvent(e);
			return false;
		}
	});	
	
	$('.mainPageSelector').live('change', function(e){
		var url = $(this).val();
		var scrollElem = $('.mainContent').closest('body');
		$('.mainContent').load(url + '&type=ajax', function(data){
			scrollElem.animate({scrollTop: 0}, 400);
			window.history.pushState(data, "Title", url);
			}
		);
	});
	


	$('.leftPages .pageSelector').live('change', function(e){
		var url = $(this).val();
		$('.leftTopics').animate({opacity: '0.5'}, 200);
		$('.left').load(url + '&type=ajax' ,function(){
			var imageH = $(window).height() - 87;
			$('.leftTopics').css("height", imageH);
			$('.leftTopics').animate({opacity: '1.0'}, 100);
		});	
		return false;
	});
	
	$('#leftPrev, #leftNext').live('click', function(){
		var url = $(this).attr('href');
		$('.leftTopics').animate({opacity: '0.5'}, 200);
		$('.left').load(url + '&type=ajax' ,function(){
			var imageH = $(window).height() - 87;
			$('.leftTopics').css("height", imageH);
			$('.leftTopics').animate({opacity: '1.0'}, 100);
		});	
		return false;	
	});

	
	$('.mainButtonsRight li').live('click', function(e){	
		
		if(e.which == 1){
			var url = $(this).find('a').attr('href');
			$section = $(this).attr('section');
			if($section == 'home'){	
				if(url != undefined){
					$('.mainButtonsRight li').removeClass('active');
					$thisLi = $(this);
					$(this).addClass('active');
					$(this).addClass('loading');
					$('.mainTitle h1').html($(this).find('a').html());
					$('.homeBodyLeft').load(url + '&type=ajax', function(data){
							$(e.document).scrollTop();
							window.history.pushState(data, "Title", url);
							$thisLi.removeClass('loading');
						}
					);

				}
				return false;
			}
			else {	
				
				if(url != undefined){
					$('.mainContent').load(url + '&type=ajax', function(data){
							var scrollElem = $('.mainContent').closest('body');
							scrollElem.animate({scrollTop: 0}, 400);
							window.history.pushState(data, "Title", url);
						}
					);
				}
				return false;
			}
		}		
	});
	
	$('#mainNext, #mainPrevious').live('click', function(e){
		var url = $(this).attr('href');
		if(e.which == 1){
				if(url != undefined){
					$('.mainContent').load(url + '&type=ajax', function(data){
							var scrollElem = $('.mainContent').closest('body');
							scrollElem.animate({scrollTop: 0}, 400);
							window.history.pushState(data, "Title", url);
						}
					);
				}
		}
	});
	
	$('#mainEntryWrite').live('submit', function(e){
	   var $isnoob = $(this).attr('isnoob');

		
       $(this).find('#mainEntryWriteSubmit').addClass('buttonLoad');   
       $(this).find('#mainEntryWriteSubmit').attr("disabled", "true");
		var postdata = $('#mainEntryWrite').serialize();
		$.post('http://www.kotusozluk.com/index.php?type=post&section=entryProcess&action=add', postdata, function(data) {
			if($('input[name=facebook]').val() == 1){
			$.post('http://www.kotusozluk.com/social/fb/send.php', postdata, function(data) {
				
				
			});}			
			var $url = 'http://www.kotusozluk.com/t/' + $('#topic_id_input').val() + '/sayfa:son/' + '&type=ajax';
			   if($isnoob == 1){
				   $.get('http://www.kotusozluk.com/noload/noobentry.get.php', function(data){
					   $.toast({
					        message:data,
					        displayTime:4000,
					        inTime:100,
					        outTime:400
					      });
				   });
			   }
			$('.mainContent').load($url, function(){
						$('.leftTopics').animate({opacity: '0.5'}, 200);
						var $url = 'http://www.kotusozluk.com/neleroluyor/';
						$('.left').load($url + '&type=ajax' ,function(){
							var imageH = $(window).height() - 87;
							$('.leftTopics').css("height", imageH);
							$('.leftTopics').animate({opacity: '1.0'}, 100);
						});	
			});
		});
		ie8SafePreventEvent(e);
		return false;
	});
	
	$('#homeStatusWrite').live('submit', function(){
       $(this).find('input[type="submit"]').addClass('buttonLoad');   
       $(this).find('input[type="submit"]').attr("disabled", "true");
		var postdata = $('#homeStatusWrite').serialize();
		var $page = $(this).attr('page');
		var url = $(this).attr('url');
		$.post('http://www.kotusozluk.com/index.php?type=post&section=entryProcess&action=addstatus', postdata, function(data) {
			if($page == 'profile'){
				var $url = $('.profileTopButtons li.active a').attr('href');
				$('.profileCenter').load($url + '&type=ajax');
			}
			else if($page == 'twit'){
				$('.profileCenter').load(url + '&type=ajax');
			}
			else if($page == 'home'){
				$('.homeBodyLeft').load(url + '&type=ajax');
			}
			else if($page == 'popup'){
				$('.inPagePopup .innerContent').html('');
				$('.inPagePopup').css('display', 'none');
				   $.toast({
				        message: 'iletiniz gönderildi',
				        displayTime:2000,
				        inTime:100,
				        outTime:400
				      });
			}
		});
		return false;
	});
	
	$('#mainTopicSearch').live('submit', function(){	
		$submitButton = $(this).find('input[type="submit"]');
		$submitButton.addClass('buttonLoad');  
		var $url = $(this).attr('action') + '&' + $(this).serialize() + '&type=ajax';
		$('.mainContent').load($url, function(data){
			var scrollElem = $('.mainContent').closest('body');
			scrollElem.animate({scrollTop: 0}, 400);
			window.history.pushState(data, "Title", $url);
			$submitButton.removeClass('buttonLoad');  
		});
		
		return false;
	});
	
	$('#popupStatusWrite').live('submit', function(){
       $(this).find('input[type="submit"]').addClass('buttonLoad');   
       $(this).find('input[type="submit"]').attr("disabled", "true");
		var postdata = $('#popupStatusWrite').serialize();
		var $page = $(this).attr('page');
		var $status_id = $(this).find('input[name="status_id"]').val();
		$.post('http://www.kotusozluk.com/index.php?type=post&section=entryProcess&action=addstatus', postdata, function(data) {
			$('.inPagePopup .innerContent').html('');
			$('.inPagePopup').css('display', 'none');
				$parent = $('li#' + $status_id).find('.statuBody');
				$.get('http://www.kotusozluk.com/noload/statusreply.get.php', { status_id : $status_id }, function(data){
						$parent.find('.statuComment').css('display', 'block').html('').animate({opacity: '0.1'}, 200);
						$parent.find('.statuComment').html('').animate({opacity: '0.1'}, 200);
						$parent.find('.statuComment').remove();
						$parent.append('<div class="statuComment" style="display: block;"></div>');
						$parent.find('.statuComment').html(data);
						$parent.find('.statuComment').animate({ opacity: '1.0'}, 200);
				}, 'html');
		});
		return false;
	});
	
	$('#mainEntryEdit').live('submit', function(){
		$(this).find('#mainEntryWriteSubmit').addClass('buttonLoad');
       $(this).find('#mainEntryWriteSubmit').attr("disabled", "true");
		var postdata = $('#mainEntryEdit').serialize();
		var $entry_id = $('input[name="entry_id"]').val();
		var $isstatus = $('input[name="isstatus"]').val();
		$.post('http://www.kotusozluk.com/index.php?type=post&section=entryProcess&action=edit', postdata, function(data) {
			if($isstatus == 1){
				$('li#' + $entry_id ).find('.statuBodyContent').html(data);
				$('.inPagePopup .innerContent').html('');
				$('.inPagePopup').css('display', 'none');
			}
			else {
				$('li#' + $entry_id ).replaceWith(data);
				$('.inPagePopup .innerContent').html('');
				$('.inPagePopup').css('display', 'none');
			}
		});
		return false;
	});
	$('#mainEntryDelete').live('submit', function(){
       $(this).find('#mainEntryWriteSubmit').addClass('buttonLoad');   $(this).find('#mainEntryWriteSubmit').attr("disabled", "true");
		var postdata = $('#mainEntryDelete').serialize();
		var $entry_id = $('input[name="entry_id"]').val();
		var $postUrl = $(this).attr('action');
		$.post($postUrl, postdata, function(data) {
			$('li#' + $entry_id ).remove();
			$('.inPagePopup .innerContent').html('');
			$('.inPagePopup').css('display', 'none');
		});
		return false;
	});	
	
	$('#mainEntryReport').live('submit', function(){
       $(this).find('input[type="submit"]').addClass('buttonLoad');   
	   $(this).find('input[type="submit"]').attr("disabled", "true");
		var postdata = $(this).serialize();
		var $entry_id = $('input[name="entry_id"]').val();
		var $postUrl = $(this).attr('action');
		$.post($postUrl, postdata, function(data) {
			$('li#' + $entry_id ).removeClass('active');
			$('.inPagePopup .innerContent').html('');
			$('.inPagePopup').css('display', 'none');
					   $.toast({
				        message: 'entry ispiyonlandı, hayırlı olsun',
				        displayTime:2000,
				        inTime:100,
				        outTime:400
				   });
		});
		return false;
	});	
	
	
	$('#mainStatusDelete').live('submit', function(){
       $(this).find('#mainEntryWriteSubmit').addClass('buttonLoad');   $(this).find('#mainEntryWriteSubmit').attr("disabled", "true");
		var postdata = $('#mainStatusDelete').serialize();
		var $status_id = $('input[name="status_id"]').val();
		var $postUrl = $(this).attr('action');
		$.post($postUrl, postdata, function(data) {
			$('li#' + $status_id ).remove();
			$('.inPagePopup .innerContent').html('');
			$('.inPagePopup').css('display', 'none');
		});
		return false;		
	});
	
	$('#mainEntryMove').live('submit', function(){
       $(this).find('#mainEntryWriteSubmit').addClass('buttonLoad');   
       $(this).find('#mainEntryWriteSubmit').attr("disabled", "true");
		var postdata = $('#mainEntryMove').serialize();
		var $entry_id = $('input[name="entry_id"]').val();
		$.post('http://www.kotusozluk.com/index.php?type=post&section=entryProcess&action=move', postdata, function(data) {
			if(data.match(/http/)){
				$url = data + '&type=ajax';
				$('.mainContent').load($url);
				$('.inPagePopup .innerContent').html('');
				$('.inPagePopup').css('display', 'none');
			} else {
				$('.inPagePopup .innerContent').html(data);
			}
		});
		return false;		
	});
	
	$('#mainWonder').live('submit', function(){
		$(this).find('#mainEntryWriteSubmit').attr("disabled", "true");
		var postdata = $('#mainWonder').serialize();
		$.post('http://www.kotusozluk.com/index.php?type=post&section=topicProcess&action=addWonder', postdata, function(data) {
				$('.inPagePopup .innerContent').html(data);
		});
		return false;		
	});
	
	$('#mainTopicMove, #mainTopicClose, #mainTopicEdit').live('submit', function(){
		$(this).find('#mainEntryWriteSubmit').addClass('buttonLoad');   $(this).find('#mainEntryWriteSubmit').attr("disabled", "true");
			var postdata = $(this).serialize();
			var $postUrl = $(this).attr('action');
			$.post($postUrl, postdata, function(data) {
				$('.inPagePopup .innerContent').html(data);
			});
			return false;				
	});
	
	/*$('#messageWrite').live('submit', function(){
        $('#messageWriteSubmit').attr("disabled", "true");
		var postdata = $('#messageWrite').serialize();
		$.post('http://www.kotusozluk.com/index.php?type=post&section=messageProcess&action=send', postdata, function() {
			alert("SDSADFASDFASDFASdf");
		});
		return false;
	});	*/
	
	$('#mainEntryWriteDraft').live('click', function(){
		
		saveDraft();
	});
	

	
	var saveDraft = function(){
		$('#mainEntryWriteDraft').attr('disabled', 'true');
		var postdata = $('#mainEntryWrite').serialize();
		$.post('http://www.kotusozluk.com/index.php?type=post&section=entryProcess&action=adddraft', postdata, function(data) {
			$('#mainEntryWriteDraftInfo').css('display', 'block');
			$('#mainEntryWriteDraftInfo').css('text-align', 'center');
			$('#mainEntryWriteDraftInfo').val(data);
		});
		$('#mainEntryWriteDraft').removeAttr('disabled');
	};
	
	$('#sendfacebook').live('click', function(){
		if($('input[name=facebook]').val() == 0){
			$('input[name=facebook]').val('1');
			$(this).removeClass('bsocialnot');
			$(this).addClass('bsocialok');
		$url = 'http://www.kotusozluk.com/social/fb/facebook-kontrol.php';
			$.get($url, function(data){
				var durum = data;
				if (durum == '1')
				{
				alert('bu özelliği kullanmak için, facebook aplikasyonumuzu bir kereye mahsus olmak üzere onaylamanız gerekmektedir.\nonay sayfasına yönlendiriliyorsunuz...');
				var url = "https://www.facebook.com/dialog/permissions.request?app_id=288994467789378&display=page&next=http%3A%2F%2Fapps.facebook.com%2Fkotu-sozluk%2Findex.php&response_type=code&state=569884ee512e960e1f9670521748a5ae&canvas=1&perms=user_status%2Cpublish_stream";
				var left = (screen.width/2)-500;
var top = (screen.height/2)-175;
window.open (url, 'kötü sözlük facebook aplikasyonu', 'toolbar=no, location=no, directories=no, status=no, menubar=no, scrollbars=no, resizable=no, copyhistory=no, width=1000, height=350, top='+top+', left='+left);				
}	
			
			});
	
		}
		else {
			$('input[name=facebook]').val('0');
			$(this).removeClass('bsocialok');
			$(this).addClass('bsocialnot');			
		}
	});
	
	$('#sendtwitter').live('click', function(){
		if($('input[name=twitter]').val() == 0){
			$('input[name=twitter]').val('1');
			$(this).removeClass('bsocialnot');
			$(this).addClass('bsocialok');
		}
		else {
			$('input[name=facebook]').val('0');
			$(this).removeClass('bsocialok');
			$(this).addClass('bsocialnot');			
		}
	});
	
	$('#questionAnonym').live('click', function(){
		if($('input[name=is_annon]').val() == 0){
			$('input[name=is_annon]').val('1');
			$(this).removeClass('bsocialnot');
			$(this).addClass('bsocialok');
		}
		else {
			$('input[name=is_annon]').val('0');
			$(this).removeClass('bsocialok');
			$(this).addClass('bsocialnot');			
		}
	});	
	
	$('.entryList li').live('hover', function(){
		var $entryActionButtons = $(this).find('.entryActionButtons');
		if($entryActionButtons.css('display') == 'none')
			$entryActionButtons.css('display', 'block');
		else
			$entryActionButtons.css('display', 'none');
	});
	
	$('.msgreceiver').live('click', function(){
		if($(this).val() == 'kime?'){
			$(this).val('');
			$(this).addClass('msgactive');
		}
	});
	
	$('.entryActionButtons input').live('click', function(){
		if($(this).attr('id') == 'like'){
			$.post('http://www.kotusozluk.com/index.php?type=post&section=entryProcess&action=rate', 
					{
						user_id : $(this).attr('userid'),
						entry_id : $(this).attr('entryid'),
						vote : 'like'
					}
					, function(){
				
			});
			$(this).removeClass('like');
			$(this).addClass('likevoted');
			$(this).attr('id', 'likevoted');
			$(this).parent().find('.dislike').attr('disabled', 'true');
			$entryId = $(this).attr('entryid');
			$rateSuggest = $('li#' + $entryId + ' .rateSuggest');
			$.get('http://www.kotusozluk.com/noload/entryratesuggest.get.php', function(data){
			
				$rateSuggest.html(data);
				$rateSuggest.css('height', 'auto');
			});
		}
		else if($(this).attr('id') == 'likevoted'){
			$.post('http://www.kotusozluk.com/index.php?type=post&section=entryProcess&action=unrate', 
					{
						user_id : $(this).attr('userid'),
						entry_id : $(this).attr('entryid'),
						vote : 'like'
					}
					, function(){
				
			});
			$(this).removeClass('likevoted');
			$(this).addClass('like');
			$(this).attr('id', 'like');
			$(this).parent().find('.dislike').removeAttr('disabled');
		}
		else if($(this).attr('id') == 'dislike'){
			$.post('http://www.kotusozluk.com/index.php?type=post&section=entryProcess&action=rate', 
					{
						user_id : $(this).attr('userid'),
						entry_id : $(this).attr('entryid'),
						vote : 'dislike'
					}
					, function(){
				
			});
			$(this).removeClass('dislike');
			$(this).addClass('dislikevoted');
			$(this).attr('id', 'dislikevoted');
			$(this).parent().find('.like').attr('disabled', 'true');
		}
		else if($(this).attr('id') == 'dislikevoted'){
			$.post('http://www.kotusozluk.com/index.php?type=post&section=entryProcess&action=unrate', 
					{
						user_id : $(this).attr('userid'),
						entry_id : $(this).attr('entryid'),
						vote : 'dislike'
					}
					, function(){
				
			});
			$(this).removeClass('dislikevoted');
			$(this).addClass('dislike');
			$(this).attr('id', 'dislike');
			$(this).parent().find('.like').removeAttr('disabled');
		}
		else if($(this).attr('id') == 'fav'){
			$.post('http://www.kotusozluk.com/index.php?type=post&section=entryProcess&action=addfavorite',{user_id : $(this).attr('userid'),entry_id : $(this).attr('entryid')});
			$(this).removeClass('fav');
			$(this).addClass('favadded');
			$(this).attr('id', 'favadded');
		}
		else if($(this).attr('id') == 'favadded'){
			$.post('http://www.kotusozluk.com/index.php?type=post&section=entryProcess&action=removefavorite', 
					{
						user_id : $(this).attr('userid'),
						entry_id : $(this).attr('entryid')
					}
					, function(data){
						prompt('dad', data);
				
			});
			$(this).removeClass('favadded');
			$(this).addClass('fav');
			$(this).attr('id', 'fav');
		}
		else if($(this).attr('id') == 'follow'){
			$.post('http://www.kotusozluk.com/index.php?type=post&section=userProcess&action=followUser', 
					{
						following_id : $(this).attr('userid')
					}
					, function(data){
						
				
			});
			$(this).removeClass('follow');
			$(this).addClass('followed');
			$(this).attr('id', 'followed');
		}
		else if($(this).attr('id') == 'followed'){
			$.post('http://www.kotusozluk.com/index.php?type=post&section=userProcess&action=unfollowUser', 
					{
						following_id : $(this).attr('userid')
					}
					, function(){
				
			});
			$(this).removeClass('followed');
			$(this).addClass('follow');
			$(this).attr('id', 'follow');
		}
		else if($(this).attr('id') == 'edit'){
			var $entry_id = $(this).attr('entry_id');
			var $user_id = $(this).attr('user_id');
			$('li#' + $entry_id).addClass('active');
			$('.inPagePopup').css('width', '50%');
			$('.inPagePopup').css('display', 'block');
			$('.popupTitle').html('entry düzenleme');
			var $url = 'http://www.kotusozluk.com/index.php?type=mini&section=entryedit&entry_id=' + $entry_id + '&user_id=' + $user_id;
			$('.inPagePopup .innerContent').load($url);
		}
		else if($(this).attr('id') == 'move'){
			
			var $entry_id = $(this).attr('entry_id');
			var $user_id = $(this).attr('user_id');
			$('li#' + $entry_id).addClass('active');
			$('.inPagePopup').css('width', '30%');
			$('.inPagePopup').css('display', 'block');
			$('.popupTitle').html('entry taşı');
			var $url = 'http://www.kotusozluk.com/index.php?type=mini&section=entrymove&entry_id=' + $entry_id + '&user_id=' + $user_id;
			$('.inPagePopup .innerContent').load($url);
		}
		else if($(this).attr('id') == 'delete'){
			var $entry_id = $(this).attr('entry_id');
			var $user_id = $(this).attr('user_id');
			$('li#' + $entry_id).addClass('active');
			$('.inPagePopup').css('width', '30%');
			$('.inPagePopup').css('display', 'block');
			$('.popupTitle').html('entry sil');
			var $url = 'http://www.kotusozluk.com/index.php?type=mini&section=entrydelete&entry_id=' + $entry_id + '&user_id=' + $user_id;
			$('.inPagePopup .innerContent').load($url);
		}
		else if($(this).attr('id') == 'report'){
			
			var $entry_id = $(this).attr('entry_id');
			var $user_id = $(this).attr('user_id');
			$('li#' + $entry_id).addClass('active');
			$('.inPagePopup').css('width', '30%');
			$('.inPagePopup').css('display', 'block');
			$('.popupTitle').html('entry taşı');
			var $url = 'http://www.kotusozluk.com/index.php?type=mini&section=entryreport&entry_id=' + $entry_id + '&user_id=' + $user_id;
			$('.inPagePopup .innerContent').load($url);
		}
		else if($(this).attr('id') == 'msg'){
			var $to_user = $(this).attr('user_name');
			var $entry_id = $(this).attr('entry_id');
			$('.inPagePopup').css('width', '600px');
			$('.inPagePopup').css('display', 'block');
			$('.popupTitle').html('mesaj gönder');
			$url = 'http://www.kotusozluk.com/index.php?type=mini&section=sendmessage&to_user=' + $to_user + '&entry_id=' + $entry_id;
			$('.inPagePopup .innerContent').load($url);			
		}
		else if($(this).attr('id') == 'mention'){
			var $to_user = $(this).attr('user_name');
			var $entry_id = $(this).attr('entry_id');
			$('.inPagePopup').css('width', '600px');
			$('.inPagePopup').css('display', 'block');
			$('.popupTitle').html('ileti yaz');
			$url = 'http://www.kotusozluk.com/index.php?type=mini&section=statuswrite&mention=' + $to_user + '&entry_id=' + $entry_id;
			$('.inPagePopup .innerContent').load($url);			
		}
		else if($(this).attr('id') == 'gorseledit'){
			var $gorsel_id = $(this).attr('gorsel_id');
			$('.inPagePopup').css('width', '600px');
			$('.inPagePopup').css('display', 'block');
			$('.popupTitle').html('görsel düzenleme');
			$url = 'http://www.kotusozluk.com/index.php?type=mini&section=gorseledit&gorsel_id=' + $gorsel_id;
			$('.inPagePopup .innerContent').load($url);			
		}
		else if($(this).attr('id') == 'gorselsil'){
			var $gorsel_id = $(this).attr('gorsel_id');
			$('.inPagePopup').css('width', '200px');
			$('.inPagePopup').css('display', 'block');
			$('.popupTitle').html('görsel silme');
			$url = 'http://www.kotusozluk.com/index.php?type=mini&section=gorselsil&gorsel_id=' + $gorsel_id;
			$('.inPagePopup .innerContent').load($url);			
		}
				else if($(this).attr('id') == 'videoedit'){
			var $gorsel_id = $(this).attr('gorsel_id');
			$('.inPagePopup').css('width', '600px');
			$('.inPagePopup').css('display', 'block');
			$('.popupTitle').html('görsel düzenleme');
			$url = 'http://www.kotusozluk.com/index.php?type=mini&section=videoedit&gorsel_id=' + $gorsel_id;
			$('.inPagePopup .innerContent').load($url);			
		}
		else if($(this).attr('id') == 'videosil'){
			var $gorsel_id = $(this).attr('gorsel_id');
			$('.inPagePopup').css('width', '200px');
			$('.inPagePopup').css('display', 'block');
			$('.popupTitle').html('görsel silme');
			$url = 'http://www.kotusozluk.com/index.php?type=mini&section=videosil&gorsel_id=' + $gorsel_id;
			$('.inPagePopup .innerContent').load($url);			
		}
		else if($(this).attr('id') == 'share'){
				if($(this).hasClass('active')){
					$(this).parent().find('div').slideUp('fast');
					$(this).removeClass('active');
				}
				else {
					$('.shareArea div').slideUp('fast');
					$('.shareArea a').removeClass('active');
					$(this).addClass('active');	
					$(this).parent().find('div').slideDown("fast");
				}
		}
		
	});
	
	$('.topicActionButtons input').live('click', function(){
		if($(this).attr('id') == 'merge'){
			var $topic_id = $(this).attr('topic_id');
			$('.inPagePopup').css('width', '30%');
			$('.inPagePopup').css('display', 'block');
			$('.popupTitle').html('başlık birleştir/taşı');
			var $url = 'http://www.kotusozluk.com/index.php?type=mini&section=topicmerge&topic_id=' + $topic_id;
			$('.inPagePopup .innerContent').load($url);		
		}
		else if($(this).attr('id') == 'close'){
			var $topic_id = $(this).attr('topic_id');
			$('.inPagePopup').css('width', '30%');
			$('.inPagePopup').css('display', 'block');
			$('.popupTitle').html('başlık yasakla');
			var $url = 'http://www.kotusozluk.com/index.php?type=mini&section=topicclose&topic_id=' + $topic_id;
			$('.inPagePopup .innerContent').load($url);		
		}  		
		else if($(this).attr('id') == 'edit'){
			var $topic_id = $(this).attr('topic_id');
			$('.inPagePopup').css('width', '30%');
			$('.inPagePopup').css('display', 'block');
			$('.popupTitle').html('başlık düzenle');
			var $url = 'http://www.kotusozluk.com/index.php?type=mini&section=topicedit&topic_id=' + $topic_id;
			$('.inPagePopup .innerContent').load($url);		
		} 
		else if($(this).attr('id') == 'removeTrend'){
			var $topic_id = $(this).attr('topic_id');
			$postUrl = 'http://www.kotusozluk.com/index.php?type=post&section=topicProcess&action=removeTrend';
			$.post($postUrl, {topic_id : $topic_id}, function(data){
					$.toast({
				        message: data,
				        displayTime:2000,
				        inTime:100,
				        outTime:400
				   });
			});
		} 
		else if($(this).attr('id') == 'backTrend'){
			var $topic_id = $(this).attr('topic_id');
			$postUrl = 'http://www.kotusozluk.com/index.php?type=post&section=topicProcess&action=backTrend';
			$.post($postUrl, {topic_id : $topic_id}, function(data){
					$.toast({
				        message: data,
				        displayTime:2000,
				        inTime:100,
				        outTime:400
				   });
			});				
		} 
		else if($(this).attr('id') == 'addTrendNews'){
			var $topic_id = $(this).attr('topic_id');
			$postUrl = 'http://www.kotusozluk.com/index.php?type=post&section=topicProcess&action=addTrendNews';
			$.post($postUrl, {topic_id : $topic_id}, function(data){
					$.toast({
				        message: data,
				        displayTime:2000,
				        inTime:100,
				        outTime:400
				   });
			});				
		}
		else if($(this).attr('id') == 'delTrendNews'){
			var $topic_id = $(this).attr('topic_id');
			$postUrl = 'http://www.kotusozluk.com/index.php?type=post&section=topicProcess&action=delTrendNews';
			$.post($postUrl, {topic_id : $topic_id}, function(data){
					$.toast({
				        message: data,
				        displayTime:2000,
				        inTime:100,
				        outTime:400
				   });
			});				
		} 		
	});
	
	$('.wonderButton').live('click', function(){
		var $topic_id = $(this).attr('topic_id');
		var $topic_name = $(this).attr('topic_name');
		$('.inPagePopup').css('width', '30%');
		$('.inPagePopup').css('display', 'block');
		$('.popupTitle').html('ukte - ' + $topic_name);
		var $url = 'http://www.kotusozluk.com/index.php?type=mini&section=wonder&topic_id=' + $topic_id;
		$('.inPagePopup .innerContent').load($url);		
	});
	$('.wonderDelete').live('click', function(){
			var $topic_id = $(this).attr('topic_id');
			$postUrl = 'http://www.kotusozluk.com/index.php?type=post&section=topicProcess&action=deleteWonder';
			$.post($postUrl, {topic_id : $topic_id}, function(data){
					$.toast({
				        message: data,
				        displayTime:2000,
				        inTime:100,
				        outTime:400
				   });
			});		
	});
	
	$('.profileContinue').live('click', function(){
		var $lastid = $(this).attr('lastid');
		var $filter = $(this).attr('filter');
		var $user = $(this).attr('user');
		$(this).html('<center>...</center>');
		$(this).removeClass('profileContinue');
		$.get('http://www.kotusozluk.com/index.php', { type: 'ajax', section: 'profile', user: $user, filter : $filter, lastid : $lastid, isappend : '1'}, function(data){			
			$('.profileContentList').append(data);			
		});
	});
	
	$('.twitContinue').live('click', function(){
		var scrollElem = $(this).closest('body');
		var $lastid = $(this).attr('lastid');
		var $action = $(this).attr('action');
		var $user = $(this).attr('user');
		$(this).html('<center>...</center>');
		$(this).removeClass('twitContinue');
		var targetOffsetTop = $(this).offset().top;
		$.get('http://www.kotusozluk.com/index.php', { type: 'ajax', section: 'twit', user: $user, action : $action, lastid : $lastid, isappend : '1'}, function(data){			
			$('.profileContentList').append(data);	
			scrollElem.animate({scrollTop: targetOffsetTop}, 400);
		});
	});
	

	
	$('.homeContinue').live('click', function(){
		var scrollElem = $(this).closest('body');
 		var $lastid = $(this).attr('lastid');
		var $action = $(this).attr('action');
		$(this).html('<center>...</center>');
		$(this).removeClass('homeContinue');
		var targetOffsetTop = $(this).offset().top;
		$.get('http://www.kotusozluk.com/index.php', { type: 'ajax', section: 'home', action : $action, lastid : $lastid, isappend : '1'}, function(data){			
			$('.homeContentList').append(data);
			scrollElem.animate({scrollTop: targetOffsetTop}, 400);
		});
	});
	$('.messageInboxContinue').live('click', function(){
		var scrollElem = $(this).closest('body');
 		var $lastusermessage = $(this).attr('lastusermessage');
		var $action = $(this).attr('action');
		$(this).html('<center>...</center>');
		$(this).removeClass('messageInboxContinue');
		var targetOffsetTop = $(this).offset().top;
		$.get('http://www.kotusozluk.com/index.php', { type: 'ajax', section: 'messages', action : 'inbox', lastusermessage : $lastusermessage, isappend : '1'}, function(data){			
			$('.messagesContentList').append(data);
			scrollElem.animate({scrollTop: targetOffsetTop}, 400);
		});
	});
	
	$('.innerTwitCount').live('click', function(){
		var $lastid = $(this).attr('lastid');
		var $action = $(this).attr('action');
		var $user = $(this).attr('user');
		var $lastid = $('.profileContentList li:first').attr('id');
		$thisDiv = $(this);
		$(this).html('<center><img src="http://www.kotusozluk.com/theme/kotusozluk/images/yukleniyor.gif" /></center>');
		$(this).removeClass('profileContinue');
		$.get('http://www.kotusozluk.com/index.php', { type: 'ajax', section: 'twit', user: $user, action : 'timelinenew', lastid : $lastid, isappend : '1'}, function(data){			
			$('.profileContentList').prepend(data);		
			$thisDiv.html('');			
		});
		
	});
	
	$('ul.personalPopupNavigation li').live('click', function(){
		$('ul.personalPopupNavigation li').removeClass('active');
		$(this).addClass('active');
		$url = 'http://www.kotusozluk.com/noload/personalInfo.php?isappend=1&action=' + $(this).attr('id');
		$('.personalPopupLeft').load($url);
	});
	
	$('.profileTopButtons li').live('click', function(){
		var $url = $(this).find('a').attr('href');	
		$('.profileCenter').load($url + '&type=ajax', function(data){
			window.history.pushState(data, "Title", $url);
		});
		
		return false;
	});
	
	$('.profileRightLinks a, .profileChangePage a').live('click', function(){
		var $url = $(this).attr('href');
		$('.profileCenter').load($url + '&type=ajax', function(data){
			window.history.pushState(data, "Title", $url);
			
		});
		$('body').animate({scrollTop: 0}, 100);
		
		return false;
		
	});
	
	
	$('#profileFollowButton').live('click', function(){
		var $following_id = $(this).attr('user_id');
		var $durum = $(this).attr('durum');
		if ($durum == '2') {
			$.post('http://www.kotusozluk.com/index.php?type=post&section=userProcess&action=unfollowUser', { following_id : $following_id }, function() {});
			$(this).html('takip et');
			$(this).removeClass('active');
			$(this).attr('durum','1');
		}
		if ($durum == '1') {
			$.post('http://www.kotusozluk.com/index.php?type=post&section=userProcess&action=followUser', { following_id : $following_id }, function() {});
			$(this).html('takip etme');
			$(this).addClass('active');
			$(this).attr('durum','2');
		}
	
	});
	

	
	$('#profileMessageButton').live('click', function(){
		var $to_user = $(this).attr('user_name');
		$('.inPagePopup').css('width', '600px');
		$('.inPagePopup').css('display', 'block');
		$('.popupTitle').html('mesaj gönder');
		$url = 'http://www.kotusozluk.com/index.php?type=mini&section=sendmessage&to_user=' + $to_user;
		$('.inPagePopup .innerContent').load($url);
	});
	
	$('#profileMentionButton').live('click', function(){
		var $to_user = $(this).attr('user_name');
		$('.inPagePopup').css('width', '600px');
		$('.inPagePopup').css('display', 'block');
		$('.popupTitle').html('ileti yaz');
		$url = 'http://www.kotusozluk.com/index.php?type=mini&section=statuswrite&mention=' + $to_user;
		$('.inPagePopup .innerContent').load($url);
	});
	/* REGISTER - KONTROL */
	
	$('#regNick').change(function(){
		var $nick = $(this).val();
		if($nick != ''){
			$url = 'http://www.kotusozluk.com/index.php?type=mini&section=register&action=nick&nick=' + $nick;
			$('#registerNickDiv').load($url);
		}
		else {
			$('#registerNickDiv').html('');
		}
		$('#regUrl').val('http://kotusozluk.com/' + $nick.replace(/ /g, '_' ).toLowerCase());
	});
	
	$('#regPassValid').change(function(){
		if($(this).val() == $('#regPass').val()){
			$url = 'http://www.kotusozluk.com/index.php?type=mini&section=register&action=password&result=1';
			$('#registerPassDiv').load($url);
			if($('#registerPassDiv').find('.registerOkIcon')){
				$('#regNickValidCheck').val('1');
			}
		}
		else {
			$url = 'http://www.kotusozluk.com/index.php?type=mini&section=register&action=password&result=2';
			$('#registerPassDiv').load($url);
			$('#registerNickValidCheck').val('0');
		}
	});
	$('#regMail').change(function(){
		var $email = $(this).val();
		if($email != ''){
			$url = 'http://www.kotusozluk.com/index.php?type=mini&section=register&action=email&email=' + $email; 
			$('#registerMailDiv').load($url);
		
		}
		else {
			$('#registerMailDiv').html('');
		}
	});
	$('#regMailValid').change(function(){
		if($(this).val() == $('#regMail').val()){
			$url = 'http://www.kotusozluk.com/index.php?type=mini&section=register&action=emailvalid&result=1'; 
			$('#registerMailValidDiv').load($url);
		}
		else {
			$url = 'http://www.kotusozluk.com/index.php?type=mini&section=register&action=emailvalid&result=2'; 
			$('#registerMailValidDiv').load($url);
		}
	});	
	
	$('#regCaptcha').change(function(){
		$captchaValue = $(this).val();
		$captchaQuestion = $('#captchaQuestion').val();
		if($captchaValue != ''){
			$url = 'http://www.kotusozluk.com/index.php?type=mini&section=register&action=captcha&a=' + $captchaValue + '&q=' + $captchaQuestion;
			$('#registerCaptchaDiv').load($url);
		}
	});
	
	$('#userRegister').live('submit', function(){
		var $emailValid = false;
		var $passwordValid = false;
		var $nickValid = false;
		var $agreementValid = false;
		var $captchaValid = false;
		
		
		var $nick = $('#regNick').val();
		$nick = $nick.replace(/ /g, '_' ).toLowerCase();	
		if($nick != ''){
			$url = 'http://www.kotusozluk.com/index.php?type=mini&section=register&action=nick&nick=' + $nick;
			$('#registerNickDiv').load($url);
			if($('#registerNickDiv').children().hasClass('registerOk')){
				$nickValid = true;
			}
			else if($('#registerNickDiv').children().hasClass('registerWarning')){
				$nickValid = false;
			}
		}
		else {
			$('#registerNickDiv').html('');
			$nickValid = false;
		}
		$('#regUrl').val('http://kotusozluk.com/' + $nick.replace(/ /g, '_' ).toLowerCase());	
		
		
		if($('#regPassValid').val() == $('#regPass').val() && $('#regPass').val() != ''){
			$url = 'http://www.kotusozluk.com/index.php?type=mini&section=register&action=password&result=1';
			$('#registerPassDiv').load($url);
			if($('#registerPassDiv').children().hasClass('registerOk')){
				$passwordValid = true;
			}
			else if($('#registerPassDiv').children().hasClass('registerWarning')){
				$passwordValid = false;
			}
		}
		else {
			$url = 'http://www.kotusozluk.com/index.php?type=mini&section=register&action=password&result=2';
			$('#registerPassDiv').load($url);
			$('#registerNickValidCheck').val('0');
			$passwordValid = false;
		}
		

		
		var $email = $('#regMail').val();
		if($email != ''){
			$url = 'http://www.kotusozluk.com/index.php?type=mini&section=register&action=email&email=' + $email; 
			$('#registerMailDiv').load($url);
			if($('#registerMailDiv').children().hasClass('registerOk')){
				$emailValid = true;
			}
			else if($('#registerMailDiv').children().hasClass('registerWarning')){
				$emailValid = false;
			}			
		}
		else {
			$('#registerMailDiv').html('');
			$emailValid = false;
		}
		
		
			
		if($('#regMailValid').val() == $('#regMail').val() && $('#regMail').val() != ''){
			$url = 'http://www.kotusozluk.com/index.php?type=mini&section=register&action=emailvalid&result=1'; 
			$('#registerMailValidDiv').load($url);
			$emailValid = true;
		}
		else {
			$url = 'http://www.kotusozluk.com/index.php?type=mini&section=register&action=emailvalid&result=2'; 
			$('#registerMailValidDiv').load($url);
			$emailValid = false;
		}
		
		$captchaValue = $('#regCaptcha').val();
		$captchaQuestion = $('#captchaQuestion').val();
		if($captchaValue != ''){
			$url = 'http://www.kotusozluk.com/index.php?type=mini&section=register&action=captcha&a=' + $captchaValue + '&q=' + $captchaQuestion;
			$('#registerCaptchaValid').load($url);
			if($('#registerCaptchaValid').children().hasClass('registerOk')){
				$captchaValid = true;
			}
			else if($('#registerCaptchaValid').children().hasClass('registerWarning')){
				$captchaValid = false;
			}		
		}
		else {
			$captchaValid = false;
		}
		
		
		if(!$nickValid || !$emailValid || !$passwordValid){
			alert('Hatalı bölümler var, tekrar gözden geçirin');
			return false;
		}

	});
	
	/* SETTINGS */
	
	$('#settingsEducation').live('change', function(){
		if($(this).val() == 'lisans' || $(this).val() == 'ön-lisans' || $(this).val() == 'lisansüstü'){
			$('#settingsUniversity').css('display', 'block');
		}
		else {
			$('#settingsUniversity').val('');
			$('#settingsUniversity').css('display', 'none');
		}
		if($(this).val() == 'lisans' || $(this).val() == 'lisansüstü'){
			$('#settingsDepartment2').css('display', 'block');
			$('#settingsDepartment1').css('display', 'none');
		}
		else if($(this).val() == 'ön-lisans'){
		$('#settingsDepartment2').css('display', 'none');
			$('#settingsDepartment1').css('display', 'block');
			}
		else {
		$('#settingsDepartment2').css('display', 'none');
			$('#settingsDepartment1').css('display', 'none');
			}
	});
	
	$('#settingsCountry').live('change', function(){
		if($(this).val() == 'türkiye'){
			$('#settingsCity').css('display', 'block');
		}
		else {
			$('#settingsCity').val('');
			$('#settingsCity').css('display', 'none');
		}
	});
	
	$('#profileInfo').live('submit', function(){
		var postdata = $('#profileInfo').serialize();
		$.post('http://www.kotusozluk.com/index.php?type=post&section=settings&action=profile', postdata, function(data) {
			
			$('#settingsResult').css('display', 'block');
			$('#settingsResult').css('width', '130px');
			$('#settingsResult').html(data);
		});
		return false;
	});
	
	$('#settingsSocialSelect, #settingsSocialOther').live('change', function(){
		if($(this).val() == 'other'){
			$('#settingsSocialList').append('<li><div class="settingsFormLeft">isim: <input type="text" id="settingsSocialOther" size="10"></div><div class="settingsFormCenter">adres: <input name="facebook" id="settingsSocialInput"/></div><div class="settingsFormRight"></div><div class="clear"></div></li>');
		}
		$(this).parent().parent().find('#settingsSocialInput').attr('name', $(this).val());

	});
	
	$('#settingsSocialNew').live('click', function(){
		$('#settingsSocialList li:first').clone().appendTo('#settingsSocialList');
	});
	
	$('#avatarCrop').live('submit', function(){
		var postdata = $('#avatarCrop').serialize();
		$.post('http://www.kotusozluk.com/index.php?type=post&section=avatar&action=thumbcrop', postdata, function(){
			$('#avatarCrop').css('display', 'none');
			$('#smallAvatarButton').css('display', 'block');
			$('#settingsThumb').imgAreaSelect({remove:true});
		});
		
		return false;
	});
	

	$('#avatarUpload').live('submit', function(){

		$(this).parent().find('#avatarUploadResult').remove();
		$(this).parent().append('<iframe id="avatarUploadResult" name="avatarUploadResult" style="display: none;">');
		$(this).attr('target', 'avatarUploadResult');
		$('#settingsThumb').imgAreaSelect({remove:true});
		$('#settingsThumbSmall').css({width: '60px', height: '60px', margin: '0'});
		$('#avatarUploadResult').load(function(){
			$('#settingsThumb').attr('src', $(this).contents().find('big').html());
			$('#settingsThumbSmall').attr('src', $(this).contents().find('thumb').html());
		});
	});
	
	$('#smallAvatarButton').live('click', function (){
		$('#settingsThumbSmall').attr('src', $('#settingsThumb').attr('src'));
		
		var scaleX = 60 / (173 || 1);
		var scaleY = 60 / (173 || 1);
	  
		var $imageWidth = $('#settingsThumb').css('width').replace('px', '');
		var $imageHeight = $('#settingsThumb').css('height').replace('px', '');
		
		if($imageHeight < 120){
			$minHeight = $imageHeight;
			$minWidth = $imageHeight;
			$x2 = $imageHeight;
			$y2 = $imageHeight;
		} else {
			$minHeight = 120;
			$minWidth = 120;
			$x2 = 120;
			$y2 = 120;
		}
		
		$('#settingsThumbSmall').css({
			width: Math.round(scaleX * $imageWidth) + 'px',
			height: Math.round(scaleY * $imageHeight) + 'px',
			marginLeft: '-' + Math.round(scaleX * 0) + 'px',
			marginTop: '-' + Math.round(scaleY * 0) + 'px'
		});
		
		$('#avatarCrop').css('display', 'block');
		$('#smallAvatarButton').css('display', 'none');
	
		
		$('#settingsThumb').imgAreaSelect({
			handles: true,
			aspectRatio: '1:1',
			minHeight: $minHeight,
			minWidth: $minWidth,
			maxHeight: 173,
			x1: 0,
			y1: 0,
			x2: $x2,
			y2: $y2,
			onSelectChange: cropPreview,
	        onSelectEnd: function (img, selection) {
	            $('input[name="x1"]').val(selection.x1);
	            $('input[name="y1"]').val(selection.y1);
	            $('input[name="width"]').val(selection.width);
	            $('input[name="height"]').val(selection.height);            
	        }
		});
	});
	
	var cropPreview = (function(img, selection){
		var scaleX = 60 / (selection.width || 1);
		var scaleY = 60 / (selection.height || 1);
	  
		$('#settingsThumbSmall').css({
			width: Math.round(scaleX * $('#settingsThumb').css('width').replace('px', '')) + 'px',
			height: Math.round(scaleY * $('#settingsThumb').css('height').replace('px', '')) + 'px',
			marginLeft: '-' + Math.round(scaleX * selection.x1) + 'px',
			marginTop: '-' + Math.round(scaleY * selection.y1) + 'px'
		});
	});
	
	$('.banListButtons input').live('click', function(){
		if($(this).attr('current_value') == '1'){
			$sendvalue = 0; $removeClass = 'bsocialnot'; $addClass = 'bsocialok';
		}
		else {
			$sendvalue = 1; $removeClass = 'bsocialok'; $addClass = 'bsocialnot';
		}
		
		$user_id = $(this).attr('user_id');
		$ban_user_id = $(this).attr('ban_user_id');
		$filter = $(this).attr('field');
		
		$url = 'http://www.kotusozluk.com/index.php?type=post&section=userProcess&action=updateBan&filter=' + $filter;
		$postdata = '&user_id=' + $user_id + '&ban_user_id=' + $ban_user_id + '&' + $filter + '=' + $sendvalue;
		$.post($url, $postdata);
		$(this).removeClass($removeClass);
		$(this).addClass($addClass);
		
	});
	
			$('.entryActionButtons2 input').live('click', function(){
		if($(this).attr('id') == 'begendim'){
			var $gorsel_id = $(this).attr('gorsel_id');
			$url = 'http://www.kotusozluk.com/gorseloy.php?oy=1&id=' + $gorsel_id;
			$('.inPagePopup .innerContent').load($url);			
			alert('oyunuz gönderildi!');
		}
		else if($(this).attr('id') == 'begenmedim'){
			var $gorsel_id = $(this).attr('gorsel_id');
			$url = 'http://www.kotusozluk.com/gorseloy.php?oy=2&id=' + $gorsel_id;
			$('.inPagePopup .innerContent').load($url);	
			alert('oyunuz gönderildi!');
		}
			if($(this).attr('id') == 'vbegendim'){
			var $gorsel_id = $(this).attr('gorsel_id');
			$url = 'http://www.kotusozluk.com/videooy.php?oy=1&id=' + $gorsel_id;
			$('.inPagePopup .innerContent').load($url);			
			alert('oyunuz gönderildi!');
		}
		else if($(this).attr('id') == 'vbegenmedim'){
			var $gorsel_id = $(this).attr('gorsel_id');
			$url = 'http://www.kotusozluk.com/videooy.php?oy=2&id=' + $gorsel_id;
			$('.inPagePopup .innerContent').load($url);	
			alert('oyunuz gönderildi!');
		}
	});
	$('.friendListButtons input').live('click', function(){
		//alert('hello');
		if($(this).attr('current_value') == '1'){
			$sendvalue = 0; $removeClass = 'bsocialnot'; $addClass = 'bsocialok';
		}
		else {
			$sendvalue = 1; $removeClass = 'bsocialok'; $addClass = 'bsocialnot';
		}
		
		$user_id = $(this).attr('user_id');
		$following_id = $(this).attr('following_id');
		
		$url = 'http://www.kotusozluk.com/index.php?type=post&section=userProcess&action=approveFollower';
		$postdata = '&user_id=' + $user_id + '&following_id=' + $following_id + '&is_approved=' + $sendvalue;
		
		//alert($url);
		//alert($postdata);
		$.post($url, $postdata);
		$(this).removeClass($removeClass);
		$(this).addClass($addClass);
		$(this).attr('value', 'onaylı');
		
	});
	
	$('#messageWrite').live('submit', function(){
		postdata = $(this).serialize();
		$url = $(this).attr('href');
		$textarea = $(this).find('textarea');
		$.post('http://www.kotusozluk.com/index.php?type=post&section=messageProcess&action=send', postdata, function(data){
			if($url != undefined){
				$url = $url + '&type=ajax';
				$('.profileContentList').load($url);
				$textarea.val('');
			} else {
				if(data.match(/http/)){
					window.location = data;
				} else {
					$('#messageError').html(data);
				}
			}
		});
		return false;
	});
	
	$('.messagesAppend').live('click', function(){
		
		$user_id = $(this).attr('user_id');
		$last_id = $(this).attr('last_id');
		$.get('http://www.kotusozluk.com/index.php', 
				{type: 'ajax', 
				 userid: $user_id, 
				 last_id : $last_id, 
				 section: 'messagesUser'
				}, 
			function(data){
					$('.profileContentList').prepend(data);
			}
		);
		$(this).html('...');
		$(this).removeClass('messagesAppend');
		return false;
	});
	
	$('.messagesContentList .statuBodyInfo a').live('click', function(){
		$action = $(this).attr('action');
		$from_user_id = $(this).attr('from_user_id');
		$to_user_id = $(this).attr('to_user_id');
		$message_id = $(this).attr('message_id');
		if($action == 'alldelete' || $action == 'allarchive' || $action == 'markread'){
			$te = $(this);
		}
		$.post('http://www.kotusozluk.com/index.php?type=post&section=messageProcess&action=' + $action, 
				{
					from_user_id : $from_user_id,
					to_user_id : $to_user_id,
					message_id : $message_id
				},
				function(){
					if($action == 'alldelete' || $action == 'allarchive'){
						$('li#' + $from_user_id).remove();
					}
					else if($action == 'markread'){
						$te.html('okunmadı olarak işaretle');
						$te.attr('action', 'marknotread');
					}
					else if($action == 'marknotread'){
						$te.html('okundu olarak işaretle');
						$te.attr('action', 'markread');						
					}
					else {
						$('li#' + $message_id).remove();
					}
				});
	});
	
	$('.leftMenu a, .leftBottomPages a').live('click', function(){
		if($(this).attr('id') != 'hrefMain'){
			
			$(this).find('div').addClass('leftMenuActive');
			$('.leftTopics').animate({opacity: '0.5'}, 200);
			var $url = $(this).attr('href');
			$('.left').load($url + '&type=ajax' ,function(){
				var imageH = $(window).height() - 87;
				$('.leftTopics').css("height", imageH);
				$('.leftTopics').animate({opacity: '1.0'}, 100);
			});	
			return false;
		}
		else {
			var scrollElem = $('.mainContent').closest('body');
			$('.mainContent').animate({opacity: '0.5'}, 200);
			$url = '';
			$.get('http://www.kotusozluk.com/noload/guzelinden.get.php', function(data){
				$('ul.leftTopicList li a').removeClass('active');
				$('.mainContent').load(data + '&type=ajax', function(data2){
					$('.mainContent').animate({opacity: '1.0'}, 100);
					
					scrollElem.animate({scrollTop: 0}, 400);
					window.history.pushState(data2, "Title", data);
				});
				ie8SafePreventEvent(e);
			});

			return false;		
		}
	});
	

	
	$('.todayButton').live('click', function(){
		var $url = $(this).find('a').attr('href');
		$('.left').load($url + '&type=ajax' ,function(){
			var imageH = $(window).height() - 87;
			$('.leftTopics').css("height", imageH);
		});	
		return false;		
	});
	
	
	
	$('.inPagePopup .close').live('click', function(){
		$('.inPagePopup .innerContent').html('');
		$('.inPagePopup').css('display', 'none');
		$('.mainBody ol li').removeClass('active');
	});
	
	/* TWIT */
	
	$('.statuButton').live('click', function(){
		if($(this).attr('id') == 'favorite'){
		
			$.post('http://www.kotusozluk.com/index.php?type=post&section=entryProcess&action=addfavorite', 
					{
						user_id : $(this).attr('userid'),
						status_id : $(this).attr('statusid')
					}
					, function(data){
			});
			$(this).html('favorilendi');
		}
		else if($(this).attr('id') == 'delete'){
			var $status_id = $(this).attr('statusid');
			var $user_id = $(this).attr('userid');
			$('.inPagePopup').css('width', '400px');
			$('.inPagePopup').css('display', 'block');
			$('.popupTitle').html('ileti sil');
			var $url = 'http://www.kotusozluk.com/index.php?type=mini&section=entrydelete&status_id=' + $status_id + '&user_id=' + $user_id;
			$('.inPagePopup .innerContent').load($url);			
		}
		else if($(this).attr('id') == 'share'){
			if($(this).hasClass('active')){
				$(this).parent().find('div').slideUp('fast');
				$(this).removeClass('active');
			}
			else {
				$('.shareArea div').slideUp('fast');
				$('.shareArea a').removeClass('active');
				$(this).addClass('active');	
				$(this).parent().find('div').slideDown("fast");
			}
			
		}
		else if($(this).attr('id') == 'retweet'){
			var $rt_user_id = $(this).attr('rtuserid');
			var $rt_status_id = $(this).attr('rtstatusid');
			var $postdata = '&rt_user_id=' + $rt_user_id + '&rt_status_id=' + $rt_status_id;
			$.post('http://www.kotusozluk.com/index.php?type=post&section=entryProcess&action=retweet', $postdata, function(data) {
				
			});	
			$(this).html('paylaşıldı');
			$(this).attr('id', 'i');
		}
		else if($(this).attr('id') == 'reply'){
			var $status_id = $(this).attr('statusid');
			var $user_id = $(this).attr('userid');
			$('.inPagePopup').css('width', '600px');
			$('.inPagePopup').css('display', 'block');
			$('.popupTitle').html('cevapla : #' + $status_id);
			var $url = 'http://www.kotusozluk.com/index.php?type=mini&section=statusreply&status_id=' + $status_id + '&reply_to=' + $user_id;
			$('.inPagePopup .innerContent').load($url);					
		}
		else if($(this).attr('id') == 'rate'){
			$.post('http://www.kotusozluk.com/index.php?type=post&section=entryProcess&action=rate', 
					{
						user_id : $(this).attr('userid'),
						entry_id : $(this).attr('entryid'),
						vote : 'like'
					}
					, function(){
				
			});
			$(this).html('beğendin');
		}
		else if($(this).attr('id') == 'edit'){
			var $entry_id = $(this).attr('entryid');
			var $user_id = $(this).attr('userid');
			$('li#' + $entry_id).addClass('active');
			$('.inPagePopup').css('width', '50%');
			$('.inPagePopup').css('display', 'block');
			$('.popupTitle').html('entry düzenleme');
			var $url = 'http://www.kotusozluk.com/index.php?type=mini&section=entryedit&entry_id=' + $entry_id + '&user_id=' + $user_id;
			$('.inPagePopup .innerContent').load($url);
		}
		else if($(this).attr('id') == 'deleteentry'){
			var $entry_id = $(this).attr('entryid');
			var $user_id = $(this).attr('userid');
			$('li#' + $entry_id).addClass('active');
			$('.inPagePopup').css('width', '30%');
			$('.inPagePopup').css('display', 'block');
			$('.popupTitle').html('entry sil');
			var $url = 'http://www.kotusozluk.com/index.php?type=mini&section=entrydelete&entry_id=' + $entry_id + '&user_id=' + $user_id;
			$('.inPagePopup .innerContent').load($url);
		}
		else if($(this).attr('id') == 'report'){
			
			var $entry_id = $(this).attr('entry_id');
			var $user_id = $(this).attr('user_id');
			$('li#' + $entry_id).addClass('active');
			$('.inPagePopup').css('width', '30%');
			$('.inPagePopup').css('display', 'block');
			$('.popupTitle').html('entry taşı');
			var $url = 'http://www.kotusozluk.com/index.php?type=mini&section=entryreport&entry_id=' + $entry_id + '&user_id=' + $user_id;
			$('.inPagePopup .innerContent').load($url);
		}
		else if($(this).attr('id') == 'comment'){
			$parent = $(this).parent().parent();
			var $status_id = $(this).attr('status_id');
			$.get('http://www.kotusozluk.com/noload/statusreply.get.php', { status_id : $status_id }, function(data){
				$parent.find('.statuComment').html('');
				$parent.find('.statuComment').remove();
				$parent.append('<div class="statuComment" style="opacity: 0.2">' + data + '</div>');
				$parent.find('.statuComment').animate({ opacity: '1.0'}, 200);
			}, 'html');
		}
		
	});
	
	$('#binEdit').live('click', function(){
		var $entry_id = $(this).attr('entry_id');
		var $user_id = $(this).attr('user_id');
		$('li#' + $entry_id).addClass('active');
		$('.inPagePopup').css('width', '50%');
		$('.inPagePopup').css('display', 'block');
		$('.popupTitle').html('entry düzenleme');
		var $url = 'http://www.kotusozluk.com/index.php?type=mini&section=entryedit&entry_id=' + $entry_id + '&user_id=' + $user_id + '&isstatus=1';
		$('.inPagePopup .innerContent').load($url);
	});
	
	$('#binBack').live('click', function(){
		var $entry_id = $(this).attr('entry_id');
		var $user_id = $(this).attr('user_id');		
		var $ismod = $(this).attr('is_mod');
		
		var $url = 'http://www.kotusozluk.com/index.php?type=post&section=entryProcess&action=binback';
		if($ismod == 0){
			$postdata = '&entry_id=' + $entry_id + '&user_id=' + $user_id + '&ismod=0';
		}
		else {
			$postdata = '&entry_id=' + $entry_id + '&user_id=' + $user_id + '&ismod=1';
		}
		
		$.post($url, $postdata, function(data){
			if(data == '2'){
				$('li#' + $entry_id).remove();
			}
			else {
				alert("Yönetici Onayı Bekliyor!");
			}
		});
	});
	
	$('#binDelete').live('click', function(){
		var $entry_id = $(this).attr('entry_id');
		var $user_id = $(this).attr('user_id');		
		
		var $url = 'http://www.kotusozluk.com/index.php?type=post&section=entryProcess&action=bindelete';
		var	$postdata = '&entry_id=' + $entry_id + '&user_id=' + $user_id;
		$.post($url, $postdata, function(data){
			$('li#' + $entry_id).remove();
		});
	});	
	
	$('.questionButton a').live('click', function(){
		if($(this).attr('id') == 'answer'){
			var $question_id = $(this).attr('question_id');
			var $user_id = $(this).attr('user_id');
			$('.inPagePopup').css('width', '600px');
			$('.inPagePopup').css('display', 'block');
			$('.popupTitle').html('soruyu cevapla');
			var $url = 'http://www.kotusozluk.com/index.php?type=mini&section=answerquestion&question_id=' + $question_id + '&to_user_id=' + $user_id;
			$('.inPagePopup .innerContent').load($url);						
		}
		else if($(this).attr('id') == 'delete'){
			var $question_id = $(this).attr('question_id');
			var $user_id = $(this).attr('user_id');
			$('.inPagePopup').css('width', '600px');
			$('.inPagePopup').css('display', 'block');
			$('.popupTitle').html('soruyu sil');
			var $url = 'http://www.kotusozluk.com/index.php?type=mini&section=deletequestion&question_id=' + $question_id + '&to_user_id=' + $user_id;
			$('.inPagePopup .innerContent').load($url);						
		}
		else if($(this).attr('id') == 'deleteanswer'){
			var $question_id = $(this).attr('question_id');
			var $user_id = $(this).attr('user_id');
			$('.inPagePopup').css('width', '600px');
			$('.inPagePopup').css('display', 'block');
			$('.popupTitle').html('cevabı sil');
			var $url = 'http://www.kotusozluk.com/index.php?type=mini&section=deleteanswer&question_id=' + $question_id + '&to_user_id=' + $user_id;
			$('.inPagePopup .innerContent').load($url);						
		}				
	});
	
	$('#profileQuestionDelete').live('submit', function(){
       $(this).find('#mainEntryWriteSubmit').addClass('buttonLoad');   $(this).find('#mainEntryWriteSubmit').attr("disabled", "true");
		var postdata = $('#profileQuestionDelete').serialize();
		var $question_id = $('input[name="question_id"]').val();
		var $postUrl = $(this).attr('action');
		$.post($postUrl, postdata, function(data) {
			$('li#' + $question_id ).remove();
			$('.inPagePopup .innerContent').html('');
			$('.inPagePopup').css('display', 'none');
		});
		return false;
	});
	
	$('#profileAnswerDelete').live('submit', function(){
       $(this).find('#mainEntryWriteSubmit').addClass('buttonLoad');   $(this).find('#mainEntryWriteSubmit').attr("disabled", "true");
		var postdata = $('#profileAnswerDelete').serialize();
		var $question_id = $('input[name="question_id"]').val();
		var $postUrl = $(this).attr('action');
		$.post($postUrl, postdata, function(data) {
			$('.questionAnswer').filter('#' + $question_id ).remove();
			$('.inPagePopup .innerContent').html('');
			$('.inPagePopup').css('display', 'none');
		});
		return false;
	});
	
	$('#profileQuestionAnswer').live('submit', function(){
       $(this).find('#mainEntryWriteSubmit').addClass('buttonLoad');   $(this).find('#mainEntryWriteSubmit').attr("disabled", "true");
		var postdata = $('#profileQuestionAnswer').serialize();
		var $question_id = $('input[name="question_id"]').val();
		var $postUrl = $(this).attr('action');
		$.post($postUrl, postdata, function(data) {
			$('.questionList li#' + $question_id).html(data);			
			$('.inPagePopup .innerContent').html('');
			$('.inPagePopup').css('display', 'none');
			
		});
		return false;
	});	
	
	$('#profileQuestionAsk').live('submit', function(){
		   $submitButton = $(this).find('#mainEntryWriteSubmit');
		   $submitButton.addClass('buttonLoad');   
		   $submitButton.attr("disabled", "true");
			var postdata = $(this).serialize();
			var $postUrl = $(this).attr('action');
			$(this).find('textarea').val('')
			$.post($postUrl, postdata, function(data) {
				$submitButton.removeClass('buttonLoad');
				$submitButton.removeAttr('disabled');
				   $.toast({
				        message: 'sorunuz gönderildi',
				        displayTime:2000,
				        inTime:100,
				        outTime:400
				   });
				   
			});
			return false;		
	});
	
	$('.statuRightInfo input').live('click', function(){
		$parentLi = $(this).parent().parent();
		if($(this).attr('id') == 'like'){
			
			$.post('http://www.kotusozluk.com/index.php?type=post&section=entryProcess&action=unrate', 
					{
						user_id : $(this).attr('user_id'),
						entry_id : $(this).attr('entry_id'),
						vote : 'like'
					}
					, function(data){
		
				
			});
			$parentLi.remove();
		}
		else if($(this).attr('id') == 'dislike'){
			
			$.post('http://www.kotusozluk.com/index.php?type=post&section=entryProcess&action=unrate', 
					{
						user_id : $(this).attr('user_id'),
						entry_id : $(this).attr('entry_id'),
						vote : 'dislike'
					}
					, function(data){
						
				
			});
			$parentLi.remove();
		}
		else if($(this).attr('id') == 'favadded'){
			
			$.post('http://www.kotusozluk.com/index.php?type=post&section=entryProcess&action=removefavorite', 
					{
						user_id : $(this).attr('user_id'),
						status_id : $(this).attr('status_id')
					}
					, function(data){
				
			});
			$parentLi.remove();
		}
	});
	
	$('.statusContinue').live('click', function(){
		$entry_id = $(this).attr('entry_id');
		$parent = $(this).parent();
		$parent.animate({ opacity: '0.5' }, 100);
		$(this).remove();
		$.get('http://www.kotusozluk.com/noload/entrycontent.get.php', { entry_id : $entry_id } ,function(data){
			$parent.html(data);
			$parent.animate({ opacity: '1.0'}, 100);
		});
	});
	
	$('.followButton').live('click', function(){	
			$user_id = $(this).attr('user_id');
			$following_id = $(this).attr('following_id');
			$(this).attr('disabled', 'true');
			$('li#' + $following_id).animate({ opacity: '0.5'}, 100);
			$.post('http://www.kotusozluk.com/index.php?type=post&section=userProcess&action=followUser', 
					{
						following_id : $following_id
					}
					, function(data){
						$.get('http://www.kotusozluk.com/noload/homesuggestions.get.php', { user_id : $user_id, single: '1' } ,function(data){
							
							$('li#' + $following_id).replaceWith(data);
							$('li#' + $following_id).animate({ opacity: '1.0'}, 100);
						});
				
			});
	});
	
	$('.topSlide').click(function(){
		$('.navigation li').find('div').slideUp("fast");
		if($(this).parent().find('div').css('display') == 'none'){
			$(this).parent().find('div').slideDown("fast");	
		}

		if($(this).attr('id') == 'personalInfo'){
			$.get('http://www.kotusozluk.com/noload/personalInfo.php', function(data){
				$('.topUserInfo').html(data);
			});
		}
		
		return false;
	});
	
});
$(window).resize(function() {
	var imageH = $(window).height() - 87;
	$(".leftTopics").css("height", imageH);
});



function openMenu(divName, divName2){
	if($('.' + divName).css('display') == 'none'){
		$('.' + divName).slideDown("fast");
		$('.todayButton').css('background-color', '#fcfcfc');
		$('.arrowButton').css('background-color', '#fcfcfc');	
	}
	else {
		$('.' + divName).slideUp("fast");
		$('.todayButton').css('background-color', '#f5f5f5');
		$('.arrowButton').css('background-color', '#f5f5f5');
		
	}
}

function showHide(id){
	if($('#' + id).css('display') == 'none'){
		$('#' + id).css('display', 'block');
	}
	else {
		$('#' + id).css('display', 'none');
	}
}

function setCookie(c_name,value,exdays)
{
var exdate=new Date();
exdate.setDate(exdate.getDate() + exdays);
var c_value=escape(value) + ((exdays==null) ? "" : "; expires="+exdate.toUTCString());
document.cookie=c_name + "=" + c_value;
}

function slideUpDown(id){
	if($('#' + id).css('display') == 'none'){
		$('#' + id).slideDown("fast");
		setCookie(id,'acik',2);
	}
	else {
		$('#' + id).slideUp("fast");
		setCookie(id,'kapali',2);
	}
}
var rand = Math.random();
function onlineYukle1() { $('#topOnlines').load('/onlines/onlinesu.php?rand='+rand); }
function onlineYukle2() { $('#topOnlines').load('/onlines/onlinesz.php?rand='+rand); }

function ie8SafePreventEvent(e){
    if(e.preventDefault){ e.preventDefault()}
    else{e.stop()};
	
	
    e.returnValue = false;
    e.stopPropagation();    
}


(function($) {
	toasting = false; 	//Global to check if toast is being displayed
	toastQue = [];		//Array to store messages if a message is already being displayed
	
	//return new toastmessage object
	$.toast = function (options) {
		return new toastmessage(options);
	};
	
	var toastmessage = function(options){
		var defaults = {message:"This is a Toast", displayTime:2000, inTime:300, outTime:200, maxWidth:400}; 
			
			//check if currently displaying, if so then add the new one to the que
			if(!window.toasting){
				window.toasting = true;
				var toast;
				
				options = $.extend(defaults, options);
		   		
		   		//create the new element and add it to the document
				toast = $("<div class='toast'>"+options.message+"</div>");
				$("body").append(toast);
				
				//make sure it toast isn't too wide and center it
				//TODO: add options for where to display the notification like bottom-right or top-center
				//TODO: See if there is a faster way to do this, Firefox lags a bit on this step
				toast.css({
					"max-width":options.maxWidth+"px",
					"top":(($(window).height() - toast.outerHeight()) / 2) + $(window).scrollTop() + "px",
					"left":(($(window).width() - toast.outerWidth()) / 2) + $(window).scrollLeft() + "px"
				});
				
				//Show the toast message
				toast.fadeIn(options.inTime);
				
				//Hide the toast and remove it from the document after the set amount of time
				setTimeout(function(){
					toast.fadeOut(options.outTime, function(){
						toast.remove(); 
						window.toasting = false;
						
						if(window.toastQue.length > 0){
							next = window.toastQue.pop();
							$.toast(next);
						}
					});
				}, options.displayTime);
			} else {
				window.toastQue.unshift(options);
			}
	};
})(jQuery);

(function(jQuery){

	jQuery.hotkeys = {
		version: "0.8",

		specialKeys: {
			8: "backspace", 9: "tab", 13: "return", 16: "shift", 17: "ctrl", 18: "alt", 19: "pause",
			20: "capslock", 27: "esc", 32: "space", 33: "pageup", 34: "pagedown", 35: "end", 36: "home",
			37: "left", 38: "up", 39: "right", 40: "down", 45: "insert", 46: "del", 
			96: "0", 97: "1", 98: "2", 99: "3", 100: "4", 101: "5", 102: "6", 103: "7",
			104: "8", 105: "9", 106: "*", 107: "+", 109: "-", 110: ".", 111 : "/", 
			112: "f1", 113: "f2", 114: "f3", 115: "f4", 116: "f5", 117: "f6", 118: "f7", 119: "f8", 
			120: "f9", 121: "f10", 122: "f11", 123: "f12", 144: "numlock", 145: "scroll", 191: "/", 224: "meta"
		},

		shiftNums: {
			"`": "~", "1": "!", "2": "@", "3": "#", "4": "$", "5": "%", "6": "^", "7": "&", 
			"8": "*", "9": "(", "0": ")", "-": "_", "=": "+", ";": ": ", "'": "\"", ",": "<", 
			".": ">",  "/": "?",  "\\": "|"
		}
	};

	function keyHandler( handleObj ) {
		// Only care when a possible input has been specified
		if ( typeof handleObj.data !== "string" ) {
			return;
		}

		var origHandler = handleObj.handler,
			keys = handleObj.data.toLowerCase().split(" ");

		handleObj.handler = function( event ) {
			// Don't fire in text-accepting inputs that we didn't directly bind to
			if ( this !== event.target && (/textarea|select/i.test( event.target.nodeName ) ||
				 event.target.type === "text") ) {
				return;
			}

			// Keypress represents characters, not special keys
			var special = event.type !== "keypress" && jQuery.hotkeys.specialKeys[ event.which ],
				character = String.fromCharCode( event.which ).toLowerCase(),
				key, modif = "", possible = {};

			// check combinations (alt|ctrl|shift+anything)
			if ( event.altKey && special !== "alt" ) {
				modif += "alt+";
			}

			if ( event.ctrlKey && special !== "ctrl" ) {
				modif += "ctrl+";
			}

			// TODO: Need to make sure this works consistently across platforms
			if ( event.metaKey && !event.ctrlKey && special !== "meta" ) {
				modif += "meta+";
			}

			if ( event.shiftKey && special !== "shift" ) {
				modif += "shift+";
			}

			if ( special ) {
				possible[ modif + special ] = true;

			} else {
				possible[ modif + character ] = true;
				possible[ modif + jQuery.hotkeys.shiftNums[ character ] ] = true;

				// "$" can be triggered as "Shift+4" or "Shift+$" or just "$"
				if ( modif === "shift+" ) {
					possible[ jQuery.hotkeys.shiftNums[ character ] ] = true;
				}
			}

			for ( var i = 0, l = keys.length; i < l; i++ ) {
				if ( possible[ keys[i] ] ) {
					return origHandler.apply( this, arguments );
				}
			}
		};
	}

	jQuery.each([ "keydown", "keyup", "keypress" ], function() {
		jQuery.event.special[ this ] = { add: keyHandler };
	});

})( jQuery );

