jQuery(document).ready(function() {

    jQuery("#tabs, .sub-tabs").tabs();
    jQuery('.column-one li').removeClass('ui-tabs-selected ui-state-active');
    jQuery('.column-one li a').click( function() {
        jQuery('.column-resources ul li').removeClass('ui-tabs-selected ui-state-active');
        jQuery('.resource-image-right').show();
        jQuery('.column-resources-right').hide();
        jQuery('.resource-image-left').hide();
        jQuery('.column-resources').show();
    });

    jQuery('.column-resources ul li a').click( function() {
        jQuery('.resource-image-right').hide();
        jQuery('.column-resources-right').show();
    });

    /* added for search field default value */
    jQuery('.search-text').blur(function(){if(this.value == '') this.value='Search...' ;});
    jQuery('.search-text').focus(function(){if(this.value == 'Search...') this.value='';} );

    jQuery('.wpcf7-submit, #submit').live('click', function(){
        var phone_validation = /^\(?(\d{3})\)?[.\- ]?(\d{3})?[.\- ]?(\d{4})$/;
        var phone = jQuery('#telephone').val();
        var fax = jQuery('#fax').val();
        if(!phone.match(phone_validation)) {
            var response = jQuery('.wpcf7-response-output');
            response.removeClass('wpcf7-display-none');
            response.addClass('wpcf7-display');
            response.text('Phone number format invalid.');
            jQuery('#telephone').val('');
        }
        if(!fax.match(phone_validation)) {
            jQuery('#fax').val('');
        }

    var zip_validation = /^\d{3,5}$/;
        var zip = jQuery('#zip').val();
        if(!zip.match(zip_validation)) {
            var response1 = jQuery('.wpcf7-response-output');
            response1.removeClass('wpcf7-display-none');
            response1.addClass('wpcf7-display');
            response1.text('Zip Code format invalid.');
            jQuery('#zip').val('');
        }
    });

    jQuery('.prevlink').click(function(){
        var prev_click_id = jQuery(this).parent().parent().parent().prev().attr('id');
        jQuery('.'+prev_click_id+' a').trigger('click');
        return false;
    });
    jQuery('.nextlink').click(function(){
        var next_click_id = jQuery(this).parent().parent().parent().next().attr('id');
        jQuery('.'+next_click_id+' a').trigger('click');
        return false;
    });

});

jQuery(window).load(function(){
    

//    var image_height = jQuery('.resource-image-left').height();
//    var final_h = (image_height/2)+17;
//    jQuery('.resource-image-left').css('margin-top', '-'+(final_h)+'px').show();
//    image_height = jQuery('.resource-image-right .alignleft').height();
//    final_h = (image_height/2)+17;
//    jQuery('.resource-image-right .alignleft').css('margin-top', '-'+(final_h)+'px').show();
//
//    image_height = jQuery('.resource-image-right .alignright').height();
//    final_h = (image_height/2)+17;
//    jQuery('.resource-image-right .alignright').css('margin-top', '-'+(final_h)+'px').show();

    jQuery('.ajax-loader').hide();
    jQuery('.resources-right img').show();

    var url = document.URL;
    var id = url.substring(url.lastIndexOf('#'));
    if( id.indexOf('#') == 0 ) {
        if(document.getElementById('main-'+id.substring(1))){
            jQuery('#main-'+id.substring(1)+' a').trigger('click');
            jQuery(id+' .ui-tabs-nav li:first-child a').trigger('click');
        } else {
            var cat = (jQuery('.'+id.substring(1)).parent().parent().attr('id'));
            jQuery('#main-'+cat+' a').trigger('click');
            jQuery('.'+id.substring(1)+' a').trigger('click');
        }
        window.location.hash = '#main-wrapper';
        window.location.hash = '#';
    }
});


