var general = { 
	
	// OnLoad functions
	init: function(){
		this.bubbleEvt();
		this.contentRotator();
		this.consultSelect();
		this.langSelToggle();
	},
	
	bubbleEvt: function() {
		general.equalHeight($('.blurbrow1 .blurb-content'));
		
			
		if ($('.info-text').length > 0) {
			$('.info-text').append('<div class="top"></div>')
		}
		
		if ($('.paging').length > 0) {
			$('.paging div a').parent('div').addClass('highlighted')
		}
		
		$("#news-see-all").click(function(){
			general.toogleNews(this);
			return false;
		});
		
		$(".print a").click(function(){
			window.print();
			return false;
		});
		
		
		if( $("ul.submenu").length > 0 ) {
			general.fixMenuHeight();
		}
		
			
	},
	
	toogleNews: function(e) {
		$(e).prev().children("li.display-none").slideDown("slow", function(){$(e).hide("slow");});
		
	},
	
	contentRotator: function(e) {		
		$contentRow = $("#content .content-row");
		$contentRowTitle = $("#content .content-row-title");
		$contentRowInfo = $("#content .content-row-info");
		$contentBg = $("#content .content-bgs");
				
		/* init if page is loaded and we need to show first row of content */
		if ($contentRow.css('display','none')) {
			$contentBg.hide()
			$contentBg.eq(0).fadeIn('fast')
			$contentRow.eq(0).fadeIn('fast')
			$contentRowInfo.eq(0).fadeIn('fast')
		} 
				
		$contentRowTitle.hover(function(){
			if(!$(this).hasClass("on")){							
				$rowIndex = $(this).index('.content-row-title');
				$contentRow.hide();
				$contentBg.fadeOut("fast");
				$contentRowInfo.hide();
				$contentRowTitle.removeClass("on");
				
				$(this).addClass("on");
				$contentBg.eq($rowIndex).fadeIn('fast')
				$contentRow.eq($rowIndex).fadeIn('fast')
				$contentRowInfo.eq($rowIndex).show()
			}
		}, 
		function () {});

	},
	
	
	fixMenuHeight:function() {
		var mh = $('.main-content').height();
		var sh = $(".submenu").height();
		$(".main-content").css("height","");
		
		if( sh > mh ) { 
			$(".main-content").height(sh+100);
		}	
	},
	
	
	consultSelect: function(e) {
		if($('.consult-list').length>0) {
			$('.consult-list').css('display','none')	
			$("#"+$(".country-select-holder a:first").attr('class')).css({display: 'block'})
			general.fixMenuHeight();
		}
		
		$(".country-select-holder a").click(function(){	
			$('.consult-list').css('display','none')
			$("#"+$(this).attr('class')).css('display','block');
			general.fixMenuHeight();
			return false;		
		});
	},
	
	equalHeight: function(group) {
	   tallest = 0;
	   group.each(function() {
	      thisHeight = $(this).height();
	      if(thisHeight > tallest) {
	         tallest = thisHeight;
	      }
	   });
	   group.height(tallest);
	},
		
	langSelToggle: function() {	
		$elm = $('.international-wrapper');
		$linkList = $('#international');	
		elmOrgTop = -255;
	   
		$('.international-opener').toggle(function() {
			$elm.css("z-index","1000");									   
			$elm.animate({
				top: elmOrgTop + $linkList.height() + 29+'px'
			}, 200);	
			$(this).addClass('open')		
		}, function() {
			
			$elm.animate({
				top: elmOrgTop+'px'
			}, 200, function(){$elm.css("z-index","888");});
			$(this).removeClass('open')	
		});	
		return false;		
	}	
		
}

$(document).ready(function(){			   
	general.init();
});
