// Place your application-specific JavaScript functions and classes here
// This file is automatically included by javascript_include_tag :defaults
jQuery(document).ready(function() {
  if(!$.browser.msie)
  {
    DD_roundies.addRule('.rc', '5px', true);
  }
  DD_roundies.addRule('.rc', '5px', true);
  var field = $('#newsletter_email');
  if(field)
  {
    field.focus(function(e) {
      this.value = '';
    });
    field.blur(function(e) {
      this.value = 'enter your email address and hit return';
    });
  }
  
  $('#latest_upload .recent_hover').mouseover(function() {
    $(this).css({
      'background-color' : '#333133', 
      'border-color' : '#79c143'
    });
  });
  $('#latest_upload .recent_hover').mouseleave(function() {
    $(this).css({
      'background-color' : '#1a1a1a', 
      'border-color' : '#6ce413'
    });
  });
  
  if($("img.tooltip").length > 0) { $("img.tooltip").tooltip(); }
  // -----------------------------
  // accordion
  // -----------------------------
  if($('#accordion').length > 0) {;   
    $("#accordion").accordion({ activeitem: 'none' });
  }
	if($('ul#mix_accordion').length > 0) {
    $("ul#mix_accordion").accordion({ activeitem: 'none' });
  }
  // -----------------------------
  // Image flow
  // -----------------------------
  if($('#gallery_images').length > 0) {
    
    var img_flow = new ImageFlow();
	  img_flow.init({ 
	    ImageFlowID: 'gallery_images',
	    captions: false,
	    startID: 5,
	    reflections: false,
	    onClick: 'void(0)',
	    imageCursor: 'pointer',
	    slider: false
    });
    $('#gallery_images img').lightBox();
  }
  if($('#mobile_gallery_images').length > 0)
  {
    $('#mobile_gallery_images a').lightBox();
  }
  // ----------------------------
  // home page slideshow
  // ----------------------------
  $(function() {
    setInterval("slideSwitch()", 5000);
  });

  $(document).ready(function(){
  	$("a[href^='http']").not("[href*='clubthompsons.com']").attr('target','_blank');
  });
});


function slideSwitch() {
  var $active = $('#slideshow img.active');
  if ($active.length == 0) $active = $('#slideshow img:last');
  var $next =  $active.next().length ? $active.next() : $('#slideshow IMG:first');
  $active.addClass('last-active');
  $next.css({ opacity: 0.0 })
  .addClass('active')
  .animate({opacity: 1.0}, 1000, function() {
      $active.removeClass('active last-active');
  });
}

function new_win(url,windowname,w,h,x,y)
{    
  var w = window.open(url, windowname,
              "location=no,resizable=no,toolbar=no,scrollbars=no,menubar=no,status=no,directories=no,width="+w+",height="+h+",left="+x+",top="+y+"");
  w.focus();
}

function save_mp3(string) 
{
  if(typeof string == 'string')
  {
    mp3 = string;
  }
  //window.win = open(mp3);
  //setTimeout('win.document.execCommand("SaveAs")', 500);
  
  Response.ContentType = 'audio/mpeg';
  Response.AppendHeader("content-disposition:", "attachment; filename=" + mp3);
  Response.WriteFile(Server.MapPath(mp3));
}