
$(window).bind('load', function() {
// SVG Map init:
	if($('#map').size() && Raphael) {
		$.get(BASE_HREF + "js/map-all.xml", function(svg) {

		var attrOkres = {
			fill: "#bebebe",
			stroke: "#fff",
			cursor: 'pointer',
			"stroke-width": 2,
			"stroke-linejoin": "round"
		};

		var attrOkresHighlite = {
			fill: "#7ebd3d",
			stroke: "#ffffff",
			cursor: 'default',
			"stroke-width": 2,
			"stroke-linejoin": "round"
		};

		var attrKraj = {
			stroke: "#ffffff",
			cursor: 'pointer',
			"stroke-width": 2,
			"stroke-linejoin": "round"
		};
		var areaType = $('#areaType').val() || 'cr';
		var areaId = $('#areaId').val() ;
		var paperSize = { width: 410, height: 240 };

		var bbox = { x: 0, y: 0, width: paperSize.width, height: paperSize.height };
		var translate = { x: 0, y: 0 };
		var scale = 1;

		var R = Raphael("map", paperSize.width, paperSize.height);

		$('#map img').remove();

		var renderArea = function($path, attr, transform) {
			transform = transform || false;
			var key = $path.attr('id');
			var d = $path.attr('d');
			var label = $path.attr('inkscape:label');
			if(areaType != 'cr') label = 'Okres ' + label;

			var kraj = R.path(attr, d);

			$(kraj.node)
			.bind('mouseenter', function(e) {
				if($.browser.mozilla || $.browser.msie) {
					kraj.animate({ fill: '#7ebd3d' }, 200);
				}
				else kraj.attr({ fill: '#7ebd3d' });
			})
			.bind('mouseout', function(e) {
				if($.browser.mozilla || $.browser.msie) kraj.animate({ fill: '#bebebe' }, 200);
				else kraj.attr({ fill: '#bebebe' });
				$('.candidate').empty();
			})
			.bind('click', function(e) {
				return window.location.href = '.?region='+key;
			});
		};

			if(areaType == 'cr') {
				var $cr = $('g#layer1 path', svg);
				var cr = R.path(attrKraj, $cr.attr('d'));
				cr.scale(scale, scale);
				cr.translate(translate.x, translate.y);

				$('g#layer2 path', svg).each(function() {
					//alert(BASE_REGION);
					if($(this).attr('id') == BASE_REGION) { 
						renderArea($(this), attrOkresHighlite, 1);
						
					}
					else{ 
						renderArea($(this), attrOkres, 1);
					}
				});

				$('#mapform-kraj').bind('change', function() {
					var name = $select.val();
					if(name != 'cela-cr') {
						name = name.slice(5);
						if(name != 'praha' && name != 'vysocina') name +=  '-kraj';
					}
					document.location = BASE_HREF + KDEVAMMOHOUPOMOCI_URI + '/' + name + '/';
				});
			}
		});
	}
});


$.fn.pause = function(milli,type) {
	milli = milli || 1000;
	type = type || "fx";
	return this.queue(type,function(){
		var self = this;
		setTimeout(function(){
			$.dequeue(self);
		},milli);
	});
};

$.fn.clearQueue = $.fn.unpause = function(type) {
	return this.each(function(){
		type = type || "fx";
		if(this.queue && this.queue[type]) {
			this.queue[type].length = 0;
		}
	});
};
