/*
Site:          wisinski-group.com
Page:          functions.js
Created:       Nov 29 2007
Last Modified: Feb 05 2008
=================================================
ryan masuga, masugadesign.com
ryan@masugadesign.com | Copyright 2008
================================================= */
$(document).ready( function(){
	
	//alert("loadedxx2");
	
/* ==> homepage quotes */
	$('#splash_testimonial').innerfade({ 
		animationtype: 'fade', 
		speed: 2000, 
		timeout: 6000, 
		type: 'sequence', 
		containerheight: '230px' 
	});  



/* ==> homepage jump menu */
	$("#searchCatSelect").change(function(){
		// document.location.href=$("#searchCatSelect option[@selected]").val();
		 document.location.href = $(this).val();
		return false;
	});	 


/* ==> login form at top of each page on site */
	var textUser = 'Username';
	var textPass = 'Password';
	var userField = $("#account_form input#username");
	var passField = $("#account_form input#pass");
	userField.attr("value", textUser); 
	passField.attr("value", textPass);
	// if default text is there on focus, clear it out, otherwise leave it alone
	userField.focus( function(){if(userField.val() == textUser){userField.attr("value", '');}});
	passField.focus( function(){if(passField.val() == textPass){passField.attr("value", '');}});
	// when leaving field, check if it's empty; put default text back
	userField.blur( function(){if(userField.val() == ''){userField.attr("value", textUser); }});
	passField.blur( function(){if(passField.val() == ''){passField.attr("value", textPass); }});


/* ==> favorites links: add */
	$('a.fav_do').click(function() {
		var thisID = $(this).attr("id");
		$.get(this.href, { theID: thisID }, function(data) {
			$('a#'+thisID).parent().html(data)
				.css({ backgroundColor: "#F8FFCC" })
				.animate({ backgroundColor: "white" }, 1000)
				.append('<br /><a href="/wg/members/saved_properties/">View my saved properties &raquo;</a>');
		});return false;
	});

/* ==> favorites links: delete */
	$('a.fav_delete').click(function() {	
		var eyed = $(this).attr("id");
		$.get(this.href, { theID: eyed }, function(data) {
			$('a#'+eyed).parent().html(data)
				.css({ backgroundColor: "#F8FFCC" })
				.animate({ backgroundColor: "white" }, 1000)
				.animate({opacity: 1.0}, 500)
				.fadeOut("normal");
		});return false;
	});

/* ==> favorites links: delete (from the saved page - a little different structure) */
	$('a.fav_delete_saved').click(function() {	
		var eyed = $(this).attr("id");
		//alert($(this).parent().attr('class'));
		//return false;
		$.get(this.href, { theID: eyed }, function(data) {
			$('a#'+eyed).parent().html(data)
				.css({ backgroundColor: "#F8FFCC" })
				.animate({ backgroundColor: "white" }, 2000)
				.animate({opacity: 1.0}, 1500);
			$('#resultBlockWrap'+eyed)
				.animate({opacity: 1.0}, 1000)
				.slideUp("slow");
		});return false;
	});


/* ==> gallery rotation on property listing pages */
	$('#imagethumbs li a').click(function() {
		var newSrc = $(this).attr('href');
		var targetImg = $('#largeimage img');
		var parentItem = $(this).parents("li");

		parentItem.siblings(".active").removeClass("active");
		parentItem.addClass("active");

		ShowPhoto( $(this), newSrc );
		return( false );
	});

/* ==> extended text on intro pages */
		$('#oview_extended').hide();
		$("a#overview").click(function(){
        $('#oview_extended').slideToggle();
        if(this.innerHTML == "Hide Extended Text") {
          $(this).html("Read More...");
        } else {
          $(this).html("Hide Extended Text");
        }return false;
     }); 


}); /* close ready */




function ShowPhoto( objSource, strPath ){
	var objPhotoFrame = $( "#largeimage" );
	var objPhoto = null;
		objPhoto = $('#largeimage img');
	
		// ensure we have the pic.
		if (objPhoto.length){
			objPhoto.fadeOut("normal", function(){
					objPhoto.attr("src", strPath);
					ShowPhotoDo( objSource, objPhoto );
				}
				);
		}
}

function ShowPhotoDo( objSource, objPhoto ){
	var objImage = new Image();
	objImage.src = objPhoto.attr("src");
	if (objImage.complete != false) {
		objPhoto.fadeIn("normal");
	} else {
		setTimeout(
			function(){
				ShowPhotoDo( objSource, objPhoto );
			},
			100
			);			
	}
}



