	// --------------------------------------------------------------------------
	//		Config
	// --------------------------------------------------------------------------	 


	var expandSpeed 		= 400;	// Speed at which the jobtable row expands


	// --------------------------------------------------------------------------
	//		Document ready 
	// --------------------------------------------------------------------------	 
	
	
	$(document).ready(function()
	{

		//	Expand jobdetails
		$('.jobtable tr.basic').live('click', function(event)
		{
		    // Only proceed if the event wasn't caused by clicking a link
		    // (dirty solution to overcome stopPropagation() not working on live() events)
		    if ( $(event.target).is('a') ) { return; }
		    
            if ($(this).next('tr').filter(':not(:animated)').hasClass('extended'))
		    {
			    $(this).next('tr').find('div.wrapper').stop(true, true).slideToggle(expandSpeed);
			    openGMap($(this).next('tr').find('.googlemap'), 1, 1);
		    }		
		})


        // Tell a Friend
        $('a.tellAFriend').live('click', function()
        {
        	getTellAFriendForm($(this).attr('id').substr(3));
            return false;
        })
        
        // Jump to last viewed job when returning from detail page
		var detailJob = window.location.hash;
		detailJob = detailJob.substr(1);
		if(detailJob){
			$.scrollTo($('a[title="'+detailJob+'"]'));
		}

	})
	
	
	// --------------------------------------------------------------------------
	// 		Window resize
	// --------------------------------------------------------------------------
	

	$(window).resize(function()
	{
		// Experimental: hide date cells on small resolutions
		
		if ($(document).width() < 1024)
		{
		    $('.jobtable col.dat, .jobtable td.date').hide()
		}
		else
		{
	    	$('.jobtable col.dat, .jobtable td.date').show()
		}
	})
	
	
	// --------------------------------------------------------------------------
	//		Functions
	// --------------------------------------------------------------------------	 
	

	//	Tell a Friend
	
	function getTellAFriendForm( jobId )
	{
	    $.ajax(
	    {
			type: "GET",
			url: "/job/" + jobId + "/tell-a-friend",
			data: '',
			async: false,
			success: function(data)
			{
				$.modal('<div id="tellAFriendForm">' + data + '</div>', 
				{
				    overlayClose: true,
				    autoResize: true,
				    autoPostion: true,
				    onOpen: function (dialog) 
				    {
	                    dialog.overlay.fadeIn(200, function ()
	                    {
		                    dialog.data.show();
                            dialog.container.fadeIn(200);
                            dialog.container.css('height', 'auto');
                            dialog.data.css('height', 'auto');
	                    });
                    }
				});
			}
		});
	}


	function tellAFriendRequest( jobId )
	{
        $.ajax(
        {
            type: "POST",
            url: "/job/" + jobId + "/tell-a-friend",
            data: $('form').serialize(),
            success: function(data)
            {
                $("#tellAFriendForm").html(data);
                $(window).trigger('resize.simplemodal');
           	}
        });
	    return false;
	}


	// 	Google Map

	function openGMap(element)
	{
	    var config = jQuery.parseJSON($(element).html())
        var latitude = config['latitude']
        var longitude = config['longitude']
        var text = config['name']
        
        
        if ( GBrowserIsCompatible()) {
		    $(element).show();
		    
            var map = new GMap2( document.getElementById($(element).attr('id')) );

            map.addControl( new GLargeMapControl() );
		    map.setCenter( new GLatLng( 0,0 ), 0 );

		    var markerpt = new GPoint( longitude, latitude );
		    var marker = new GMarker( markerpt );
			var bounds = new GLatLngBounds();
		    GEvent.addListener( marker, "click", function() { marker.openInfoWindowHtml( text ); });

		    var point = new GLatLng( latitude, longitude );
		    bounds.extend( point );

		    map.addOverlay( marker );

	        map.setZoom(11);

		    map.setCenter( bounds.getCenter() );
		}
	
	}
