var jFeed = jQuery.noConflict();
var Feeds = {
	isFeedComplete: false,
	Init		: function (pageowner_id, username, app_id, k,container,limit, notificationLimit) {
					this.PageOwnerId = pageowner_id;
					this.AppId 		 = app_id;
					this.k			 = k;
					this.PagingFeed  = new Paginator(limit);
					this.PagingNotification = new Paginator(notificationLimit);
					Layout.Container	 = container; 
					jFeed('#' + Layout.Container).css('background-color', '#FFF');
					this.Username = username;
					if (username != "" && (username == pageowner_id)) {
						Layout.showNotification = true;
					}else {
						Layout.showNotification = false;
					}
					Layout.GenerateLayout();
					//All variables are set,now get feeds !
					this.GetFeeds();
					if (username != "" && (username == pageowner_id)) {
						jFeed(document).ready(function(){
							Ftunnel.Init();
						});
					}
					
					if (Layout.showNotification == true) {
						Cookie.GetNotificationCountCookie();
						this.ShowNotificationCount();
					}
					
				},
	InitGeneralFeed: function(pageowner_id,app_id,k,container,limit,username) {
					this.CommentAllowed = true;
					this.PageOwnerId 	= pageowner_id;
					this.AppId 			= app_id;
					this.k				= k;
					this.Username		= username;
					Layout.Container 	= container;
					this.PagingGeneralFeed = new Paginator(limit);
					Layout.showNotification = false;
					Layout.GenerateLayout();
					this.GetGeneralFeeds();					
				},
	InitSearchFeed: function(app_id, container, limit, key, username) {
					Layout.Container = container;
					this.AppId = app_id;
					this.PagingFeed = new Paginator(limit);
					this.Username = username;
					Feeds.FeedTab = 'search';
					Layout.showNotification = false;
					Layout.GenerateLayout();
					jFeed('.feedHiddenButtonBac').hide();
					jFeed('#feedSearchInput').val(key);
					Fsearch.IsFriendSearch = 0;
					Fsearch.Search();
				},
	InitFeedBox : function(container, pageowner, app_id, key) {
					Layout.BoxContainer = container;
					Feeds.GetFeedBox(pageowner, app_id, key);
				},
	Username	: '',
	CurrentTab	: 'unread',
	PageOwnerId : '',
	PagingFeed	: '',
	PagingNotification : '',
	PagingGeneralFeed: '',
	AppId		: '',
	k			: '',
	CommentAllowed: true,
	FeedUrl		: 'http://livefeed.mynet.com/app/feed.php?cf=?',
	NotificationUrl : 'http://notification.mynet.com/GetNotifications.php?cf=?',
	GeneralFeedUrl: 'http://livefeed.mynet.com/app/feed.php?cf=?&op=gf',
	PrivacyUrl : 'http://livefeed.mynet.com/app/privacy.php',
	CommentUrl: 'http://livefeed.mynet.com/app/comment.php?cf=?',
	LikeUrl:'http://livefeed.mynet.com/app/like.php',
	WaitingIcon: '<img src="http://img3.mynet.com/feed/loadComment.gif" />',
	SearchUrl	: 'http://livefeed.mynet.com/app/search.php?cf=?',
	ShortenUrl	: 'http://myn.tc/app/client.php?cf=?',
	ShowNotificationCount: function()  {
							if (Cookie.TotalNotifications > 0) {
								jFeed('#notification_count').html('('+Cookie.TotalNotifications+')');
							}else {
								jFeed('#notification_count').html('');
							}
						},
	GetGeneralFeeds : function () {
						jFeed('#' + Layout.moreFeedWidget).html('Yükleniyor...');
						jFeed.ajax({
							type: 'GET',
							url: this.GeneralFeedUrl,
							data: 'pageowner_id='+this.PageOwnerId+'&app_id='+this.AppId+'&k='+this.k+'&limit='+this.PagingGeneralFeed.limit,
							dataType: 'jsonp',
							success: function(data) {
								var defaultShowNumber = 5;
								var totalNum = data.f.length;
								if (totalNum <= defaultShowNumber) {
									var rotate = 0;
									FeedParser.Parse(data);
								}else {
									var rotate = totalNum - defaultShowNumber;
									//put default ones
									FeedParser.tmp = new Object();
									FeedParser.tmp.f = new Array();
									FeedParser.tmp.t = data.t;
									FeedParser.tmp.f = data.f.slice(rotate,totalNum);
									FeedParser.ShowMoreLink = false;
									FeedParser.Position = 'prepend';
									FeedParser.Parse(FeedParser.tmp);
									//Take rotating ones	
									FeedParser.RotateFeeds = data.f.slice(0,rotate);
									FeedParser.RotateFeeds.t = data.t;
									//Configure set time out
									var passedTime = 0;
									for (i=rotate-1;i>=0;i--) {
										//Generate random time for each item.
										var timeout = Math.floor(Math.random()*11);
										passedTime += timeout;
										FeedParser.Rotate(i, passedTime);
									}	
								}
							},
							error: this.HandleError
						});
					},
	FeedTab		: 'default',
	GetFeedBox	: function(pageowner, app_id, key) {
					jFeed.ajax({
						type: 'GET',
						url: this.FeedUrl,
						data: 'op=gfs&pageowner_id=' + pageowner + '&app_id=' + app_id + '&k=' + key,
						dataType: 'jsonp',
						success: function(data) {
							FeedParser.ParseFeedBox(data);
						},
						error: this.HandleError
					});
				},
	GetFeeds 	: function () {
					jFeed.ajax ({
						type: 'GET',
						url: this.FeedUrl,
						data: 'op=g&pageowner_id='+this.PageOwnerId+'&app_id='+this.AppId+'&k='+this.k+'&page='+this.PagingFeed.page+'&limit='+this.PagingFeed.limit,
						dataType: 'jsonp',
						success: function (data) {
								FeedParser.Parse(data);
								Feeds.isFeedComplete = true;
						},
						error: this.HandleError
					});
	},
	ClearFeedArea: function() {
				jFeed('.newFeedContain').empty();
				jFeed('.newFeedHideContain').empty();
				jFeed('.feedHideShow').empty();
				Privacy.ClearHideOptions();
				jFeed('#' + Layout.moreFeedWidget).html('YÃ¼kleniyor...');
				Feeds.PagingFeed.page = 1;
	},
	GetMiniFeed: function () {
				if (Control.isRequestAvailable()) {
					Control.requestSend();
					jFeed.ajax({
						type: 'GET',
						url: this.FeedUrl,
						data: 'op=m&pageowner_id=' + this.PageOwnerId + '&app_id=' + this.AppId + '&k=' + this.k + '&page=' + this.PagingFeed.page + '&limit=' + this.PagingFeed.limit,
						dataType: 'jsonp',
						success: function (data) {
							FeedParser.Parse(data);
							Control.requestDone();
						},
						error: this.HandleError
					});
				}
	},
	jsonReady	: true,
	GetAllNotifications : function() {
							jFeed.ajax({
								type: 'GET',
								url: this.NotificationUrl,
								dataType: 'jsonp',
								data: 'op=g&limit=' + Feeds.PagingNotification.limit + '&page=' + Feeds.PagingNotification.page,
								success: function (data) {
									NotificationParser.Parse(data);
									//indicates request is done and avaible for other requests
									Control.requestDone();
								},
								error: this.HandleError
							});
				},
	GetUnreadNotifications: function() {
							jFeed.ajax({
								type: 'GET',
								url: this.NotificationUrl,
								dataType: 'jsonp',
								data: 'op=u&limit=' + this.PagingNotification.limit,
								success: function (data) {
									NotificationParser.Parse(data);
									//indicates request is done and avaible for other requests
									Control.requestDone();
								},
								error: this.HandleError
							});	
						},
	GetNotificationContentDiv: function() {
								if (this.CurrentTab == 'unread') {
									return 'p_unread';
								}else if (this.CurrentTab == 'all') {
									return 'p_all';
								}else {
									return 'p_unread';
								}	
							},
	HandleError		: function(data) {
						alert('Bir hata oluştu lütfen sonra bir daha deneyiniz');
					}		
	};
	
	var Fsearch = {
			SearchKey : '',
			Init: function(isFriendSearch) {
				Fsearch.IsFriendSearch = isFriendSearch;
				Feeds.ClearFeedArea();
				Feeds.FeedTab = 'search';
			},
			IsFriendSearch: 1,
			Search: function() {
				var searchKey = jFeed.trim(jFeed('#feedSearchInput').val());
				if (searchKey == "" || searchKey.length < 3 ) {
					return false;
				}

				if (Control.isRequestAvailable()) {
					Control.requestSend();
					jFeed.ajax({
						type: 'GET',
						url: Feeds.SearchUrl,
						data: 'op=s&f='+Fsearch.IsFriendSearch+'&s='+searchKey + '&page=' + Feeds.PagingFeed.page + '&limit=' + Feeds.PagingFeed.limit,
						dataType: 'jsonp',
						success: function (data) {
							FeedParser.Parse(data);
							Fsearch.SearchKey = searchKey;
							Fsearch.Highlight();
							Control.requestDone();
						},
						error: this.HandleError
					});
				}
			},
			Highlight: function () {
				var x = Olasilik(Fsearch.SearchKey);
				for (i=0; i<x.length; i++ ) {
					jFeed('.newFeedContain').highlight(x[i]);
				}
			}
	};
	
	var Privacy = {
		Hide: function (feed_id, hash) {
			if (Control.isRequestAvailable()) {
				Control.requestSend();
				jFeed.ajax({
					type:'GET',
					url: Feeds.PrivacyUrl,
					dataType: 'jsonp',
					data: 'op=f&fid=' + feed_id + '&h=' + hash,
					success: function (data) {
						if (data.s) {
							Privacy.ShowLayout(feed_id);
							Privacy.BindActions(feed_id,hash);		
						}
						Control.requestDone();
						jFeed('#' + hash).find('img').remove();
					},
					error: this.HandleError
				});
			}
		},
		HideBack: function(feed_id, hash) {
			if (Control.isRequestAvailable) {
				Control.requestSend();
				jFeed.ajax({
					type:'GET',
					url: Feeds.PrivacyUrl,
					dataType: 'jsonp',
					data:'op=fb&fid=' + feed_id + '&h=' + hash,
					success: function(data) {
							if (data.s) {
								jFeed('#info_' + feed_id).remove();
								jFeed('#feed_' + feed_id).show('slow');
							}
							Control.requestDone();
					},
					error: this.HandleError
					
				});
			}
		},
		ShowLayout: function (feed_id) {
			
			jFeed('#feed_' + feed_id).hide('slow');
			var xhtmlContent = '<div class="feedHideMsgContain clr" id="info_' + feed_id + '">';
			xhtmlContent += 'Haber gizlendi. <a class="h_back">Geri al</a> veya <a class="h_others">buna benzer diğer haberleri de gizle.</a>';
			xhtmlContent += '<div class="feedHideSelection" style="display:none;">';
			xhtmlContent += Privacy.GetOptions(feed_id);
			xhtmlContent += '</div></div>';
			jFeed('#feed_' + feed_id).after(xhtmlContent);
			
		},
		BindActions: function (feed_id,hash) {
			jFeed('#info_' + feed_id + ' a, #info_'+feed_id+ ' input:button').unbind('click').bind('click',function(){
					var action = jFeed(this).attr('class');
					if (action == 'h_back') {
						Privacy.HideBack(feed_id, hash);
					}else if (action == 'h_others') {
						jFeed('#info_' + feed_id + ' div.feedHideSelection').show();
					}else if (action == 'h_save') {
						var selected =jFeed("#info_" + feed_id).find('input[name=privacy_option]:checked').val();
						if (typeof(selected) == 'undefined') {
							return ;
						}
						jFeed(this).parent().append(Feeds.WaitingIcon);
						Privacy.SaveOption(feed_id, hash, selected);
					}else if (action == 'h_cancel'){
						jFeed('#info_' + feed_id + ' div.feedHideSelection').hide();
					}
			});
		},
		SaveOption: function (feed_id, hash, selected) {
			var option = Privacy.GetFeedOption(feed_id);
			var hide_id = "";
			var hide_type = "";
			var hide_option = "";
			switch (selected) {
				case "1":	hide_id = option.owner;	hide_type = 'u'; hide_option = 0; 	break;
				case "2":	hide_id = option.fl; hide_type = 'u'; hide_option = 0;		break;
				case "3":	hide_id = option.fl; hide_type = 'u'; hide_option = 1;		break;
				case "4": 	hide_id = option.fc; hide_type = 'u'; hide_option = 0;		break;
				case "5":	hide_id = option.fc; hide_type = 'u'; hide_option = 1; 		break;
				case "6":	hide_id = option.template.id; hide_type="t"; hide_option=0;	break;
				default: return;
			}
			if (Control.isRequestAvailable()) {
				Control.requestSend();
				jFeed.ajax({
					type:'GET',
					url: Feeds.PrivacyUrl,
					dataType: 'jsonp',
					data:'op=o&fid=' + feed_id + '&h=' + hash + '&id=' + hide_id + '&t=' + hide_type + '&a=' + hide_option,
					success: function(data) {
							Control.requestDone();
							if (data.s) {
								jFeed('.newFeedContain').empty();
								Feeds.PagingFeed.page = 1;
								Privacy.ClearHideOptions();
								Feeds.GetFeeds();
								Layout.ShowMessage('Haberler gizlendi', 10000);
							}
					},
					error: this.HandleError
				});
			}
			
		},
		GetOptions: function (feed_id) {
			var xhtmlContent = "";
			var option = Privacy.GetFeedOption(feed_id);
			if (option.owner != Feeds.Username) {
				xhtmlContent += '<span class="rwFeed clr"><input type="radio" class="fsel" name="privacy_option" value="1"><label class="fLab">' + option.owner + ' kullanıcısından gelen haberleri gizle.</label></span>';
			}
			if (typeof(option.fl) != "undefined") {
				xhtmlContent += '<span class="rwFeed clr"><input class="fsel" type="radio" name="privacy_option" value="2"><label class="fLab">' + option.fl + ' kullanıcısından gelen haberleri gizle.</label></span>';
				xhtmlContent += '<span class="rwFeed clr"><input class="fsel" type="radio" name="privacy_option" value="3"><label class="fLab">' + option.fl + ' kullanıcısının arkadaşlarından gelen haberleri gizle.</label></span>';
			}
			if (typeof(option.fc) != "undefined") {
				xhtmlContent += '<span class="rwFeed clr"><input class="fsel" type="radio" name="privacy_option" value="4"><label class="fLab">' + option.fc + ' kullanıcısından gelen haberleri gizle.</label></span>';
				xhtmlContent += '<span class="rwFeed clr"><input class="fsel" type="radio" name="privacy_option" value="5"><label class="fLab">' + option.fc + ' kullanıcısının arkadaşlarından gelen haberleri gizle.</label></span>';
			}
			xhtmlContent += '<span class="rwFeed clr"><input class="fsel" type="radio" name="privacy_option" value="6"><label class="fLab">Tüm ' + option.template.name + ' haberlerini gizle.</label></span>';
			xhtmlContent += '<div class="feedHideBtn clr"><input type="button" class="h_save" value="Kaydet"/> <a class="h_cancel">Vazgeç</a></div>';
			return xhtmlContent;
		},
		GetFeedOption: function (feed_id) {
			for (i=0; i<Privacy.HideOptions.length; i++) {
				if (Privacy.HideOptions[i].fid == feed_id) {
					return Privacy.HideOptions[i];
				}
			}
		},
		HideOptions: [],
		TotalHided:0,
		ClearHideOptions: function () {
			Privacy.HideOptions = [];
			Privacy.TotalHided = 0;
		},
		PrepareHideOptions: function (data) {
			//Reset hide options
			var option = {};
			option.fid = data.fid;
			
			//set owner
			option.owner = data.o;
			
			//set template
			option.template = {};
			option.template.id = data.tid;
			option.template.name =  data.tn;
			
			//set friend likers
			if (data.fl.length > 0) {
				for (i=data.fl.length-1; i>=0; i--) {
					if (data.fl[i] != data.o && data.fl[i] != Feeds.Username) {
						option.fl = data.fl[i];
						break;
					}
				}
			}
			if (data.fc.length > 0) {
				for (i=data.fc.length-1; i>=0; i--) {
					if (data.fc[i] != data.o && data.fl[i] != Feeds.Username) {
						option.fc = data.fc[i];
						break;		
					}
				}
			}
			if (typeof(option.fc) != 'undefined' && typeof(option.fl) != 'undefined') {
				if (option.fc == option.fl) {
					delete option.fc;
				}
			}
			 
			if (data.hi.s == false) {
				option.unhide = data.hi;
			}
			Privacy.HideOptions.push(option);
		},
		ShowHide: function () {
			jFeed('.feedHideShow').hide();
			jFeed('.newFeedHideContain').show();
		},
		Undo: function (feed_id, hash){
			var option = Privacy.GetFeedOption(feed_id);
			if (Control.isRequestAvailable()) {
				Control.requestSend();
				jFeed.ajax({
					type:'GET',
					url: Feeds.PrivacyUrl,
					dataType: 'jsonp',
					data:'op=un&fid=' + feed_id + '&h=' + hash + '&id=' + option.unhide.hid + '&t=' + option.unhide.ty + '&a=' + option.unhide.a,
					success: function(data) {
							Control.requestDone();
							if (data.s) {
								jFeed('.newFeedContain, .newFeedHideContain, .feedHideShow ').empty();
								Feeds.PagingFeed.page = 1;
								Privacy.ClearHideOptions();
								Feeds.GetFeeds();
								Layout.ShowMessage('Haberlerin geri alındı.',10000);
							}
					},
					error: this.HandleError
				});
			}
		},
		Delete: function (feed_id, hash) {
				if (Control.isRequestAvailable()) {
					Control.requestSend();
					jFeed.ajax({
						type: 'GET',
						url: Feeds.PrivacyUrl,
						data: 'op=d'+'&fid=' +  feed_id + '&h=' + hash,
						dataType: 'jsonp',
						success: function (data) {
							if (data.s) {
								jFeed('#feed_' + feed_id).hide('slow');
							}
							Layout.ShowMessage('Sistemden silinmesi biraz zaman alabilir.',5000);
							Control.requestDone();
						},
						error: this.HandleError
					});
				}
		}
	};
	
	var FeedParser = {
		RotateFeeds	 : '',
		Position : 'append',
		ShowMoreLink : true,
		Rotate: function (i, timeout) {
				setTimeout(function(){
					var tmp = new Object();
					tmp.f = new Array();
					tmp.f[0] = FeedParser.RotateFeeds[i];
					tmp.t = FeedParser.RotateFeeds.t;
					FeedParser.Parse(tmp);
					var offset = jFeed('#feed_' + tmp.f[0].fid).height();
					Ftunnel.FixScroll(offset);
				},timeout * 1000);
			},
		PutFeed: function (data, xhtmlContent) {
			if (typeof(data.hi) == 'undefined' || data.hi.s) {
				if (FeedParser.Position == 'append') {
					jFeed('.newFeedContain').append(xhtmlContent);
				}else if (FeedParser.Position == 'prepend') {
					jFeed('.newFeedContain').prepend(xhtmlContent);
				}
			}else {
				Privacy.TotalHided++;
				if (FeedParser.Position == 'append') {
					jFeed('.newFeedHideContain').append(xhtmlContent);
				}else if (FeedParser.Position == 'prepend') {
					jFeed('.newFeedHideContain').prepend(xhtmlContent);
				}
			}
			
		},
		ParseFeedBox: function (data) {
				if (data.f.length > 0) {
					var xhtml = '<div class="listUserContainFeed" id="f_box">';
					jFeed.each(data.f, function(i,lineData) {
						xhtml += '<div class="listFeedItem">';
						xhtml += '<div class="listFeedData clr">';
						var profileUrl = AppLinks.concatAppProfileLink(data.pu, lineData.o);
						var profileImgPath = Avatar.getPicture(lineData.o);
						var img = '<img src="'+profileImgPath+'" onerror="Avatar.getDefault(this)"/>';
						if (lineData.u != "") {
							var contentUrl = lineData.u;
						}else {
							var contentUrl = profileUrl;
						}
						xhtml += '<a class="listFeedAvatar" href="'+profileUrl+'">' + img + '</a>';
						xhtml += '<div class="listFeedInfo">' + '<p><a href="' + profileUrl  + '">'+lineData.o+'</a></p><p><a href="'+ contentUrl +'">' + lineData.m+ '</a></p></div>';
						xhtml += '</div>';
						xhtml += '<div class="listFeedTime">'+DateParser.getDifference(lineData.dt, data.t)+'</div>';
						xhtml += '</div>';
					});
					xhtml += '</div>';
				}
				jFeed('#' + Layout.BoxContainer).html(xhtml);
				FeedParser.RotateFeedBox();
		},
		RotateFeedBox: function() {
			var clone = jFeed('#f_box div:first').clone();
			jFeed('#f_box div:first').remove();
			jFeed('#f_box').append(clone);
			window.setTimeout(function(){FeedParser.RotateFeedBox();}, 3000);
		},
		Parse: function (data) {
				if (data.f.length > 0) {
					//Privacy.ClearHideOptions();
					jFeed('.newFeedHideContain').hide();
					jFeed.each(data.f, function (i,lineData) {
						var uniqueId = "feed_"+lineData.fid;
						if (jFeed('#' + uniqueId).length == 0) {
							var xhtmlContent = '<div id="'+uniqueId+'">'
												+ lineData.c
												+ '</div>';
							FeedParser.PutFeed(lineData, xhtmlContent);
							if (typeof lineData.u == 'string') {
								var time = '<span class="newFeedUserInfo"><a href="' + lineData.u + '" target="_blank" class="newFeedUserInfo shorted">('+DateParser.getDifference(lineData.dt, data.t) + ')</a></span>';
							}else {
								var time = '<span class="newFeedUserInfo"> ('+DateParser.getDifference(lineData.dt, data.t) + ')</span>';
							}
							jFeed('#' + uniqueId + ' div.newFeedContent div.newFeedContentContain div.newFeedBar a.newFeedSiteInfo').before(time);
							if (Feeds.CommentAllowed) {
								if (Feeds.PageOwnerId == Feeds.Username && Feeds.Username != '') {
									Privacy.PrepareHideOptions(lineData);
								}
								FeedParser.CommentLayout(lineData.fid, uniqueId, lineData.app, lineData.o, lineData.h);
								FeedParser.ShowActions(lineData.fid, lineData.fl, lineData.o, lineData.hi, lineData.tl, lineData.tc, lineData.st);
								Fcomment.ShowFriendCommenters(lineData.fc,lineData.tc,lineData.app,lineData.fid);
								Flike.ShowLikers(lineData.fl,lineData.tl,lineData.app,lineData.fid);
								Fcomment.ShowComments(lineData.co, lineData.tc, lineData.fid, lineData.app, data.t, lineData.o);
							}
							
							var imgPath = Avatar.getPicture(lineData.o);
							var img = '<img src="'+imgPath+'" onerror="Avatar.getDefault(this)"/>';
							jFeed('#' + uniqueId + ' span[class=feedSourceImage]').html(img);
							if (lineData.app != Feeds.AppId) {
								jFeed('#'+ uniqueId+' a').attr('target', '_blank');
							}
							if (i==0) {
								return;
							}
						}
					});
				}else {
					if (Feeds.FeedTab == 'search') {
						var text = jFeed('#feedSearchInput').val();
						jFeed('.newFeedContain').append('<b>' + text + '<b> kelimesi ile ilgili aramanda sonuç bulunamadı.');
					}else {
						jFeed('.newFeedContain').append('Burada yeni bir haber yok. Başkaları neler yapıyor görmek istersen <a href="http://eksenim.mynet.com/ep/AllFeed.aspx?mt=4">buraya tıklayabilirsin</a>');
					}
				}
				if (Privacy.TotalHided > 0) {
					jFeed('.feedHideShow ').html('<a onclick="Privacy.ShowHide();">Gizlenen haberi göster. (' + Privacy.TotalHided + ')</a>').show();
				}
				
				FeedParser.BindActions();
								
				jFeed('.fVideoLink').unbind('click').bind('click', function(){
					var app_id = jFeed(this).parents('.newFeedContentContain').children('.feedCommentsContain').attr('aid');
					var videoId = jFeed(this).attr('vid');
					jFeed(this).parents('div[class=newFeedVideo]').attr('id','newFeedVideo');
					fVideo.playVideo(videoId,'newFeedVideo',app_id);
				});
				
				jFeed('.bVideoLink').unbind('click').bind('click',function(){
					var videoId = jFeed(this).attr('vid');
					jFeed(this).parents('div[class=newFeedVideo]').attr('id','newFeedVideo');
					bVideo.playVideo(videoId,'newFeedVideo');
				});
				
				jFeed('.fPhotoLink').unbind('click').bind('click', function(){
					jFeed(this).attr('rel','div.overlay');
					
					var image = new Image();
					image.onload = function() {
						FeedParser.SetImageDim(this);
					};
					var photoLink = jFeed(this).attr('src');
					var tmp = photoLink.lastIndexOf(".");
					var bigPhotoLink = photoLink.substr(0,tmp-1) + 'b' + photoLink.substr(tmp);
					image.src = bigPhotoLink;
					jFeed('#fPhotoOverlay').html('<a onclick="jFeed.closeOverlay();" class="closePhoto">Kapat</a>').append(image).append('<div class="fPhotoTitle">'+jFeed(this).attr('title')+'</div>');
				});
				if (FeedParser.ShowMoreLink) {
					FeedParser.configureMoreLink(data.f.length);
				}else {
					jFeed('#' + Layout.moreFeedWidget).html('');
				}
		},
		CommentLayout: function (feed_id, unique_id, app_id, uid, hash) {
					var xhtmlContent = '<div class="feedCommentsContain clr" fid="'+feed_id+'" aid="'+app_id+'" uid="'+uid+'" id="'+hash+'">';
					xhtmlContent += '<div class="feedCommentButton clr">';
					xhtmlContent += '</div>';
					xhtmlContent += '<div class="feedCommentFriendContain clr"></div>';
					xhtmlContent += '<div class="feedCommentLikeContain clr"></div>';
					xhtmlContent += '<div class="feedCommentContent clr"></div>';
					xhtmlContent += '<div class="feedAddContain" style="display:none;"><textarea name="body"></textarea><input type="button" value="Gönder" class="feedCommentAdd" /><a  class="feedCommentCancel">Vazgeç</a><span class="f_error"></span></div>';
					xhtmlContent += '</div>';
					jFeed('#' + unique_id + ' div.newFeedContentContain' ).append(xhtmlContent);
		},
		ShowActions: function(feed_id,fLikes,owner,hideStatus, totalLikes, totalComments,title){
					var patt = new RegExp('(^|,)' + fLikes.toString() + '(,|$)',"i");
					var xhtmlContent = "";
					
					if (totalComments < Fcomment.Limit) {
						xhtmlContent += '<a  class="c_feed">Yorumla</a>';
					} 
					//Check user has already liked it.
					if (patt.test(Feeds.Username) && Feeds.Username != "") {
						if (xhtmlContent != "") {
								xhtmlContent += " - ";
						}
						xhtmlContent += '<a class="l_feed" s="1">Beğenmekten vazgeç</a>';
					}else {
						if (totalLikes < Flike.Limit) {
							if (xhtmlContent != "") {
								xhtmlContent += " - ";
							}
							xhtmlContent += '<a class="l_feed" s="0">Beğen</a>';
						}
					}
					if (xhtmlContent != "") {
						xhtmlContent += " - ";
					}
					xhtmlContent += '<a class="s_feed" title="'+title+'">Paylaş</a>';
					
					if (Feeds.Username == Feeds.PageOwnerId && Feeds.Username != "") {
						if (hideStatus.s) {
							if (xhtmlContent != "") {
								xhtmlContent += " - ";
							}
							xhtmlContent += '<a class="h_feed">Gizle</a>';
						}else {
							if (xhtmlContent != "") {
								xhtmlContent += " - ";
							}
							xhtmlContent += '<a class="un_feed">Geri al</a>';
						}
						if (owner == Feeds.Username) {
							if (xhtmlContent != "") {
								xhtmlContent += " - ";
							}
							xhtmlContent += '<a class="d_feed">Sil</a>';
						}
					}
					
					
					jFeed(".feedCommentsContain[fid=" + feed_id + "] div.feedCommentButton").html(xhtmlContent);
					
		},
		BindActions: function(){
				jFeed('.feedCommentButton  a').each(function(){
					var action = jFeed(this).attr('class');
					//Check username for any action except share
					if (Feeds.Username == "" && (action != 'shorted') && (action != 's_feed')) {
						jFeed(this).attr('rel','div.overlay').unbind('click').bind('click',function(){
							myHtmlLogin.login();
						});
					}else {
						//Bind Comment actions
						if (action == 'c_feed') {
							jFeed(this).unbind('click').bind('click',function(){
								jFeed(this).parents('.feedCommentsContain').children('div.feedAddContain').toggle().children('textarea').focus();
							});
						//Bind Like action
						}else if (action == 'l_feed') {
							jFeed(this).unbind('click').bind('click',function(){
								jFeed(this).append(Feeds.WaitingIcon);
								var feed_id = jFeed(this).parents('.feedCommentsContain').attr('fid'); 
								var hash = jFeed(this).parents('.feedCommentsContain').attr('id');
								var status = jFeed(this).attr('s');
								if (status == "0") {
									Flike.ChangeLike(feed_id,'set', hash);
								}else if (status == "1") {
									Flike.ChangeLike(feed_id,'unset', hash);
								}
							});
						//Bind Delete Action
						}else if (action == 'd_feed') {
							jFeed(this).unbind('click').bind('click', function(){
								jFeed(this).append(Feeds.WaitingIcon);
								var feed_id = jFeed(this).parents('.feedCommentsContain').attr('fid');
								var hash = jFeed(this).parents('.feedCommentsContain').attr('id');
								Privacy.Delete(feed_id, hash);
							});
						//Bind hide action
						}else if (action == 'h_feed') {
							jFeed(this).unbind('click').bind('click', function(){
								jFeed(this).append(Feeds.WaitingIcon);
								var feed_id = jFeed(this).parents('.feedCommentsContain').attr('fid');
								var hash = jFeed(this).parents('.feedCommentsContain').attr('id');
								Privacy.Hide (feed_id,hash);
							});
						//Bind Unhide action	
						}else if (action == 'un_feed') {
							jFeed(this).unbind('click').bind('click',function(){
								jFeed(this).append(Feeds.WaitingIcon);
								var feed_id = jFeed(this).parents('.feedCommentsContain').attr('fid');
								var hash = jFeed(this).parents('.feedCommentsContain').attr('id');
								Privacy.Undo(feed_id,hash);
							});
						}
					}
					
					//Share action does not require login
					if (action == 's_feed') {
						jFeed(this).unbind('click').bind('click', function(){
							var feed_id = jFeed(this).parents('.feedCommentsContain').attr('fid');
							var url = jFeed('#feed_' + feed_id).find('a.shorted').attr('href');
							var title = jFeed(this).attr('title');
							Fshare.Show(url,title);
						});
					}
					
					
				});
				
				//More comment action
				jFeed('.moreComment').unbind('click').bind('click', function(){
					var feed_id = jFeed(this).parents('.feedCommentsContain').attr('fid');
					var feedAddContain = jFeed(this).parents('.feedCommentsContain').children('div.feedAddContain'); 
					Fcomment.MoreComments(feed_id);
					feedAddContain.toggle().children('textarea').focus();
				});
				
				jFeed('textarea[name=body]').unbind('keyup').bind('keyup', function(event){
					if (event.keyCode == 13) {
						jFeed(this).nextAll('.feedCommentAdd').click();
					}
				});
				
				//Add comment action
				jFeed('.feedCommentAdd').unbind('click').bind('click',function(){
					if (Feeds.Username == "") {
						myHtmlLogin.login();
					}else {
						Fcomment.Save(jFeed(this));
					}
				});
				//Binding cancel comment action
				jFeed('.feedCommentCancel').unbind('click').bind('click', function(){
					jFeed(this).parent().hide();
				});
				
				
		},
		SetImageDim: function (element) {
					jFeed('#fPhotoOverlay').css({width: element.width, height: element.height});
					jFeed('#fPhotoOverlay').jOverlay();
		},
		configureMoreLink: function(totalNum) {
			var moreLink = jFeed('#' + Layout.moreFeedWidget);
			Feeds.PagingFeed.page+=1;
			if (totalNum > 0) {
				moreLink.html('<a>Daha fazla göster</a>').show();
			}else {
				moreLink.html('').hide();
			}
		}
	};
	
	var NotificationParser = {
		Parse		: function (data) {
						var xhtmlContent = "";
						var notificationContentDiv = Feeds.GetNotificationContentDiv();
						var readCount = 0;
						if (data.d.length > 0) {
							jFeed.each(data.d, function (i, lineData) {
								xhtmlContent += '<li class="bildirimListContain ';
								if (lineData.st == 0) {
									xhtmlContent += 'bListDeactive ';
								}else {
									readCount +=1;
								}
								xhtmlContent	+='clr">'
												 + lineData.c
												 + '<span class="listTime">('+DateParser.getDifference(lineData.dt, data.t)+')</span>'
												 + '</li>';
							});
							//Append for coming notifications
							if (Feeds.PagingNotification.isAppend) {
								jFeed('#' + notificationContentDiv).append(xhtmlContent);
							}else {	//If it is first page, change all html	
								jFeed('#' + notificationContentDiv).html(xhtmlContent);
							}
						}else {
							//jFeed('#' + Layout.moreNotificationWidget).html('Okunmamış bildirim bulunmamaktadır').show();
							//Display none for more link
						}
						NotificationParser.configureMoreLink(data.d.length,readCount);
						
		},
		configureMoreLink : function (totalNum, readCount) {
								Feeds.PagingNotification.isAppend = true;
								var moreLink = jFeed('#'+Layout.moreNotificationWidget);
								if (totalNum > 0) {
									moreLink.html('<a>Daha fazla göster</a>');
								}else {
									if (Feeds.CurrentTab == 'unread') {
										var text = 'Okunmamış bildirim bulunmamaktadır';
									}else {
										var text = 'Daha fazla bildirim bulunmamaktadır';
									}
									moreLink.html(text).unbind('click');
								}
								if (Feeds.CurrentTab == 'all') {
									Feeds.PagingNotification.page += 1;
									moreLink.unbind('click');
									moreLink.bind('click', function() {Feeds.GetAllNotifications();});
								}else {
									moreLink.unbind('click');
									moreLink.bind('click', function() {Feeds.GetUnreadNotifications();});
								}
								if (readCount > 0) {
									var newTotal = Cookie.TotalNotifications - totalNum;
									if (newTotal > 0) {
										Cookie.SetNotificationCountCookie(newTotal);
									}else {
										Cookie.SetNotificationCountCookie(0);
									}
								}
								
		}
	};
	
	var Cookie = {
		TotalNotifications : '',
		CookieName : 'mylcount',
		Ns: '',
		GetCookie : function(name) {
						var c=document.cookie;
						//var name = Cookie.CookieName;
						if (c.indexOf(name)!=-1) { 
        					if(c.substr(c.indexOf(name)+name.length,1) !== "=") return false;
							pos1=c.indexOf("=", c.indexOf(name))+1; 
        					pos2=c.indexOf(";",pos1);  
       						if(pos2==-1)    pos2=c.length;
       						data=c.substring(pos1,pos2);
       						data = data.split('.');
       						return data;
						}else {
							return false;
						}
						
					},
		GetNsCookie: function() {
						if (Cookie.Ns == "") {
							Cookie.SetNsCookie();
						}
						return Cookie.Ns;
					},
		SetNsCookie: function() {
					Cookie.Ns = Cookie.GetCookie('nfs');
		},
		GetNotificationCountCookie : function() {
										var data = this.GetCookie(Cookie.CookieName);
										if (data == false || data[2] == -1) {
											this.GetNotificationCount();
										}else {
											Cookie.TotalNotifications = data[2];
										}
									},
		
		SetNotificationCountCookie : function(count) {
										Cookie.TotalNotifications = count;
										Feeds.ShowNotificationCount();
										var date = new Date();
 												date =  Math.floor(date.getTime());
 												var cookie = Cookie.GetCookie(Cookie.CookieName);
 												if (cookie == false) {
 													var data = '0'+'.'+date+'.'+Cookie.TotalNotifications+'.'+date+'.'+'0'+'.'+date+'.'+'0'+'.'+date;
 												}else {
 													var data= cookie[0]+'.'+cookie[1]+'.'+Cookie.TotalNotifications+'.'+date+'.'+cookie[4]+'.'+cookie[5]+'.'+cookie[6]+'.'+cookie[7];
 												}
 												Cookie.setCookie(Cookie.CookieName,data,5,"/", ".mynet.com");
									},
		
		GetNotificationCount: function () {
								jFeed.ajax({
										type: 'GET',
										url: Feeds.NotificationUrl,
										dataType: 'jsonp',
										data:'op=n',
										success:function (data) {Cookie.SetNotificationCountCookie(data.count);}, 
										error: this.HandleError
									});
							},
		GetUsername: function(){
				var uid = Cookie.GetCookie('uvid');
				var username = "";
				if (uid != false) {
					username = uid.toString().substr(32);
				}
				return username;
		},
		setCookie: function(name, value, dakika, path, domain, secure){
					if(value.length > 4000)	return false;
					if(dakika !== 0 ){
						var d=new Date();
						d.setTime(d.getTime()+(dakika*60*1000));
						var expires="; expires="+d.toGMTString();  
					}else{
						var expires = "";
					}
					var path = path ? 	  ";path="+path:';path=/';
					var domain = domain ? ";domain="+domain:'';
					var secure = secure ? ";secure="+secure:'';
					document.cookie = name+"="+value+expires+path+domain+secure;
				}
		};
	
	var Fshare = {
			Site: 'canli.eksenim.mynet.com',
			LinkShareUrl: 'http://uprof.mynet.com/linksharing.php?',
			Surl: '',
			GetTypeCode: function (strCode) {
				switch (strCode) {
					case 'fb':
						return 4;
					case 'ff':
						return 11;
					case 'tw':
						return 6;
					case 'ek':
						return 0;
					default:
						return 0;
				}
			},
			Show: function(url,title) {
				Fshare.Clear();
				jFeed('#shareOverlay').jOverlay();
			
				//Show Urls
				jFeed('#f_url').val(url);
				Fshare.ShortenUrl(url);
				
				jFeed('.s_option').each(function(){
					jFeed(this).bind('click', function() {
						var type = Fshare.GetTypeCode(jFeed(this).attr('t'));
						if (type == 6) { //Send shorten url
							if (Fshare.Surl != "") {
								url = Fshare.Surl;
							}else {
								url = jFeed('#f_url').val();
							}
						}else {
							url = jFeed('#f_url').val();
						}
						var redirectUrl = Fshare.LinkShareUrl + 'url=' + url + '&title=' + title + '&enc=UTF-8' + '&site=' + Fshare.Site + '&link=' + type;
						jFeed(this).attr('href', redirectUrl);
					});
				});
			},
			ShortenUrl: function(url) {
				jFeed('#l_short_url').append(Feeds.WaitingIcon);
				jFeed.ajax({
					type: 'GET',
					url: Feeds.ShortenUrl,
					data: 'u=' + url,
					dataType: 'jsonp',
					success: function(data) {
						jFeed('#l_short_url img').remove();
						if (typeof data.code === 'undefined') {
							Fshare.Surl = 'http://myn.tc/' + data;
							jFeed('#f_short_url').val(Fshare.Surl);
						}
					}
				});
			},
			Clear: function() {
				jFeed('#f_short_url, #f_url').val('');
			}
	};
	
	var Layout = {
		moreFeedWidget: 'showMoreFeed',
		moreNotificationWidget: 'showMoreNotification',
		Container : '',
		BoxContainer: '',
		showNotification : true,
		ShowMessage: function (msg, timeout) {
			var id = 'warn_' + Math.floor(Math.random()*1000+1);
			var xhtmlContent = '<div class="feedNewsWar" id="'+id+'">';
			xhtmlContent += msg;
			xhtmlContent += '</div>';
			jFeed('.newFeedContain').prepend(xhtmlContent);
			window.setTimeout(function(){
				jFeed('#' + id).remove();
			},timeout);
		},
		IsOpen: function(){
					if (jFeed('#notificationClose').hasClass('bUp')) {
						return true;
					}else {
						return false;
					}
				},
		IsClose: function(){
					if (jFeed('#notificationClose').hasClass('bDown')) {
						return true;
					}else {
						return false;
					}
				},
		Open: function(){
				jFeed('#notificationClose').removeClass('bDown').addClass('bUp').html('Gizle');
				jFeed('#notification_place').show();
			},
		Close:function(){
				Feeds.PagingNotification.isAppend = false;
				jFeed('#notificationClose').removeClass('bUp').addClass('bDown').html('GÃ¶ster');
				jFeed('#notification_place').hide();
		},
		ArrowClick: function(){
				if (Layout.IsClose()) {
					
					if (Feeds.CurrentTab == 'unread') {
						Feeds.GetUnreadNotifications();
					}else if (Feeds.CurrentTab == 'all') {
						Feeds.PagingNotification.page = 1;
						Feeds.GetAllNotifications();
					}
					Layout.Open();
					
				}else if (Layout.IsOpen()) {
					Layout.Close();
					jFeed('#'+Feeds.GetNotificationContentDiv()).empty();
				}
		},
		UnreadTabClick: function() {
				//Check avaible for request
				if (!Control.isRequestAvailable()) {
					return false;
				}else {
					//indicate request is taken for unread notifications
					Control.requestSend();
				}
				Feeds.PagingNotification.isAppend = false;
				jFeed('#l_unread').addClass('bTabLinkActive');
				jFeed('#l_all').removeClass('bTabLinkActive');
				Feeds.CurrentTab = 'unread';
				/*if (jFeed('#p_unread').html().length == 0) {
					Feeds.GetUnreadNotifications();
				}*/
				Feeds.GetUnreadNotifications();
				if (Layout.IsClose()) {Layout.Open()};
				jFeed('#p_all').hide().empty();
				jFeed('#p_unread').show();
		},
		AllTabClick: function() {
				if (!Control.isRequestAvailable()) {
					return false;
				}else {
					//indicate request is taken for unread notifications
					Control.requestSend();
				}
				Feeds.PagingNotification.isAppend = false;
				Feeds.PagingNotification.page = 1;
				jFeed('#l_unread').removeClass('bTabLinkActive');
				jFeed('#l_all').addClass('bTabLinkActive');
				Feeds.CurrentTab = 'all';
				
				/*if (jFeed('#p_all').html().length == 0) {
					Feeds.GetAllNotifications();
				}*/
				Feeds.GetAllNotifications();
				if (Layout.IsClose()){Layout.Open();};
				jFeed('#p_unread').hide().empty();
				jFeed('#p_all').show();
		},
		GenerateLayout : function(){
			var xhtmlContent = "";
			//Notification Div
			if (this.showNotification) {
				xhtmlContent 	+= '<div class="bildirimContain clr">';
				xhtmlContent	+= '<div class="bildirimTitleContain clr">';
				xhtmlContent	+= '<h2 class="bildirimTitle">Bildirimler</h2>';
				xhtmlContent	+= '<a  class="bTabLink" id="l_unread">Okunmamışlar<span id="notification_count" style="display:inline;"></span></a><a  class="bTabLink" id="l_all">Tümü</a>';
				xhtmlContent 	+= '<a  id="notificationClose" class="bildirimUpDown bDown">Göster</a>';
				xhtmlContent	+= '</div>';
				xhtmlContent	+= '<div id="notification_place"  style="display:none;">';
				xhtmlContent	+= '<ul class="unread_notifications" id="p_unread"></ul>';
				xhtmlContent	+= '<ul class="all_notifications" id="p_all" style="display:none;"></ul>';
				xhtmlContent	+= '<div class="blinkAllContain" id="'+this.moreNotificationWidget+'"><a>Daha fazla göster</a></div>';
				xhtmlContent 	+= '</div>';
				xhtmlContent 	+= "</div>";
			}else {
				
			} 
			
			//Init Feed Div
			xhtmlContent += '<div class="feedHiddenButtonBac clr"><div class="feedBslContain">';
			if (Feeds.PageOwnerId == Feeds.Username) {
				xhtmlContent += '<a id="f_news" class="active">Haberlerim</a> - <a id="f_only_me">Sadece Ben</a>';
			}else {
				xhtmlContent += 'Haberlerim';
			}
			xhtmlContent += '</div>';
			
			xhtmlContent +='<a id="feedClose" class="bildirimUpDown bUp">Gizle</a>';
			//Search !
			if (Feeds.PageOwnerId == Feeds.Username || Feeds.FeedTab == 'search') {
				xhtmlContent += '<div class="feedSearchContain clr">';
				xhtmlContent += '<input type="text" value="Ara" class="feedSearchBox" id="feedSearchInput" autocomplete="off"/><ul id="f_suggest" class="feedSearchList"></ul><a class="feedSearchButton" id="feedSearch">Ara</a>';
				xhtmlContent += '</div>';
			}
			xhtmlContent += '</div>';
			
			xhtmlContent += '<div class="newFeedContain clr">';
			xhtmlContent += '</div>';
			xhtmlContent += '<div class="feedHideShow "></div>';
			xhtmlContent += '<div class="newFeedHideContain" style="display:none;">';
			xhtmlContent += '</div>';
			
			//Photo Overlay
			xhtmlContent += '<div id="fPhotoOverlay" style="display:none;" rel="div.overlay"></div>';
			
			//Share Overlay
			xhtmlContent += '<div id="shareOverlay" class="fShareContain clr" rel="div.overlay" style="display:none;">';
			xhtmlContent += '<a class="fsClose" onclick="jFeed.closeOverlay();">Kapat</a>';
			xhtmlContent += '<div class="fShareContent clr">';
			xhtmlContent += '<h1>Sosyal Ağlarda Paylaş</h1>';
			xhtmlContent += '<form>';
			xhtmlContent += '<div class="fsRow clr"><label>URL</label><input type="text" id="f_url" /></div>';
			xhtmlContent += '<div class="fsRow clr"><label id="l_short_url">Kısa URL</label><input type="text" id="f_short_url" /></div>';
			xhtmlContent += '<div class="fsRow clr"><label>Hızlı bağlantılar</label>';
			xhtmlContent += '<div class="fShareIcoContain clr">';
			xhtmlContent += '<a class="s_option" t="ek" target="_blank"><img src="http://img3.mynet.com/eksenim/ico/e.gif" border="0" alt="Eksenim\'de paylaş"/></a>';
			xhtmlContent += '<a class="s_option" t="fb" target="_blank"><img src="http://img3.mynet.com/eksenim/ico/f.gif" border="0" alt="Facebook\'ta paylaş"/></a>';
			xhtmlContent += '<a class="s_option" t="tw" target="_blank"><img src="http://img3.mynet.com/eksenim/ico/t.gif" border="0" alt="Twitter\'da paylaş"/></a>';
			xhtmlContent += '<a class="s_option" t="ff" target="_blank"><img src="http://img3.mynet.com/eksenim/ico/ff.gif" border="0" alt="Friendfeed\'de paylaş"/></a>';
			xhtmlContent += '</div>';
			xhtmlContent += '</div>';
			xhtmlContent += '</form>';
			xhtmlContent += '</div>';
			xhtmlContent += '</div>';
			
			
			xhtmlContent += '<div id="'+this.moreFeedWidget+'"></div>';
			jFeed('#' + this.Container).html(xhtmlContent);
			jFeed('#'+this.moreFeedWidget).bind('click', function(){
				if (Feeds.FeedTab == 'default') {
					Feeds.GetFeeds();
				}else if (Feeds.FeedTab == 'minifeed') {
					Feeds.GetMiniFeed();
				}else if (Feeds.FeedTab == 'search') {
					Fsearch.Search();
				}
			});
			jFeed('#feedClose').bind('click', function(){
				var status = jFeed(this).html();
				if (status == 'Gizle') {
					jFeed(this).removeClass('bUp').addClass('bDown');
					jFeed(this).html('Göster');
				}else {
					jFeed(this).removeClass('bDown').addClass('bUp');
					jFeed(this).html('Gizle');
				}
				jFeed('.newFeedContain').toggle();
				jFeed('#'+Layout.moreFeedWidget).toggle();
			});
			
			
			//Bind Necessary actions to Links
			jFeed("#notificationClose").bind('click',this.ArrowClick);
			jFeed("#l_unread").bind('click', this.UnreadTabClick);
			jFeed("#l_all").bind('click', this.AllTabClick);
			jFeed("#f_only_me").bind('click', function(){
				jFeed(this).addClass('active');
				jFeed('#f_news').removeClass('active');
				Feeds.ClearFeedArea();
				Feeds.FeedTab = 'minifeed';
				Feeds.GetMiniFeed();
			});
			jFeed('#f_news').bind('click', function() {
				jFeed(this).addClass('active');
				jFeed('#f_only_me').removeClass('active');
				Feeds.ClearFeedArea();
				Feeds.FeedTab = 'default';
				Feeds.GetFeeds();
			});
			
			
			/* .Net - Chrome auto submit form hack ! */
			jFeed('#aspnetForm').bind('submit',function (event){
				return false;
			});
			
			/*Search function bindings*/
			jFeed('#feedSearchInput').bind('click', function(){
				if (jFeed(this).val() == 'Ara') {
					jFeed(this).val('');
				}
			}).bind('keyup',function(event){
					if (event.keyCode == '40') {
						Fsuggest.MoveDown();
					}else if (event.keyCode == '38') {
						Fsuggest.MoveUp();
					}else if (event.keyCode == '13') {
						jFeed('#feedSearch').click();
					}else {
						var text = jFeed(this).val(); 
						Fsuggest.Init(text);
					}
			});
						
			jFeed('#feedSearch').bind('click', function(){
				//Default search in friends
				var text = jFeed('#feedSearchInput').val();
				if (text.length >= 3) {
					Fsearch.Init(1);
					Fsearch.Search();
					Fsuggest.ClearSuggest();
				}
			});
			
		}
	};
	var Fsuggest = {
			Init : function(text) {
				if (text.length >= 3) {
					var xhtml = '<li f="1"><b>' + text + '</b> ile arkadaşlarında ara</li>';
					xhtml += '<li f="0"><b>' + text + '</b> ile herkesde ara</li>';
					jFeed('#f_suggest').html(xhtml);
					jFeed('#f_suggest li').bind('mouseover',function(){
						jFeed('#f_suggest li').removeClass('selected');
						jFeed(this).addClass('selected');
					});
				}else {
					Fsuggest.ClearSuggest();
				}
				Fsuggest.BindActions();
			},
			BindActions: function() {
				jFeed('#f_suggest li').bind('click', function() {
					var isFriendSearch = jFeed(this).attr('f');
					Fsearch.Init(isFriendSearch);
					Fsearch.Search();
					Fsuggest.ClearSuggest();
				})
			},
			ClearSuggest: function() {
				jFeed('#f_suggest').empty();
			},
			MoveDown: function() {
				var suggests = jFeed('#f_suggest li').length;
				if (suggests > 0) {
					var selected = jFeed('#f_suggest li.selected');
					if (selected.length == 0) {
						jFeed('#f_suggest li[f=1]').addClass('selected');
					}else {
						var x = selected.attr('f');
						if (x == "1") {
							selected.removeClass('selected');
							jFeed('#f_suggest li[f=0]').addClass('selected');
						}
					}
				}
			},
			MoveUp:function() {
				var suggests = jFeed('#f_suggest li').length;
				if (suggests > 0) {
					var selected = jFeed('#f_suggest li.selected');
					if (selected.length > 0) {
						if (selected.attr('f') == "0") {
							selected.removeClass('selected');
							jFeed('#f_suggest li[f=1]').addClass('selected');
						}
					}
				}
			}
	};
	
	
	var DateParser = {
		periods : new Array("saniye", "dakika", "saat", "gün", "hafta", "ay", "yıl", "asır"),
		lengths : new Array("60","60","24","7","4.35","12","100"),					
		getDifference: function (timestamp, currentDateTimeStamp) {
			var difference = currentDateTimeStamp - (timestamp);
			if (difference == 0) {
				return "şimdi";
			}
			if (difference > 0) {
				var ending = " önce";
			}else {
				difference = -1 * difference;
				var ending = " sonra";
			}
			for (j=0; difference>=this.lengths[j]; j++) {
				difference /= (this.lengths[j]);
			}
			difference = Math.round(difference);
			return difference + ' ' + this.periods[j] + ending;
		}
	};
	var fVideo = {
		flashvars: {
			'videolist':'',
			'autoplay': '1'
		},
		params: {
			'allowScriptAccess':'always',
			'wmode': 'transparent',
			'allowFullScreen': true
		},
		attributes: {
			'id':'flash',
			'name': 'flash'
		},
		width: '480',
		height: '360',
		playerUrl: 'http://video.mynet.com/flvplayers/vplayer1.swf',
		videoListUrl: 'http://video.mynet.com/batch/video_xml_embed.php?video_id=',
		playVideo: function (videoId, placeHolder,app_id) {
					var rand = Math.floor(Math.random()*100000+1);
					fVideo.flashvars.videolist = fVideo.videoListUrl + videoId + '-' + app_id + '-' + rand;
					swfobject.embedSWF(fVideo.playerUrl, placeHolder, fVideo.width, fVideo.height, '9.0.0', 'expressIntall.swf', fVideo.flashvars, fVideo.params, fVideo.attributes );
		}
	};
	
	var bVideo = {
		height: '320',
		width:'400',
		playerUrl: 'http://birgo.mynet.com/swf/outside_player.swf?1',
		flashVars : {
				'movieUrl' : ''
		},
		params: {
				'scale': 'noscale',
				'allowfullscreen': true
		},
		attributes: {},
		playVideo: function(videoId,placeHolder) {
			//bVideo.playerUrl = bVideo.playerUrl + '?movieUrl=' + videoId;
			bVideo.flashVars.movieUrl = videoId;
			swfobject.embedSWF(bVideo.playerUrl,placeHolder, bVideo.width, bVideo.height, '9.0.0', 'expressInstall.swf',bVideo.flashVars,bVideo.params,bVideo.attributes);	
		}
	}
	
	var Avatar = {
		eHash : [29,1000],
		eksenimUrl: 'http://i.eksenim.mynet.com/',
		getPicture: function (user) {
						return 'http://profil.eksenim.mynet.com/image?un=' + user;
		},
		getDefault: function (img) {
				img.src = "http://s.mynet.com/eksn1/DefaultImages/avatar-m.gif";
		}
	};
	
	var Control = {
		waitingRequest : false,
		isRequestAvailable : function () {
								if (Control.waitingRequest) {
									return false;
								}else {
									return true;
								}
		},
		requestDone : function () {
						Control.waitingRequest = false;
		},
		requestSend : function () {
						Control.waitingRequest = true;
		}
	};

	var Flike = {
		Limit	: 500,
		ChangeLike: function(feed_id, status, hash){
			if (Control.isRequestAvailable()) {
				Control.requestSend();
				jFeed.ajax({
					type: 'GET',
					url: Feeds.LikeUrl,
					dataType: 'jsonp',
					data: 'op='+status+'&fid='+feed_id+'&username='+Feeds.Username + '&h=' + hash,
					success: function (data) {
						var element = jFeed('.feedCommentsContain[fid=' + feed_id + '] div.feedCommentButton a.l_feed');
						var app_id = jFeed('.feedCommentsContain[fid=' + feed_id + ']').attr('aid');
						if (data.result) {
							if (status == "set") {
								Flike.AddLikers(Feeds.Username, feed_id, app_id);
								element.attr('s',1).html('Beğenmekten vazgeç');			
							}else if (status == "unset") {
								Flike.RemoveLikers(Feeds.Username,feed_id);
								element.attr('s',0).html('Beğen');
							}
						}else {
							if (status == "set") {
								element.attr('s',1).html('Bunu önceden beğenmişsiniz.Beğenmekten vazgeç');
							}
						}
						Control.requestDone();
					},
					error: this.HandleError
				});
			}
		},
		ShowLikers: function(feedLikers, totalLikes, app_id, feed_id) {
			var prefixProfileUrl = AppLinks.getAppProfile(app_id);
			var xhtmlContent = "";
			
			if (feedLikers.length > 0) {
				for (i=0; i<feedLikers.length; i++) {
					var profileLink = prefixProfileUrl + feedLikers[i];
					xhtmlContent += '<a href="' + profileLink + '">' + feedLikers[i] + '</a>, ';					
				}
			}
			if (feedLikers.length > 0) {
				xhtmlContent = xhtmlContent.substr(0,(xhtmlContent.length-2)); 
			}
			if ((totalLikes - feedLikers.length) > 0) {
				xhtmlContent += '<span class="otherLikes">';
				if (feedLikers.length > 0) {
					xhtmlContent += '<span class="conj"> ve </span>';
				}
				xhtmlContent += '<a onclick="Flike.FetchOthers(\''+feed_id+'\',\''+app_id+'\')">' + (totalLikes - feedLikers.length) + ' kişi</a> ';
				xhtmlContent += '</span>';
			}  
			if (feedLikers.length > 0 || (totalLikes - feedLikers.length) > 0) {
				xhtmlContent += " bunu beğendi";
			}
			jFeed('.feedCommentsContain[fid='+feed_id+'] div.feedCommentLikeContain').html(xhtmlContent);
		},
		AddLikers: function (username, feed_id, app_id) {
			var likeContain = jFeed('.feedCommentsContain[fid='+feed_id+'] div.feedCommentLikeContain');
			var userProfileLink = Flike.GetUserProfileLink(username,app_id); 
			if (jFeed.trim(likeContain.html()) == "") {
				likeContain.html( userProfileLink + ' bunu beğendi');
			}else {
				if (likeContain.find('a').size() == 1) {
					likeContain.prepend(Flike.GetUserProfileLink(username,app_id) + '<span class="conj"> ve </span> ');
				}else {
					likeContain.prepend(Flike.GetUserProfileLink(username,app_id) + ', ');
				}
			}
		},
		RemoveLikers: function (username,feed_id) {
			var likeContain = jFeed('.feedCommentsContain[fid='+feed_id+'] div.feedCommentLikeContain'); 
			var rmRegexp = new RegExp (",?( *)?<a[^>]*>"+username+"<\/a>","i");
			var likeString = likeContain.html();
			likeString = likeString.replace(rmRegexp,'');
			var cmRegexp = new RegExp ("^(,| )*","i");
			likeString = likeString.replace(cmRegexp,'');
			likeContain.html(likeString);
			var numOfLinks = likeContain.find('a').size();
			if (numOfLinks == 0) {
				likeContain.html('');
			}else if (numOfLinks == 1) {
				likeContain.find('span.conj').remove();
			}
		},
		GetUserProfileLink : function(username, app_id){
			var profileLink = AppLinks.getAppProfile(app_id) + username;
			return '<a href="' + profileLink + '">' + username + '</a>';
		},
		FetchOthers: function (feed_id,app_id){
			if (Control.isRequestAvailable()) {
				Control.requestSend();
				jFeed.ajax({
					type:'GET',
					url:Feeds.LikeUrl,
					dataType:'jsonp',
					data:'op=g&fid='+feed_id,
					success:function(data) {
						var prefixProfileUrl = AppLinks.getAppProfile(app_id);
						var xhtmlContent = "";
						for (i=0; i<data.length; i++) {
							var profileLink = prefixProfileUrl + data[i];
							xhtmlContent += '<a href="'+profileLink+'">' + data[i] + '</a>';
							if (i == data.length-2) {
								xhtmlContent += '<span class="conj"> ve </span>';
							}else if (i== data.length-1) {
								xhtmlContent += " bunu beğendi ";
							}else {
								xhtmlContent += ", ";
							}
						}
						jFeed(".feedCommentsContain[fid="+feed_id+"] div.feedCommentLikeContain").html(xhtmlContent);
						Control.requestDone();
					},
					error: this.HandleError
				});
			}
		}
	}	
	var Fcomment = {
		Limit	  : 500,
		MaxLength : 255,
		ShowComments: function(objComment, totalComments, feed_id, app_id,time, feed_owner) {
			if (totalComments > 0) {
				var xhtmlContent = "";
				//Add First
				if (objComment.f.c != "") {
					xhtmlContent += Fcomment.ParseComment(objComment.f, app_id, time, feed_owner);
				}
				//More Link
				if (totalComments > 2) {
					var moreComment = totalComments - 2;
					xhtmlContent += '<div class="feedMoreComment"><a class="moreComment">'+moreComment+' yorum daha ...</a></div>';
				}
				
				if (typeof(objComment.l.c) != "undefined" && totalComments > 1) {
					xhtmlContent += Fcomment.ParseComment(objComment.l, app_id, time, feed_owner);
				}
				jFeed(".feedCommentsContain[fid="+feed_id+"] div.feedCommentContent").html(xhtmlContent);
			}
		},
		ParseComment: function (objComment, app_id, time, feed_owner) {
			var xhtmlContent = '<div class="feedCommentList clr" cid="'+objComment.cid+'">';
			xhtmlContent += objComment.c;
			xhtmlContent += ' - ' + AppLinks.getAppProfileLink(app_id,objComment.u);
			xhtmlContent += ' <span class="feedAddTime">(' + DateParser.getDifference(objComment.dt, time) + ') </span>';
			if (objComment.u == Feeds.Username || Feeds.Username == feed_owner || Feeds.Username == 'eksenim') {
				xhtmlContent += '<a class="feedCommentDelete" onclick="Fcomment.Delete(this);">Sil</a>';
			}
			xhtmlContent += '</div>';
			return xhtmlContent; 
		},
		Save: function(element){
			var parent = element.parents('.feedCommentsContain');
			var feed_id = parent.attr('fid');
			var app_id = parent.attr('aid');
			var hash = parent.attr('id');
			
			var text = element.prev().val();
			if (jFeed.trim(text) == "") {
				return;
			}
			if (text.length > Fcomment.MaxLength) {
				element.parent().children('span.f_error').html('En fazla ' + Fcomment.MaxLength + ' karakter girebilirsiniz');
				return;
			}
			text = encodeURIComponent(text);
			Fcomment.DisableComment(element);
			jFeed.ajax({
				type: 'GET',
				url: Feeds.CommentUrl,
				dataType:'jsonp',
				data:'op=s&fid='+feed_id + '&c=' + text + '&u=' + Feeds.Username + '&h=' + hash,
				success: function (data) {
					if (data.result == -1) {
						myHtmlLogin.login();
					}
					if (data.status == 1) {
						var xhtmlContent = Fcomment.ParseComment(data.co,app_id, data.t);
						element.parents('.feedCommentsContain').children('div.feedCommentContent').append(xhtmlContent);
					}					
					Fcomment.EnableComment(element);
				}
			});
		},
		Delete: function(element){
			var cid = jFeed(element).parent().attr('cid');
			var fid = jFeed(element).parents('.feedCommentsContain').attr('fid');
			jFeed.ajax({
				type:'GET',
				url: Feeds.CommentUrl,
				dataType:'jsonp',
				data:'op=d&cid='+ cid + '&fid=' + fid,
				success: function(data) {
					if (data.result) {
						jFeed(element).parent().remove();
					}
				}
			});
		},
		DisableComment: function (element) {
			element.attr('disabled', true).parent().children('textarea').attr('disabled', true);
			element.parent().children('span.f_error').html(Feeds.WaitingIcon);
		},
		EnableComment: function(element) {
			element.attr('disabled', false).parent().children('textarea').attr('disabled', false).val('');
			element.parent().children('span.f_error').html('');
		},
		MoreComments: function(feed_id) {
			var container = jFeed('.feedCommentsContain[fid='+feed_id+']');
			var app_id = container.attr('aid');
			var uid = container.attr('uid');
			var hash = container.attr('id');
			
			container.children('div.feedCommentContent').children('div.feedMoreComment').html(Feeds.WaitingIcon);
			jFeed.ajax({
				type:'GET',
				url: Feeds.CommentUrl,
				data:'op=g&fid='+feed_id+'&h='+hash,
				dataType:'jsonp',
				success: function(data) {
					var xhtmlContent = "";
					jFeed.each(data.c, function (i, comment) {
						if (typeof(comment) == "object") {
							xhtmlContent += Fcomment.ParseComment(comment, app_id, data.t,uid);
						}
					});
					container.children('div.feedCommentContent').html(xhtmlContent);
					if (Feeds.FeedTab == 'search') {
						Fsearch.Highlight();
					}
				}
			});
		},
		ShowFriendCommenters: function (friendCommenters, totalComments, appId, feedId) {
			
			var prefixProfileUrl = AppLinks.getAppProfile(appId);
			var xhtmlContent = "";
			
			if (friendCommenters.length > 0) {
				for (i=0; i<friendCommenters.length; i++) {
					if (friendCommenters[i] != Feeds.Username) {
						var profileLink = prefixProfileUrl + friendCommenters[i];
						xhtmlContent += '<a href="' + profileLink + '">' + friendCommenters[i] + '</a>, ';
					}
				}
			}
			if (friendCommenters.length > 0) {
				xhtmlContent = xhtmlContent.substr(0,(xhtmlContent.length-2)); 
			}
			  
			if (friendCommenters.length > 0 && (totalComments) > 2 && xhtmlContent != "" && Feeds.Username != "") {
				xhtmlContent = "Arkadaşlarından " + xhtmlContent + " buna yorum yazdı.";
				//xhtmlContent += " buna yorum yazdÄ±";
				jFeed('.feedCommentsContain[fid='+feedId+'] div.feedCommentFriendContain').html(xhtmlContent);
			}
		}
	};
	var AppLinks = {
		getApps: function(){
			var apps = new Array();
			apps["4c2a17c7f77ca1b2d39e26df0a164b8e"] = {"profile" : "http://kavun.mynet.com/#|profile/", 
														"link": "http://kavun.mynet.com",
														"name": "kavun"};
			apps["bbb8b4f18df1b4939ffa7af657eb76a7"] = {"profile" : "http://eksenim.mynet.com/",
														"link": "http://eksenim.mynet.com/",
														"name": "eksenim"};
			apps["6f8f2cee8c797fe3cc89759ce23123f9"] = {"profile" : "http://video.mynet.com/",
														"link": "http://video.mynet.com/",
														"name": "video"};
			
			apps["084fbfb027c193c8e8af209087c9b8b8"] = {"profile" : "http://eksenim.mynet.com/",
														"link": "http://bilenkazanir.mynet.com/",
														"name": "bilenkazanir"}; 
			return apps;
		},
		getAppProfile: function(app_id){
			var apps = AppLinks.getApps();
			if (typeof(apps[app_id]) == 'object') {
				return apps[app_id].profile;	
			}else {
				return "http://eksenim.mynet.com/";
			}
		},
		getAppProfileLink: function (app_id, username) {
			var link = AppLinks.getAppProfile(app_id) + username;
			var xhtmlContent = '<a href="'+link+'">'+username+'</a>';
			return xhtmlContent;
		},
		concatAppProfileLink: function (prefix, username) {
			return String(prefix).replace('<source>', username);
		}
	}
	
	
	function Paginator(limit) {
		this.limit = limit;
		this.totalItems = '';
		this.totalPages = '';
		this.page		= 1;
		this.isAppend	= false;
		this.hasNextPage = function () {
							if (this.page >= this.totalPages) {
								return false;
							}else {
								this.page = this.page + 1;
								return true;		
							}
						};
	
	}
	var Ftunnel = {
		TryAuth:0,
		IframeUrl: "http://feed.mynet.com/f.html",
		OnlineUrl: "http://livefeed.mynet.com/app/online.php",
		Init: function(){
			Timer.Init();
			jFeed.getScript("http://s.mynet.com.tr/feed/jquery.postmessage.js", function() {
			
				/* Create iframe */
				var d = new Date();
				var iframe = document.createElement("iframe");
				iframe.setAttribute("name", 'f_iframe');
				iframe.setAttribute("id", 'f_iframe');
				iframe.setAttribute("src", Ftunnel.IframeUrl + '?r=' + d.getTime());
				iframe.style.width = "0px";
				iframe.style.height = "0px";
				
				if (iframe.attachEvent) {
					iframe.attachEvent('onload', Ftunnel.OpenFirstConnection);
				}else if (iframe.addEventListener) {
					iframe.addEventListener('load', Ftunnel.OpenFirstConnection,false);
				}else {
					iframe.onload = Ftunnel.OpenFirstConnection;
				}
    			document.body.appendChild(iframe);				
    			
				/* Bind iframe responses */
				jFeed.postmessage.bind("response", function(data) {
					var responseData =  eval("(" + data + ")");
					if (responseData.ns_changed == 1) {
						Cookie.SetNsCookie(); 
					}
					Ftunnel.HandleResponse(responseData);
					if (Ftunnel.CheckAvaible()) {
						Ftunnel.SendCommand('connect',200);
					}
				});
								
			});
		},
		OpenFirstConnection: function (){
			/* Open connection */
			Ftunnel.IframeStatus = 'loaded';
			Ftunnel.SendCommand('connect', 500);
		},
		HandleResponse: function(data) {
			var timeout = 0;
			if (typeof data.error == 'string') {
				if (data.error == 'timeout') {
					//Okay move on
				}else if (data.error == 'user_authentication') {
					Ftunnel.TryAuth += 1;
					timeout = 500; //Try after 500miliseconds
				}else {
					alert (data.error);
				}
			}
			//console.log(data);
			if (typeof data.ok == 'string') {
				feedData = eval("(" + data.ok + ")");
				if (Feeds.FeedTab == 'default' || feedData.f[0].o == Feeds.PageOwnerId) {
					if (!Ftunnel.CheckFeedExists(feedData.f[0].fid)) {
						Ftunnel.DisplayFeed(feedData);
					}
					if (typeof feedData.co == 'object') {
						if (!Ftunnel.CheckCommentExists(feedData.co.cid)) {
							Ftunnel.DisplayComment(feedData.co, feedData.f[0].app, feedData.t, feedData.f[0].o, feedData.f[0].fid);
						}
					}else if (typeof feedData.l == 'string') {
						Ftunnel.DisplayLike(feedData.l, feedData.f[0].fid, feedData.f[0].app);
					}
				}
			}
			Ftunnel.ConnectionStatus = 'free';
			
		},
		CheckCommentExists: function (cid) {
			if (jFeed('div.feedCommentList[cid='+cid+']').length) {
				return true;
			}else {
				return false;
			}
		},
		SetOnline: function() {
			 jFeed.ajax ({
					type: 'GET',
					url: Ftunnel.OnlineUrl,
					dataType: 'jsonp',
					success:function (data) {
						//Do nothing for now 
					}, 
					error: this.HandleError
				});
		},
		SendCommand: function (data,timeout) {
			Ftunnel.ConnectionStatus = 'waiting';
			window.setTimeout(function(){
				jFeed.postmessage({
					target: window.frames["f_iframe"],
					type: "parent_message",
					data: {command: data, ns: Cookie.GetNsCookie(), u:Feeds.Username}
				});
			},timeout);
		},
		
		ConnectionStatus: 'free',
		UserStatus: 'active',
		IframeStatus: 'loading',
		CheckAvaible: function(){
			if (Ftunnel.ConnectionStatus == 'free' && Ftunnel.UserStatus == 'active' && Ftunnel.TryAuth < 3 && Ftunnel.IframeStatus == 'loaded') {
				return true;
			}else {
				return false;
			}
		},
		CheckFeedExists: function(feed_id){
			if (jFeed('#feed_' + feed_id).length) {
				return true;
			}else {
				return false;
			}
		},
		DisplayFeed: function (data) {
			FeedParser.Position = 'prepend';
			FeedParser.Parse(data);
			FeedParser.Position = 'append';
			var offset = jFeed('#feed_' + data.f[0].fid).height();
			Ftunnel.FixScroll(offset);
		},
		DisplayComment: function(objComment, app_id, time, feed_owner,feed_id){
			//If comment owner is the username, do not show it again
			if (objComment.u == Feeds.Username) {
				return;
			}
			var xhtmlContent = Fcomment.ParseComment(objComment, app_id, time, feed_owner);
			jFeed(".feedCommentsContain[fid="+feed_id+"] div.feedCommentContent").append(xhtmlContent);
			var offset = jFeed(".feedCommentList[cid="+objComment.cid+"]").height();
			Ftunnel.FixScroll(offset);
		},
		DisplayLike: function(data, feed_id, app_id){
			//If liker is the username do not show it again
			if (data == Feeds.Username) {
				return;
			}
			Flike.RemoveLikers(data,feed_id);
			if (jFeed('.feedCommentsContain[fid='+feed_id+'] div.feedCommentLikeContain').html() == ""){
				Flike.AddLikers(data,feed_id,app_id);
				Ftunnel.FixScroll(jFeed('.feedCommentsContain[fid='+feed_id+'] div.feedCommentLikeContain').height());	
			}else {
				Flike.AddLikers(data,feed_id,app_id);
			}	
			
		},
		FixScroll: function (offset) {
			var curPos = jFeed(document).scrollTop();
			//console.log(offset);
			if (curPos != 0) {
				jFeed(document).scrollTop(curPos + offset);
			}
		}
};
var Timer = {
	IdleTime : 0,
	StopTime : 1200, //10 min.
	Increment: function(){
		Timer.IdleTime++;
		if (Timer.IdleTime > Timer.StopTime) {
			Ftunnel.UserStatus = 'idle';			
		}else {
			Ftunnel.UserStatus = 'active';
			if (Ftunnel.CheckAvaible()) {
				Ftunnel.SetOnline();
				Ftunnel.SendCommand('connect',500);
			}
		}
	},
	Reset: function(){
		//console.log('Timer reset');
		Timer.IdleTime = 0;
	},
	Init: function(){
		var idleInterval = setInterval("Timer.Increment();", 1000);
		jFeed(document).mousemove(function(){
			Timer.Reset();
		});
	}
};

