// When DOM is ready, prepare portfolio
$(document).ready(function()
{
   var katalystJS = new KatalystJS();
   katalystJS.prepareElements();
});

var KatalystJS = function() 
{
   var footerSearchEl;
   var footerSearchDefaultTxt = "Enter search terms";
   
   prepareElements = function()
   {
      
      footerSearchEl = $('#search_text');
      footerSearchEl.focus(function(e){  
         $(this).addClass("active");
         if($(this).attr("value") == footerSearchDefaultTxt) $(this).attr("value", "");  
      });  
      footerSearchEl.blur(function(e){  
         $(this).removeClass("active");
         if($(this).attr("value") == "") $(this).attr("value", footerSearchDefaultTxt);  
      });
      
      
      $("#archive_select").change(function (){
         window.location = $("#archive_select option:selected").val();
      });
      
      
      if ( $('#about_imgs').length > 0 )
      {         
         $('#about_imgs').innerfade({
            speed: 1000,
            timeout: 5000,
            type: 'sequence',
            containerheight: '360px'
         });
      }
      
      if ( $('.book .imgs img').length > 0 )
      {
         $('.book .imgs img').load(function () {
            $(this).fadeIn();
         });
      }
      
      
      if ( $(".book .thumbs a").length > 0)
      {        
         $(".book .thumbs a").click(function () {
         
            if( !$(this).hasClass(".selected") )
            {
               var a = $(this);
               var src = a.attr('href');
               var img = $(".imgs img", a.parent().parent()).get(0);
            
               $(this).siblings().removeClass('selected');
               $(this).addClass('selected');
                        
               img.src = src;
               $(img).css({display:'none'});
            }
                                 
            return false;
         });
      
      }
      
      
      
      if ( $(".podcast_player").length > 0)
      {
         $(".podcast_player").each(function (i)
         {
            var id = this.id;
            var mp3_url = $("#" + id + "_mp3_url").attr("href");
            //var duration = $(".podcast_duration:eq(" + i ")").text();
            //alert("duration: " + duration);
            if (id.length > 0 && mp3_url.length > 0)
            {  
               var flashvars = {};
               flashvars.player_id = id;
               flashvars.mp3_url = mp3_url;
               var params = {};
               params.menu = "false";
               var attributes = {};
               attributes.id = id;
               attributes.name = id;
               window.swfobject.embedSWF("/assets/swf/katalyst_podcast_player.swf", id, "500", "50", "9.0.0","expressInstall.swf", flashvars, params, attributes);
            }
         });
      }
      
      
      if ($("#latest_photos").length > 0)
      {
         $('#latest_photos .image a').fancyZoom({scaleImg: true, directory:'/assets/js/fancyzoom_images/'});
      }
      			

      
             
   }
   this.prepareElements = prepareElements;
}