/**
 * jQuery code to make the TinBu modules fit better with the look of our site
 */

/*function removejscssfile(filename, filetype){
	var targetelement=(filetype=="js")? "script" : (filetype=="css")? "link" : "none"; //determine element type to create nodelist from
	var targetattr=(filetype=="js")? "src" : (filetype=="css")? "href" : "none"; //determine corresponding attribute to test for
	var allsuspects=document.getElementsByTagName(targetelement);
	for(var i=allsuspects.length; i>=0; i--){ //search backwards within nodelist for matching elements to remove
		if(allsuspects[i] && allsuspects[i].getAttribute(targetattr)!=null && allsuspects[i].getAttribute(targetattr).indexOf(filename)!=-1) {
			allsuspects[i].parentNode.removeChild(allsuspects[i]) //remove element by calling parentNode.removeChild()
		}
	}
}*/

function removeExternalFile(filename, type) {
	var target_el = 'none';
	var target_attr = 'none';
	
	// Determine type of element
	switch(type) {
		case 'js':
			target_el = 'script';
			target_attr = 'src';
			break;
		case 'css':
			target_el = 'link';
			target_attr = 'href';
			break;
		case 'img':
			target_el = 'img';
			target_attr = 'src';
	}
	
	jQuery(target_el+'['+target_attr+'*='+filename+']').remove();
}

jQuery(function($) {
	// Put some space around the text ads
	$('.ctxt_box').parent().parent().parent().css({
		margin: '10px',
		width: '500px'
	});
	
	// Put some space around the graphic ads
	$('a[href*=http://www.tinbuserver.com/ads] img').css('margin', '10px auto');
	
	$('#tinbu center table.eq(1)').css('margin', '10px 0px');
	
	// Remove the onmouseover and onmouseout events from the navigation links
	$('#tinbu-nav a').attr('onmouseover', '').attr('onmouseout', '').addClass('tinbu-nav').hover(function() {
		$(this).addClass('tinbu-nav-hover');
	}, function() {
		$(this).removeClass('tinbu-nav-hover');
	});
	
	// Hide the Lycos Search Forms
	$('form[action*=javascript:GoToSearch()]').hide();
	$('form[name=SuperPagesSearch]').parent().parent().parent().parent().parent().parent().parent().parent().parent().parent().parent().parent().hide();
	
	// Unhide the stock search form
	$('form[name=FormStockSearch]').show();
	
	// Make sure the ads are marked as ads
	$('td.ctxt_box').prepend('<div style="font-size: 0.8em">ADVERTISEMENT</div>').css({borderTop: '1px solid #CCC', borderBottom: '1px solid #CCC'});
	
	
	/*** CELEB NEWS ***/
	removeExternalFile('style09.css', 'css'); // Remove all occurences "style09.css" on page
	
	// Give us some space between the rows of images
	$('td.TdCat').parent().before('<tr class="tinbu_spacer"><td colspan="3"></td></tr>');
	
	
	/*** HOROSCOPES MODULE ***/
	removeExternalFile('Horo.css', 'css'); // Remove all occurences "Horo.css" on page
	
	// Remove the background from the titlebar and set parent table widths to 100%
	$('.AH09').parents().find('table').attr('width', '100%').end().attr('background', '');
	
	// Give us some space between the rows of images
	$('a.highlightit').parent().parent().before('<tr class="tinbu_spacer"><td colspan="4"></td></tr>');
	
	// Show the 'horrorscope' forms
	$('form[name=formzodiac]').show();
	$('form[name=formchart]').show();
	$('form[name=formstarchart]').show();
	$('form[name=formpeaktime]').show();
	$('form[name=formpicks]').show();
	
	
	/*** LOTTERY MODULE ***/
	
	
	
	/*** MORTGAGES MODULE ***/
	// Show the mortgage forms
	$('form#StartSelection').show();
	$('form#moreOptionForm').show();
	$('form#form_mg_rate_list').show();
	
	
	/*** RECIPES MODULE ***/
	removeExternalFile('rcp_style01.css', 'css'); // Remove all occurences "rcp_style01.css" on page
	
	// Remove the 'border' from the recipes module
	$('td.tbltopleft').parent().css({
		background: '#CCCCCC',
		color: '#FFFFFF'
	});
	$('td div#navcontainer').parent().parent().children().each(function() {
		$(this).children('div').addClass('navcontainer');
		$(this).children('div').children('ul').addClass('navlist');
	});
	
	// Remove the 'bullets'
	$('span.BulletTxt').parent().remove();
	
	// Remove 'customize' link
	$('a.WxNav4').text('Customize My Recipe Page Color').remove();
	
	
	/*** STOCKS MODULE ***/
	// Keep the stock chart from being crowded
	$('#TinbuStockChart').parent().parent().parent().addClass('stockChart');
	$('#tinbu .TdWx table tbody tr td:eq(2) table').css('margin', '0px 0px 0px 5px');
	
	
	/*** FLIGHT-TRACKING MODULE ***/
	//removeExternalFile('fv_style09.css', 'css'); // Remove all occurences "fv_style09.css" on page
	$('form[name=FormFvSearch]').show();
	$('form[name=FORM1]').show();
	
	// Center the image at the bottom of the airline performance display
	$('td.WxBorder table tr:last td.FvDescTxt').css('text-align', 'center');
	
	$('td.hinttitle').parent().parent().css({
		padding: '10px',
		border: '1px solid #000'
	});
	
	
	/*** LOTTERY MODULE ***/
	removeExternalFile('sml02a.css', 'css');
	
	// Show the MPG Forms
	$('form[name=FormSearchByClass]').show();
	$('form[name=FormBestWorstMPG]').show();
	
	
	/*** SHOW THE MODULE ***/
	$('#loading-anim').hide();
	$('#tinbu').show();
});