function equalHeight(group) {
	tallest = 0;
	group.each(function() {
	thisHeight = $(this).height();
	if(thisHeight > tallest) {
	tallest = thisHeight;
	}
	});
	group.height(tallest);
}

(function ($) {
    $.fn.vAlign = function(container) {
        return this.each(function(i){
	   if(container == null) {
	      container = 'div';
	   }
	   var paddingPx = 0; //change this value as you need (It is the extra height for the parent element)
	   $(this).html("<" + container + ">" + $(this).html() + "</" + container + ">");
	   var el = $(this).children(container + ":first");
	   var elh = $(el).height(); //new element height
	   var ph = $(this).height(); //parent height
	   if(elh > ph) { //if new element height is larger apply this to parent
	       $(this).height(elh + paddingPx);
	       ph = elh + paddingPx;
	   }
	   var nh = (ph - elh) / 2; //new margin to apply
	   $(el).css('margin-top', nh);
        });
     };
})(jQuery);

$(document).ready(function() {
	$("#sidefooter").hide();
	$(window).load(function(){
		// execute size changes AFTER document has loaded so it works in Safari 4
		// $(".thumbnails li").vAlign();
		$(".thumbnails li img").each(function() {
			//containerheight=($(this).parent().height());
			//imageheight=$(this).height;
			//imagemargin=containerheight-imageheight;
			//alert(containerheight);
		});
		
		equalHeight($(".twoColumns .column"));
		equalHeight($("#HCB .row .hcb"));
		equalHeight($(".sl-thumb-no-summary li"));
		equalHeight($(".sl-thumb-no-summary li p"));
		equalHeight($(".eqh"));
		
		$("#sideFooter").show();
if($("#contentContainer").height()-$("#contentSide").height()>0) {
		// move sideFooter to correct position
		$("#sideFooter").css("margin-top",$("#contentContainer").height()-$("#contentSide").height());
}
		
	});
	
	$("a.fancybox").fancybox({
		'transitionIn'	:	'elastic',
		'transitionOut'	:	'elastic',
		'speedIn'		:	600, 
		'speedOut'		:	200, 
		'overlayOpacity':	0.8,
		'overlayShow'	:	true
	});

	$("#subPageList li.blockLink").hover(
	  function () {
		$(this).addClass("hover");
	  }, 
	  function () {
		$(this).removeClass("hover");
	  }
	);

	$(".blockLink").click(function(){
	  if($(this).find("a").attr("href")!==undefined) {
	   window.location=$(this).find("a").attr("href"); return false;
	  };
	});

	$("ul.youtubevideos").ytplaylist({playerWidth: 280, playerHeight:174, addThumbs:false, autoPlay: false, allowFullScreen:true, showRelated:false, holderId: 'ytvideo'});

    $('a.email').nospam({
      replaceText: true,    // BOOLEAN, optional default false. If set to true, replaces matched elements' text with the e-mail address
      filterLevel: 'normal' // STRING, optional accepts 'low' or 'normal', default 'normal'.
                            // low: email/domain/tld
                            // normal: dlt/niamod/liame (email/domain/tld reversed)
    });

	$(".hcb, ul.gallery li").hover(
	  function () {
		$(this).addClass("hover");
	  }, 
	  function () {
		$(this).removeClass("hover");
	  }
	);

	
	

// main menu
	
	$("#menu ul li").hover(
		function(){
			$(this).find("ul").stop(true,true).fadeIn(300);
			$(this).addClass("hover");
		},
		function(){
			$(this).find("ul").stop(true,true).fadeOut(250);
			$(this).removeClass("hover");
		}
		);
	//ACCORDION BUTTON ACTION (ON CLICK DO THE FOLLOWING)
	$('.accordionButton').click(function() {

		//REMOVE THE ON CLASS FROM ALL BUTTONS
		$('.accordionButton').removeClass('on');
		  
		//NO MATTER WHAT WE CLOSE ALL OPEN SLIDES
	 	$('.accordionContent').slideUp('normal');
   
		//IF THE NEXT SLIDE WASN'T OPEN THEN OPEN IT
		if($(this).next().is(':hidden') == true) {
			
			//ADD THE ON CLASS TO THE BUTTON
			$(this).addClass('on');
			  
			//OPEN THE SLIDE
			$(this).next().slideDown('normal');
		 } 
		  
	 });
	  
	
	/*** REMOVE IF MOUSEOVER IS NOT REQUIRED ***/
	
	//ADDS THE .OVER CLASS FROM THE STYLESHEET ON MOUSEOVER 
	$('.accordionButton').mouseover(function() {
		$(this).addClass('over');
		
	//ON MOUSEOUT REMOVE THE OVER CLASS
	}).mouseout(function() {
		$(this).removeClass('over');										
	});
	
	/*** END REMOVE IF MOUSEOVER IS NOT REQUIRED ***/
	
	
	/********************************************************************************************************************
	CLOSES ALL S ON PAGE LOAD
	********************************************************************************************************************/	
	$('.accordionContent').hide();


});
