var thispage = window.location.href;
thispage = thispage.toLowerCase();

function homeImage() {
    var r;

    if (document.getElementById('home') != null) {
        url = "url(/pagetemplates/template41/image/home";
        r = Math.random();
        r = (r * 10)/2; // 0 to 5
        r = Math.round(r);
      
        switch (r) {
            case 1:
                document.getElementById('home').style.backgroundImage = url + r + ".jpg)";
                break;
            case 2:
                document.getElementById('home').style.backgroundImage = url + r + ".jpg)";
                break;
            case 3:
                document.getElementById('home').style.backgroundImage = url + r + ".jpg)";
                break;
            case 4:
                document.getElementById('home').style.backgroundImage = url + r + ".jpg)";
                break;
            case 5:
                document.getElementById('home').style.backgroundImage = url + r + ".jpg)";
                break;
            default:
                document.getElementById('home').style.backgroundImage = "url(/pagetemplates/template41/image/home1.jpg)";
        }
    }
    return;
}

function commonPage() {
    //Add header and formatting to common pages
    if ((document.getElementById('inner') != null)
        && (thispage.indexOf('customcontent') < 0)
        && (thispage.indexOf('propdetail') < 0)){
            $('.common_headline').show();
            $('.page_title h1').html(pagetitle);
    }
    return;
}

function showPropDetail() {

    //side menu
    $('.pd_calls_to_action a').removeClass('pd_button').appendTo('#cta_items').wrap('<li></li>');
    $('#pd_actions_sms_send').parent().css('display', 'none');
    $('#pd_actions_sms_cancel').parent().css('display', 'none');
    $('#pd_actions_sms_send').addClass('pd_button').appendTo('#mobileDialog');
    $('#pd_actions_sms_cancel').addClass('pd_button').appendTo('#mobileDialog');
    $('.cta').show();
    $('#cta_items').show();

    //move nav
    $('.pd_nav').show();
    $('.pd_nav_prevlisting').appendTo('.nav_prev');
    $('.pd_nav_nextlisting').appendTo('.nav_next');
    $('.pd_nav_back_to_search').appendTo('.nav_modify');
    $('.pd_nav_back_to_results').appendTo('.nav_results');
    $("#cta_items li a[href*=savelisting]").clone().appendTo('.nav_save');
    $('.pd_nav_back_to_results a').text('Back to Results');
    $('.level3 li a').removeClass('ui-state-active');
    $('.level3 li a span').css('display','none');
    return;
}

function showMenu() {
  
    if (pagetitle.indexOf('Buying >') > -1) { $('#buying').show(); }
    if (pagetitle.indexOf('Selling >') > -1) { $('#selling').show(); }
    if (pagetitle.indexOf('Financing >') > -1) { $('#financing').show(); }
    if (pagetitle.indexOf('Community >') > -1) { $('#community').show(); }
    if (thispage.indexOf('\/community\/') > -1) { $('#community_ob').show(); }    
    if (pagetitle.indexOf('Market Trends >') > -1) { $('#trends').show(); }
    if (pagetitle.indexOf('Services >') > -1) { $('#services').show(); }
    if (pagetitle.indexOf('Relocation >') > -1) { $('#relocation').show(); }
    if (pagetitle.indexOf('Market Trends >') > -1) { $('#trends').show(); }
    if (pagetitle.indexOf('About Us') > -1) { $('#about').show(); }
    if (pagetitle.indexOf('Careers') > -1) { $('#careers').show(); }
    if (thispage.indexOf('companyinfo') > -1) {$('#about').show();}
    if ((pagetitle.indexOf('Property Search') > -1) ||
        (pagetitle.indexOf('Properties >') > -1)
        ) {$('#properties').show();}
    if (thispage.indexOf('toolkit') > -1) { $('.menu').load('/pagetemplates/template41/menu.htm'); }
    if (thispage.indexOf('\/office\/') > -1) { $('.menu').load('/pagetemplates/template41/menu.htm'); }
    if (thispage.indexOf('propdetail') > -1) { showPropDetail(); }
   // if (thispage.indexOf('community') > -1) { $('.side').hide(); }
    return;
}

// Doc Ready
$(document).ready(function() {
    homeImage();
    commonPage();
    showMenu();

    $('.jump').fadeIn('slow');
    $('.home_msg').appendTo('.home_msg_container');

    //Drop-down menu
    $("ul.sf-menu").supersubs({
        minWidth: 12,
        maxWidth: 27,
        extraWidth: 1
    }).superfish({
        speed: 'fast'
    });

    //Move Community Page Title
    if (thispage.indexOf('\/community\/') > -1) {
        new_title = $('h1.page_title').html();
        $('h1.page_title').hide();
        $('.page_title h1').html(new_title);
    }


});

