var curDisplay = "client00";
var clientCount = 0;
var allowSwitch = true;
var lastDisplay;

function switchDetail(newElement){
	allowSwitch = false;
	$('.clientdetail .'+curDisplay).fadeOut(150,function(){
		$('.clientdetail .'+newElement).fadeIn(150);
		allowSwitch = true;
	});
}
$(document).ready(
	function() {
		$('.rightcol a img.fadeBtn').fadeTo(0,0.65);
		$('.rightcol a img.fadeBtn').hover(
			function() {
				$(this).fadeTo(0,1);
			}, 
			function() {
				$(this).fadeTo(0,0.65);
			}
		);
		$("a.inline").fancybox({
			overridePos: true,
			width: 465,
			height: 640,
			showCloseButton: true,
			titleShow: false,
			autoDimensions: false
		});
		$("a.inlinejen").fancybox({
			overridePos: true,
			width: 480,
			height: 640,
			showCloseButton: true,
			titleShow: false,
			autoDimensions: false
		});
		$("a.iframe").fancybox({
			width: 500,
			height: 300,
			showCloseButton: true,
			titleShow: false,
			autoDimensions: false
		});	
		/*
		$(".clientprofile").hover(
			function(){
				$('.clientprofile .client00').css('z-index',100);
				$('.clientprofile .client00').fadeIn(0);
			},
			function(){
				$('.clientprofile .client00').css('z-index',1);
				if(curDisplay != 'client00') {
					$('.clientprofile .client00').fadeOut(0);
				}
			}
		);
		
		$("#Map area").hover(
			function(){
				$('.clientprofile .client00').css('z-index',997);
				$('.clientprofile .client00').fadeIn(0);
				$('.clientprofile .'+$(this).attr('rel')).css('z-index',998);
				$('.clientprofile .'+$(this).attr('rel')).fadeIn(150);
			},
			function(){
				$('.clientprofile .client00').css('z-index',1);
				$('.clientprofile .client00').fadeIn(0);
				if(curDisplay != $(this).attr('rel')){
					$('.clientprofile .'+$(this).attr('rel')).css('z-index',1);
					$('.clientprofile .'+$(this).attr('rel')).fadeOut(150);
				} else {
					$('.clientprofile .'+curDisplay).css('z-index',100);
				}
			}
		);
		*/
		$("#Map area").hover(function(){
				$('.clientprofile .'+$(this).attr('rel')).css('z-index',998);
				$('.clientprofile .'+$(this).attr('rel')).fadeIn(0);
			}, function(){
				if(curDisplay != $(this).attr('rel')){
					$('.clientprofile .'+$(this).attr('rel')).fadeOut(0);
					$('.clientprofile .'+$(this).attr('rel')).css('z-index',1);
				} else {
					$('.clientprofile .'+$(this).attr('rel')).css('z-index',1);
				}
			}
		);
		$("#Map area").click(function(){
		    $('.clientprofile .client00').css('z-index',1);
			$('.clientprofile .'+curDisplay).fadeOut(0);
			switchDetail($(this).attr('rel'));
			curDisplay = $(this).attr('rel');
			$('.clientprofile .'+curDisplay).css('z-index',100);
			$('.clientprofile .'+curDisplay).fadeIn(0);
			clientCount = $('#Map area').index($(this))+1;
		});
		$('.nextClient').click(function(){
			if(allowSwitch == true) {										
				if(clientCount < 6){
					clientCount++;
				} else {
					clientCount = 1;
				}
				$("#Map area:eq("+(clientCount-1)+")").trigger('click');
			}
		});
		$('.prevClient').click(function(){
			if(allowSwitch == true) {																				
				if(clientCount > 1){
					clientCount--;
				} else {
					clientCount = 6;
				}
				$("#Map area:eq("+(clientCount-1)+")").trigger('click');
			}
		});
	}
);
