var Page = {
    init: function () {
        Page.gridfitter();
        Page.collapse();
        Page.initialCollapse();
        Page.headhover();
        Page.embedAudioSetup();
        Page.embedAudio();
    },
    collapse: function () {
        $(".tsetse .head").click(function () {
            $(this).parent().children('.content-panel').toggle('blind', {}, 1000);
        }),
        $(".blogwatch .head").click(function () {
            $(this).parent().children(".content-panel").toggle('blind', {}, 1000);
        });
    },
    headhover: function () {
       $('.head').hover(function() {
            $(this).addClass('headhover');
       }, function() {
            $(this).removeClass('headhover');
       });
    },
    initialCollapse: function () {
        $('.tsetse .content-panel').hide();
        $('.blogwatch .content-panel').hide();
    },
    gridfitter: function () {
        $('#blog .content-panel img').each(function () {
            var width = this.width;
            var height = this.height;
            if (width > 500) {
                var newWidth = 500;
                var factor = newWidth/width;
                this.width = newWidth;
                this.height = Math.round(height*factor);
                var width = this.width;
                var height = this.height;
            }
            var grid = Math.floor(height/24);
            var newHeight = grid*24;
            var factor = newHeight/height;
            this.height = newHeight;
            this.width = Math.round(width*factor);
            if (this.style.cssFloat=="left") {
                this.style.marginRight="20px";
            }
            if (this.style.cssFloat=="right") {
                 this.style.marginLeft="20px";
            }
        });
    },
    earthquakeMap: function () {
      if (GBrowserIsCompatible()) {
           $('.quake_map').each( function () {
               var loc = $(this).html().split(',');
               var map = new GMap2(this, {backgroundColor: '#99b3cc'});
               var latitude = Number(loc[0]);
               var longitude = Number(loc[1]);
               var epicenter = new GLatLng(latitude, longitude)
               var bubble = new GMarker(epicenter)
               map.setMapType(G_PHYSICAL_MAP);
               map.addControl(new GSmallZoomControl());
               map.setCenter(epicenter, 12);
               map.addOverlay(bubble)
           });
        }
    },
    corners: function () {
        $('.section').corners("10px");
    },
    embedAudioSetup: function() {
        AudioPlayer.setup("http://www.northcoastjournal.com/media/js/audio-player/player.swf", {  
            width: 500  
        });  
    },
    embedAudio: function() {
        $('.audio_player').each(function() {
            var url = $(this).find('a')[0]['href'];
            AudioPlayer.embed(this.id, {soundFile: url});
        });
    }
};

$(document).ready(Page.init);

