jQuery().ready(function() {
	// Stop conflicts with mootools
	jQuery.noConflict();
	
	// simple accordion
	jQuery('#list1a').accordion({
		header: 'a.accord',
		active: ":eq(0)",
		alwaysOpen: false,
		//event: 'mouseover',
		// this line makes display locations the visible frame on home page.. need to make it 'similar homes' on pages that have similar homes!
		autoheight: false
	});
	
	// For any sort menus
	if (jQuery('div.sort')) {
		//jQuery('div.sort').bind('mouseout', function(e) { jQuery('div.sort').accordion('activate', -1); });
		jQuery('div.sort').accordion({
			header: 'h3',
			active: ":eq(1)",
			alwaysOpen: false,
			//event: 'mouseover',
			// this line makes display locations the visible frame on home page.. need to make it 'similar homes' on pages that have similar homes!
			autoheight: false
		});
		
		// add a slight opacity to the menu
		jQuery('div.sort > ul').css('opacity', 0.8);
	}
	
	// This is for the my ventura page, that unmarks the ventura homes
	jQuery('a.unmark').bind('click', function(e) {
		
		
		if (this.href.search(/ajax/) == -1) {
			this.href = this.href + '/ajax/true';
		}
		
		jQuery.get(this.href);
		
		jQuery(this).parent().parent().parent().animate({'opacity':0.01},1000, function(ee) {
			jQuery(this).slideUp(500, function(eee) {
//				jQuery(this).hide();
				jQuery(this).remove();
				
				if(jQuery('.homes-listing').size() == 0) {
					jQuery('#nolistings').show();
				}
			});
		});
		
		return false;
	});
	
	
	jQuery('a.searchagain').bind('click', function(e) {
		this.href = 'javascript:;'
		
		$('search_results').style.display = 'none';
		$('search_opt').style.display = 'block';
		
	});

	
	
	jQuery('a.bookmark').bind('click', function(e) {
		// Are we marking or unmarking?
		var opts = {
			url: this.href,
			type: 'GET',
			success: null
		}
		var me = this;
		
		if (this.href.search(/\/add\//) != -1) {  // marked
			opts.success = function(e) {
				jQuery(me).animate({'opacity':0.01},500, function(ee) {
					jQuery(me).text("Remove from My Ventura");
					jQuery(me).addClass('remove');
					jQuery(me).removeClass('add');
					// update the new HREF
					this.href = this.href.replace(/add\//,'remove/');
					jQuery(me).animate({'opacity':1});
				});
			};
		} else { //unmarked
			opts.success = function(e) {
				jQuery(me).animate({'opacity':0.01},500, function(ee) {
					jQuery(me).text("Add to My Ventura");
					jQuery(me).addClass('add');
					jQuery(me).removeClass('remove');
					// update the new HREF
					this.href = this.href.replace(/remove\//,'add/');
					jQuery(me).animate({'opacity':1});
				});
			};
		}
		
		if (this.href.search(/ajax/) == -1) {
			this.href = this.href + '/ajax/true';
		}
		
		jQuery.ajax(opts);
		return false;
	});

	var Glossary = new Tips($$('acronym'), { 
		initialize:function(){
			this.fx = new Fx.Style(this.toolTip, 'opacity', {duration: 500, wait: false}).set(0);
		},
		onShow: function(toolTip) {
			this.fx.start(1);
		},
		onHide: function(toolTip) {
			this.fx.start(0);
		}
	});
	
	jQuery('#tblawards1 th.title').bind('click', function(e){
		var tarid = this.id;
		tarid = tarid.replace(/awth/,'awtd');
//		alert(tarid)
//		alert($(tarid).style.display)
		if ($(tarid).style.display == 'none' || $(tarid).style.display == '') {
			$(tarid).style.display = 'block';
			this.parentNode.className = 'selected';
		} else {
			$(tarid).style.display = 'none';
			this.parentNode.className = '';
		}
	});
	
//	font = new Font(document.getElementById('main'), [0.9,1,1.1,1.2,1.3,1.4,1.6], {fx: {unit: 'em', duration:0}});

});


function bookmarkMe(obj) {
	jQuery.ajax({
		type: 'GET',
		url: obj.href,
		dataType: 'xml',
		beforeSend: function (xhr) {
			xhr.setRequestHeader('User-Agent', 'AJAX/1.0-jquery');
		},
		success: function(data) {
			//alert("Success: " + data);
			if (data.responseXML.getElementsByTagName('success').length) {
				obj.className = 'bookmark added';
				obj.innerHTML = 'Added to Favorites';
			}
		},
		complete: function(data) {
			alert(data);
			obj.className = 'bookmark added';
			obj.innerHTML = 'Added to Favorites';
		}
	});

	return true;
}

function showSpec(spec) {
	if ($('vanspec')) $('vanspec').style.display = 'none';
	if ($('claspec')) $('claspec').style.display = 'none';
	if ($('vspspec')) $('vspspec').style.display = 'none';
	if ($(spec)) $(spec).style.display = 'block';
}

