jQuery(function() {
  // aggregate menu active behaviour
	var aggregate_menu = jQuery('.aggregate_menu ul li a')
	var slider         = jQuery('#aggregate .aggregate_slider')
	var sliderInnerHTML = null
	
	aggregate_menu.click(function() {
		jQuery('.aggregate_menu ul li').removeClass('active')
		jQuery(this).parent('li').addClass('active')
		
		switch(jQuery(this).attr('id')) {
			case "widget_aggregate_twitter_link":
				if(!sliderInnerHTML)
				  sliderInnerHTML = slider.html();
				
				jQuery.ajax({type: 'GET',
				             url: window.location.protocol + '//' + window.location.host + ':' + window.location.port + '/widget_aggregate/player/twitter_user',
				             success: function(html){
				                var user = html.replace(/<\/?[^>]+(>|$)/g, ""); 
				                slider.html("<div class='info'><a target='blank' href='http://twitter.com/" + user + ">follow on twitter</a></div>"); 
				             }
				          });
				break;
			case "widget_aggregate_youtube_link":
			case "widget_aggregate_flickr_link":
				if(sliderInnerHTML)
					slider.html(sliderInnerHTML);
				break;
		}
	});

  // default active ambassador profile
  //jQuery('#aggregate #ambassadeurs a.amb_lex_immers').addClass('active')

  // aggregate ambassadeurs(images) header behaviour 
  
	jQuery('#ambassadeurs ul li a').click(function () {
    
	    jQuery('#ambassadeurs li img').each( function () {
			var amb_name = $(this).parent('a').parent('li').attr('class')
			
			$(this).attr('src', '/img/aggregate/' + amb_name + '_off.png');
			$(this).attr('class', '');					
		});
	  
		var current_amb = jQuery(this).parent('li').attr('class');
		var amb_image = jQuery(this).children('img');
		
		amb_image.attr('src', '/img/aggregate/' + current_amb + '_on.png');
		amb_image.attr('class', 'active');		
		
	    var amb_head = jQuery("#aggregate #ambassador_head")
	    var klass = jQuery(this).attr('class')
	    
	    var d_width = '130px'
	    var d_margin = '-6px 0 0 150px'
	
	    switch(true) {
	      case klass.indexOf('tim_akkerman') != -1:
	        amb_head.css({'background-image': 'url(' + window.location.protocol + '//' + window.location.host + '/img/aggregate/agg_tim.gif)',
	        			  'background-repeat': 'no-repeat'});
	        break;
	      case klass.indexOf('pierre_wind') != -1:
	        amb_head.css({'background-image': 'url(' + window.location.protocol + '//' + window.location.host + '/img/aggregate/agg_pierre.gif)',
	        			  'background-repeat': 'no-repeat'
	                      });
	        break;
	      case klass.indexOf('soumiya_abalhaya') != -1:
	        amb_head.css({'background-image': 'url(' + window.location.protocol + '//' + window.location.host + '/img/aggregate/agg_soumiya.gif)',
	        			  'background-repeat': 'no-repeat'});
	        break;
	      case klass.indexOf('lex_immers') != -1:
	        amb_head.css({'background-image': 'url(' + window.location.protocol + '//' + window.location.host + '/img/aggregate/agg_lex.gif)',
						  'background-repeat': 'no-repeat'
	                      });
	        break;
	      case klass.indexOf('dennis_weening') != -1:
	        amb_head.css({'background-image': 'url(' + window.location.protocol + '//' + window.location.host + '/img/aggregate/agg_dennis.gif)',
	                      'background-repeat': 'no-repeat'
	                      });
	        break;
	      case klass.indexOf('jessica_mendels') != -1:
	        amb_head.css({'background-image': 'url(' + window.location.protocol + '//' + window.location.host + '/img/aggregate/agg_jessica.gif)',
	        	          'background-repeat': 'no-repeat'
	                      });
	        break;
	  	  default: 
	        amb_head.css({'background-image': 'url(' + window.location.protocol + '//' + window.location.host + '/img/aggregate/agg_lex.gif)',
	        			  'background-repeat': 'no-repeat'
	                      });
	      break;
		} 
		
		jQuery('#aggregate').supersleight();
	});
  
  
	jQuery(".aggregate_minimize_btn").toggle( function () {
            jQuery('.aggregate_toggle').slideUp();
            jQuery(this).children('img').attr('src', '/img/aggregate/maximize_btn.gif');
      }, function () {
            jQuery('.aggregate_toggle').slideDown();
            jQuery(this).children('img').attr('src', '/img/aggregate/minimize_btn.gif');
      }
    );
    
    jQuery('.aggregate_helpme_btn a').hover( function () {
			jQuery(this).children('img').attr('src', '/img/aggregate/jouwstap_button_rollover.png');
		}, 	function () {
			jQuery(this).children('img').attr('src', '/img/aggregate/jouwstap_button.png');
		}
	);  
	
});

	function ambOn(amb, img) {
		jQuery(img).attr('src',  '/img/aggregate/' + amb + '_on.png');	
		jQuery(img).supersleight();
	}
				
	function ambOut(amb, img) {
		if(jQuery(img).attr('class') != 'active') {
			jQuery(img).attr('src',  '/img/aggregate/' + amb + '_off.png');	
			jQuery(img).supersleight();
		}
	}
