var loadingImg = webroot+'img/ajax-loader.gif';
var loadingImgBlue = webroot+'img/ajax-loader-blue.gif';

function getId(ele_id) {
	var split = ele_id.split("_");
	return split[1];
}

function updateCoords(c) {
	$('#x').val(c.x);
	$('#y').val(c.y);
	$('#w').val(c.w);
	$('#h').val(c.h);
};

function checkCoords() 
{ 
  if ($('#x').val() != '') return true; 
  alert('Maak eerst een selectie.'); 
  return false; 
}; 

function popup() {
	$('a.popup').click(function(){
		var href = $(this).attr('href');
		var shref = href.split("/");
		window.open(href, shref[shref.length-1], 'width=700,height=500,scrollbars=yes,toolbar=no,location=no'); 
		return false;
	});
}

function slideAdminTools() {
	$('#adminTools li a#slideTools').click(function() {
		var top = $('#adminTools').css('top');
		if (top == '-208px'){
			$.post(webroot+"pages/adminToolsSession/1");
			$("#adminTools").animate({"top": "0px"}, { "duration": 300, "easing": "easeOutSine" });
		}
		else{
			$.post(webroot+"pages/adminToolsSession/0");
			$("#adminTools").animate({"top": "-208px"}, { "duration": "slow", "easing": "easeOutSine" });
		}
	});
	return false;
}

function external() {
	$("a[rel='external']").click(function(){
    	window.open($(this).attr('href'));
    	return false;
    });
}

function fancyBox() {
	$("a.fancybox").fancybox({'overlayColor':'#000'});
}

function tooltip() {
	$('#educations ul li a').tooltip({ 
	    track: true, 
	    delay: 0, 
	    showURL: false, 
	    showBody: " - ", 
	    fade: 250 
	});
}

function createTableSortable(table, action) {
	$(table).sortable({ 
		items: 'tr', 
		placeholder: 'ui-state-highlight', 
		forceHelperSize: true,
		helper: function(e, tr) {
			var $originals = tr.children();
			var $helper = tr.clone();
			$helper.children().each(function(index) {
				$(this).width($originals.eq(index).width())
			});
			return $helper;
		},
		axis: 'y', 
		handle: '.move',
		items: 'tr:not(.head)',
		update: function(e, ui){
            $.ajax({
                type: "POST",
                url: webroot+action,
                data: "itemId=&newOrder="+$(table).sortable('toArray'),
                error: function(msg){
                    $("#JQresult").html(msg);
                },
                success: function(msg){
                    $("#JQresult").html(msg);
                }
            });
		}
	});
}
