var blog_url;

$(document).ready(function()
{
	blog_url = $("#networkpub_plugin_url").val();
	
	$(".counter_links").each(function()	{							
							$(this).bind("click", function(e) {		
										var w = 716, h = 480;
										var left = (screen.width/2)-(w/2);
										var top  = (screen.height/2)-(h/2);
	
										link = $(this).attr('href');
										newwindow=window.open(link,'socialdiscuss','toolbar=no, location=no, directories=no, status=no, menubar=no, scrollbars=yes, resizable=no, copyhistory=no, width='+w+', height='+h+', top='+top+', left='+left);
	
										if (window.focus) {
											newwindow.focus();
										}								
										
										return false;
							});
	});

	$("#idNWPubContent").hide();
	$('#idNWPub').live("click", function() {
		$("#idNWPubContent").toggle( "fast", function() {
										myElementText = $("#idNWPub").text();
										if(myElementText == 'Edit') {
											$("#idNWPub").text("Hide");
											$.post(blog_url+"social-discussions-networkpub_ajax.php", {type:'load'}, function(data) {
												if(data == '500') {
													$("#idAPIBox").html('<div class="msg_error">Error occured while removing the API Key. As a workaround, you can remove this publishing at the following link: <a href="http://www.linksalpha.com/user/publish">LinksAlpha Publisher</a> </div>');
												} else {
													$("#idAPIBox").html(data);	
												}
											});										
										}
										else if (myElementText == 'Hide') {
											$("#idNWPub").text("Edit");
										}
									}				
		);		
		
	});
	
	$("#idProfileContent").hide();
	$('#idProfile').click( function() {
		$("#idProfileContent").toggle( "fast", function() {
										myElementText = $("#idProfile").text();
										if(myElementText == 'Edit') {
											$("#idProfile").text('Hide');
										}
										else if (myElementText == 'Hide') {
											$("#idProfile").text('Edit');
										}
									}				
							);			
	});

	$("#idPosColorsContent").hide();
	$('#idPosColors').click( function() {
		$("#idPosColorsContent").toggle( "fast", function() {
										myElementText = $("#idPosColors").text();
										if(myElementText == 'Edit') {
											$("#idPosColors").text("Hide");
										}
										else if (myElementText == 'Hide') {
											$("#idPosColors").text("Edit");
										}
									}				
							);			
	});

	$("#idPosColorsContentWidget").hide();
	$('#idPosColorsWidget').click( function() {
		$("#idPosColorsContentWidget").toggle( "fast", function() {
										myElementText = $("#idPosColorsWidget").text();
										if(myElementText == 'Edit') {
											$("#idPosColorsWidget").text("Hide");
										}
										else if (myElementText == 'Hide') {
											$("#idPosColorsWidget").text("Edit");
										}
									}				
							);			
	});
	
	$("#idIconsContent").hide();
	$('#idIcons').click( function() {
		$("#idIconsContent").toggle( "fast", function() {
										myElementText = $("#idIcons").text();
										if(myElementText == 'Edit') {
											$("#idIcons").text("Hide");
										}
										else if (myElementText == 'Hide') {
											$("#idIcons").text("Edit");
										}
									}				
							);		
	});

	
	$("#idSSContent").hide();
	$('#idSS').click( function() {
		$("#idSSContent").toggle( "fast", function() {
										myElementText = $("#idSS").text();
										if(myElementText == 'Edit') {
											$("#idSS").text("Hide");
										}
										else if (myElementText == 'Hide') {
											$("#idSS").text("Edit");
										}
									}				
							);		
	});
	
		
	$(".networkpubre").live("click", function(e) {
		var key = $(this).attr("id");
		if(key) {
			$.post(blog_url+"social-discussions-networkpub_ajax.php", {key:key, type:'remove'}, function(data) {
				if(data == '500') {
					$("#networkpub_msg").html('<div class="msg_error">Error occured while removing the API Key. As a workaround, you can remove this publishing at the following link: <a href="http://www.linksalpha.com/user/publish">LinksAlpha Publisher</a> </div>');
				} else {
					$("#r_"+key).remove();
					$("#networkpub_msg").html('<div class="msg_success">API Key has been removed successfully</div>');	
				}
		    });
		} 
		return false;
	});	
	
		
	$(function() {
		$("#tabs").tabs();
	});
		
	
});