/**
 * --------------------------------------------------------------------------------
 * @desc Initialization Scripts (in most cases using livequery)
 *  
 * --------------------------------------------------------------------------------
 */
jQuery(function($){
    
    
    
     $("#ws_contact_me_submit").live('click',function(){       
             $("#ws_contact_me_form").submit();
    });
        
    $('#ws_submit_newsletter_form').live('click', function(){
        
        $('#ws_form_newsletter').submit();
    });
    
    $("ul.sf-menu").superfish({
        autoArrows:  false,                           // disable generation of arrow mark-up 
        dropShadows: false,
        delay:         500
        
    }); 
   
    //$('#ws_navigation_wrapper>ul>li').hover(website.module.navigation.displaySubItems, website.module.navigation.hideSubItems);
    $('input[type|="image"]').css('border','0px');
    //$('input[type|="image"]').css('margin-top','10px');
    $('input[type|="image"]').css('min-width','0px');
    
    $('input[type|="image"]').css('vertical-align','middle');
    
    //$("td:contains('$')").css('background-color', '#DDD');
    //$('table[width|="512"] tr:nth-child(1)').css('background-color', '#666');
    //$('tr[style|="background-color: rgb(102, 102, 102);"]').css('background-color', '#666');
    //$('table[class|="bordercolor"] tr:nth-child(1)').each (function(){
    //    if ($(this).attr('width') == "512"){
    //    $(this).css('background-color', '#DDD');
    //    }
    //});
    
    
    if (window.location.href.indexOf('tester.cfm') > -1){
        $('#ws_page_header').html('MLS Test Page');
    }
    if (window.location.href.indexOf('areaselect.cfm') > -1 || window.location.href.indexOf('AreaSelect.cfm') > -1 || window.location.href.indexOf('SearchCriteria.cfm') > -1 || window.location.href.indexOf('searchcriteria.cfm') > -1){
        $('#ws_page_header').html('MLS Search By Map');
        $('#ws_mls_reciprocity_area').attr('id', 'ws_mls_reciprocity_map');
        $('#ws_links_properties_map').addClass('current_main_sub_navigation_item');
    }
    if (window.location.href.indexOf('addysearch.cfm') > -1){
        $('#ws_page_header').html('MLS Address Search');
        $('#ws_mls_reciprocity_area').attr('id', 'ws_mls_reciprocity_address_search');
        $('#ws_links_properties_map').addClass('current_main_sub_navigation_item');
    }
    if (window.location.href.indexOf('mlssearch.cfm') > -1){
        $('#ws_page_header').html('MLS Number Search');
        $('#ws_mls_reciprocity_area').attr('id', 'ws_mls_reciprocity_number_search');
        $('#ws_links_properties_number').addClass('current_main_sub_navigation_item');
    }
    
    if (window.location.href.indexOf('res_sale_form.cfm') > -1){
        $('#ws_page_header').html('MLS Text Search');
        $('#ws_mls_reciprocity_area').attr('id', 'ws_mls_reciprocity_text_search');
        $('#ws_links_address').addClass('current_main_sub_navigation_item');
    }
    if (window.location.href.indexOf('res_sale_result.cfm') > -1){
        $('#ws_page_header').html('Search Results');
        $('#ws_mls_reciprocity_area').attr('id', 'ws_mls_reciprocity_search_results');
        $('#ws_links_address').addClass('current_main_sub_navigation_item');
    }
    if (window.location.href.indexOf('res_sale_result_detail.cfm') > -1){
        $('#ws_page_header').html('Property Details');
        $('#ws_mls_reciprocity_area').attr('id', 'ws_mls_reciprocity_property_details');
        $('#ws_links_address').addClass('current_main_sub_navigation_item');
    }
    
    //$('#ws_mls_reciprocity_search_results .primaryaccentcolor').parent().parent().find('tr:nth-child(1)').css('border-bottom', 'border','1px solid #ff8600');
    //$('#ws_mls_reciprocity_search_results .primaryaccentcolor').parent().parent().find('tr:nth-child(1)').css('border','1px solid #ff8600');
    //$('#ws_mls_reciprocity_search_results .primaryaccentcolor').parent().parent().find('tr:nth-child(4)').css('background-color', '#ddd');
    $('#ws_mls_reciprocity_search_results .primaryaccentcolor').parent().parent().find('tr:nth-child(5)').css('background-color', '#f1f1f1');
    //$('#ws_mls_reciprocity_search_results .primaryaccentcolor').parent().parent().find('tr:nth-child(5)').css('background-color', '#f1f1f1');
    
    $('#ws_mls_reciprocity_search_results table[width|="512"]').attr('cellspacing','0');
    $('#ws_mls_reciprocity_search_results img[alt|="Thumbnail Image"]').css('border','1px solid #666');
    $('#ws_mls_reciprocity_search_results table[width|="510"]').attr('cellspacing','0');
    $('#ws_mls_reciprocity_search_results select').parent().parent().css('width','300px');
    $('#ws_mls_reciprocity_search_results form').css('display','inline');
    
    $('#ws_mls_reciprocity_property_details table').attr('cellspacing','0');
    $('#ws_mls_reciprocity_property_details table').attr('cellpadding','0');
    // The <tr> 7 parents up ... encompases the property image.
   
    //$('#mlsr_main_image_div').parent().css('background-color','#F0F0F0');
    // Center the property image.
    $('#mlsr_main_image_div').parent().css('text-align','center');
    // Change the background color of the property image area.
    $('#mlsr_main_image_div').parent().parent().parent().parent().parent().parent().parent().parent().find('tr:first-child').css('background-color','#F0F0F0');
    // Remove a break tag between the prev / search and the address
    $('#mlsr_main_image_div').parent().parent().parent().parent().parent().parent().parent().parent().parent().parent().parent().parent().parent().parent().find('br:nth-child(5)').remove();
    // Make the address above the main property image bold and with some padding.
    $('#mlsr_main_image_div').parent().parent().parent().parent().parent().parent().parent().parent().parent().parent().parent().parent().parent().find('.titleLarge').first().parent().css('font-weight','bold');
    $('#mlsr_main_image_div').parent().parent().parent().parent().parent().parent().parent().parent().parent().parent().parent().parent().parent().find('.titleLarge').first().parent().css('padding','20px');
    // Make the property amount larger and give it some space from the description.
    $('#mlsr_main_image_div').parent().parent().parent().parent().parent().parent().css('background-color','#F0F0F0');
    $('#mlsr_main_image_div').parent().parent().parent().parent().parent().parent().css('color','#FF8600');
    $('#mlsr_main_image_div').parent().parent().parent().parent().parent().parent().css('font-size','20px');
    $('#mlsr_main_image_div').parent().parent().parent().parent().parent().parent().css('padding-bottom','17px');
    
    $('#ws_mls_reciprocity_property_details a[title|="Additional Photos"]').attr('style','display:block;padding-top:10px;');
    
    // Description and features padding:
    $('#mlsr_main_image_div').parent().parent().parent().parent().parent().parent().parent().parent().find('tr:nth-child(3)').find('td').attr('style','padding-top:20px;padding-left:40px;padding-right:40px;padding-bottom:10px;');
    $('#mlsr_main_image_div').parent().parent().parent().parent().parent().parent().parent().parent().find('tr:nth-child(4)').find('td').attr('style','padding-top:10px;padding-left:40px;padding-right:40px;padding-bottom:20px;');
    $('#mlsr_main_image_div').parent().parent().parent().parent().parent().parent().parent().parent().find('tr:nth-child(4)').find('td').attr('style','padding-top:10px;padding-left:40px;padding-right:40px;padding-bottom:20px;');

    website.module.mlrs.stylePropertyDetailTable(5,'#ddd');
    website.module.mlrs.stylePropertyDetailTable(6,'#f1f1f1');
    website.module.mlrs.stylePropertyDetailTable(7,'#ddd');
    website.module.mlrs.stylePropertyDetailTable(8,'#f1f1f1');
    website.module.mlrs.stylePropertyDetailTable(9,'#ddd');
    website.module.mlrs.stylePropertyDetailTable(10,'#f1f1f1');
    website.module.mlrs.stylePropertyDetailTable(11,'#ddd');

    $('#mlsr_main_image_div').parent().parent().parent().parent().parent().parent().parent().parent().find('tr:nth-child(12)').find('td').attr('style','padding-top:20px;padding-left:40px;padding-right:40px;padding-bottom:0px;');
    $('#mlsr_main_image_div').parent().parent().parent().parent().parent().parent().parent().parent().find('tr:nth-child(13)').find('td').attr('style','padding-top:20px;padding-left:40px;padding-right:40px;padding-bottom:0px;');
    $('#mlsr_main_image_div').parent().parent().parent().parent().parent().parent().parent().parent().find('tr:nth-child(14)').find('td').attr('style','padding-left:40px;padding-right:40px;padding-bottom:0px;');
    
    
    $('#ws_quicksearch_region').val(library.fn.getParam('region'));
    $('#ws_quicksearch_pt').val(library.fn.getParam('pt'));
    $('#ws_quicksearch_mnprc').val(library.fn.getParam('mnprc'));
    $('#ws_quicksearch_mxprc').val(library.fn.getParam('mxprc'));
    
    $('#ws_admin_featured_large img').live('click', function(){
        var valueToUse = 'Do not use this property for that.';
        if (this.src.indexOf('no_pic.png') == -1){
            valueToUse = this.src.replace('lowres','highres');
        }
        
        $('#ws_admin_property_large_image').val(valueToUse);
    });
    
    if(jQuery().jCarouselLite){
        $("#ws_admin_featured_large").jCarouselLite({
            btnNext: ".ws_admin_next1",
            btnPrev: ".ws_admin_prev1",
            visible:5,
            scroll:3
           
        });
    }
    
    $('#ws_admin_featured_medium img').live('click', function(){
        var valueToUse = 'Do not use this property for that.';
        if (this.src.indexOf('no_pic.png') == -1){
            valueToUse = this.src.replace('lowres','medres');
        }
        
        $('#ws_admin_property_medium_image').val(valueToUse);
    });
    
    if(jQuery().jCarouselLite){
        $("#ws_admin_featured_medium").jCarouselLite({
            btnNext: ".ws_admin_next2",
            btnPrev: ".ws_admin_prev2",
            visible:5,
            scroll:3
        });
    }
    
    $('#ws_admin_featured_small img').live('click', function(){
        var valueToUse = 'Do not use this property for that.';
        if (this.src.indexOf('no_pic.png') == -1){
            valueToUse = this.src;
        }
        
        $('#ws_admin_property_small_image').val(valueToUse);
    });
    
    if(jQuery().jCarouselLite){
        $("#ws_admin_featured_small").jCarouselLite({
            btnNext: ".ws_admin_next3",
            btnPrev: ".ws_admin_prev3",
            visible:5,
            scroll:3
        });
    }
    
    

    
    
});
