var xyz = {
	init: function(){
		this.xyzBox();
	
		$('#nav ul li#item_31').addClass('first');
	},
	
	xyzBox: function(){
		$('.xyzBox').each(function(){
			var txt = $(this).html();
			
			$(this).html('');
		
			$(this).append('<div class="xyzBoxTop"></div>');
			$(this).append('<div class="xyzBoxContent">' + txt + '<div class="spacer"></div></div>');
			$(this).append('<div class="xyzBoxBottom"></div>');
		});
		
		$('.xyzBoxSmall').each(function(){
			var txt = $(this).html();
			var title = $(this).attr('title');
			var id = $(this).attr('id');
			
			$(this).html('');
		
			$(this).append('<div class="xyzBoxSmallTop"></div>');
			$(this).append('<div class="xyzBoxSmallContent"><div class="xyzBoxSmallTitle">' + title + '</div>' + txt + '</div>');
			$(this).append('<div class="xyzBoxSmallBottom"></div>');
			
			$(this).find('.xyzBoxSmallTitle').click(function(){
				window.location = "?page=32&id=" + id.substr(3,id.length);
			});
		});
		
		$('.xyzBoxSaljare').each(function(){
			var txt = $(this).html();
			var id = $(this).attr('id');
			
			$(this).html('');
		
			$(this).append('<div class="xyzBoxSaljareTop"></div>');
			$(this).append('<div class="xyzBoxSaljareContent">' + txt + '</div>');
			$(this).append('<div class="xyzBoxSaljareBottom"></div>');
			
			$(this).find('.xyzBoxSaljareTitle').click(function(){
				window.location = "?page=32&id=" + id.substr(3,id.length);
			});
		});
	},
	
	saljare: function(){
		$('.xyzBoxSaljare#empty').each(function(){
			$(this).find("a.addSaljare").each(function(){
				$(this).click(function(){
					if(confirm('Vill du lägga till en säljare på denna sida?')){
						var id = $(this).attr('id');
						var parent = $(this).attr('rel');
						
						$.ajax({
							type: "POST",
							url: "/inc/saljare_add.asp",
							data: "user=" + id + "&parent=" + parent,
							success: function(data){
								if(data == 'No Auth'){
									alert('Du har inte behörighet att lägga till säljare!');
								} else {
									return true;
								}
							}
						});
					} else {
						return false;
					}
				});
			});
		});
		
		$('.xyzBoxSaljare').find('a.delBtn').click(function(){
			var id = $(this).attr('id');
		
			if(confirm('Vill du ta bort denna säljare?')){
				$.ajax({
					type: "POST",
					url: "/inc/saljare_del.asp",
					data: "id=" + id,
					success: function(data){
						if(data == 'No Auth'){
							alert('Du har inte behörighet att ta bort säljare!');
							
							return false;
						} else {
							return true;
						}
					}
				});
				
			} else {
				return false;
			}
			
		});
	}
}
