var pop_view_current = 0; //for image
var pop_view_path = '../';
var pop_view_path_to_images = "/dialog/images/";
var pop_view_width="500";
var pop_view_height="";
var pop_view_top=125;
// global variable "pop_view_path_to_images" should be set in phpt file, like this:
// print_js_inline('var pop_view_path_to_images="'.escape_js_quotes(get_static_file_path()).'images/marketplace/";');

function classifieds_pop_view(pop_path,pop_width,pop_height,pop_top) {
	if(pop_width&&pop_width!=""){
	pop_view_width=pop_width ; }
	if(pop_height&&pop_height!=""){
	pop_view_height=pop_height ;}
		if(pop_top&&pop_top!=""){
	pop_view_top=pop_top ;}
  popup = new pop_dialog('classifieds_pop_view_dialog share_pop_dialog');
  popup.show_ajax_dialog_custom_loader(
          '&#36733;&#20837;&#20013;...',pop_path);
}

function prev_image() {
    if (pop_view_current > 0) {
        hide('c_image_'+pop_view_current); 
        pop_view_current -=1;
        show('c_image_'+pop_view_current);
        ge('current_image').innerHTML = pop_view_current+1;
    } 
    show_correct_buttons();
    return false;
}

function next_image() {
  hide('c_image_' + pop_view_current);
  pop_view_current += 1;
  if (!ge('c_image_'+pop_view_current)) {
    pop_view_current -= 1; // reset to spot before end
  }
  show('c_image_'+pop_view_current);
  ge('current_image').innerHTML = pop_view_current+1;
  show_correct_buttons();
  return false;
}

function show_correct_buttons() {
    if (pop_view_current > 0) {
        ge('prev_image_button').src=pop_view_path_to_images+'leftPicCan.gif';
    } else {
        ge('prev_image_button').src=pop_view_path_to_images+'leftPic.gif';
    }
    if (!ge('c_image_'+(pop_view_current+1))) {
        ge('next_image_button').src=pop_view_path_to_images+'rightPicCant.gif';
    } else {
        ge('next_image_button').src=pop_view_path_to_images + 'rightPic.gif';
    }
}

function close_dialog(dialog_to_close) {
  pop_view_current = 0; // reset current
  generic_dialog.get_dialog(dialog_to_close).fade_out(100);
}

function pop_view_resize_image(img) {
    var width = 300;
    var height = 225;
    
    show(img); //need this to get acces to these attributes
    if (img.width > width) {
        img.height = (width*img.height)/img.width;
        img.width = width;
        pop_view_resize_image(img);
    } else {
        if (img.height > height) {
        img.width = (height*img.width)/img.height;
        img.height = height;
        pop_view_resize_image(img);
        }
    }
    hide(img); //hide it
}
