var messageid = 0;
var last_flow_id = 9999999999999999;
var icon_bubble_timeout;
var div_hover = [ "header_menu_item", "content_menu_item", "content_menu_item_edit", "game_list_small", "action_button", "editable", "front_supplier", "search_sort_item", "search_type_item", "flow_menu_button", "icon_button", "search_item", "c2a_container", "review_clickable" ];
var glink_pictures = [];
var ajax
var months = ["", "January", "February", "March", "April", "May", "June", "July", "August", "September", "October", "November", "December"]


function ReadyBindEvents() {
	$(".game_list_medium").mouseenter(function() {
		$(this).addClass('game_list_medium_hover');
		$(this).children().filter('.game_list_medium_packshot').addClass('game_list_medium_hover_packshot');
	}).mouseleave(function() {
		$(this).removeClass('game_list_medium_hover');
		$(this).children().filter('.game_list_medium_packshot').removeClass('game_list_medium_hover_packshot');		
	});
	

	jQuery.each(div_hover, function() {
		divname = this;
		$("." + divname).unbind("mouseenter mouseleave").bind("mouseenter mouseleave", function(e) {
			if ($(this).hasClass($(this).attr('class').split(' ')[0] + "_active") == false) { 
				$(this).toggleClass($(this).attr('class').split(' ')[0] + "_hover");
			}
	    });
	});
	
	$(":button, :submit").unbind("mouseenter mouseleave").bind("mouseenter mouseleave", function(e) {
		if ($(this).hasClass("button_hover")) {
			$(this).removeClass("button_hover").css('background-color', '');		
		} else {
			$(this).addClass("button_hover").css('background-color', '#3d4550');
		}
    });
    
   $(".hidden-autoheight").each(function(){ 
		$(this).css("height", $(this).height()+"px").hide();
	}); 
	
	
	$(".user_list_icons_opacity_effect").mouseenter(function(){
		$(this).css('opacity', '1')
	}).mouseleave(function() {
		$(this).css('opacity', '0.7')
	});	
	
	$(".highlight_row").mouseenter(function() {
		$(this).addClass('highlight_row_hover');
	}).mouseleave(function() {
		$(this).removeClass('highlight_row_hover');
	});
	
	$(".user_list_icons_opacity_effect").css('opacity', '0.5');


	$(".icon_bubble_hover").mouseenter(function() {
		var obj = $(this);
		
		if (obj.hasClass('icon_bubble_hover') == false) return;
		if ($("#icon_bubble").css('display') != 0) $("#icon_bubble").css('display', 'none');
		$("#icon_bubble").html(obj.attr('bubble'));
		$("#icon_bubble").css('left', obj.offset().left  + (obj.innerWidth() / 2) - ($("#icon_bubble").width() / 2) - 8);
		$("#icon_bubble").css('top', obj.offset().top - ($("#icon_bubble").height() + 8) - 5);
		$("#icon_bubble").show();

	}).mouseleave(function() {
		$("#icon_bubble").hide();
	});	


	$(".follow_button").click(function () { 
		if ($(this).html() == 'Follow') {
			$(this).html('Unfollow')
			gid = $(this).attr('data');
			name = $(this).attr('data2');
			message_queue('text|You are now following <a href="/profile/' + name + '/">' + name +'</a>|s');
			$.post("/users/ajax/follow/", { action: 1, profile_id: gid } );
		} else {
			$(this).html('Follow')		
			gid = $(this).attr('data');
			name = $(this).attr('data2');
			message_queue('text|You stop following <a href="/profile/' + name + '/">' + name + '</a>|s');
			$.post("/users/ajax/follow/", { action: 0, profile_id: gid } );
		}
	});

	$(".comment_textarea").focus(function () { 
		$(".comment_hidden_" + $(this).attr('data')).show();
		$(this).removeClass('comment_textarea_defocus');
		$(this).addClass('comment_textarea_focus');
		if ($(this).val() == 'Write a comment...') $(this).val('');
		$(this).elastic();
	});

	$(".comment_textarea").blur(function () {
		if ($(this).val() == '') {
			$(".comment_hidden_" + $(this).attr('data')).hide();
			$(this).removeClass('comment_textarea_focus');
			$(this).addClass('comment_textarea_defocus');
			$(this).css('height', '13px');					
			$(this).val('Write a comment...');
		}
	});


	$(".placeholder").each(function () {
		$(this).val($(this).attr('placeholder'));
	});
	
	$(".placeholder").focus(function () {
		if ($(this).val() == $(this).attr('placeholder')) {
			$(this).val('');
			$(this).addClass('placeholder_focus');
		}
	});

	$(".placeholder").blur(function () {
		if ($(this).val() == '') {
			$(this).removeClass('placeholder_focus');
			$(this).val($(this).attr('placeholder'));
		}
	});
	
	$(".sharebar_textarea").focus(function () {
		if ($(this).val() == $(this).attr('placeholder') || $(this).val() == 'http://') {
			$(this).removeClass('sharebar_textarea_defocus');
			$(this).addClass('sharebar_textarea_' + $(this).attr('data') + '_focus');
			$("#sharebar_buttons_" + $(this).attr('data')).show();
			if ($(this).attr('data') == 'flow') $(this).elastic();
			if ($(this).val() == $(this).attr('placeholder')) {
				if ($(this).attr('data') == 'glink') {
					//$(this).val('http://');
					$(this).val('');
				} else {
					$(this).val('');				
				}				
			} 
		}

		if ($(this).attr('data') == 'glink' && $("#sharebar_edit_glink").css('display') == 'block') {
			$("#sharebar_edit_glink").hide();
			$("#sharebar_buttons_glink").show();
		}
		
	});

	$(".sharebar_textarea").blur(function () {
		if ($(this).val() == '' || $(this).val() == 'http://') {		
			$(this).removeClass('sharebar_textarea_' + $(this).attr('data') + '_focus');
			$(this).addClass('sharebar_textarea_defocus');
			$(this).css('height', '13px');
			$("#sharebar_buttons_" + $(this).attr('data')).hide();
			$("#sharebar_edit_glink_loading").hide();
			$("#sharebar_edit_glink").hide();			
			$(this).val($(this).attr('placeholder'));

		}
	});
	

	$('#sharebar_glink_game_input').autocomplete('/games/autocomplete/', {
		width: 260, multiple: false, matchContains: true, formatItem: autocomplete_formatItem, formatResult: autocomplete_formatResult, max: 30
	}).result(function(event, item) {
		$("#sharebar_glink_game_span").html(item[1]);
		$("#sharebar_glink_gameid_input").val(item[0]);

		if (isIE()) {
			setTimeout("hide('#sharebar_glink_game_input')", 0);
			setTimeout("show('#sharebar_glink_game_span')", 0);		
		} else {
			$("#sharebar_glink_game_input").hide();
			$("#sharebar_glink_game_span").show();
		}
		if (item[3] == '1') $("#sharebar_glink_game_icon").attr('src', MEDIA_URL + '/img/packshots/' + item[0] + '_icon32x32.jpg');
	});
	

	$("#sharebar_textarea_review").autocomplete('/games/autocomplete/', {
		width: 635, multiple: false, matchContains: true, formatItem: autocomplete_formatItem, formatResult: autocomplete_formatResult
	}).result(function(event, item) {
		document.location = '/game/' + item[2] + '/myopinion/'
	});
	
	$(".bluronenter").keydown(function(e) {
		if (e.keyCode == 13) {
			$(this).blur();
			return false;
		}
	});
		
	$("#sharebar_glink_game_span").click(function () {
		$("#sharebar_glink_game_span").hide();
		$("#sharebar_glink_game_input").show().focus();
		$("#sharebar_glink_game_icon").attr('src', MEDIA_URL + '/img/packshots/default_icon32x32.jpg');		
		$("#sharebar_glink_game_span").html('');
		$("#sharebar_glink_gameid_input").val('0');
	});
	
	$("#sharebar_glink_title").click(function () {
		$("#sharebar_glink_title").hide();
		$("#sharebar_glink_title_input").show().focus();
		$("#sharebar_glink_isautotitle").val('0');
	});
		
	$("#sharebar_glink_title_input").blur(function () {
		$("#sharebar_glink_title").text($("#sharebar_glink_title_input").val());
		$("#sharebar_glink_title_input").hide();
		$("#sharebar_glink_title").show();	
	});

	$("#sharebar_glink_description").click(function () {
		$("#sharebar_glink_description").hide();
		$("#sharebar_glink_description_input").show().focus();
		$("#sharebar_glink_isautodescription").val('0');	
		
	});
		
	$("#sharebar_glink_description_input").blur(function () {
		$("#sharebar_glink_description").text($("#sharebar_glink_description_input").val());
		$("#sharebar_glink_description_input").hide();
		$("#sharebar_glink_description").show();	
	});
	
	$("#sharebar_glink_nopicture_input").change(function () {
		if ($(this).attr('checked')) {
			$("#sharebar_glink_pictures_panel").fadeTo("normal", 0);
		} else {
			$("#sharebar_glink_pictures_panel").fadeTo("normal", 1);
		}
	});

	$(".hud_button_effect").mouseenter(function() {
		if ($(this).hasClass('hud_button_effect') == false) return;
		$(this).animate({opacity: "1"}, 100);
	}).mouseleave(function() {
		if ($(this).hasClass('hud_button_effect') == false) return;	
		$(this).animate({opacity: "0.5"}, 100);
	});
	
	$(".track_button").click(function () { 
		if ($(this).html() == 'Track') {
			$(this).html('Untrack');
			$.post("/users/ajax/track/", { action: 1, game_id: $(this).attr('data') }, function(data) {
				message_queue(data);
			});
		} else {
			$(this).html('Track');
			$.post("/users/ajax/track/", { action: 0, game_id: $(this).attr('data') }, function(data) {
				message_queue(data);
			});
		}
	});
	
	$(".addtomygames_button").click(function () { 
		message_queue('ajax|/users/ajax/mygames/popup/' + $(this).attr('data') + '/|i');
	});	
	
	$("#global_search_input").keydown(function(e) {
		if (e.keyCode == 13) document.location='/search/?search=' + $(this).val();
	});
	
	$("#header_search_go").click(function(e) {
		document.location='/search/?search=' + $("#global_search_input").val();
	});
	
	$(".c2a_container").mouseenter(function() {
		src = $(this).find('img').attr('src');
		$(this).find('img').attr('src', src.substr(0, src.length-4) + '_hover.gif');
	}).mouseleave(function() {
		src = $(this).find('img').attr('src');
		$(this).find('img').attr('src', src.substr(0, src.length-10) + '.gif');		
	});	
	
}

