Cufon.replace('h2, h1');

$(window).load(function () {
    $('#page_property .thumb').each(function(){
        var img = new Image();
        img.src = this.href;
    });
});

$().ready(function(){
    
    //EMAIL FORM
    $('#email_submit').val('ajax');//changes the submission type.
    $('#email_form form').submit(function(){
        $('#email_status').html('<p class="email_loading">working...</p>');
        $('form').ajaxSubmit({target:'#email_status', url:'email.inc.php'});
        return false;
    });

    //Property Photo Gallery
    $('#property_photos li a').click(function(){
        $('#property_photo').css('background-image', 'url('+$(this).attr('href')+')');
        $('#property_photos li a').css({cursor:'pointer', opacity:1});
        $(this).css({cursor:'inherit', opacity:0.35});
        return false;
    });
    $('#property_photos li a:first').click();

    if($('body').attr('id')=='page_home'){
        
        //HOMEPAGE ROTATOR
        $('#community_info').show();
        var i = 1;
        var speed = 4500;
        var timeOut;
        var $splash = $('#splash');
        var $wrapper = $('#communities_wrapper');
        var place='great_waters'
        var preload = new Image();
        
        $('.reynolds_plantation a.current').css({cursor:'default'});
        
        function changeSplash(id){
            clearTimeout(timeOut);
            var bgSplash = $wrapper.css('background-image');
            var bgWrapper = 'url(images/'+id+'.jpg)';
            
            $('#community_info li a').removeClass().css({cursor:'pointer'});
            $('#community_info li[class='+id+'] a').addClass('current').css({cursor:'default'});
            
            $('#community_description div').hide();
            $('#community_description div[class='+id+']').show();
            
            $splash.stop().css({'background-image':bgSplash}).show();
            $wrapper.css({'background-image':bgWrapper});
            
            if(id=='reynolds_plantation'){
                place='great_waters';
            } else if (id=='great_waters'){
                place='reynolds_landing';
            } else if (id=='reynolds_landing'){
                place='harbor_club';
            } else if (id=='harbor_club'){
                place='cuscowilla';
            } else if (id=='cuscowilla') {
                place='kingston';
            } else {
                place='reynolds_plantation';
            }
            
            preload.src = 'images/'+place+'.jpg';
            
            $splash.stop().fadeOut('normal', function(){
                if($('#communities_wrapper').attr('class')!='hover'){
                    timeOut = setTimeout(function(){ changeSplash(place); }, speed);
                }
            });
        }
        
        preload.src = 'images/great_waters.jpg';
        timeOut = setTimeout(function(){ changeSplash(place); }, speed);
          
        $('#communities_wrapper').hover(function(){
            $(this).addClass('hover');
            $('#community_info').stop().animate({'bottom':0}, 'normal');
            clearTimeout(timeOut);
        },function(){
            $(this).removeClass();
            $('#community_info').stop().animate({'bottom':-130}, 'normal');
            timeOut = setTimeout(function(){ changeSplash(place); }, speed);
        });
        
        $('#community_info li a').click(function(){
            if($(this).attr('class')!='current'){
                changeSplash($(this).parent().attr('class'));
            }
            return false;
        });
    }
    
});
