/*
 * Copyright (c) 2002-2007 Julien WILK (http://LDDb.com/)
 * Not to be modified/reused without authorization.
 */
 
var in_input = false;

var rt_picture = 0;
var rt_sound   = 0;
var rt_package = 0;

document.onkeydown = function (E)
{
  var r;
  var modifier;

  if(typeof(E)=='undefined')
  {
    E = event;
    r = event.keyCode;
  }
  else
    r = E.keyCode;

  modifier = (E.shiftKey || E.altKey || E.ctrlKey);

  if(!in_input && !modifier) // Can't allow someone hitting a key in a search field to trigger shortkey!
  {
    switch(String.fromCharCode(r).toLowerCase())
    {
      case 'c':
        if(document.coll != 'undefined')
          document.coll.submit();
      break;
  
      case 'e':
        if(document.merge != 'undefined')
          document.merge.submit();
      break;

      case 'i':
        if(document.clone != 'undefined')
          document.clone.submit();
      break;
  
      case 'l':
        if(document.laserrot != 'undefined')
          document.laserrot.submit();
      break;
  
      case 'm':
        if(document.modify != 'undefined')
          document.modify.submit();
      break;
  
      case 's':
        if(document.shop != 'undefined')
          document.shop.submit();
      break;

      case 'u':
        if(document.update != 'undefined')
          document.update.submit();
      break;
  
      case 'w':
        if(document.wish != 'undefined')
          document.wish.submit();
      break;
    }
  }
}

function toggle_rating(cat,id,cond)
{
	if(cond) // dynamic mouse hoovering
	{
		for(i=1;i<=5;i++)
		{
			if(i<=id)
				$(cat+i).src = '/images/icon/star.gif';
		  else
				$(cat+i).src = '/images/icon/star2.gif';
		}
		switch(id)
		{
			case 1: $('rating_comment').innerHTML = 'A shame';
			break;
			case 2: $('rating_comment').innerHTML = 'Poor';
			break;
			case 3: $('rating_comment').innerHTML = 'Average';
			break;
			case 4: $('rating_comment').innerHTML = 'Good';
			break;
			case 5: $('rating_comment').innerHTML = 'Excellent';
			break;
		}
	}
	else // set display value
	{
		id=eval('rt_'+cat);
		for(i=1;i<=5;i++)
		{
			if(i<=id)
		  {
			$(cat+i).src = '/images/icon/star.gif';
		  	//$('rt_reset').style.display = '';
		  	new Effect.Appear('rt_reset');
			}
		  else
				$(cat+i).src = '/images/icon/star2.gif';

		}
		$('rating_comment').innerHTML = '';
	}
}

function update_rating_cb(val)
{
	var param = val.split(':');
  var cat = param[0];
  var rating = param[1];

  if(rating == -1)
  {
  	rt_picture = 0;
    toggle_rating('picture',0,false)
  	rt_sound = 0;
    toggle_rating('sound',0,false)
  	rt_package = 0;
    toggle_rating('package',0,false)

	 	new Effect.Fade('updating');
		new Effect.Fade('rt_reset');

    $('rating_comment').innerHTML = 'Cleared!';
    setTimeout("$('rating_comment').innerHTML = ''", 750);
  }
  else
  {
    eval('rt_'+cat+'='+rating);
    toggle_rating(cat,0,false);
  
  	$('rt_'+cat+'_updating').style.display = 'none';
  	$('rt_'+cat+'_updated').style.display = '';

    $('rating_comment').innerHTML = 'Saved!';
    new Effect.Appear('rating_comment');
    
    //setTimeout("$('rt_"+cat+"_updated').style.display = 'none'", 750);
    setTimeout("Effect.Fade('rt_"+cat+"_updated',{duration:1.0})", 750);
    setTimeout("$('rating_comment').innerHTML = ''", 750);
    //setTimeout("$('rt_reset').style.display = ''", 750);
    new Effect.Appear('rt_reset');
  }
}

function update_rating(cat,rating,id)
{
	if(rating == -1)
	{
		$('updating').style.display = '';
		sajax_update_rating(cat,rating,id,update_rating_cb);
	}
	else
  {
  	current = eval('rt_'+cat);
    if(current != rating)
	  {
	    $('rt_'+cat+'_updating').style.display = '';
	    $('rating_comment').innerHTML = 'Saving ...';
	    sajax_update_rating(cat,rating,id,update_rating_cb);
  	}
  }
}

function display_url()
{
  Element.hide('url_off');
  new Effect.Appear('url_on', {duration: 0.5, queue: 'end'});
}

function hide_url()
{
  Element.hide('url_on');
  new Effect.Appear('url_off', {duration: 0.5, queue: 'end'});
}

function toggle_bids(status)
{
	if(status=='')
		//$('bids').style.display = 'none';
		new Effect.Fade('bids');
	else
		//$('bids').style.display = '';
		new Effect.Appear('bids');
}

function moviegoods_cover_cb(val)
{
	Element.hide('moviegoods_cover');
	Element.hide('moviegoods_loading');
	if(val!='')
	{
		$('moviegoods_cover').innerHTML = val;
		new Effect.Appear('moviegoods_cover', {duration: 2.0});
	}
}

function moviegoods_cover(id)
{
	sajax_moviegoods_cover(id,moviegoods_cover_cb);
}

function intrada_cover_cb(val)
{
	Element.hide('intrada_cover');
	Element.hide('intrada_loading');
	if(val!='')
	{
		$('intrada_cover').innerHTML = val;
		new Effect.Appear('intrada_cover', {duration: 2.0});
	}
}

function intrada_cover(id)
{
	sajax_intrada_cover(id,intrada_cover_cb);
}
