// JavaScript Document
jQuery.noConflict();
jQuery.fn.reverse = [].reverse;

jQuery(function($) {

	var agent = navigator.userAgent.toLowerCase(); 

	     if ($.browser.msie)         { $('body').addClass('ie ie'+$.browser.version.substr(0,1)); }
	else if (agent.match(/chrome/i)) { $('body').addClass('chrome'); }
	else if (agent.match(/safari/i)) { $('body').addClass('safari'); }

	if (agent.match(/iphone/i)) { $('body').addClass('iphone'); }

	//Move the sidebar on the home page to the right place based on a HTML comment in the code!!!
	if (($sidebar = $('#sidebar')).length > 0 && ($sidebardiv = $('div.movesidebarhere')).length > 0) {
		$sidebardiv.replaceWith($sidebar);
		$sidebar.show();
	}

	$('#body #content h1').next('h2').addClass('topofpage');

	//Links page - Sorts out a few layout issues - DO NOT REMOVE!!
	$('#body #content .post_column_1 h2').prevUntil('div').remove();	//Remove blank space before headings in the links page
	$('#body #content .post_column_1').next('br').remove();				//Remove blonk space between columns in the links page
	$('#body #content .post_column_1 p:not(:has(a))').addClass('linktitle');
	$('#body #content .post_column_1 p:has(a)').addClass('link');
	$('#body #content .post_column_1 p:empty').remove();				//Remove empty P tags in link lists

	$('#news-sidebar li.widget-container.widget_search #s').addClass('clearOnFocus').attr({ value : "Type your search here...", 
																						    alt   : "Type your search here..." });

	$('.clearOnFocus').live('focus', function() { if ($(this).val() == $(this).attr('alt')) { $(this).val('').addClass('focus'); } });
	$('.clearOnFocus').live('blur', function()  { if ($(this).val() == '') { $(this).val($(this).attr('alt')).removeClass('focus'); } });

	$(':has(p)').find('p:first').addClass('first');
	$(':has(p)').find('p:last').addClass('last');

	$('table tbody').each(function() { $(this).children('tr:odd').addClass('even'); $(this).children('tr:even').addClass('odd'); });

	//Validate newsletter form (basic validation!)
	$('#subForm').submit(function() {

		var returnVal = true;
		var firstOffender = false;

		$(this).find('input:text').each(function() {

			if ($(this).val() == '' || $(this).val() == $(this).attr('alt')) {
				returnVal = false;
				firstOffender = (firstOffender == false ? $(this) : firstOffender);
			}

		});

		firstOffender.focus();
		return returnVal;

	});

	$('.property_content .prop_images .small_images img').click(function() {
		$(this).parent().siblings('.big_image').attr("src", $(this).attr("src"));
	});

});

