﻿
$(document).ready(function() {

    if ($.browser.msie) $('#panels .norotate li').css({opacity:1});
    
    $('.rotate').each(function() {
        var li = $(this).find('li');
        $(li[1]).css({opacity:0});
        $(li[2]).css({opacity:0});
        $(li[3]).css({opacity:0});
    });

    var panel = 0, interval = 8000;
    
    var rotateInterval = setInterval(rotate, interval);
    
    function rotate() {
        $('.rotate').find('li').animate({opacity:0}, 1000);
        $('.rotate').find('li').eq(++panel).animate({opacity:1}, 1000);
        if (panel == 3) panel = -1;
    }
    
    $('#panels .norotate').bind('mouseenter',
        function() {
            clearInterval(rotateInterval);
            $('#panels .norotate, #panels a.logo').css({opacity:0.25});
            $(this).css({opacity:1, cursor:'pointer'}).parent().find('h3 a').addClass('hover').end().find('a.logo').css({opacity:1});
        }
    ).bind('mouseleave',
        function() {
            $('#panels .norotate, #panels a.logo').css({opacity:1});
            $(this).parent().find('h3 a').removeClass('hover');
            rotateInterval = setInterval(rotate, interval);
        }
    ).click(
        function() {
            var targetloc = $(this).parent().find('h3 a').attr('href');
            (targetloc == '/residential/houses/HomesForSale.aspx' || targetloc == '/residential/resort') ? location.href = targetloc : window.open(targetloc);
            return false;
        }
    );
    
    $('#panels h3, #panels a.logo').hover(
        function() {
            $(this).parent().find('.norotate').trigger('mouseenter');
        },
        function() {
            $(this).parent().find('.norotate').trigger('mouseleave');
        }
    );
})