$(function() {
    // top nav
    $('#topNav li').each(function(){
        var $this=$(this),
            thisURL=$this.find('a').attr('href');
        $this.hover(
            function() {
                $this.find('.dropDownContent').slideDown('fast');
            },
            function() {
                var t=setTimeout(function(){
                    $this.find('.dropDownContent').slideUp('fast');
                },500);
                
                $this.find('.dropDownContent')
                    .hover(function(){
                        clearTimeout(t);
                    }).click(function(){
                        location.href=thisURL;
                    });;
            }
        );
    });
    
    // font sizer
    $('#font-sizer a').each(function(i,o) {
        var $this=$(this);
        
        if (i==0)
            $this.parent().addClass('active');
        $this.bind('click', function(event) {
            event.preventDefault();
            var fontSize='';
            switch (parseInt($this.attr('href').split('#')[1])) {
                case 12: fontSize=''; break;
                case 14: fontSize='1.2em'; break;
                case 16: fontSize='1.4em'; break;
                default: fontSize='';
            }
            $this.parent().addClass('active').siblings().removeClass('active');
            _gaq.push(['_trackEvent','Font Size','Click',fontSize]);
            $('.content:not(.no-resize)').css({'font-size':fontSize});
        });
    });
    if (!$('#wrapper_GY').hasClass('Home')) {
        $('#font-sizer').show();
    }
    
    // cycle blast
    $('.blast ul').cycle({
        fx: 'scrollUp',
        speed: 300,
        timeout: 12000,
        delay: -2000
    });
    
    // populate presentations
    $('.presentations_list').each(function(i, o) {
        var strOutput = '',
            date, month, day, year;
        $.ajax({
            url: 'presentations.js',
            dataType: 'json',
            success: function (resp, status, xhr) {
                for (var i=0, l=resp.length; i<l; i+=1) {
                  strOutput += '<li><strong>' + resp[i].date + ': ' + resp[i].speaker + '</strong><br />'
                      + '<strong>Topic:</strong> ' + resp[i].topic + '<br />'
                      + '<strong>Orgnization:</strong> ' + resp[i].organization + '<br />'
                      + '<strong>Location:</strong> ' + resp[i].location + '<br />';
                  strOutput += (resp[i].time.length > 0) ?  '<strong>Time:</strong> ' + resp[i].time + '<br />' : '';
                  strOutput += '<span> ' + resp[i].audience + '</span>'
                      + '</li>';
                }
                o.innerHTML = strOutput;
            }
        });
    });
    
    // highlight presentation of the day
    /*$('.presentations_list li').each(function(i, o) {
        var dataDate = $(this).data('date'),
            presentDate = new Date(dataDate).toDateString(),
            today = new Date().toDateString();

        if (presentDate == today) {
            $(this, 'span').css({'color': '#DEB4B5'});
            //$()
        }
    });*/
    
    
    /*var dateParts = strDate.split(".");

var date = new Date(dateParts[2], (dateParts[1] - 1) ,dateParts[0]);*/

    
    $('.photo_swatch').find('img').each(function() {
        var thisImg=$(this);
        thisImg.hover(
            function() {
                $('.photo_swatch').find('img').addClass('imgFilter');
                thisImg.removeClass('imgFilter');
            },
            function() {
                $('.photo_swatch').find('img').removeClass('imgFilter');
            }
        );
    });

    // toggles the slickbox on clicking the noted link  
    $('#toggle').bind('click', function(event) {
        event.preventDefault();
        var $this = $(this);
        $('#drop').toggle(400, function() {
            $this.text(($this.text() == 'more>')?'<hide':'more>');
        });
    });

    var options={
        beforeSubmit: processForm
    };
    
//    $('#frmMailingList').ajaxForm(options);
    
    /* about us image select */
    $('#box_Staff a').each(function(i,o) {
        var $this = $(this);
        if (document.location.pathname.indexOf($this.attr('href'))>-1) {
            $(this).closest('li').addClass('on');
            return false;
        }
    });
    
    /* analytics */
    $('a.ext_link').bind('click',function(event) {
        event.preventDefault();
        _gaq.push(['_trackEvent','External Link','Click',this.href]);
        window.open(this.href);
    });
    
    $('a.pdf').bind('mouseup click',function(event) {
        event.preventDefault();
        if (event.type !== 'click') {
            _gaq.push(['_trackEvent','PDF','Download',this.href]);
            window.open(this.href);
        }
    });

    $('a.vcf').bind('click',function(event) {
        _gaq.push(['_trackEvent','VCF','Download',this.href]);
    });
    
    $('a.mail').bind('click',function(event) {
        _gaq.push(['_trackEvent','MailTo','Click',this.href]);
    });

});

// process form
function processForm(formData, jqForm, options) {
    $('#submit').disabled=true;
    $('#submit').value="Processing...";
        
    $('#frmMailingList').validate();
}
/*
$(function(){
    if (url.indexOf('tarayn')>-1) {
        $('#about_us_image').attr('src','').css({background:'#666'}).attr('alt','').wrap('<span/>').html('Image Not<br/>Available.').css({color:'#eee',paddingTop:'30px',textAlign:'center'});
    }
});*/
