	jQuery.fn.mapper = function ( mapImage) {

		var $mapImage = jQuery(mapImage);
		var origImage = jQuery(mapImage).attr('src');

		return this.each( function(index) {
		
			jQuery(this)
			
				.mouseover( function (e) {
					var img =  jQuery(e.target).attr('img');
					if (img) $mapImage.attr('src', img);
				})
				
				.mouseout( function () { $mapImage.attr('src',origImage); } );
				
		});
	};
	
	(function ($) {
		$.fn.gmap = function ( src ) {

			if (!GBrowserIsCompatible()) return;
			
			var address = $(src).text();
			
			return this.each( function(index) {
				var map = new GMap2( this );
				map.addControl(new GSmallMapControl());
	   			var geocoder = new GClientGeocoder();   			 
	   			 
	   			geocoder.getLatLng(address,
		    	function(point) {
		      		if (!point) {
		       			jQuery("#gmap").hide();
		      		} else {
		        		map.setCenter(point, 13);
		        		var marker = new GMarker(point);
		        		map.addOverlay(marker);
		        		marker.openInfoWindowHtml(address);
		      		}
		    	});
			});	
			
		}

		$.fn.paging = function (options) {
			var defaults = {
				parent : document.body,
				prevText : " &laquo; edellinen ",
				nextText : " seuraava &raquo; "
			};
			options = $.extend(defaults, options);
			
			return this.each( function () {
				var $a = $(this).find('a');
				
				$(options.parent).html('');
				
				$a.each( function ( index ) {
				
					if (  document.location.href == this  )
					{
						if ($a.get(index-1)) $(options.parent).append('<a href="'+$a.get(index-1)+'" class="ed">'+options.prevText+'</a>');
						if ($a.get(index+1)) $(options.parent).append('<a href="'+$a.get(index+1)+'" class="seur">'+options.nextText+'</a>');
					}
				});
	  		});
		};

	 })(jQuery);

/* This function is CM-specific. */
	
	/* This replaces media place holder images with mediaplayers */

	(function ($) {
	 
	 	$(
	 		function()
	 		{
	 			$("img.mediaHolder").each(
	 				function (index) {
	 					var a = this.id.split('|');
						var playerType = a[0];
						var src = a[1];
						var id = "media_"+index;
						var w = this.width;
						var h = this.height
					
						var div = $('<div class="mediaholder"></div>').css({ width:w+"px", height:h+"px", display:'inline' });
					
						$(this).hide();
						$(this).before( div );
						
					try {
						switch ( playerType )
						{
							case "flash" :
								div.html( new SWFObject(src, id, w, h, 8).getSWFHTML () );							
								break;
							case "mediaplayer" :
								var mp = new SWFObject("/js/ced/lib/player.swf",id,w,h,9);
								mp.addParam("allowfullscreen","true");
								mp.addVariable("width",w);
								mp.addVariable("height",h);
								mp.addVariable("file",src);
								div.html(mp.getSWFHTML());
								break;
							case "youtube" :
								var mp = new SWFObject(src,id,w,h,9);
								mp.addParam("allowfullscreen","true");
								mp.addVariable("width",w);
								mp.addVariable("height",h);
								div.html(mp.getSWFHTML());
								break;
							case "wmvplayer" :
								new jeroenwijering.Player(div.get(0), '/js/ced/lib/wmvplayer.xaml', { file : src, height : h+"", width : w+"" } );
								break;
						}
					} catch (error) {
							alert("Error embedding media player for "+playerType+" : "+src+"\n"+error);
					}
			
					
	 				}
	 			
	 			);
	 		}
	 	
	 	)
	 
	 
	 })(jQuery);