// JavaScript Document

$(document).ready(function(){
	var classes_str = $('body').attr('class');
	var section = parseInt(classes_str.substr(classes_str.indexOf("l1-")+3,classes_str.indexOf(" l2")-(classes_str.indexOf("l1-")+3)));
	var subsection = parseInt(classes_str.substr(classes_str.indexOf("l2-")+3,classes_str.indexOf(" l3")-(classes_str.indexOf("l2-")+3)));
	var subsubsection = parseInt(classes_str.substr(classes_str.indexOf("l3-")+3,classes_str.length-(classes_str.indexOf("l3-")+3)));
	$('ul#contentTabs > li').each(function(i){
		if (subsubsection-1==i) {
			$(this).addClass('selected');
		}
	});
	$('ul#subNavigation li.selected ul > li').each(function(i){
		if (subsection-1==i) {
			$(this).addClass('selected');
			$(this).parents('li.menuparent').addClass('subselected');
		}
	});
	$('ul#subNavigation > li').each(function(i){
		if (section-1==i) {
			$(this).addClass('selected');
			if ($(this).is('.menuparent')) {
				$("ul",this).show();
			} else {
				$(this).append('<div class="bottomShadow"></div>');
			}
		}
	});
	
	if ($.browser.msie && $.browser.version.substr(0,1)<7) { // Fix IE 6 idiocy
		//$('body').prepend('<div class="warning">You are using Internet Explorer 6 or lower. This browser is no longer supported by Microsoft. Please <a href="http://www.ieaddons.com/en/" traget="_blank">upgrade</a>.</div>')
		$('ul#subNavigation li.selected > a').addClass('selected');
		$('.randomLoadDiv > div').hide();
		$('ul#subNavigation li.subselected > a').css('background-image','none');
		$('#subContentColumn .imageBox .content > *:first-child').css('margin-top','17px');
		//$('a.greenbtn:hover span').css('background-position','right -22px');
		$('#content > *:first-child, #tabColumns .tabcolumn .content  > *:first-child, ul#subNavigation > li.selected:first-child').addClass('noTopMargin');
		$('#tabColumns .tabcolumn .title > *').css({
			'margin':'0',
			'color':'#0083c6',
			'padding':'6px 10px 4px 10px',
			'font-size':'12px',
			'line-height':'12px'
		});
		if ($('#mainContentColumn.wide').length != 0 && $('#dropdownNav').length !=0) { // Move the dropdown cuz IE6 can't handle the truth
			$('#dropdownNav').css({
				'position':'relative',
				'float':'right',
				'margin-top':'25px'
			});
			$('#contentTop').prepend($('#dropdownNav'));	
		} else if ($('#dropdownNav').length !=0) {
			$('#dropdownNav').css({
				'position':'relative',
				'float':'right',
				'margin-top':'25px',
				'margin-bottom':'20px'
			});
			$('#subContentColumn').css({
				'padding-top':'0'
			});
			$('#subContentColumn').prepend($('#dropdownNav'));
			
		}
	}
	
	$('#contentTabs .tabcolumn .content  > *:first-child, #content .imageBox .content *:first-child').addClass('noTopMargin');
	
	if ($('#dropdownNav').length !=0) {
		$('#dropdownNav ul li a').each(function(i){
			var href_str = $(this).attr('href');
			var location_str = document.location.href;
			if (location_str.indexOf(href_str) > -1) {
				$(this).parents('li').addClass('selected');	
			}
		});
		$('#dropdownNav ul li.selected a').each(function(i){
			var selectedText_str = $(this).text();
			if (selectedText_str.length > 30) {
				selectedText_str = selectedText_str.substring(0,30) + "...";
			}
			$('#selectedDropdown_text').text(selectedText_str); 
		});
		$('#selectedDropdown,#dropdownNav ul').hover(
			function() {
				$('#dropdownNav ul').show();
			},
			function() {
				$('#dropdownNav ul').hide();
			}
		);
	}
	/*
	$('#dropdownNav a').click(function(event){
		//event.preventDefault();
		$('#dropdownNav ul').hide();
		$('#dropdownNav ul li.selected').removeClass('selected');
		$(this).parents('li').addClass('selected');
		var selectedText_str = $(this).text();
		if (selectedText_str.length > 30) {
			selectedText_str = selectedText_str.substring(0,30) + "...";
		}
		$('#selectedDropdown_text').text(selectedText_str); 
	});
	*/
	
	$('.randomLoadDiv').each(function(i) {
		$(this).children('div').hide();
		var totalDivs = $(this).children('div').length;
		var randomDiv = Math.floor(Math.random()*totalDivs);
		$(this).children('div').eq(randomDiv).show();
	});
	
});