$(document).ready(function () {

	ReadyBindEvents();
	
	$("#login_box_button").click(function() {
		if ($("#login_box").hasClass('hidden')) {
			$("#login_box").animate({height: 'toggle', opacity: 1}, 300).removeClass('hidden');
			$(this).addClass('header_menu_item_hover_active');
		} else {
			$("#login_box").animate({height: 'toggle', opacity: 0}, 300).addClass('hidden');
			$(this).removeClass('header_menu_item_hover_active');		
		}
	});
	
	var kkeys = [], konami = "38,38,40,40,37,39,37,39,66,65";
	$(document).keydown(function(e) {
		kkeys.push( e.keyCode );

		if ( kkeys.toString().indexOf( konami ) >= 0 ){
			$(document).unbind('keydown',arguments.callee);
			$.post("/users/ajax/konami/", { oh: 'yeah' }, function(data) {
				if (data == '1') message_reload();
			});
			
		}
	});
	
	$(".front_supplier").click(function() {
		if ($(this).hasClass('clickable')) {
			$(".front_supplier_radiobox").removeClass('radiobox_checked');
			$("#" + $(this).attr('id') + "_radiobox").addClass('radiobox_checked');
			$(".front_supplier_panel").addClass('hidden');
			$("#" + $(this).attr('id') + "_panel").removeClass('hidden');
			
			if ($(this).attr('supplier_id') == '2' && $("#front_supplier2_price").html().substr(0, 1) == '<') { //AMAZON
				$.post('/store/ajax/amazon/price/', {'asin': $("#front_supplier2_price").attr('asin')}, function(data) {
					$("#front_supplier2_price").html(data);
				});
			}
		}
	});
	
});

