Cufon.replace('h1, h2, h3, #features_nav a', {hover:true});
( function($) {
    $().ready(function(){
    
        // Zebra Striping
        function stripe(){
            $('tr:odd').css({'background-color':'#f7f7f7'});
        }
        
        if($('#page_home').length !== 0){
            //HOMEPAGE ROTATOR
            $("<img id='splash_photo2' class='splash_photo' alt='' />").appendTo("#splash");
            (function rotate(num, speed, max){
                var img = new Image();
                function swap(){
                    $('#splash_photo2').attr({'src':img.src}).fadeIn('slow', function(){
                        $('#splash_photo1').attr({'src':img.src});
                        $(this).hide();
                        rotate(num >= max ? 1 : num+1, speed, max);
                    });
                }
                img.onload = function(){setTimeout(swap, speed);};
                img.src = 'images/splash'+num+'.jpg';
            }(2, 3500, 7));
            
            //NEWSLETTER
            var newsletterDefault = $("#newsletter_address").val();
            $("#newsletter_confirm").css({display:'none'});
            
            $("#newsletter .submit").click(function(){
                $("#newsletter_confirm").val($("#newsletter_address").val());
                $('#email_status').html('<span class="email_loading">working</span>');
                $("#newsletter form").ajaxSubmit();
                $("#newsletter form").ajaxSubmit({target:'#email_status', url:'newsletter.inc.php'});
                return false;
            });
        }
        
        else if($('#page_contact').length !== 0){
            //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:'class_email.php'});
                return false;
            });
        }
        
        else if($('#page_guide').length !== 0){
            //BUYER'S GUIDE FORM
            $('#submit_type').val('ajax');
            $('#buyers_guide form').submit(function(){
                $('#email_status').html('<span class="email_loading">working...</span>');
                $('form').ajaxSubmit({target:'#email_status', url:'buyers_guide.inc.php'});
                return false;
            });
        }
        
        else if($('#page_area').length !== 0){
            // Directory Sorter
            stripe();
            $('th').each(function(){ $(this).wrapInner('<a href="#" />'); });
            $('th').live('click', function(){
                if($(this).attr('class')!=='current'){
                    var
                    column = $('tr:first').children().index(this),
                    rows = $('tr:gt(0)').get(),
                    table = '';
                    rows.sort(
                        function(a, b){
                            var x, y;
                            
                            if(!$.support.opacity){
                                x = a.getElementsByTagName('td')[column].innerText;
                                y = b.getElementsByTagName('td')[column].innerText;
                            } else {
                                x = a.getElementsByTagName('td')[column].textContent;
                                y = b.getElementsByTagName('td')[column].textContent;
                            }
                            
                            if(x==''){ return 1; }
                            if(y==''){ return -1; }
                            if(x > y){ return 1; }
                            if(x < y){ return -1; }
                            return 0;
                        }
                    );
                    
                    
                    rows.unshift($('tr:first')[0]);
                    
                    $(this).addClass('current').siblings().removeClass();
                    
                    for(i in rows){
                        table += '<tr>'+rows[i].innerHTML+'</tr>';  
                    }
                    
                    $('table').html(table);
                    
                    stripe();
                }
                return false;
            });
        }
        
        else if($('#page_map').length !== 0){
        }
        
        else if($('#page_property').length !== 0){
            
            //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();
            
            //Property Map
            google.load("maps", "3.x", {other_params:"sensor=false", callback:function(){
                var geocoder = new google.maps.Geocoder(),
                address = $('#geocode').text();
                if (geocoder) {
                    geocoder.geocode( { 'address': address}, function(results, status) {
                    if (status == google.maps.GeocoderStatus.OK) {
                        
                        var options = {
                            zoom: 13,
                            center: results[0].geometry.location,
                            mapTypeId: google.maps.MapTypeId.ROADMAP,
                            mapTypeControlOptions: {style: google.maps.MapTypeControlStyle.DROPDOWN_MENU},
                            navigationControlOptions: {style: google.maps.NavigationControlStyle.SMALL},
                            scrollwheel:false
                        },
                        map = new google.maps.Map(document.getElementById("splash"), options),
                        marker = new google.maps.Marker({
                            position: results[0].geometry.location,
                            map:map
                        }),
                        info = new google.maps.InfoWindow({
                            content:address
                        });
                        
                        info.open(map,marker);
                    } else {
                      alert("Geocode was not successful for the following reason: " + status);
                    }
                  });
                }
            }});
        }
    });
}(jQuery));



