/******************************************************/
/*                                                    */
/*                  Javascript for                    */
/*   Michael Geraci dot Com - By Michael P. Geraci    */
/*    www.michaelgeraci.com - copyright 2006-2009     */
/*                                                    */
/******************************************************/

// Load these functions when the document is ready:
$(function(){
	loadSpecialStylesheets();
	indexFixes();
	clickableMasthead();
	groupsPageFixes();
	disclaimerFixes();
	// addToAbout();
});

function loadSpecialStylesheets(){
	if (jQuery.browser.safari) {
		$('head').append("<link type='text/css' rel='stylesheet' href='http://www.hcxdesign.com/storage/taxi/safari.css'>");
	}
	if ( jQuery.browser.msie && (jQuery.browser.version.substr(0, 1) == '6') ) {
		$('.xg_module_head h2').each(function(){
			content = $(this).html();
			if (content == 'About') {
				$(this).parents('.xg_1col').attr('id', 'rightColumn');
			} else if (content == 'Admin Options') {
				$(this).parents('.xg_1col').attr('id', 'adminLeft');
			}
		});
		$('head').append("<link type='text/css' rel='stylesheet' href='http://www.hcxdesign.com/storage/taxi/ie6.css'>");
	}
	if ( jQuery.browser.msie && (jQuery.browser.version.substr(0, 1) == '7') ) {
		$('head').append("<link type='text/css' rel='stylesheet' href='http://www.hcxdesign.com/storage/taxi/ie7.css'>");
	}
	if ( jQuery.browser.msie && (jQuery.browser.version.substr(0, 1) == '8') ) {
		$('head').append("<link type='text/css' rel='stylesheet' href='http://www.hcxdesign.com/storage/taxi/ie8.css'>");
	}
}

// on index page
function indexFixes(){
	if (window.pathname = '/') {
		// remove line under groups
		$('.xg_module_head h2').each(function(){
			content = $(this).html();
			if (content == 'Groups') {
				$(this).parent().css('border-bottom', '0px');
				$(this).html('JOIN A GROUP BELOW TO VOICE YOUR OPINION');
			}
		});
		$('div.tb p.xg_lightfont').css('display', 'none');
		$('div.tb h3 a').each(function(){
			if ( $(this).html() == 'Other Motorists' ){
				$(this).html('Other<br>Motorists');
			}
		});
	}
}

function clickableMasthead(){
	$('#xg_masthead').click(function(){
		window.location.href = 'http://taxioftomorrow.ning.com';
	});
}

function groupsPageFixes(){
	if (window.location.toString().match(/group/)) {
		// get rid of information and the line below it
		$('.xg_span-12 .xg_module .xg_module_head').css('display', 'none');

		// make the container for the image and description wider
		$('.xg_span-12 .xg_module .xg_module_body').css('width', '725px');

		// get rid of line to left of image
		$('.xg_span-12 .xg_module .xg_module_body .xg_column:first').css('border-left', 'none').css('float', 'left');

		// get rid of group meta
		$('.xg_span-12 .xg_module .xg_module_body .xg_column:last p:last').css('display', 'none');

		// add a special class to the description of the group
		$('.xg_span-12 .xg_module .xg_module_body .xg_column:last').attr('id', 'groupDescription');

		// change the width of the description block
		if (window.location.toString().match(/cyclist/)) {
			$('#groupDescription').css('width', '300px');
		}
		if (window.location.toString().match(/disabled/)) {
			$('#groupDescription').css('width', '520px').css('margin-left', '0px');
		}
		if (window.location.toString().match(/owners/)) {
			$('#groupDescription').css('width', '400px');
		}
		if ( (window.location.toString().match(/pedestrian/)) || (window.location.toString().match(/pedistrian/)) ) {
			$('#groupDescription').css('width', '400px');
		}
		if (window.location.toString().match(/visitor/)) {
			$('#groupDescription').css('width', '400px');
			$('#groupDescription p').html($('#groupDescription p').html().replace(/work\. /, 'work.<br>'));
		}
		if (window.location.toString().match(/designers/)) {
			$('#groupDescription').css('width', '505px');
			$('#groupDescription p').html($('#groupDescription p').html().replace(/ and /, '<br>and '));
		}
		if (window.location.toString().match(/other/)) {
			$('#groupDescription').css('width', '380px');
			$('#groupDescription p').html($('#groupDescription p').html().replace(/the road/, 'the<br>road'));
		}
		if (window.location.toString().match(/marketers/)) {
			$('#groupDescription').css('width', '280px');
		}

		// on the main groups listing
		if ( window.location.toString().match(/groups\/$/) || window.location.toString().match(/groups$/) ) {
			// take the groups out of their individual ul's
			liString = '';
			$('.xg_list_groups ul').each(function(){
				liString += $(this).html();
				$(this).remove();
			});
			$('.xg_list_groups').append('<ul id="groupsPageList">' + liString + '</ul>');
		// in an individual group
		} else if ( window.location.toString().match(/group\/.+$/) ){
			// move the group members to under the about
			// only if we are on the list of all groups
			$('.xg_module_head h2').each(function(){
				content = $(this).html();
				if (content.match(/Members.+/)) {
					members = $(this).parents('.xg_module').html();
					$(this).parents('.xg_module').remove();
				}
			});
			$('.module_about').after(members);
		}

		// add the 'select a question to answer' above the list
		$('.module_forum').before('<div class="selectAQuestion">Select a question to answer</div>');

		// add 'comment wall' above comments
		$('.module_forum').after('<div class="selectAQuestion" style="margin-top: 20px;">Comment Wall</div>');
	}
}

function disclaimerFixes(){
	// if the footer is showing, add the disclaimer link
	if ($('#xg_foot').length != 0) {
		$('#xg_foot p.right').append('&nbsp;&nbsp;|&nbsp;&nbsp;<a href="http://taxioftomorrow.ning.com/page/disclaimer-1">Disclaimer</a>');
	}
	
	// if we're on the disclaimer page, fix it up
	if (window.location.toString().match(/disclaimer/)) {
		// delete elements we don't want
		$('#xn_bar, #xg_head, #xg_foot, .xg_span-4, ul.navigation, .xg_headline').css('display', 'none');
		
		// widen the shown div
		$('.xg_column').css('width', '737px').css('border', '0px').css('margin-top', '100px').css('position', 'relative').css('left', '100px');
	}
}

function addToAbout(){
	$('.xg_module_head h2').each(function(){
		content = $(this).html();
		if (content.match(/About/)) {
			$(this).parents('.xg_module').append('<p style="font-size: 1em;">This is a project of <a href="http://www.hcxdesign.com" target="_blank">Human Condition</a> and is not affiliated with The City of New York or the NYC TLC. <a href="http://www.hcxdesign.com" target="_blank">Human Condition</a> is an insight and innovation firm that strives to create unbiased insight to allow real innovation to flourish.</p>');
		}
	});
}