function load_player_comic(id, lang)
{
  var flashvars = {
    lang : lang,
    ftml_url : '/comic_player/ftml/comic_player_ftml.php',
    id   : id
  };

  var params = {
    menu:"false",
    bgcolor:"#FFFFFF",
    wmode:"transparent"
  };

  var attributes = {};

  swfobject.embedSWF("/comic_player/comic_player.swf", "comic_player", "600", "760", "9.0.0", "/toolaka/addon/swfobject/expressInstall.swf", flashvars, params, attributes);
}

// used to call swf
function getswf(movieName)
{
  var isIE = navigator.appName.indexOf("Microsoft") != -1;
  return (isIE) ? window[movieName] : document[movieName];
}

// ask player swf to create the image
var lightview_image_title;
function get_big_image(title)
{
  lightview_image_title = title;
  var page_one_exists = (big_image_url != "/toolaka/media/blank.gif");
  var page = getswf("comic_player").get_big_image(page_one_exists);
  if (page == "1" && page_one_exists) {
    // image of page 1 already exists
    image_ready(big_image_url);
  }
  return false;
}

// called by player swf when the image is ready
function image_ready(image_path)
{
  if (image_path == "") {
    alert ("erreur !");
  } else {
    // If you have firebug installed you can run this from your console, have fun.
    Lightview.show({ href: image_path, title: lightview_image_title});
  }
}


function tshirt_image_ready(image_path)
{
  if (image_path == "") {
    alert ("erreur !");
  } else {
    var rand = Math.round(Math.random() * 10000);
    var reg = new RegExp("(\.jpg)", "g");
    
    document.location.href = "/shop.html?id=" + item_id + "&file=" + image_path.replace(reg, "-" + rand + ".jpg");
  }
}


// called by swf to set the comic size
function set_item_size(size_x, size_y)
{
  var w = parseInt(size_x) * (600/450);
  var h = parseInt(size_y) * (600/450);
  $('player_inside').style.width = w+'px';
  $('player_inside').style.height = h+'px';
  //alert('Original : '+size_x+'x'+size_y+"\nResize : "+w + 'x' + h);
}


var close_widget = "";
function show_tell_a_friend()
{
  var obj = getswf("comic_player");
  // replace close function by mine
  if (close_widget == "") {
    close_widget = STTAFFUNC.closeWidget;
    STTAFFUNC.closeWidget = function (obj) {
      close_widget(obj);
      var obj = getswf("comic_player");
      // show the swf
      obj.style.visibility = "visible";
    }
  }
  // hide the swf
  obj.style.visibility = "hidden";
  cw(this, {id:'2009022411011', link: window.location, title: document.title });
  return false;
}


function create_tshirt_image(width, height)
{
  // slidedown the waiting message
  Effect.toggle('tshirt_wait', 'slide', { afterFinish: function( )
    {
      getswf("comic_player").create_tshirt_image(width, height);
    }
  });



  return false;
}



function tip_help(id, title, content)
{
	new Tip(id, content, {
		title: title,
		stem: 'bottomRight',
		hook: { target: 'topRight', tip: 'bottomRight' },
		offset: { x: -2, y: 0 },
		width: 200,
		border: 4,
    radius: 4			
	});
}






var last_div = null;
var menu_slide_execute = true; 

function menu_slide(div)
{
  var type = 1;
  
  if(type == 1)
  {
  // disable effect on the link already clicked
  if(last_div != div && menu_slide_execute == true)
  {
    menu_slide_execute = false;    

    // slideup the last menu opened
    if(last_div) 
    {
      //Effect.SlideUp(last_div);
      Effect.toggle(last_div, 'slide', { afterFinish: function( )  
        {
          // slidedown the menu selected
          Effect.toggle(div, 'slide', { afterFinish: function( )  
            {
              menu_slide_execute = true;
              //$(div).style.overflow = 'visible';        
            }
          });
        }
      });
    }
    else
    {
      // slidedown the menu selected
      Effect.toggle(div, 'slide', { afterFinish: function( )  
        {
          menu_slide_execute = true;
        }
      });
    }

    last_div = div; 
    

    //$(div).element _overflow="null"
  }
  
  }
  else if (type == 2)
  {
    if(last_div) {
      $(last_div).style.display = "none";
    }
    last_div = div;
    $(div).style.display = "block";
  }
    
  return false;
}





function starbox(rate, count, message)
{
  new Starbox('rate', rate, {
    total: count,
    ghosting: true,
    rerate: false,
    //indicator: message,
    onRate:  function(element, info) {
      pageRequest('/toolaka/php/ajax.php?type=item_vote&pack_id='+pack_id+'&id='+item_id+'&rate='+info.rated, 'item_rate_msg');
    }
  });
}



function starboxChangedText(event) 
{
  pick = (event.memo.rating || 0).round() - 1;


  // for restoring, store the indicator text on the star if it was not set before.
  if(!this.starboxResetText) {
    this.starboxResetText = $('item_rate_msg').innerHTML;
  }

  $('item_rate_msg').update([
    rate_level[0],
  	rate_level[1],
  	rate_level[2],
  	rate_level[3],
  	rate_level[4]
  ][pick]);

}

function starboxLeftText()
{
  $('item_rate_msg').innerHTML = this.starboxResetText
  this.starboxResetText = null;
}

function starboxRatedText()
{
  //var split = this.starboxResetText.split(' ');
  //split[0]++;
  //$('item_rate_msg').innerHTML = split[0] + ' ' + split[1];
}

// attach the custom events on DOM loaded
document.observe('dom:loaded', function() {

  $('rate').observe('starbox:changed', starboxChangedText) // observe the mouseover
  //.observe('starbox:rated', starboxRatedText) // observe the click
  .observe('starbox:left', starboxLeftText); // observe the mouseout
});
