/* 
 * awesomebox
 */

$(function(){
  /* create elements */
  $('body')
    .append('<div id="awesomebox-overlay">&nbsp;</div>') //overlay
    .append('<div id="awesomebox"><div id="ab_inner"></div></div>') //container
  ;
  /* setup overlay */
  $('#awesomebox-overlay')
    .css({position:'absolute',left:'0',top:'0',width:'100%',height:'100%',backgroundColor:'#000000',opacity:'0'})
    .css('z-index','990')
    .click(function(){awesomebox_hide();}) //start hide process
    .hide()
  ;
  /* setup positioning of container */
  $('#awesomebox')
    .css({position:'absolute',left:0,top:50,width:'100%',textAlign:'center',opacity:'0'})
    .css('z-index','991')
    .click(function(){$('#awesomebox-overlay').click();}) //as with overlay...
    .hide()
  ;
  /* setup container */
  $('#ab_inner')
    .css({backgroundColor:'black',margin:'0 auto',width:609,Height:500,textAlign:'center'})
    .click(function(){return false;}) //clicking the box doesnt start hide process
  ;
  /* container UI */
  $('#ab_inner')
    .append('<img id="ab_closeimg" src="exit.png" style="float:right;" />') //close button
    .append('<h2>&nbsp;</h2>') //heading
    .append('<div id="ab_content" style="font-size:9pt"></div>') //content
  ;
  $('#ab_closeimg')
    .css({cursor:'pointer',margin:'4 5 0 0',backgroundColor:'#666666'})
    .hover(function(){
      $(this).animate({backgroundColor:'#CCCCCC'},500)
    },function(){
      $(this).animate({backgroundColor:'#666666'},500)
    })
    .click(function(){$('#awesomebox-overlay').click();}) //as with overlay...
  ;
  $('#ab_inner h2')
    .css({textAlign:'left',margin:'0',padding:'6px 0 0 8px',color:'white',backgroundColor:'black',fontSize:'14pt'})
  ;
  $('#ab_content')
    .css({position:'relative',textAlign:'center',margin:'0',padding:'7px 14px 14px 12px'})
  ;
  
});

function awesomebox_hide() {
  $('#awesomebox-overlay')
    .delay(250)
    .fadeOut(400)
  ;
  $('#awesomebox')
    .fadeOut(400,function(){
      $('#ab_content').html('');
      $('.shell object, .shell embed')
        .css('visibility','')
      ;
    })
  ;
}

function awesomebox_show() {
  $('.shell object, .shell embed')
    .css('visibility','hidden')
  ;
  $('#awesomebox-overlay')
    .css('height',$(document).height())
    .fadeTo(400,0.6)
  ;
  $('#awesomebox')
    .delay(250)
    .fadeTo(400,1)
  ;
}

function awesomebox(heading,content) {
  //gather information from object to customize the awesomebox
  //var target=$(object);
  
  //position the awesomebox
  //var newtop = target.offset().top-400;
  var newtop = 120;
  newtop = (newtop>0) ? newtop : 0;
  $('#awesomebox')
    .css('top',newtop)
  ;
  
  $('.shell object, .shell embed')
    .css('visibility','hidden')
  ;
  //show the overlay
  $('#awesomebox-overlay')
    .css('height',$(document).height())
    .fadeTo(400,0.6,function(){
      // var nt=parseInt($('#awesomebox').css('top'));
      // window.scrollTo(0,(nt>15)?(nt-15):0);
    })
  ;
  //set the title
  $('#awesomebox h2')
    .text(heading)
  ;
  //set the description
  $('#ab_content')
    .html(content)
  ;
  $('#awesomebox')
    .delay(250)
    .fadeTo(400,1,function(){
      // $('#ab_content')
        // .fadeTo(100,1)
      // ;
    })
  ;
  
  return false;
}

function ab_vid(heading,source){
  awesomebox(
    heading,
    '&nbsp;'+writeflashv(
      'FLVPlayer_Progressive',576,432,
      'MM_ComponentVersion=1&skinName=Clear_Skin_3&autoPlay=true&autoRewind=false&streamName='+source+'',
      '#ffffff'
    )
  );
}

function media_vid() {
  ab_vid('FFH on What Can I Eat\'s "2-Minute Foodle"','ffh2mf.flv');
}

