$(document).ready(function(){

	// function backgroundFix(){
	// 	left = (1500 - $(window).width())/2;	 
	// 	if ($(window).width() > 960) {
	// 		$('.background-image').css("left", - left);		
	// 	};	
	// }	

	function backgroundChange(area){
		if($(".background-image img."+area).is(":hidden")){
			$(".background-image img:visible").fadeOut("slow");
			$(".background-image img."+area).fadeIn("slow");
		}
	}
	
	// backgroundFix();
	// $(window).resize(function(){
 //    	backgroundFix();
 //   	})
	
	//map page
	/*$("a.map-link").hover(function(){
		area = $(this).attr('id');
		$("#areas-large").removeClass();
		$("#areas-large").addClass(area);		
	});*/	


	$(".area").hide();
	/*$("a.area-link").click(function(){
		$(".area").fadeOut();
		contentArea = $(this).attr('id');
		$(".area#"+contentArea).fadeIn();	
		$("a.map-link").hide();		
		backgroundChange(contentArea)
		return false;
	}); */

	$("a.area-link").click(function(){
		$(".area").fadeOut();
		contentArea = $(this).attr('rel');
		$("#"+contentArea).fadeIn();	
		$("a.map-link").hide();		
		backgroundChange(contentArea)
		return false;
	});

	$("a.area-back, #areas-large").click(function(){
		if($(".area").is(":visible")){
			$("#areas-large").removeClass();
			$(".area").fadeOut();
			$("a.map-link").show();
			backgroundChange("default");
		}
		return false;
	});
	
	/*$('a.area-link, .areas li a').mouseenter(function(){
		add = $(this).attr('rel');
		//$("#areas-large").removeClass();
		$('#areas-large').addClass(add);	
	});
	
	$('a.area-link, .areas li a').mouseleave(function(){
		add = $(this).attr('rel');
		$('#areas-large').removeClass(add);
	});*/
	
	$("#map-rio").mouseenter(function(){
		$("#rio-btn").stop(true,true).show();
	});
	
	$("#map-rio").mouseleave(function(){
		$("#rio-btn").stop(true,true).hide();
	});
	
	$("#map-singapore").mouseenter(function(){
		$("#singapore-btn").stop(true,true).show();
	});
	
	$("#map-singapore").mouseleave(function(){
		$("#singapore-btn").stop(true,true).hide();
	});
	
	$("#map-calgary").mouseenter(function(){
		$("#usa").stop(true,true).show();
	});
	
	$("#map-calgary").mouseleave(function(){
		$("#usa").stop(true,true).hide();
	});
	
	$("#map-houston").mouseenter(function(){
		$("#usa").stop(true,true).show();
	});
	
	$("#map-houston").mouseleave(function(){
		$("#usa").stop(true,true).hide();
	});
	
	$("#map-aberdeen").mouseenter(function(){
		$("#europe").stop(true,true).show();
	});
	
	$("#map-aberdeen").mouseleave(function(){
		$("#europe").stop(true,true).hide();
	});
	
	$("#map-london").mouseenter(function(){
		$("#europe").stop(true,true).show();
	});
	
	$("#map-london").mouseleave(function(){
		$("#europe").stop(true,true).hide();
	});
	
	$("#map-johannesburg").mouseenter(function(){
		$("#africa").stop(true,true).show();
	});
	
	$("#map-johannesburg").mouseleave(function(){
		$("#africa").stop(true,true).hide();
	});
	
	$("#map-perth").mouseenter(function(){
		$("#australia").stop(true,true).show();
	});
	
	$("#map-perth").mouseleave(function(){
		$("#australia").stop(true,true).hide();
	});
	
	$("#map-sydney").mouseenter(function(){
		$("#australia").stop(true,true).show();
	});
	
	$("#map-sydney").mouseleave(function(){
		$("#australia").stop(true,true).hide();
	});

	//team page
	//top section
	/*$(".profile").hide();
	$(".names a").click(function(){
		var profile = $(this).attr("id");		
		$(".names").hide();	
		$(".profile").hide();
		$(".profile#"+profile).fadeIn();
		var height = $(".profile#"+profile).height() + 60;
		$(".content").animate({height: height});		
		backgroundChange($(this).attr("class"));
		return false;
	});*/
	
	$(".profile").hide();
	$(".names a").click(function(){
		var profile = $(this).attr("rel");		
		$(".names").hide();	
		$(".profile").hide();
		$(".profile#"+profile).fadeIn().css("display", "inline");
		var height = $(".profile#"+profile).height() + 60;
		$(".content").animate({height: height});		
		backgroundChange($(this).attr("class"));
		return false;
	});

	//team table
	$("#profiles .team-profile").hover(function(){
		name = $(this).find('img').attr("id");
		staffloc = $(this).find('img').attr("class");
		name = name.replace('profile-', '');
		$('a[rel~="'+name+'"]').css('font-weight', 'bold');
		var name1 = name.replace('-', '<br />');
//		$('#'+name).css('font-weight', 'bold');
		$('<p class="view"><span>'+name1+'</span><br /><br /><br /><a href="#" rel="'+name+'" class="'+staffloc+'">View Profile >></a></span></p>').appendTo(this);		
		$("p.view a").click(function(){				
			//$(".names a#"+$(this).attr("rel")).click();
			var profile = $(this).attr("rel");		
			$(".names").hide();	
			$(".profile:visible").hide();
			$(".profile#"+profile).fadeIn().css("display", "inline");
			var height = $(".profile#"+profile).height() + 60;
			$(".content").animate({height: height});		
			//$(".content").css({"height": "385px"});	
			//$(".profile#"+profile).css({"height": "385px"});
			backgroundChange($(this).attr("class"));
			$("html").scrollTo({top:'0px'},1000);
			return false;			
		});
		
	}, function(){
		$(".view").remove();
		//$('#'+name).css('font-weight', 'normal');
		$('a[rel~="'+name+'"]').css('font-weight', 'normal');
	});

	//backbutton for teams
	$("a.back-link").click(function(){
		$(".profile").hide();
		$(".content").animate({height: 250});	
		$(".names").fadeIn();
	});

	//services accoridan
	/*$(".accordian p:not(:first)").hide();
	$(".accordian p:first").slideDown();

	$(".accordian h3").click(function(){	
	
		 var src = $("h3").find('img').attr("src").replace("-down", "");
         $("h3:not(.closing)").find('img').attr("src", src);
				
		 var src = $(this).find('img').attr("src").match(/[^\.]+/) + "-down.png";
		 $(this).find('img').attr("src", src);

		
		$('.accordian').find('p.auto-close:visible').slideUp();
		
		
        z = $(this).attr("class");
        $(this).next("p").slideDown( "fast", function(){
        	backgroundChange(z);
        });       
	});*/
	
	
	//Hide P Tags - NOT FIRST
	
	$('.accordian p').not(':first').hide();

	
	// CLICK HANDLER FOR REST
	$(".accordian h3").click(function()
	{
		$(".accordian p").slideUp();
		
		if($(this).next('p').is(':visible')){
			//IF P IS SHOWING - HIDE IT
			$(this).next('p').slideUp();
			$(this).css("background-image", "url(images/background/pointer-blue-down.png)");
		} else {
			// ELSE SHOW IT
			$(this).next('p').slideDown();
			$(this).css("background-image", "url(images/background/pointer-blue-up.png)");
			z = $(this).attr("class");	
			backgroundChange(z);
		}											   
	});

	
	
	
	//Our Experience accoridan
	$(".experience-accordian .section .text-area").hide();
	//$(".experience-accordian .section:first h3").css("background-image", "url(images/background/pointer-white-down.png)");

	$(".experience-accordian .section h3").click(function(){					
		if($(this).parent().children(".text-area:visible").size() > 0){
			$(this).parent().children(".text-area").slideUp();
			$(this).css("background-image", "url(images/background/pointer-white-down.png)");			
			backgroundChange("default");
		} else {
			$(this).parent().children(".text-area").slideDown();
			$(this).css("background-image", "url(images/background/pointer-white-up.png)");
			z = $(this).attr("class");
			backgroundChange(z);
		}
	});
	
	
	

	//locations page
	
	//$(".location:not(:first)").hide();

	$("#london-address").show();

	
	
	$("a.area-link").click(function(){				
		$(".location").hide();
		mapLocation = $(this).attr('id');
		mapLocation = mapLocation.replace('map-', '');
		$("#"+mapLocation+'-address').fadeIn();
		backgroundChange(mapLocation);
		return false;		
	});
	
	$('a.location-link').mouseenter(function(){
		var add = $(this).attr('id');
		//$("#locations-contact").removeClass();
		$('#locations-contact').addClass(add);
	});
	
	$('a.location-link').mouseleave(function(){
		var add = $(this).attr('id');
		$("#locations-contact").removeClass();
		//$('#locations-contact').addClass(add);
	});	

});