function isIE() {
	if (jQuery.support.leadingWhitespace == true) {
		return false;
	} else {
		return true;
	}
}

function toggle(obj) {
	$(obj).toggle();
}

function hide(obj) {
	$(obj).hide();
}

function show(obj) {
	$(obj).show();
}

function slidetoggle(obj) {
	$(obj).slideToggle();
}
	
function autocomplete_formatItem(row) {
	return row[1];
}

function autocomplete_formatResult(row) {
	return row[1];
}

function admin_reveal() {
	$(".admin_reveal").slideToggle();
}

function message_reload() {
	$.get('/users/ajax/messages/get/', function(response){
		lines = response.split(/\r\n|\r|\n/);
		for (x in lines) {
			message_queue(lines[x]);
		}
	});
}

function message_queue(message) {
	messageid = messageid + 1
	data = message.split('|'); 
	text = '';
	type = data[0];
	
	if (type == 'text' || type == 'ajax' || type == 'success' || type == 'error') {
		if (type == 'ajax') {
			$.get(data[1] + '?messageid=' + messageid, function(response){
				if (response.substr(0,1) == '0') { 
					message_queue(response.substr(1));
				} else {
					message_create(messageid, type, response);		
				}
				
			});
		} else {
			message_create(messageid, type, data[1]);
		}
		
		if (data[2] == 'i') {
			//
		} else if (data[2] == 'l') {
			setTimeout("message_hide('" + messageid + "')", 9200);		
		} else {
			setTimeout("message_hide('" + messageid + "')", 5600);
		}
	} else if (type == 'analytics') {
		pageTracker._trackPageview(data[1]);
	} 
}

