
(function ($) {
  Drupal.Panels = {};

  Drupal.Panels.autoAttach = function() {
    if ($.browser.msie) {
      // If IE, attach a hover event so we can see our admin links.
      $("div.panel-pane").hover(
        function() {
          $('div.panel-hide', this).addClass("panel-hide-hover"); return true;
        },
        function() {
          $('div.panel-hide', this).removeClass("panel-hide-hover"); return true;
        }
      );
      $("div.admin-links").hover(
        function() {
          $(this).addClass("admin-links-hover"); return true;
        },
        function(){
          $(this).removeClass("admin-links-hover"); return true;
        }
      );
    }
  };

  $(Drupal.Panels.autoAttach);
})(jQuery);
;
jQuery(document).ready(function($) {
	
	// ------ DATA ------
	
	var patterns = new Array(
		"15,46,22,46,22,59,28,59,28,57,35,57,35,37,40,24,46,24,46,62,57,62,68,50,83,50,93,63,93,79,99,79,99,98,105,98,105,109,114,109,114,96,120,96,120,66,124,66,124,48,131,48,131,55,140,55,140,48,169,48,169,54,157,66,157,74,167,66,172,66,172,55,179,55,179,48,186,48,186,57,191,57,193,63,200,65,200,57,235,22,235,16,122,16,107,1,41,0,15,20",
		"200,65,200,57,256,1,316,1,334,10,344,32,344,41,337,41,337,50,350,63,356,63,356,74,348,74,328,55,320,36,302,28,289,15,286,32,298,41,298,51,279,59,272,74,277,90,300,96,300,102,298,107,290,107,268,98,260,78,245,78,245,93,236,93,227,84,220,97,212,102,206,111,197,111,197,102,217,80,217,65",
		"302,28,294,28,303,40,303,51,311,59,311,80,300,80,300,96,300,102,298,107,290,107,268,98,260,78,245,78,245,93,236,93,227,84,220,97,212,102,206,111,197,111,197,102,217,80,217,65,200,65,193,63,144,116,138,116,137,125,142,126,144,122,162,122,166,118,202,118,206,122,227,122,267,145,321,145,358,119,358,106,366,98,367,46,357,27,350,27,347,31,347,43,341,49,351,60,356,60,356,74,352,74,352,81,345,81,328,55,320,36",
		"95,145,137,124,138,115,144,116,193,63,191,57,186,57,186,48,179,48,179,55,172,55,172,66,167,66,155,76,155,64,149,64,149,54,142,54,142,62,137,62,137,58,131,58,131,48,124,48,124,66,120,66,120,96,114,96,114,109,105,109,105,98,99,98,99,79,95,79,95,86,79,94,54,86,54,71,46,71,46,24,40,24,35,37,35,57,28,57,28,79,23,79,23,59,22,59,22,46,15,46,15,30,11,30,11,39,4,39,4,59,0,59,0,86,5,105,12,119,18,125,24,131,56,145"
	);
	/* Patterns are for: */
	var targets = new Array(
    'sourcing',
	  'engineering',
    'design',
    'development'
	);
	
	var links = new Array();
	$('#article .content a').each(function(index) {
    var link = $(this).attr('href');
    // trace('link',link);
    var templinks = link.split('/');
		links.push( {title:$(this).html().toLowerCase().trim().replace(/\s/gi, "-"),href:$(this).attr('href'),pid:$.inArray( templinks[templinks.length-1], targets) } );
	});
  // trace(links);
	// ------ HTML ------

	var url_img = $('#article').css('backgroundImage');
	var path = url_img.match(/http:\/\/.+\.[a-z]{3,4}/gi);
	var html = '<img id="logo-map" src="'+ path  +'" usemap="#map-nav" />\
	<map name="map-nav" id="map">';
	for (var i=0; i < links.length; i++) {
	  if( links[i].pid!=-1 )
		  html += '<area id="area-'+links[i].pid+'" title="'+links[i].title+'" href="'+links[i].href+'" shape="poly" coords="'+patterns[links[i].pid]+'"/>';
	};
	html += '</map>';
	$('#article .content').html(html);
	
	// ------ EVENT ------
	// ------ patterns ------
	$('area').hover(function() {
		f_hightlight_patterns($(this));
	}, function() {
		f_unhightlight_patterns($(this));
	});

	function f_hightlight_patterns($o){
	  
	  var id = $o.attr('id');
	  var pid = parseInt( id.match(/\d*$/) );
		$('#article').css({backgroundPosition: '-'+(pid+1)*400+'px 0'});

		$('#block-views-menu-services-menu-services a').each(function() {
			var regexp = new RegExp( $o.attr('href'), 'gi');
			if( $(this).attr('href').search(regexp) != -1 ) $(this).addClass('active');
			$('h2', $(this).parents('.block-menu')).addClass('active');
		});
	}
	function f_unhightlight_patterns($o){
		$('#article').css({backgroundPosition: '0 0'});
		$('#block-views-menu-services-menu-services a,#block-views-menu-services-menu-services h2').removeClass('active');
	}
	
	// ------ nav ------
	$('#block-views-menu-services-menu-services a').hover(function() {
		f_hightlight_nav($(this));
	}, function() {
		f_unhightlight_nav($(this));
	});

	function f_hightlight_nav($o){
		var index;
		$('area').each(function() {
			var regexp = new RegExp( $o.attr('href'), 'gi');
			var id = $(this).attr('id');
  	  var pid = parseInt( id.match(/\d*$/) );
			if( $(this).attr('href').search(regexp) != -1 ) index = pid;
		});
		$('#article').css({backgroundPosition: '-'+(index+1)*400+'px 0'});	
	}
	function f_unhightlight_nav($o){
		$('#article').css({backgroundPosition: '0 0'});
	}
	
});;

