/* -----------------------------------------
 0.0 getUrlVars JQUERY FUNCTIONS
 -----------------------------------------*/

$.extend({
  getUrlVars: function(){
    var vars = [], hash;
    var hashes = window.location.href.slice(window.location.href.indexOf('?') + 1).split('&');
    for(var i = 0; i < hashes.length; i++)
    {
      hash = hashes[i].split('=');
      vars.push(hash[0]);
      vars[hash[0]] = hash[1];
    }
    return vars;
  },
  getUrlVar: function(name){
    return $.getUrlVars()[name];
  }
});

/* -----------------------------------------
 1.0 JQUERY FUNCTIONS
 -----------------------------------------*/

jQuery(document).ready(function($){
	
	/* -----------------------------------------
	 1.1 Show hide submenu
	 -----------------------------------------*/

	$('#menu .submenu').each(function () {
		var submenu = $(this);
		submenu.parent('li').hover(
	      function () {
	        submenu.show();
	        $(this).addClass('selected');
		  },
		  function () {
	        submenu.hide();
	        //alert($(this).find('li.selected').index());
	        if($(this).find('li.selected').index() < 0)
	        {
	        	//alert('remove');
	        	$(this).removeClass('selected');
	        }
		  }
		);
	});
	$("#menu li.policies a:eq(0)").click(function(){
		return false;
	});
	

	
	/* -----------------------------------------
	 1.2 Tabs
	 -----------------------------------------*/
	
	$('.tabs').each(function (i) {
		
		var tab = $(this);
		
		tab.children('.wrapper').hide();
		
		// creation of the tabs links following h2 text inside the wrapper
		
		tab.children('.wrapper:eq('+i+')').before('<ul></ul>');
		
		tab.find('h2').each(function () {
			var h2 = $(this);
			tab.children('ul').append('<li><a href=""><span><strong>'+h2.text()+'</strong></span></a></li>');
		});
		
		tab.find('ul a').each(function (j) {
			var a = $(this);
			
			a.click(function()
			{
				tab.children('.wrapper').hide();
				tab.find('ul a').removeClass('selected');
				
				tab.children('.wrapper:eq('+j+')').show();
				a.addClass('selected');
				//alert(i);
				return false;
			});
			
		});
		
		tab.children('.wrapper').wrapInner('<div class="innerWrapper"></div>');
		
		tab.find('h2').hide();
		
		tab.find('.wrapper:eq(0)').show();
		tab.find('a:eq(0)').addClass('selected');

	      
	});
	
	/* -----------------------------------------
	 1.3 LEFT MENU SELECTED LINK
	 -----------------------------------------*/
	
	
	var url = window.location.href.substring(window.location.href.indexOf('/health-eu/')+1,window.location.href.indexOf('.htm'));
	
	$("#menu a[href*="+url+"]").each(function () {
		$(this).parent('li').addClass('selected');
	});
	
	$("#menu ul li.selected").parents('.submenu').parent().addClass('selected');
	
	
	/* -----------------------------------------
	1.4 HIDE EVENTS TO COME WHEN PAGE > 1
	-----------------------------------------*/
	
	var pageNumber = $.getUrlVar('Page');
	//alert(pageNumber);
	
	if(pageNumber > 1){
		$(".block.toCome").hide();
		$(".block.toCome").eq(0).prev('.mainTitle').hide();
		//alert("elemets hided");
	}
	
	/* -----------------------------------------
	1.5 Hide related to if no link
	-----------------------------------------*/
	$(".block .content small").each(function () {
	if(($('a',this).length)< 1 )
		{
			$(this).hide();
		}
	});
	
	/* -----------------------------------------
	1.0 Hide related to if no link
	-----------------------------------------*/
	$(".green_dropdown select").change(function() {

		var value = $(this).val();
		
		if(value != 'all')
		{
			$("div.snapshots").hide();
			$("div.snapshots > a[rel="+value+"]").parent().show();
		}
		else
		{
			$("div.snapshots").show();
		}

	});

});