function message_create(id, type, text) {

	code = '<div id="message_id_' + id + '" class="message message_type_' + type + ' hidden" data="' + id +'">';
	code += '<div class="message_icon"><img src="' + MEDIA_URL + '/img/icon_message_' + type + '.png"></div>';
	if (type == 'ajax') code += '<div class="message_close" onclick="message_hide(\'' + id + '\');"><img src="' + MEDIA_URL + '/img/icon_message_close.png"></div>';	
	code += '<div id="message_id_' + id + '_content" class="message_content"></div>';
	code += '</div>'
	
	$("#hud_messages").append(code);
	$("#message_id_" + id + "_content").html(text);
	setTimeout("message_show('" + id + "')", 100);
}

function message_show(id) {
	h = ($("#message_id_" + id).height());
	$("#message_id_" + id).css('height', 0).show();
	
	$("#message_id_" + id).animate({height: h, marginTop: "3"}, 300);
	$("#message_id_" + id).animate({opacity: "1"}, 400);	
}

function message_hide(id) {
	$("#message_id_" + id).animate({opacity: "0"}, 400);
	$("#message_id_" + id).slideUp();	
}

function pwnz(ctype, oid) {
	$.post("/pwnz/ajax/add/", { content_type: ctype, object_id: oid },
		function(buffer){
			data = buffer.split('|')
			if (data[0] == 1) {
				var now = new Date();
				$(".pwnz_img_" + ctype + "_" + oid).attr('src', MEDIA_URL + '/img/pwnz_box_click.gif?' + now.getTime());
				$(".pwnz_counter_" + ctype + "_" + oid).html((parseInt($(".pwnz_counter_" + ctype + "_" + oid).html())+1));
				
				
				if ($("#hud_pwnz_slot_5").length > 0 && !$("#hud_pwnz_slot_5").hasClass('hidden')) { $("#hud_pwnz_slot_5").addClass('hidden');
				} else if ($("#hud_pwnz_slot_4").length > 0 && !$("#hud_pwnz_slot_4").hasClass('hidden')) { $("#hud_pwnz_slot_4").addClass('hidden');
				} else if ($("#hud_pwnz_slot_3").length > 0 && !$("#hud_pwnz_slot_3").hasClass('hidden')) { $("#hud_pwnz_slot_3").addClass('hidden');
				} else if ($("#hud_pwnz_slot_2").length > 0 && !$("#hud_pwnz_slot_2").hasClass('hidden')) { $("#hud_pwnz_slot_2").addClass('hidden');
				} else { $("#hud_pwnz_slot_1").addClass('hidden');
				}
				
				message_queue("success|" + data[1] + "|s");
				//notification_create('pwnz', '-1');
			} else {
				message_queue("error|" + data[1] + "|s");
			}
			
		}
	 );			

}

