/*jQuery(document).ajaxSend(function(event, request, settings) {
	alert('esta');
	if (typeof(AUTH_TOKEN) == "undefined") return;
	// This next line is the key!
	if (settings.type == 'GET') return; // Don't add anything to a get request let IE turn it into a POST.
	settings.data = settings.data || "";
	settings.data += (settings.data ? "&" : "") + "authenticity_token=" + encodeURIComponent(AUTH_TOKEN);
});*/



var object = new ArgumentURL(); 

function doGoogleMap(page)  {
	
    //jQuery(document).ready(function(){
//$(function() { //this is the same as doc.ready
//$(window).load(function () {

            
            jQuery('#map1').jmap('init', {'mapType':G_NORMAL_MAP,'mapCenter':[41.3868326, 2.1614238],'mapZoom':16});
            
            //jQuery('#address-submit-1').click(function(){
			//jQuery('address').afterload(function() {
			//alert(jQuery('#address').val());
                jQuery('#map1').jmap('SearchAddress', {
                    'query': jQuery('#address').val(),
                    'returnType': 'getLocations'
                }, function(result, options) {
                    
                    var valid = Mapifies.SearchCode(result.Status.code);
                    if (valid.success) {
                    jQuery.each(result.Placemark, function(i, point){
                      jQuery('#map1').jmap('AddMarker',{
					  			'pointTitle' : 'Despacho de ' + page,
                                'pointLatLng':[point.Point.coordinates[1], point.Point.coordinates[0]]
								});
                                /*'pointHTML':point.address,
								'pointHTML': '<html>Calle Aribau, 21<BR>08011 Barcelona <BR>Espa&ntilde;a<BR>Contacto: Rosa Vaqués<br />Tel. 34 934 512 837 <br />Fax. 34 902 955 798 <br /><a href="mailto:barcelona@periciales.es">barcelona@periciales.es</a></html>'});*/
								//alert(point.Point.coordinates[1]);
								//alert(point.Point.coordinates[0]);
						
							jQuery('#map1').jmap('MoveTo', {
								'mapCenter': [point.Point.coordinates[1], point.Point.coordinates[0]], 
							 	'mapZoom': 16, 
							 	'centerMethod': 'pan'
                        	});
						});
						
                    } else {
                        jQuery('#address').val(valid.message);
                    }
					
					
               // });
                //return false;	
            });
            
			
        //});
		
		//return false;
		
}   

$(function() {
		   
	if (object != null)
	{
		if (object.size()>0)
		{
			var file = object.getArgument('file');
			var city = object.getArgument('city');
			
			if ((file != null) && (city != null))
			{
				//alert(file);
				var office = $("#office");
				var google = $("#google");
				var address = $("#address");
				var verbose = $("#verbose");
				var picture = $("#picture");
				var portrait = $("#portrait");
				var map = $("#googleMap");
				
				$('#shortcutCity').text(city);
				
	
				office.slideUp();	
				//office.load( file + '.html #' + city + ' #office');
				office.load( file + ' #office');
				office.slideDown();
				
				//map.slideUp();
				//google.load( file + ' #' + city + ' #google input', function(data){
				google.load( file + ' #google input', function(data){
																
																$(window).load = doGoogleMap(city);
																
																/*$(window).load(function () {
																	doGoogleMap();
																});*/
															});
				//map.slideDown();
														
				
				verbose.slideUp();	
				//verbose.load(file + ' #' + city + ' #verbose');
				verbose.load(file + ' #verbose');
				verbose.slideDown()
				
				/*switch(file)
				{
					case "mexico.html":
					case "reinounido.html":
					case "argentina.html":
							picture.hide();
							break;
							
					default:{				
						picture.slideUp();
						//picture.load(file + ' #' + city + ' #picture img');
						picture.load(file + ' #picture img');
						picture.slideDown();
					}
				}*/
				picture.slideUp();
				//picture.load(file + ' #' + city + ' #picture img');
				picture.load(file + ' #picture img');
				picture.slideDown();
				
				/*portrait.fadeOut('slow');				
				//picture.load(file + ' #' + city + ' #picture img');
				portrait.load(file + ' #portrait img');
				//picture.slideDown();
				//picture.animate({opacity: 1.0}, 3000);
				portrait.fadeIn('slow');*/
				
				portrait.fadeIn(5000, function(){
						portrait.load(file + ' #portrait img');
				});


			}
		}
	}
	//return false;
});	
				

$.fn.pause = function(duration) {    $(this).animate({ dummy: 1 }, duration);    return this;};

function loadFile(file, city)
{
	if ((file != null) && (city != null))
	{
		//alert(file);
		var office = $("#office");
		var google = $("#google");
		var address = $("#address");
		var verbose = $("#verbose");
		var picture = $("#picture");
		var portrait = $("#portrait");
		var map = $("#googleMap");
		
		$('#shortcutCity').text(city);
		

		office.fadeOut('slow');	
		//office.load( file + '.html #' + city + ' #office');
		office.load( file + ' #office');
		office.fadeIn('slow');
		
		//map.slideUp();
		//google.load( file + ' #' + city + ' #google input', function(data){
		google.load( file + ' #google input', function(data){
														
														$(window).load = doGoogleMap(city);
														
														/*$(window).load(function () {
															doGoogleMap();
														});*/
													});
		//map.slideDown();
												
		
		verbose.fadeOut('slow');	
		//verbose.load(file + ' #' + city + ' #verbose');
		verbose.load(file + ' #verbose');
		verbose.fadeIn('slow');
		
		/*switch(file)
		{
			case "mexico.html":
			case "reinounido.html":
			case "argentina.html":
					picture.fadeOut('slow');
					picture.hide();
					break;
					
			default:{				
				picture.fadeOut('slow');				
				//picture.load(file + ' #' + city + ' #picture img');
				picture.load(file + ' #picture img');
				//picture.slideDown();
				//picture.animate({opacity: 1.0}, 3000);
				picture.fadeIn('slow');
			}
		}*/
		
		picture.fadeOut('slow');				
		//picture.load(file + ' #' + city + ' #picture img');
		picture.load(file + ' #picture img');
		//picture.slideDown();
		//picture.animate({opacity: 1.0}, 3000);
		picture.fadeIn('slow');


		/*portrait.fadeOut('slow');				
		//picture.load(file + ' #' + city + ' #picture img');
		portrait.load(file + ' #portrait img');
		//picture.slideDown();
		//picture.animate({opacity: 1.0}, 3000);
		portrait.fadeIn('slow');*/
		
		/*.fadeOut(2000, function(){
						//portrait.fadeOut('slow');
						
						portrait.fadeIn(2000, function()
						{
							portrait.load(file + ' #portrait img');
						});
				});*/
				
				//portrait.load(file + ' #portrait img', function () { $(this).fadeIn("slow"); }); 
				
				//$(file + '#portrait img').bind("load", function () { $(this).fadeIn(); }); 
				
				//portrait.load(file + ' #portrait img').hide();
				//portrait.fadeIn('slow');
				
				// fade in images already loaded: 
portrait.fadeOut(500); 
// and tell pending images to do the same, once they've finished loading: 
portrait.load(file + ' #portrait img', function () { 
    $(this).fadeIn(3000); 
}).hide(); 


	}
	
}

function url() {
	 window.location = "../../esp/offices/office.html?file=barcelona.html&city=Barcelona";
}


