/*
CSS Browser Selector v0.3.4 (Sep 29, 2009)
Rafael Lima (http://rafael.adm.br)
http://rafael.adm.br/css_browser_selector
License: http://creativecommons.org/licenses/by/2.5/
Contributors: http://rafael.adm.br/css_browser_selector#contributors
*/
function css_browser_selector(u){var ua = u.toLowerCase(),is=function(t){return ua.indexOf(t)>-1;},g='gecko',w='webkit',s='safari',o='opera',h=document.getElementsByTagName('html')[0],b=[(!(/opera|webtv/i.test(ua))&&/msie\s(\d)/.test(ua))?('ie ie'+RegExp.$1):is('firefox/2')?g+' ff2':is('firefox/3.5')?g+' ff3 ff3_5':is('firefox/3')?g+' ff3':is('gecko/')?g:is('opera')?o+(/version\/(\d+)/.test(ua)?' '+o+RegExp.$1:(/opera(\s|\/)(\d+)/.test(ua)?' '+o+RegExp.$2:'')):is('konqueror')?'konqueror':is('chrome')?w+' chrome':is('iron')?w+' iron':is('applewebkit/')?w+' '+s+(/version\/(\d+)/.test(ua)?' '+s+RegExp.$1:''):is('mozilla/')?g:'',is('j2me')?'mobile':is('iphone')?'iphone':is('ipod')?'ipod':is('mac')?'mac':is('darwin')?'mac':is('webtv')?'webtv':is('win')?'win':is('freebsd')?'freebsd':(is('x11')||is('linux'))?'linux':'','js']; c = b.join(' '); h.className += ' '+c; return c;}; 

css_browser_selector(navigator.userAgent);

//$(function() {
//	$('.truncate_area').truncate({max_length: 235});
//});



function adjustHeadingWhiteBG(){
	
/*	if( $('.page_heading h1 span').text().length > 0 ){
		$('.page_heading h1 span').text($('.page_heading h1 span').text().toUpperCase());
	}else{
		$('.page_heading h1').text($('.page_heading h1').text().toUpperCase());
	}*/
		
	var height_white_bg = 0
	if ($('.home_page_heading').length > 0) {
		height_white_bg = $('.home_page_heading h1').height()-40;
	}
	else {
		height_white_bg = $('.page_heading h1').height()-25;
	}
	if (height_white_bg > 0){
		$('#heading_background').css('height', height_white_bg+'px');
	}
}

function setLeftPanelArea(){
	//Comment these 2 out to show the webparts
		$('#main_panel_middle_left_explore_expanded').hide();
		$('#main_panel_middle_left_popular_expanded').hide();

         	// Expand  
  	      $('#main_panel_middle_left_explore').click(function() {
			$('#main_panel_middle_left_explore').hide();
      		$("#main_panel_middle_left_explore_expanded").slideToggle("slow");
    		});
			
		$('#main_panel_middle_left_popular').click(function() {
			$('#main_panel_middle_left_popular').hide();
     			$("#main_panel_middle_left_popular_expanded").slideToggle("slow");
    		});

       
		// Collapse 		
		$('#main_panel_middle_left_explore_expanded a img').click(function() {				
     			$("#main_panel_middle_left_explore_expanded").slideToggle("slow", function() {
				$('#main_panel_middle_left_explore').show();
			});
   		});		
		$('#main_panel_middle_left_popular_expanded a img').click(function() {				
      		$("#main_panel_middle_left_popular_expanded").slideToggle("slow", function() {
				$('#main_panel_middle_left_popular').show();
			});
   		});
    
	moveFooter();
}


function moveFooter(){
	var moveAmount = 0;
	var windowHeightHolder = $(window).height();
	var windowHeightHolder2 = $('#main_panel').height() + $('#bottom_panel').height();	
	if (windowHeightHolder < windowHeightHolder2)
	{
		moveAmount = $('#bottom_panel').height();
	}
	else
	{
		moveAmount = windowHeightHolder - $('#main_panel').height();
	}
	$('#bottom_panel').css('height', moveAmount +'px');		
}

function resizeBackgroundPanel() {
	var resizeTimer = null;	
	$(window).resize(function(){
  		moveFooter();
	});
}
resizeBackgroundPanel();

function subjectListLastItem(){
	$("#black_box_text ul.browse_by_subject_white li a:last").addClass("browse_by_subject_last_item");
}

function articleListLastItem(){
	$("div#article_box_text div.menuItemContainer:last").addClass("menuItemContainerLast");
}

function languageLevelsLastItem(){
	$("#black_box_text div.language_level:last").addClass("language_level_last");
}

function toggleYellowCMArea(){
	var s = $('#home_yellow_text').html();

	s = s.replace(/^(\s*<br\s*\/?>)*\s*|\s*(<br\s*\/?>\s*)*$/g, '');
		
	if( s.length == 0 ){
		$('#home_yellow_box').css('display','none');
	}
	moveFooter();
}

function toggleBookContentManagedArea(){
	if ($('.content_managed_text').length == 0){
		// do something here
		//alert('dont exist');
		$('.insight_object').css('background','none');
		
/*		$('#book_black_box_content_background').css('min-height',202);
		$('#book_black_box_content').css('min-height',202);
		$('#book_black_box_area').css('min-height',202);*/
		
	}	
}

function adjustRelatedArticlesBox(){
	//alert('adjustRelatedArticlesBox')
	if($('.menuItemContainer').length == 0){
		//alert('menuItemContainer = 0');
		$('#article_box_content').css('height','45px');
		$('#article_box_content').css('overflow-y','hidden');
	}
}