function Olasilik(text) {
    var replaces = "şğüçıöü ŞĞÜİÇÖ";
    var replaces_true = "sguciou SGUICO";
    var t = text.toLowerCase();
    for(var i=0;i<replaces.length;i++) {
          t = t.replace(eval("/"+replaces.substr(i,1)+"/gi"),replaces_true.substr(i,1));
    }
    var olasilik = new Array();
    var z = text.toLowerCase()
    var before = z;
    for(var i=0;i<replaces_true.length;i++) {
    	if (text.toLowerCase() != z && z != before) { 
          olasilik.push(z);
          z = before;
    	}
        z = z.replace(eval("/"+replaces_true.substr(i,1)+"/gi"),replaces.substr(i,1));
    }
    if (before != z) {
    	olasilik.push(z)
    }
    olasilik.push(t);
    return olasilik;
}

jQuery.fn.highlight = function(pat) {
    function innerHighlight(node, pat) {
     var skip = 0;
     if (node.nodeType == 3) {
      var pos = node.data.toUpperCase().indexOf(pat);
      if (pos >= 0) {
       var spannode = document.createElement('span');
       spannode.className = 'highlight';
       var middlebit = node.splitText(pos);
       var endbit = middlebit.splitText(pat.length);
       var middleclone = middlebit.cloneNode(true);
       spannode.appendChild(middleclone);
       middlebit.parentNode.replaceChild(spannode, middlebit);
       skip = 1;
      }
     }
     else if (node.nodeType == 1 && node.childNodes && !/(script|style)/i.test(node.tagName)) {
      for (var i = 0; i < node.childNodes.length; ++i) {
       i += innerHighlight(node.childNodes[i], pat);
      }
     }
     return skip;
    }
    return this.each(function() {
     innerHighlight(this, pat.toUpperCase());
    });
};

jQuery.fn.removeHighlight = function() {
return this.find("span.highlight").each(function() {
 this.parentNode.firstChild.nodeName;
 with (this.parentNode) {
  replaceChild(this.firstChild, this);
  normalize();
 }
}).end();
};