var tags = {
	type:['tags','post_tags','keywords'],
	getTags: function(module_id,type){
		$.ajax( //ajax request starting
			{
		       url: "/controlpanel/gettags/" + module_id + "/" + type,
               type:"GET",//request is a POSt request
		       dataType: "html",
		       success: function(r) //trigger this on success
			   {
				tags.renderTags(r.responseText,type);
			   }
		    });
	},
	renderTags: function(html,type){
		$('#' + type + '_list').html(html);
		reloadPreviewFrame();
		
	},
	addTag: function(tag_input,module_id,type){
		var ele = $('#'+tag_input);
		var tag = ele.val();
		ele.val('');
		$.ajax( //ajax request starting
				{
			       url: "/controlpanel/addtag/",
	               type:"POST",//request is a POSt request
			       dataType: "html",
			       data: {tag:tag, module_id:module_id,type:type},
			       success: function(r) //trigger this on success
				   {
					tags.renderTags(r,type);
				   }
			    });
	},
	removeTag: function(module_id,tag_id,type,e){
		
		$.ajax( //ajax request starting
				{
			       url: "/controlpanel/removetag/" + module_id + "/" + tag_id + "/" + type,
	               type:"POST",//request is a POSt request
			       dataType: "html",
			       success: function(r) //trigger this on success
				   {
					tags.renderTags(r,type);
				   }
			    });
	
	}
		
}


var module = {
		postOpen: false,
		init: function(){
			
			
			//postToggle
			$('.tvPost').click(function(e){
				e.preventDefault();
				module.togglePost($(this).attr('href'));
			});
		},
		togglePost: function(url){
			if(module.postOpen == true){
				$('#postContainer').hide('slow');
				$('#postContainer').html('');
			} else {
				module.postOpen = true;
				$.ajax( //ajax request starting
						{
					       url: url,
			               type:"GET",//request is a POSt request
					       dataType: "html",
					       success: function(r) //trigger this on success
						   {
							$('#postContainer').html(r);
							$('#postContainer').show('slow');
						   }
				});
			}
		},
		loadConversation: function(module_id){
			
		}
}

function reloadPreviewFrame(){
	window.frames['previewFrame'].document.location.reload();
	
}

function togglePost(url){

	

}

function closePost(){
	Effect.Fade('twitterPost');
}

function usHref(href) {
	
	   var fullUrl = href.split('/');
	   var url = [];
	   for(var i=0, l=fullUrl.length; i<l; i++ ){
		   if(fullUrl[i] != '' && fullUrl[i] != null){
		   		url.push(fullUrl[i]);
		   }
	   }
	   var test = url[(url.length - 1)].split('?');   
	   var ret = {
			   urlParts: url,
			   params: {}
	   };
	   	
	   if(typeof(test[1]) == "undefined") return ret;
	   test[1].replace(/([^&=]+)=([^&=]*)/g, function(m, key, val) {
		   ret.params[key] = val;
		 });
	   return ret;
	}

$(document).ready(function() {	
	module.init();

});