$(document).ready(function() {

    $("ul.tabs").tabs("div.panes > div");
    //$("ul.tabs").tabs("div.panes > div", {effect: 'fade'});

    $("#home_tab ul.content_tabs").tabs("#home_tab div.content_panes > div", {
        effect: 'fade',
        onClick: function() {
            replace_picture_randomly("#home_content_header_image");
        }
    });

    $("#professionals_tab ul.content_tabs").tabs("#professionals_tab div.content_panes > div", {
      effect: 'fade'
        //onClick: function() {
        //    replace_picture_randomly("#professionals_content_header_image");
        //}
    });

    $("#about_tab ul.content_tabs").tabs("#about_tab div.content_panes > div", {
      effect: 'fade'
    });

    $("#content .accordion").tabs("#content .accordion div.pane", {
        tabs: 'h2',
        effect: 'slide',
        initialIndex: null
    });

    $(".sample_call_link").overlay({expose: {color: '#000', opacity: 0.5},
        onClose: function() {flowplayer().stop();}
    });

   flowplayer("playah", "/flowplayer/flowplayer.commercial-3.1.5.swf", {
       key: '#$57b6b409fd15fab49c3',
       playlist: [
           // JPG image
           '/images/phone.jpg',
           // audio, requires audio plugin. custom duration
           {url: '/files/finethanx_sample_call.mp3'}
       ],
       plugins: {
         controls: {
              backgroundColor:'#002200',
              height: 30,
              fullscreen: false,
              url: '/flowplayer/flowplayer.controls-3.1.5.swf'
          } ,
           audio: {
               url: '/flowplayer/flowplayer.audio-3.1.2.swf'
           }
       }
   });

    $(".caregiver_sample_call_link").overlay({expose: {color: '#000', opacity: 0.5},
        onClose: function() {flowplayer().stop();}
    });

   flowplayer("caregiver_playah", "/flowplayer/flowplayer.commercial-3.1.5.swf", {
       key: '#$57b6b409fd15fab49c3',
       playlist: [
           // JPG image
           '/images/phone.jpg',
           // audio, requires audio plugin. custom duration
           {url: '/files/Caregivercall.mp3'}
       ],
       plugins: {
         controls: {
              backgroundColor:'#002200',
              height: 30,
              fullscreen: false,
              url: '/flowplayer/flowplayer.controls-3.1.5.swf'
          } ,
           audio: {
               url: '/flowplayer/flowplayer.audio-3.1.2.swf'
           }
       }
   });

});

function replace_picture_randomly(div) {
    var currindex = $(div).html().match((/\d/))[0];
    var index = Math.floor(Math.random()*5) + 1;
    while (index == currindex) {
        index = Math.floor(Math.random()*5) + 1;
    };
    var filename = "horizontal" + index + ".jpg";
    $(div).html("<img src='/images/marketing/" + filename + "' />");

}
