var img_w=440;
var p=0-img_w;
$(document).ready(function() {
for (var i = 1; i <= $("#img_group_count").val(); i++){
  $("#act_img_"+i).val(0);
  $('#isbtn_back_'+i).hide();
  //alert();
  if (img_titles[i-1][0] == '' && img_auths[i-1][0] != '' ){
    $('#img_slide_desc_'+i).html('&#169; ' + img_auths[i-1][0]);
  }else if (img_titles[i-1][0] != '' && img_auths[i-1][0] != '' ){
    $('#img_slide_desc_'+i).html('&#169; ' + img_auths[i-1][0]+': '+ img_titles[i-1][0]);
  }else{
    $('#img_slide_desc_'+i).html('');
  }
}
})
function islide(direction,img_count,id){
  
  //var position = $("#container").position();

  var act_img = $("#act_img_"+id).val();
  if (direction == 'forward' && act_img < img_count-1){
    //$("#container").css('left',position.left - 320 + 'px');
    //$("#container").animate({left:position.left - 320 + 'px'},{ queue:true, duration:1500 } );
    var position = (p*act_img) - img_w;

    $("#container"+id).animate({left:position + 'px'},{ queue:true, duration:1500 } );
    act_img++;
  }
  if (direction == 'back' && act_img>0){
    //$("#container").css('left',position.left + 320 + 'px');
    //$("#container").animate({left:position.left + 320 + 'px'},1500);
    var position = (p*act_img) + img_w;

    $("#container"+id).animate({left:position + 'px'},{ queue:true, duration:1500 } );
    act_img--;
  }

  if (img_titles[id-1][act_img] == '' && img_auths[id-1][act_img] != '' ){
    $('#img_slide_desc_'+id).html('&#169; ' + img_auths[id-1][act_img]);
  }else if (img_titles[id-1][act_img] != '' && img_auths[id-1][act_img] != '' ){
    $('#img_slide_desc_'+id).html('&#169; ' + img_auths[id-1][act_img]+': '+ img_titles[id-1][act_img]);
  }else{
    $('#img_slide_desc_'+id).html('');
  }
  if (act_img == 0){
    $('#isbtn_back_'+id).hide();
  }else{
    $('#isbtn_back_'+id).show();
  }

  if (act_img == img_count - 1){
    $('#isbtn_forward_'+id).hide();
  }else{
    $('#isbtn_forward_'+id).show();
  }
  $("#act_img_"+id).val(act_img);
}

function toggle_text(){
  if($('#slide_txt').is(':hidden')){
    $('#slide_txt').slideDown('fast');
    $('#toggle_lnk').css('background','url(/' + path_to_theme + '/images/txt_up.png) center left no-repeat');
  }else{
    $('#slide_txt').slideUp('fast');
    $('#toggle_lnk').css('background','url(/' + path_to_theme + '/images/txt_down.png) center left no-repeat');
  } 
}

function toggle_text2(p){
  if($('#slide_txt'+p).is(':hidden')){
    $('#slide_txt'+p).slideDown('fast');
    $('#toggle_lnk'+p).css('background','url(/' + path_to_theme + '/images/txt_up.png) center left no-repeat');
  }else{
    $('#slide_txt'+p).slideUp('fast');
    $('#toggle_lnk'+p).css('background','url(/' + path_to_theme + '/images/txt_down.png) center left no-repeat');
  } 
}

function openwin(name,w,h){
  var win = (window.open('',name,'toolbar=0,location=0,directories=0,status=0,menubar=0,scrollbars=0,resizable=1,width='+w+',height='+h));

    if (win.outerWidth){
      win.moveTo((screen.width-win.outerWidth)/2,(screen.height-win.outerHeight)/2);
    }else{
      win.moveTo((screen.width-win.document.body.clientWidth)/2,(screen.height-win.document.body.clientHeight)/2);
    }
}

function move_div(id,left,top){
  top = top - $("#"+id).height() -20;
  //$("#"+id).css({left: left, top: top});
  $("#"+id).css({top: top});
}

function show_div(id){
  for (var i = 0; i < 3; i++){
    if ( i != id ){
      $("#latest-btn"+i).attr('src','/' + path_to_theme + '/images/hot_off.png');
    }else{
      $("#latest-btn"+i).attr('src','/' + path_to_theme + '/images/hot_on.png');    
    }
    $("#latest_images" + i).hide();
  }
  $("#latest_images" + id).show();
}
