// common.js

function flowPlayerAPI(e)
{
	var keycode;
	window.event ? keycode = window.event.keyCode : keycode = e.which;
	if(keycode == 32 && $('.player:focus')){
		$f("fms").toggle();
		e.preventDefault();
	}
}

function fixExternal(){
	$('a[target=_blank]').each(function(){
		$(this).attr('target', '');
	});
}

function fixMarkup(tag,string){
	var arr = document.getElementsByTagName(tag);
	for (var i=0; i < arr.length; i++){
		if (arr[i].innerHTML === string){
			$(arr[i]).remove();
		}
	}
};

$(document).ready(function() {

	fixExternal();
	fixMarkup('label','Or');
	
	if ($('form').attr('action')){
		$('form').each(function(e){
			if($(this).attr('action') === 'search-the-register'){
				$(this).addClass('searchRegForm');
			}
		});
	}
	
	if (document.getElementById('forum') || document.getElementById('contact_form')){
		document.getElementById('main').style.width = '570px';
	}
	
	//Accessiblity extras 
	if($('.player')) window.onkeypress = function(e){flowPlayerAPI(e)};
	
	var defaultSearchValue = $("input[name='keywords']").val();
	$("input[name='keywords']").focus(function() {
		if($(this).val() == defaultSearchValue) $(this).val('');
	}).blur(function() {
		if($(this).val() == '') $(this).val(defaultSearchValue);
	});
	$(".nav li a.active").parent().prev().children("a").css("border-right", "none");
	$(".nav li a").each(function(){
		var txt = $(this).text();
		$(this).html('<span>'+ txt + '</span>');
    });
    $(".nav li a span").each(function(){
		var h = $(this).height();
		var ph = $(this).parent().height();
		var mh = (ph - h) / 2;
		$(this).css('padding-top', mh);
    });
    $(".linksx").hide();
    $(".link_category a").click(function() {
		if($(this).hasClass("open")) {
			$(this).parent().next(".linksx").slideUp("slow");
			$(this).removeClass("open");
		} else {
			$(this).parent().next(".linksx").slideDown("slow");
			$(this).addClass("open");
		}
		return false;
    });
    // hide inactive tabs
    $(".tabbed_content.inactive").hide();
    $(".tabs li a").click(function() {
		var link = $(this).attr("href");
		// hide active
		$(".tabbed_content.active").addClass("inactive").removeClass("active").hide();
		$(link).addClass("active").removeClass("inactive").show();
		return false;
    });
   
    //Strip blank list items for IE
    function stripBlank(el){
		this.el = el;
		jQuery(this.el).filter(function(){
			return jQuery(this).text() =='';
		}).remove();
    }
    
    stripList = new stripBlank('li');
    
    if(document.getElementById('forumTable')){
		document.getElementById('main').style.width='660px';
		$("#forumTable tr:odd td").css("background-color", "#EEE").addClass('odd');
    }
    
});

