/* 
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */


$(document).ready(function() {

    $('#directory .openview').hide();
    $('#careers .openview').hide();
    $('#expertise .openview').hide();


    $('#directory .closedview').click(function(){
        if ( $(this).children('.detailscontainer').is(':hidden') ){
            $(this).children('.detailscontainer').fadeIn();
            $(this).next('div').slideUp();
			$(this).find('.accordion').removeClass('close');						
        }
        else{
            $(this).children('.detailscontainer').fadeOut();
            $(this).next('div').slideDown();
			$(this).find('.accordion').addClass('close');
        }

    });

    $('#careers .closedview').click(function(){
        if ( $(this).next('div').is(':hidden') ){
            $(this).next('div').slideDown();
            $(this).addClass('active');
			$(this).find('.accordion').addClass('close');
        }
        else{
            $(this).next('div').slideUp();
            $(this).removeClass('active');
			$(this).find('.accordion').removeClass('close');
        }

    });

    $('#expertise .closedview').click(function(){
        if ( $(this).next('div').is(':hidden') ){
            $(this).next('div').slideDown();
			$(this).find('.accordion').addClass('close');            
        }
        else{
            $(this).next('div').slideUp();
            $(this).removeClass('active');
			$(this).find('.accordion').removeClass('close');
        }

    });

	// Global Reach Map - jQuery Version

	$('div#zoom_europe').click(function(){
		$('div#world').fadeOut(200);
	});

	$('div#zoom_world').click(function(){
		$('div#world').fadeIn(200);
	});

	$('div#zoom_europe, div#zoom_world').hover(function(){
		$(this).css('background-position','bottom left');
	},function(){
		$(this).css('background-position','top left');	
	});

	$('div.list h6').click(function(){
		if ($(this).siblings('ul').is(':visible')) {
			$(this).siblings('ul').slideUp('fast');
		} else {
			$('div.list ul').slideUp('fast');
			$(this).siblings('ul').slideDown('fast');
		};
	});

	$('div.list ul li').click(function(){
		clickedclass = $(this).attr('class');
		clickedtitle = $(this).attr('title');
		if (clickedclass == 'world') {
			$('div#world').fadeIn(200);
		} else {
			$('div#world').fadeOut(200);
		}
		$('div.label,div.info').hide();
		$('div.label[title="' + clickedtitle + '"],div.info[title="' + clickedtitle + '"]').stop().fadeIn(100);
		$('div.label,div.info,div#' + clickedtitle).css('z-index','15');
	});

    $('div.label').each(function(i) {
        var name = $(this).attr('title');
        var prepositionx = parseInt($('div#' + name).css('left'));
        var positionx = prepositionx - 6 + 'px';
        var prepositiony = parseInt($('div#' + name).css('top'));
        var positiony = prepositiony - 6 + 'px';
        $(this).css('top', positiony);
        $(this).css('left', positionx);
    });

    $('div.info').each(function(i) {
        var name = $(this).attr('title');
        var prepositionx = parseInt($('div#' + name).css('left'));
        if (prepositionx > 700) {
		var positionx = prepositionx - 202 + 'px';
		$(this).find('h6').css('padding','0 8px 4px 8px');
		} else {
		var positionx = prepositionx - 6 + 'px';
		}
        var prepositiony = parseInt($('div#' + name).css('top'));
        var positiony = prepositiony - 6 + 'px';
        $(this).css('top', positiony);
        $(this).css('left', positionx);
    });


	$('div.pin').mouseover(function(){
		$('div.label,div.info').hide();
		var over = $(this).attr('id');
		$(this).css('z-index','15');
		$('div.label,div.info').css('z-index','15');
		$('div[title="' + over + '"]').stop().fadeIn(100);
	});

	$('div.label,div.info').mouseover(function(event){
		$('div.label').hide();
		$(this).show();	
		$(this).css('z-index','15');
	});

	$('div.label,div.info').mouseleave(function(){
		$(this).fadeOut(100,function(){
			$('div.label').css('z-index','4');
			$('div.info').css('z-index','4');	
			$('div.pin').css('z-index','4');
		});
	});

});
