function deleteImage(id)
{
	     var file = 'delete_image.php';
		 idnew = id.split('.');
		 $.post(file, { data: id });
		 $("#img_"+idnew[0]).remove();
}

$(function()
{
	$('.left2').height(Number($(document).height() - 220)).jScrollPane({hideFocus:true});
	$('.left').jScrollPane({hideFocus:true});
	
});
function login() {
$(".overlay").show();
$("#login").show();

}
function join() {
$("#medverka").show();
$(".overlay").show();
}
function info() {
$(".overlay").show();
$(".popup2").show();
}


function update() {
$.get('ajax.php?type=updatesession', function(data) {

});
setTimeout('update()',5000);
}

$(document).ready(function() {
update();

$(".overlay").click(function() {
$(".popup2,.overlay").hide();
$("#login").hide();
$("#medverka").hide();
});
$(".close").click(function() {
$(".popup2,.overlay").hide();
$("#login").hide();
$("#medverka").hide();
});
var width = $(document).width();

$("#map_canvas").css("width",$(".right2").width() + "px");
$("#map_canvas").css("height",$(".right2").height() + "px");
$(".buttons").css("margin-left",Math.abs(Number(width/2) - Number(175)) + "px");

$("#edgetoedge li").click(function() {
if($(this).hasClass("newsactive")) {
return false;
}
$(".right2").hide();
$(".newscontent").html("Laddar...");
$(".right2").css("margin-left","-0%");
setTimeout(function() {
setTimeout(function() {$(".right2").show(); },200);
$(".right2").animate({"margin-left": "49%"}, "slow");
},200);
$(".newscontent").css("margin","1%");
var id = $(this).attr("id").replace("news_","");
$(".newsactive").removeClass("newsactive").addClass("newsinactive");
$(this).addClass("newsactive");

$.get("ajax.php", { type: "news", id: id },
   function(data){
    $(".newscontent").html(data);
   });

});
/*
$("#edgetoedge_companies li").click(function() {
if($(this).hasClass("newsactive")) {
return false;
}
$(".right2").hide();
$(".newscontent").html("Laddar...");
$(".right2").css("margin-left","-0%");
setTimeout(function() {
setTimeout(function() {$(".right2").show(); },200);
$(".right2").animate({"margin-left": "49%"}, "slow");
},200);
$(".newscontent").css("margin","1%");
var id = $(this).attr("id").replace("company_","");
$(".newsactive").removeClass("newsactive").addClass("newsinactive");
$(this).addClass("newsactive");

$.get("ajax.php", { type: "companies", id: id },
   function(data){

$(".newscontent").html(data);
	$('#slides').slides({
				preload: true,
				preloadImage: 'img/loading.gif',
				play: 5000,
				pause: 2500,
				hoverPause: true
			});
   });

});

*/
$("#edgetoedge_events li").click(function() {

if($(this).hasClass("newsactive")) {
return false;
}
$(".right2").hide();
$(".newscontent").html("Laddar...");
$(".right2").css("margin-left","-0%");
setTimeout(function() {
setTimeout(function() {$(".right2").show(); },200);
$(".right2").animate({"margin-left": "49%"}, "slow");
},200);
$(".newscontent").css("margin","1%");
var id = $(this).attr("id").replace("event_","");
$(".newsactive").removeClass("newsactive").addClass("newsinactive");
$(this).addClass("newsactive");

$.get("ajax.php", { type: "events", id: id },
   function(data){
    $(".newscontent").html(data);
   });

});


$("#save1").live("click",function() {
var startdate = $("#startdate").val();
var enddate = $("#enddate").val();
var title = $("#titel").val();
var desc = $("#descr").val();

$.post("ajax.php?addevent=1", { startdate: startdate, enddate: enddate, title: title, desc: desc },
   function(data) {
if(data != "0") {
$("#eventlist").prepend(data);
} else {
alert("Något gick fel!");
}
   });

});
$(".events").live("click",function() {
var id =  $(this).attr("id").replace("event_","");
var startdate = $("#startdate_"+id).html();
var enddate = $("#enddate_"+id).html();
var title = $("#title_"+id).html();
var desc = $("#desc_"+id).html();

$("#startdate").val(startdate);
$("#enddate").val(enddate);
$("#titel").val(title);
$("#descr").val(desc);
$(".edit").css("display","block");
$(".edit").attr("id",id);
});

$(".edit").live("click",function() {
var id = $(this).attr("id");
var startdate = $("#startdate").val();
var enddate = $("#enddate").val();
var title = $("#titel").val();
var desc = $("#descr").val();


$.post("ajax.php?updateevent=1", { startdate: startdate, enddate: enddate, title: title, desc: desc, id:id },
   function(data) {
if(data != "0") {
$("#startdate_"+id).html(startdate);
$("#enddate_"+id).html(enddate);
$("#title_"+id).html(title);
$("#desc_"+id).html(desc);

$("#startdate").val("");
$("#enddate").val("");
$("#titel").val("");
$("#descr").val("");

$(".edit").css("display","none");
} else {
alert("Något gick fel!");
}
   });


});


$(".delete").live("click",function() {
var id = $(this).attr("id");
$.get("ajax.php?type=delete&id="+id, function(data){
$("#event_"+id).remove();
});
});

$(".delete2").live("click",function() {
var id = $(this).attr("id");
$.get("ajax.php?type=deletepic&id="+id, function(data){
$("#pic_"+id).remove();
});

});
});
function newevent() {
var startdate = $("#startdate").val("");
var enddate = $("#enddate").val("");
var title = $("#titel").val("");
var desc = $("#descr").val("");
$(".edit").css("display","none");
}
