/**
 * Created by JetBrains PhpStorm.
 * User: anaxamaxan
 * Date: 7/28/11
 * Time: 10:46 PM
 * To change this template use File | Settings | File Templates.
 */
$(document).ready(function(){
    //generic loading image
    var $loadingimg = $('<img src="/img/loading.gif" alt="loading">');
    
    //tooltips
    $('abbr, .tooltip, a.helplink, a[title]').tipsy({fade:true, gravity: $.fn.tipsy.autoNS, delayIn:500, delayOut:200});
    
    //datepicker
    $('.date').datepicker();
    
    /* Replace headings with fancy text. */
    Cufon.replace('h1.imagetext', { fontFamily: 'zapfino' });
    Cufon.replace('h2.imagetext', { fontFamily: 'futura' });
    
    /* Table sorter */
    tblsort = {
        setup : function(){
            var hdrs = {};
            $('table.columnsort th').each(function(i){
                if($(this).hasClass('nosort')) {
                    hdrs[i] = {sorter:false};
                }
                i++;
            });
            $('table.columnsort').tablesorter({widgets:['zebra'],headers:hdrs});
        }
    }
    tblsort.setup();
    
    /****** Shadowbox *******/
    Shadowbox.init();
    
    /**************** Sustainability Designation dialog popup *************/
    sustainability_desig = {
        setup : function(){
            $('a.sdlabel').each(function(){
                var $dialog = $('<div></div>').append($loadingimg.clone());
                var $link = $(this).one('click', function() {
                    $dialog
                            
                        .load($link.attr('href'))
                        .dialog({
                            title: 'Sustainability Designation',
                            width: 400,
                            height: 300,
                            buttons: {
                                'OK': function() {
                                    $( this ).dialog( "close" );
                                }
                            }
                        });

                    $link.click(function(e) {
                        $dialog.dialog('open');
                        return false;
                    });
                    return false;
                });
            });            
        }
        
    }
    
    sustainability_desig.setup();
    
    /************* Pageboxes ******************/
    pagebox = {
        setup : function(){
            $('a.pagebox').each(function(){
                var $dialog = $('<div></div>').append($loadingimg.clone());
                var $link = $(this).one('click', function() {
                    $dialog
                        .load($link.attr('href'))
                        .dialog({
                            title: '',
                            width: 600,
                            height: 400,
                            buttons: {
                                'OK': function() {
                                    $( this ).dialog( "close" );
                                }
                            }
                        });

                    $link.click(function(e) {
                        $dialog.dialog('open');
                        return false;
                    });
                    return false;
                });
            });            
        }
    }
    pagebox.setup();
});

