$(function(){
  $('#content_tabs').hrzAccordion({
    openOnLoad : 5, //shoes
    fixedWidth : '652'
  });

  $('#content_tabs h2').click(function(e){
    e.preventDefault();
    $('#icon_navigation li a').removeClass('selected');
    var id = this.id
    $('#icon_navigation li a.' + id.substring(0, id.lastIndexOf('_'))).addClass('selected');
  });

  $('#icon_navigation li a.shoes').addClass('selected');
  $('#icon_navigation li a').click(function(e){
    e.preventDefault();
    $($(this).attr('href') + '_tab').click();
    $('#icon_navigation li a').removeClass('selected');
    $(this).addClass('selected');
  });

  $firstShoe = $('#shoe_thumbs a:first img');
  $('#shoe_preview img').attr('src', $firstShoe.attr('src')).attr('alt', $firstShoe.attr('alt'));
  $('#shoe_preview h3').html($firstShoe.attr('alt'));
  $('#shoe_preview a#details').attr('href', $firstShoe.attr('longdesc'));
  $('#shoe_thumbs a').hover(function(e){
    var img = $('img', this);
    $('#shoe_preview img').attr('src', $(img).attr('src')).attr('alt', $(img).attr('alt'));
    $('#shoe_preview h3').html($(img).attr('alt'));
    $('#shoe_preview a#details').attr('href', $(img).attr('longdesc'));
    $('#shoe_preview a#buy').attr('href', $(img).attr('name'));
  });

  $firstPic = $('#pic_thumbs a:first img');
  $('#pic_preview img').attr('src', $firstPic.attr('src')).attr('alt', $firstPic.attr('alt'));
  $('#pic_thumbs a').hover(function(e){
    $('#pic_preview img').replaceWith($(this).html());
  });

  $firstVideoImg = $('#video_thumbs a:first img');
  $('#vid_thumb img').attr('src', $firstVideoImg.attr('src'));
  $('#vid_thumb img').attr('alt', $firstVideoImg.attr('alt'));
  $('#vid_desc').html($('#video_thumbs a:first').attr('title'));
  $('#video_thumbs a')
    .attr('href', '#TB_inline?height=408&width=699&inlineId=tb_video')
    .append($('#video_thumbs img.video_play').clone())
    .hover(
      function(e){
        $('#vid_thumb img').attr('src', $('img:first', this).attr('src')).attr('alt', $('img:first', this).attr('alt')).css('display', 'inline');
        $('#vid_desc').html($(this).attr('title'));
        var pos = $('img:first', this).position();
        $('img.video_play', this).css({'display':'inline', 'position':'absolute', 'top':pos.top, 'left':pos.left});
      },
      function(e){
        $('#vid_thumb img').attr('src', '').attr('alt', '').css('display', 'none');
        $('#vid_desc').html('&nbsp;');
        $('img.video_play', this).css({'display':'none', 'position':'static'});
      }
    )
    .click(function(e){
      e.preventDefault();
      var s = $('img', this).attr('src');
      if(s.indexOf('http://') === -1){
        s = '/'+s;
      }
      var a = $('img', this).attr('alt');
      tb_show(a,this.href,'');
      flowplayer('flashvideo', '/lib/swf/flowplayer-3.1.1.swf',{
        plugins:{
          controls:{
            backgroundGradient: 'none',
            backgroundColor   : 'transparent',
            borderRadius      : '10',
            autoHide          : 'always'
          }
        },
        canvas:{
          backgroundColor   : '#222',
          backgroundGradient: 'medium'
        },
        clip:{
          url           : s.replace('/img/', '/flv/').replace('\.jpg', '\.flv'),
          autoPlay      : false,
          autoBuffering : true
        }
      });
      this.blur();
      return false;
    });

  $('#onfield').click(function(e){
    e.preventDefault();
    $('#stat_info').addClass('onthefield').removeClass('offthefield');
  });
  $('#offfield').click(function(e){
    e.preventDefault();
    $('#stat_info').addClass('offthefield').removeClass('onthefield');
  });
});