/*
function notification_create(owner, text) {
	messageid = messageid + 1
	$("#hud_counter_" + owner).append('<div id="notification_' + messageid + '" class="hud_counter_notification">' + text +'</div>')
	$('#notification_' + messageid).animate({ top: "-50px", opacity: "0" }, 3000 );
	$("#hud_counter_" + owner).effect("highlight", {color: "red"}, 2000);      
}
*/

function ask_confirmation(text, link) {
	if (confirm(text)) {
		document.location = link;
	}
}

function help_popup(slug) {
	window.open ('/help/' + slug + '/popup/', 'help', config='height=560, width=360, toolbar=no, menubar=no, scrollbars=yes, resizable=no, location=no, directories=no, status=no')
}

function displaywire(id) {

	//if ($("#wire_" + id).css('display') == 'block') {
	//	$("#wire_element_" + id).animate({paddingLeft: "10px"});
	//} else {
	//	$("#wire_element_" + id).animate({paddingLeft: "18px"});
	//}
	$("#wire_" + id).slideToggle();

}

function flow_uncache(id) {
	$.get('/flows/ajax/uncache/' + id + '/');
}

function invalidate_template_cache(id) {
	$.get('/flows/ajax/invalidate/' + id + '/');
}

function flow_delete(id) {
	if (confirm("Are you sure you want to remove this flow entry?")) {
		$.get('/flows/ajax/delete/' + id + '/');
		$("#flow_item_" + id).fadeOut();
	}
}

function flow_comment(id) {
	if ($("#comment_form_" + id).css('display') == 'none') {
		$("#comment_form_" + id).show();
	}

	$("#comment_textarea_" + id).focus();	
}


function flow_comment_add(id) {
	usertext = $("#comment_textarea_" + id).val()
	if (usertext == '') return;

	$("#comment_submit_" + id).attr("disabled", "disabled");
	
	$.post("/comments/ajax/add/", { content_type_id: '19', object_id: id, text: usertext }, function(data){ 
		if (data == '0') {
			alert('An error occured...');
		} else {
			$("#flow_item_" + id + "_comments").append(data);
		}
		$("#comment_submit_" + id).removeAttr("disabled");		
		$("#comment_textarea_" + id).val('');
		$("#comment_textarea_" + id).blur();
		ReadyBindEvents();		
 	});	
	
}

function sharebar_flow_add(user_id) {

	usertext = $("#sharebar_textarea_flow").val();
	if (usertext == '') return;
	$("#sharebar_submit_flow").attr("disabled", "disabled");
	
	$.post("/flows/ajax/add/", { user_id: user_id, text: usertext }, function(data){ 
		if (data == '0') {
			alert('An error occured...');
		} else {
			$("#flows_data").prepend(data);
		}

		$("#sharebar_submit_flow").removeAttr("disabled");
		$("#sharebar_textarea_flow").val('');
		$("#sharebar_textarea_flow").blur();
		ReadyBindEvents();
 	});	
}

function comment_delete(id) {
	if (confirm("Are you sure you want to remove this comment?")) {
		$.get('/comments/ajax/delete/' + id + '/');
		$("#comment_item_" + id).fadeOut();
	}
}

function sharebar_action(action) {
	$(".sharebar_actions_container").children().removeClass('sharebar_action_active');
	$("#sharebar_action_" + action).addClass('sharebar_action_active');	

	oldaction = $(".sharebar_textarea:visible").attr('data');
			
	$("#sharebar_textarea_" + oldaction).hide();

	$("#sharebar_textarea_" + action).removeClass('sharebar_highlight_rating');
	$("#sharebar_textarea_" + action).removeClass('sharebar_highlight_glink');
	if (action == 'review') $("#sharebar_textarea_" + action).addClass('sharebar_highlight_rating');
	if (action == 'glink') $("#sharebar_textarea_" + action).addClass('sharebar_highlight_glink');
		
	$("#sharebar_textarea_" + action).show();

	$("#sharebar_textarea_" + oldaction).val('');
	$("#sharebar_textarea_" + oldaction).blur();

}

