/*********************************************************************
 Author: Spartan Interactive Solutions
*********************************************************************/
function base(){
	// Cufon.replace(".century");
		
	/* set up colorbox */	
	$("a.colorbox").colorbox();
	$("a.colorbox-iframe").colorbox({width:"80%", height:"80%", iframe:true});
	$("a.colorbox-iframe-properties").colorbox({width:"930px", height:"665px", iframe:true});
	$("a.colorbox-press").colorbox({width:"50%", height:"80%", iframe:true});

	/* properties main nav item */
	$("header nav ul li#properties").click(function(){
		$(this).children("ul").children().removeClass("active");
		$(this).children("ul").slideDown(300);
	});
}

/*********************************************************************
 slideshow
*********************************************************************/
var keepSlideshowRunning = true;
var slideshowImageCount = 0;
var slideshowImage = 0;

function slideshowTimer(){
	if (keepSlideshowRunning){
		if ( slideshowImage < slideshowImageCount ){ slideshowImage++; }
		else { slideshowImage = 0; }
		/* fade images */
		$("div#slideshow img:nth-child("+slideshowImage+")").fadeIn(500);
		$("div#slideshow img:nth-child("+slideshowImage+")").siblings("img").fadeOut(500);
		/* toggle classes */
		$("div#slideshow-track table td:nth-child("+slideshowImage+")").addClass("active");
		$("div#slideshow-track table td:nth-child("+slideshowImage+")").siblings("td").removeClass("active");

		setTimeout('slideshowTimer()', 8000);
	}
}

function slideshow(){
	/* copy thumbnails to slideshow */
	$("div#slideshow-track table td").each(function(){
		slideshowImageCount++;
		$(this).attr({id:slideshowImageCount});
		$("div#slideshow").append("<img src='"+ $(this).children("div").children("img").attr('src') +"' />");
	});
	/* start slideshow */
	slideshowTimer();
	/* slide show hover */
	$("div#slideshow-track table td").hover(
		function () { $(this).addClass("hover"); }, 
		function () { $(this).removeClass("hover"); }
    );
	/* slide show click */
	$("div#slideshow-track table td").click(function(){
		keepSlideshowRunning = false;
		slideshowImage = this.id;
		/* fade images */
		$("div#slideshow img:nth-child("+slideshowImage+")").fadeIn(500);
		$("div#slideshow img:nth-child("+slideshowImage+")").siblings("img").fadeOut(500);
		/* toggle classes */
		$("div#slideshow-track table td:nth-child("+slideshowImage+")").addClass("active");
		$("div#slideshow-track table td:nth-child("+slideshowImage+")").siblings("td").removeClass("active");
	});
	
}

/*********************************************************************
 properties slideshow
*********************************************************************/
var propertiesFadeWhich = 0;
var propertiesFadeCount = 0;
var keepPropertiesFadeRunning = true;

function propertiesFadeTimer(){
	if (keepPropertiesFadeRunning){
		if( propertiesFadeWhich < propertiesFadeCount ){
			propertiesFadeWhich++;
			$("body#properties div#properties-fade div#"+propertiesFadeWhich).fadeIn(500);
			$("body#properties div#properties-fade div#"+propertiesFadeWhich).siblings("div").fadeOut(500);
			setTimeout('propertiesFadeTimer()', 7000);
		}
		else{
			propertiesFadeWhich = 1;
			$("body#properties div#properties-fade div#"+propertiesFadeWhich).fadeIn(500);
			$("body#properties div#properties-fade div#"+propertiesFadeWhich).siblings("div").fadeOut(500);
			setTimeout('propertiesFadeTimer()', 7000);
		}
	}
}

function propertiesFade(){
	$("body#properties div#properties-fade div").each(function(){
		propertiesFadeCount++;
		$(this).show();
		$(this).attr({id:propertiesFadeCount});
	});
	propertiesFadeTimer();	
	
	// halt image rotation on click of property info or image
	$("body#properties div.acc ul li").click(function(){
		if( $(this).hasClass("restart") == true ){
			keepPropertiesFadeRunning = true;
			propertiesFadeTimer();	
		}
		else{
			keepPropertiesFadeRunning = false;
			propertiesFadeWhich = this.id;
			$("body#properties div#properties-fade div#"+propertiesFadeWhich).fadeIn(500);
			$("body#properties div#properties-fade div#"+propertiesFadeWhich).siblings("div").fadeOut(500);
		}
	});
	
}

/*********************************************************************
 properties accordion
*********************************************************************/
function properties(){
	/* call slideshow */
	propertiesFade();
	
	/* find first accordion item on page load */
	$("body#properties div.acc li:first").addClass("active");
	$("body#properties div.acc li:first").children("div.properties-content").show();
	
	/* support :hover css with JS class */
	$("body#properties div.acc li").hover(
		function(){ $(this).addclass("hover") },
		function(){ $(this).removeClass("hover") }
	);
	
	/* on click of an available property */
	$("body#properties div.acc li h2").click(function(){
		/* manipulate the accordion */
		$(this).parent("li").addClass("active");
		$(this).parent("li").siblings("li").removeClass("active");
		$(this).parent("li").children("div.properties-content").slideDown();
		$(this).parent("li").siblings("li").children("div.properties-content").slideUp();
	});	
}


/*********************************************************************
 contact form
*********************************************************************/
function contact(){
	/* focus and blur for text inputs and textareas */
	$("body#contact form input.text").focus(function(){ $(this).parents("tr").addClass("focus"); });
	$("body#contact form input.text").blur(function(){ $(this).parents("tr").removeClass("focus"); });
	$("body#contact textarea").focus(function(){ $(this).parent("div").addClass("focus"); });
	$("body#contact textarea").blur(function(){ $(this).parent("div").removeClass("focus"); });
	
	/* hover for submit button */
	$("div.submit input").hover(
		function () { $(this).addClass("hover"); }, 
		function () { $(this).removeClass("hover"); }
    );
	
	/* live validation */
	var firstname = new LiveValidation('firstname');
	firstname.add( Validate.Presence );
	
	var lastname = new LiveValidation('lastname');
	lastname.add( Validate.Presence );
	
	var email = new LiveValidation('email');
	email.add( Validate.Presence );
	email.add( Validate.Email );
		
	var comments = new LiveValidation('comments');
	comments.add( Validate.Presence );
	

}




















