// JavaScript Document

// cycle slideshow

$(document).ready(function() {
	// home page slide show
    $('.cycle').cycle({
		fx: 'fade',
		speed:  2500,
		timeout:  8000,
		pause:  1,
		after:     function()
		{
			//only add the caption on the slides after the first two
			if($(this).index() < 2)
			{
            			$('#caption').hide();
            		}
            		else
            		{
            			$('#caption').html(this.alt).show();
            		}
            			
        	}
	});
	
	//display home galleries
	$(window).load(function() 
			{
				var slides_opts =
				{
					fx:     'fade', 
					speed:  'fast', 
					timeout: 4000, 
					pager:  '#thumbs',
					autostop: true,
					backwards: false,
					scrolldir: 1, // for hoverScroll
					startingSlide: 0,
					pauseOnPagerHover: true,
					// callback fn that reverses direction at the 'end' of a slideshow
					// also sets direction for hoverscroll to follow along
					end: function(options)
					{
						slides_opts.pagerAnchorBuilder = function(){};
						
						if ( slides_opts.backwards == true )
						{
							slides_opts.backwards = false;
							slides_opts.scrolldir = 1;
							slides_opts.startingSlide = 0;
						}
						else
						{
							slides_opts.backwards = true;
							slides_opts.scrolldir = -1;
							slides_opts.startingSlide = ($('#thumbs li').length-1);
						}
						
						$('.cycle2').cycle(slides_opts);
						$('#thumbs')[0].startMoving(slides_opts.scrolldir, 1);
					},
					// callback fn that creates a thumbnail to use as pager anchor
					pagerAnchorBuilder: function(idx, slide) {
						return '<li><a href="#"><img src="' + $('img', slide).attr('src') + '" width="65" height="40" /></a></li>'; 
					}
				}
				
				// setup cycle
				if ($('.cycle2').children('p').length > 1)
				{
					$('.cycle2').after('<ul id="thumbs">').cycle(slides_opts);

					// setup hoverscroll
					$('#thumbs').hoverscroll(
					{
						vertical: true,
						arrows:false,
						width: 71,
						height: 250
					});
	
					// start auto scrolling
					$('#thumbs')[0].startMoving(1, 1);
				
				}
			});

// colorbox
	$('.floorplan a, #summerbreeze a').colorbox();
//forms
	(function($){
		$.fn.edukaform = function(){
			return this.each(function(){
			   $(this).attr('value',$(this).prev().text());                            
		   
			   $(this).bind('focus',function(){
				$(this).addClass('active').attr('value',function ()
					{
						var e = $(this);
						if(e.attr('value') == e.prev().text()){
							e.attr('value','');
						}            
					});
				});
			   $(this).bind('blur',function(){
				$(this).removeClass('active').attr('value',function ()
					{
						var e = $(this);
						if(e.attr('value') == ''){						
								e.attr('value',e.prev().text());						
						}
						if($(this).next('.error')){
							if(e.attr('value') == $(this).prev().text()){
								e.next().css('display','inline');								
							}					
						}						
					});
				});
			});
			
		};
	})(jQuery);
	
	$(".footer .textbox, .footer .textarea").edukaform();
	
	//inserts a note under the phone field
	$('#contact_txtPhone').after('<br /><span class="note">without spaces and only numbers please</span>');
});

// :hover pseudo class fix for ie
sfHover = function() {
	var sfEls = document.getElementById("listMenuRoot").getElementsByTagName("LI");
	for (var i=0; i<sfEls.length; i++) {
		sfEls[i].onmouseover=function() {
			this.className+=" sfhover";
		}
		sfEls[i].onmouseout=function() {
			this.className=this.className.replace(new RegExp(" sfhover\\b"), "");
		}
	}
}
if (window.attachEvent) window.attachEvent("onload", sfHover);