function sharebar_glink_process() {
	if ($("#sharebar_textarea_glink").val() == '') return
	
	if (parseInt($("#mypp_counter").html()) <= 1) {
		message_queue("error|Sorry, you haven't enough publish points|s");
		return;	
	}
		
	$("#sharebar_buttons_glink").hide();
	$("#sharebar_edit_glink_loading").show();
	$("#sharebar_textarea_glink").attr("disabled", "disabled");
	
	if (ajax) ajax.abort();
	
	//RESET EVERYTHING!
	$("#sharebar_glink_game_span").html('').hide();
	$("#sharebar_glink_game_icon").attr('src', MEDIA_URL + '/img/packshots/default_icon32x32.jpg');		
	$("#sharebar_glink_gameid_input").val('0');	
	$("#sharebar_glink_game_input").val('').blur().show();
	$("#sharebar_glink_title").html('');
	$("#sharebar_glink_title_input").val('');
	$("#sharebar_glink_description").html('');
	$("#sharebar_glink_description_input").val('');
	$("#sharebar_glink_pictures_loading").hide();
	$("#sharebar_glink_pictures_noavailable").hide();
	$("#sharebar_glink_pictures").hide();
	$("#sharebar_glink_nopicture_input").attr('checked', '');
	$("#sharebar_glink_picture_input").val('');
	$("#sharebar_glink_picture_id").val('1');
	$("#sharebar_glink_isautotitle").val('1');
	$("#sharebar_glink_isautodescription").val('1');	
	
	url = $("#sharebar_textarea_glink").val();
	$("#sharebar_glink_url").val(url);
	
	ajax = $.post("/glinks/ajax/find/title/", { url: url },
		function(data){
			$("#sharebar_textarea_glink").attr("disabled", "");

			if (data == '0') {
				$("#sharebar_edit_glink_loading").hide();	
				$("#sharebar_buttons_glink").show();		
				message_queue("error|Sorry but the link you provided returned an error...|s");
				return;
			} 
			
			$("#sharebar_glink_title").html(data[0]);
			$("#sharebar_glink_title_input").val($("#sharebar_glink_title").text());
			$("#sharebar_glink_description").html(data[1]);
			$("#sharebar_glink_description_input").val($("#sharebar_glink_description").text());

			$("#sharebar_submit2_glink").attr("disabled", "disabled");
			$("#sharebar_edit_glink_loading").hide();
			$("#sharebar_glink_pictures_loading").show();		
			$("#sharebar_edit_glink").fadeIn();
			
			ajax = $.post("/glinks/ajax/find/pictures/", { url: url },
				function(data){
					glink_pictures = data;
					if (glink_pictures.length > 0) {
						$("#sharebar_glink_picture_total").text(glink_pictures.length);
						sharebar_glink_changepicture('0');
						$("#sharebar_glink_pictures_panel").css("opacity", 1);
						$("#sharebar_glink_pictures_loading").hide();			
						$("#sharebar_glink_pictures").fadeIn();
					} else {
						$("#sharebar_glink_pictures_loading").hide();
						$("#sharebar_glink_pictures_noavailable").show();
						$("#sharebar_glink_nopicture_input").attr('checked', 'on');					
					}	
					$("#sharebar_submit2_glink").removeAttr("disabled");
				}, "json");	
			
			
		}, "json");	


}


function sharebar_glink_changepicture(idchange) {
	id = parseInt($("#sharebar_glink_picture_id").val());
	id = id + parseInt(idchange);
	if (id > glink_pictures.length) id = id - glink_pictures.length
	if (id < 1) id = id + glink_pictures.length
	$("#sharebar_glink_picture_id").val(id);
	$("#sharebar_glink_picture_num").text(id);
	
	url = glink_pictures[(id-1)];
	$("#sharebar_glink_picture_img").attr('src', url);
	$("#sharebar_glink_picture_input").val(url);		
}

