//Libraries we're using:
//  jQuery 1.3.2
//  jQuery.scrollTo 1.4.2
//  jQuery.Tools 1.1.0 [tools.tabs-1.0.2, tools.tabs.slideshow-1.0.0, tools.tooltip-1.1.0, tools.overlay-1.1.0, tools.overlay.apple-1.0.0, tools.expose-1.0.4]
//  FancyZoom 1.1

$(document).ready(function(){
  addBlogClickHandlers();
  setupZoom();
  
  
  //setup banner slideshow
  $("#bannertabs").tabs("#bannerpanel > li", { effect:'fade', fadeOutSpeed:'slow', rotate: true }).slideshow({ autoplay: true, interval: 10000 });


  
  //setup home slideshow tabs
  $("#homeslidetabs").tabs("#homeslide > li", { effect:'fade', fadeOutSpeed:'normal', rotate: true }).slideshow({ autoplay: true, interval: 6000 });
  

  
  //setup merch column formatting > puts thumbs behind a mask
  $(".homemerchthumb img").each(function() {
    $(this).css("background","white url('" + $(this).attr("src") + "') no-repeat center center").attr("src", "img/merchmask.tall.gif");
  });

/*
  $(".homemerchthumb img").hover(
    function(){
      $(this).attr("src", "img/merchmask.tall.gif").animate({ height:"156px"}, "fast");
    },function(){
      $(this).animate({ height:"68px"}, "fast").attr("src", "img/merchmask.gif")
  });
*/

  //setup past shows tabs
  $("#pastshowstabs").tabs("#pastshowspanels > li", { effect:'slide', fadeOutSpeed:'normal' });

  $(".showthumbs li div").hover(function() {
    $(this).fadeTo("fast", 0.85);
  }, function() {
    $(this).fadeTo("fast", 1.0);
  });


  //insert the facebook icon into a link using facebookcom as a class
  $(".facebookcom").each(function() {
    $(this).attr("title", $(this).text()).html("<img src=\"img/icons/facebook-icon.png\" alt=\"Facebook\" />");
  });

  $(".twittercom").each(function() {
    $(this).attr("title", $(this).text()).html("<img src=\"img/icons/twitter-icon.png\" alt=\"Twitter\" />");
  });

});


function addBlogClickHandlers() {
  //if any link in the news pager is clicked then gather the conditions from the href and use jquery to load into the DOM
  //this allows us to load the news via an AJAX call and give visual feedback (fade out and scroll)
  $("#newspagerlinks a").click(function(e) {
    e.preventDefault(); //prevent usual click action

    //break apart href of link
    area_split = $(this).attr("href").split("area=");
    area_split = area_split[1].split("&");
          
    base_split = $(this).attr("href").split("base=");
    base_split = base_split[1].split("&");
    
    //fade out bloglist and then load new data into the parent div then re-init with a callback func
    $("#bloglist").fadeTo("normal",0.3);
    $("#homenews").load('modules/news.php?area=' + encodeURIComponent(area_split[0]) + '&base=' + encodeURIComponent(base_split[0]), function() { addBlogClickHandlers(); setupZoom(); });
    $.scrollTo("#homenews",300);
  });
}


/* Regular use functions */

function clearText(thefield,orig_value){
  if(thefield.value == orig_value)
    thefield.value = "";
}


