FUNCTIONS = {};

$(document).ready(function() {

	//FUNCTIONS.columns();
	FUNCTIONS.menu();
	FUNCTIONS.tooltip(".post-courses a","tooltip");
	
	$(document).pngFix();
	
	$('.post-courses .columns').columnize({width:220, lastNeverTallest: true });
	$('.page-template-templateschoolcityteachers-php table tr td')
		.attr('style','')
		.attr('width','');
		
	$('.page-template-templateschoolnorrateachers-php table')
		.attr('style','')
		.attr('width','');
	$('.page-template-templateschoolnorrateachers-php table colgroup')
		.remove();
	$('.page-template-templateschoolnorrateachers-php table tr td')
		.attr('style','')
		.attr('width','');
	$('.page-template-templateschoolnorrateachers-php table tr td span')
		.attr('style','')
		.attr('width','');
	
	
});

FUNCTIONS.menu = function() {
	
	//get title, if "nofollow" we want to prevent default click
	$('#menu ul li a').not('li li a').each(function() {
		var title = $(this).attr('title');
		$(this).attr('title','');
		$(this).attr('rel', title);
	});
	
	$('#menu ul li a[rel=nofollow]').live('click', function(e) {
		e.preventDefault();
	});
		
	var NavItem = $('#menu ul li').not('li li');
	$(NavItem).hover(function(){
		var buttonWidth = $(this).width();
		var menuWidth = 0;
		var offset = 0;
		var dropdownMaxWidth = 0;
		var dropdownElms = $(this).find('ul.sub-menu li a');
		$(dropdownElms).each(function() {
			if($(this).outerWidth(true) > dropdownMaxWidth) {
				dropdownMaxWidth = $(this).outerWidth(true);
			}
		});
		if(dropdownMaxWidth > buttonWidth) {
			menuWidth = dropdownMaxWidth;
			offset = - (dropdownMaxWidth - buttonWidth) / 2;
		} else {
			menuWidth = buttonWidth;
			offset = 0;
		}
		
		$('ul:first', this).css({
			top:'27px', opacity:0, display:'block', width: menuWidth, left: offset + 'px'
		});
		$('ul:first', this).animate({
			top:'31px', opacity:0.95
		}, 200);
	},function(){
		$('ul:first', this).animate({
			top:'27px', opacity:0
		}, 200, function(){
				$(this).css({
					left:'-9999em'
				});
			}
		);
	});
};

FUNCTIONS.columns = function() {

	var interviewHeight = 0;
	if($('.interview').length > 0) {
		interviewHeight = $('.interview').height();
	}
	
	var submenuHeight = 0;
	if($('.submenu').length > 0) {
		submenuHeight = $('.submenu').height();
	} else if ($('.education-menu').length > 0) {
		submenuHeight = $('.education-menu').height();
	}

	var tallest = 0;
	$('#main, #column').each(function() {
		var thisHeight = $(this).height();
		if(thisHeight > tallest) {
			tallest = thisHeight;
		}
	});
	
	if((interviewHeight + submenuHeight + 50) > $('#main').height()) {
		$('#main, #column').height(interviewHeight + submenuHeight + 50);
		console.log(interviewHeight + ' ' + submenuHeight);
	} else {
		$('#main, #column').height(tallest);
	}
};

FUNCTIONS.tooltip = function(target_items, name) {

	$('.post-courses ul li a').live('click', function(e) {
		e.preventDefault();
	});
	
	$('.post-courses ul li a').each(function() {
		$(this).attr('title','');
	});

/*
 $(target_items).each(function(i){
		$("body").append("<div class='"+name+"' id='"+name+i+"'><p><em>"+$(this).text()+"</em></p><p>"+$(this).attr('title')+"</p></div>");
		var my_tooltip = $("#"+name+i);

		if($(this).attr("title") != "" && $(this).attr("title") != "undefined" ){

		$(this).removeAttr("title").mouseover(function(){
					my_tooltip.css({opacity:0.8, display:"none"}).fadeIn(300);
		}).mousemove(function(kmouse){
				var border_top = $(window).scrollTop();
				var border_right = $(window).width();
				var left_pos;
				var top_pos;
				var offset = 12;
				if(border_right - (offset *2) >= my_tooltip.width() + kmouse.pageX){
					left_pos = kmouse.pageX+offset;
					} else{
					left_pos = border_right-my_tooltip.width()-offset;
					}

				if(border_top + (offset *2)>= kmouse.pageY - my_tooltip.height()){
					top_pos = border_top +offset;
					} else{
					top_pos = kmouse.pageY-my_tooltip.height()-offset;
					}	

				my_tooltip.css({left:left_pos, top:top_pos});
		}).mouseout(function(){
				my_tooltip.css({left:"-9999px"});
		});

		}

	});
*/
};
