/*
 *
 * Copyright (c) 2008 George Bonnes (george@olm1.com)
 * Licensed under the MIT License:
 * http://www.opensource.org/licenses/mit-license.php
 *
 * Version 1.0.1
 *
 * $LastChangedDate$
 * $Rev$
 *
 */

function expert_help_form_open() {
    $('#expert_help_form').css('display', 'block');
    
    expert_help_form_set_shim();
    
    $('#expert_help_form').centerElement()
                          .vCenterElement();
    $('#expert_help_form_shim').centerElement()
                               .vCenterElement();
                          
}

function expert_help_form_close() {
    $('#expert_help_form').css('display', 'none');
    $('#expert_help_form_shim').css('display', 'none');
}

function expert_help_form_set_shim() {
    var theform_container = document.getElementById('expert_help_form');
    var theshim = document.getElementById('expert_help_form_shim');
    theform_container.style.display = "block";
    theshim.style.top = theform_container.style.top;
    theshim.style.left = theform_container.style.left;
    theshim.style.width = theform_container.offsetWidth;
    theshim.style.height = theform_container.offsetHeight;
    //alert('container offsetHeight: ' + theform_container.style.height);
    theshim.style.zIndex = theform_container.style.zIndex + 1;
    theshim.style.display = "block";
}

function shopping_cart_product_summary_close() {
    $('#shopping_cart_product_summary').DropOutUp(300)
}


$(document).ready(function() {
    // initialize our loading div to listen for $.ajax broadcasts
    $("#loading").bind("ajaxSend", function(){
        $("#loading").centerElement()
                     .vCenterElement()
                     .jqmShow();
     }).bind("ajaxComplete", function(){
         if (ajax_error == 0) {
            $("#loading").jqmHide();
         }
     });            
     
     $("#loading").jqm({overlay: 30, trigger: false});
     
     $('.hide_on_load').css('display', 'none');
     $('.show_on_load').css('display', 'block');

     
     
    // event bubbling/event delegation method of attaching event handlers to dynamically loaded objects        
    $('body').click(function(event) {
        if ($(event.target).is('#CustomerInquiries_ajax_inquiry_save')) {
            
            //alert('CustomerInquiries_ajax_inquiry_save button click detected');                    
            ajax_form('CustomerInquiries_ajax_inquiry', 'expert_help_form', 
                // re-align our shim on callback
                (function() { ajax_form_expert_help_form_callback(); }));
        }
    });
    
    
    // bind all links with class "expert_help_form_link" to the ajax contact form
    $('.expert_help_form_link').click(function() { 
    	link_attributes = this.getAttribute('id');
        ajax_update('expert_help_form', '/customer_inquiries/ajax_inquiry/' + link_attributes, (function() { expert_help_form_open(); }))
        return false;
    });
    return false;
    
});  // end $(document).ready()




// ajax custom callbacks
function ajax_update_shopping_cart_product_summary_callback() {
    $('#shopping_cart_product_summary').css('display', 'block')
                                       .centerElement()
                                       .vCenterElement();
}

function ajax_form_expert_help_form_callback() {
    expert_help_form_open();
}

     