function sharebar_glink_add() {

	if ($("#sharebar_glink_gameid_input").val() == '0') {
		message_queue("error|Please select a related game...|s");
		return;
	}
	if ($("#sharebar_glink_description_input").val().length > 300) {
		message_queue("error|Sorry, 300 characters max in the description...|s");
		return;
	}
	
	if (parseInt($("#mypp_counter").html()) <= 0) {
		message_queue("error|Sorry, you have no publish points left|s");
		return;	
	}

	$("#sharebar_submit2_glink").attr("disabled", "disabled");
	
	$.post("/glinks/ajax/add/", $("#sharebar_glink_form").serializeArray(), function(data){ 
		if (data == '0') {
			alert('An error occured...');
		} else {
			$("#mypp_counter").html((parseInt($("#mypp_counter").html())-1));
			$("#myxp_counter").html((parseInt($("#myxp_counter").html())+10));			
			$("#flows_data").prepend(data);
		}
		
		$("#sharebar_submit2_glink").removeAttr("disabled");
		$("#sharebar_textarea_glink").val('');
		$("#sharebar_textarea_glink").blur();
		ReadyBindEvents();
 	});		
}

function flows_reload(type, oid) {
	last_flow_id = 9999999999999999;
	tempid = last_flow_id;
	
	$.post("/flows/ajax/load/", { last_flow_id: tempid, type: type, oid: oid }, function(data){
		$("#flows_data").stop().html('<div id="flows_data_' + tempid + '">' + data + '</div>').css('opacity', 1);
		ReadyBindEvents();
	});
}

function flows_more(type, oid) {
	$("#flows_more").addClass('flows_more_button_waiting');
	tempid = last_flow_id;
	$.post("/flows/ajax/load/", { last_flow_id: tempid, type: type, oid: oid }, function(data){
		$("#flows_data").append('<div id="flows_data_' + tempid + '" class="hidden">' + data + '</div>');
		$("#flows_data_" + tempid).slideDown(1000);
		setTimeout(function() { $('#flows_more').removeClass('flows_more_button_waiting'); }, 1050);
		ReadyBindEvents();
	});
}

function notification_show() {
	if ($("#hud_notifications").css('display') == 'none') {
		$("#hud_button_notifications_container").removeClass('icon_bubble_hover');
		$("#hud_button_notifications_container").removeClass('hud_button_effect');
		$("#hud_button_notifications_container").removeClass('hud_button_active');
		$("#hud_button_notifications_container").animate({opacity: "1"}, 100);
		$("#icon_bubble").hide();
		$("#hud_notifications").css('left', $("#hud_button_notifications_container").offset().left - 2);
		
		$("#hud_notifications_loader").show();
		$("#hud_notifications_data").html('');
		$("#hud_notifications").fadeIn();

		$.get("/notifications/ajax/get/", function(data) {
			if (data == 'redirect') {
				document.location = '/users/notifications/';
				return;
			}
			$("#hud_notifications_loader").hide();
			$("#hud_notifications_data").html(data);
			
		});
	} else {
		$("#hud_notifications").fadeOut();	
		$("#hud_button_notifications_container").addClass('icon_bubble_hover');
		$("#hud_button_notifications_container").addClass('hud_button_effect');
		ReadyBindEvents();
		$("#hud_button_notifications_container").animate({opacity: "0.5"}, 100);
	}
}

function nothing() {

}

function stripHTML(text){
	var re= /<\S[^><]*>/g
	return text.replace(re, "")
}


var win = null;

function popup(mypage,myname,w,h,features) {
	// Centered Pop-Up Window (v1.0)
	// (C) 2002 www.smileycat.com
	// Free for all users, but leave in this header
	
	var winl = (screen.width-w)/2;
	var wint = (screen.height-h)/2;
	if (winl < 0) winl = 0;
	if (wint < 0) wint = 0;
	var settings = 'height=' + h + ',';
	settings += 'width=' + w + ',';
	settings += 'top=' + wint + ',';
	settings += 'left=' + winl + ',';
	settings += features;
	win = window.open(mypage,myname,settings);
	//win.window.focus();
}

var twitter_active = false; 

function twitter_check() {
	var result = false;
	
	if (twitter_active) {
		return true;
	} else {
		jQuery.ajax({
			type: "GET", 
			url: '/users/ajax/twitter/check/',
			success: function(data) {
				if (data == 1) {
					twitter_active = true;
					result = true;
				}  else {
					message_queue('ajax|/users/ajax/twitter/popup/|i');
					result = false;
				}
				
			},
		 	async: false
		});
		return result;
	}

}














