var subpage = window.location.href;
var suburltemp = subpage;
var iminus = 2;//6
var imgwidth = 320;
var imgheight = 240;
var tmpwidth = 320;
var tmpheight = 240;
var izoomorigin = 0;
var vheight = 85;
function setsubheight() {
  var fram = document.getElementById('subframe');
  if ($(fram).css('display') == 'block') {
    var vtitle = document.getElementById('mytitle');
    $(fram).height($(window).height() - $(vtitle).height() - iminus);
  //$(fram).width($(window).width() -10);
  }
}
function setimgheight() {
  var fram = document.getElementById('subframe');
  if ($(fram).css('display') == 'block') {
    var vtitle = document.getElementById('mytitle');
    var vcontent = document.getElementById('mycontent');
    $(fram).height($(window).height() - $(vtitle).height() - $(vcontent).height() - iminus);
  }
}
function setsubframeheight() {
  var fram = document.getElementById('subframe');
  if ($(fram).css('display') == 'block') {
    setsubheight();
    $(window).resize( setsubheight );
    fram.src = suburltemp;
  }
}
function setimgframeheight() {
  var fram = document.getElementById('subframe');
    setimgheight();
    $(window).resize( setimgheight );
    fram.src = suburltemp;
}
function setdivheight() {
  var vdiv = document.getElementById('subdiv');
  if ($(vdiv).css('display') == 'block') {
    var vtitle = document.getElementById('mytitle');
    var vcontent = document.getElementById('mycontent');
    $(vdiv).height($(window).height() - $(vtitle).height() - $(vcontent).height() - iminus);
  }
  if (izoomorigin == 0) {
    var vimg = document.getElementById('subimg');
    tmpwidth = $(vdiv).width()-5;
    tmpheight = $(vdiv).height()-5;
    if ((imgwidth/imgheight) > (tmpwidth/tmpheight)) {
      $(vimg).width(tmpwidth);
    } else {
      $(vimg).height(tmpheight);
    }
  }
}
function setimgdivheight() {
    setdivheight();
    $(window).resize( setdivheight );
}
function setvidsize() {
  var fram = document.getElementById('subframe');
  if ($(fram).css('display') == 'block') {
    setsubheight();
    $(window).resize( setsubheight );
    fram.src = suburltemp;
  }
}
function setmysub(e) {
  var vmysub = document.getElementById('mysub');
  $(vmysub).text($(e).text());
}
function setsubframe(sturl, stthis) {
  var vtitle = document.getElementById('mytitle');
  vtitle.style.display = 'block';
  setmysub(stthis);
  var vcontent = document.getElementById('mycontent');
  vcontent.style.display = 'none';
  var fram = document.getElementById('subframe');
  fram.style.display = 'block';
  $(fram).height($(window).height() - $(vtitle).height() - iminus);
  fram.src = sturl;
  suburltemp = sturl;
}
function setimgframe(stthis) {
  var vtitle = document.getElementById('mytitle');
  var vcontent = document.getElementById('mycontent');
  var fram = document.getElementById('subframe');
  var vmysub = document.getElementById('mysub');
  vcontent.style.height = '100px';
  vtitle.style.display = 'block';
  if (fram.style.display != 'block') {
    fram.style.display = 'block';
    $(vcontent).scrollTop($(stthis).parent().offset().top - $(vtitle).height());
  }
  $(fram).height($(window).height() - $(vtitle).height() - $(vcontent).height() - iminus);
  $(vmysub).text($(stthis).children('.imgpreview').attr('title'));
  var stimgurl = $(stthis).children('.imgpreview').attr('src');
  fram.src = stimgurl;
  suburltemp = stimgurl;
}
function imgzoomin() {
  var vimg = document.getElementById('subimg');
  vimg.style.width = 'auto';
  vimg.style.height = 'auto';
  izoomorigin = 1;
}
function imgzoomout() {
  var vdiv = document.getElementById('subdiv');
  var vimg = document.getElementById('subimg');
  tmpwidth = $(vdiv).width()-5;
  tmpheight = $(vdiv).height()-5;
  if ((imgwidth/imgheight) > (tmpwidth/tmpheight)) {
    $(vimg).width(tmpwidth);
  } else {
    $(vimg).height(tmpheight);
  }
  izoomorigin = 0;
}
function imgzoom() {
  var vimg = document.getElementById('subimg');
  var vzoom = document.getElementById('bzoom');
  var izoom = document.getElementById('izoom');
  if (izoomorigin != 0) {
    var vdiv = document.getElementById('subdiv');
    tmpwidth = $(vdiv).width()-5;
    tmpheight = $(vdiv).height()-5;
    if ((imgwidth/imgheight) > (tmpwidth/tmpheight)) {
      $(vimg).width(tmpwidth);
    } else {
      $(vimg).height(tmpheight);
    }
    vimg.style.cursor='url("../images/Zoomin.cur"), auto';
    vimg.style.cursor='-webkit-zoom-in';
    vimg.style.cursor='-moz-zoom-in';
    vimg.style.cursor='zoom-in';
    izoomorigin = 0;
    vzoom.title = 'Оригинальный размер картинки';
    izoom.src = '../images/bzoomin.png';
  } else {
    vimg.style.width = 'auto';
    vimg.style.height = 'auto';
    vimg.style.cursor='url("../images/Zoomout.cur"), auto';
    vimg.style.cursor='-webkit-zoom-out';
    vimg.style.cursor='-moz-zoom-out';
    vimg.style.cursor='zoom-out';
    izoomorigin = 1;
    vzoom.title = 'Картинка по размеру окна';
    izoom.src = '../images/bzoomout.png';
  }
}
function setdivimgframe(stthis) {
  var vtitle = document.getElementById('mytitle');
  var vcontent = document.getElementById('mycontent');
  var vdiv = document.getElementById('subdiv');
  var vmysub = document.getElementById('mysub');
  var vimg = document.getElementById('subimg');
  vcontent.style.height = vheight + 'px';
  vtitle.style.display = 'block';
  if (vdiv.style.display != 'block') {
    vdiv.style.display = 'block';
    $(vcontent).scrollTop($(stthis).parent().offset().top - $(vtitle).height());
  }
  $(vdiv).height($(window).height() - $(vtitle).height() - $(vcontent).height() - iminus);
  $(vmysub).text($(stthis).children('.imgpreview').attr('title'));
  var stimgurl = $(stthis).children('.imgpreview').attr('src');
  imgwidth = $(stthis).children('.imgpreview').width();
  imgheight = $(stthis).children('.imgpreview').height();
  izoomorigin = 1;
  imgzoom()
  vimg.src = stimgurl;
  suburltemp = stimgurl;
}
function playvid(sturl, stthis) {
  var iwidth = 480;
  var iheight = 360;
  var vtitle = document.getElementById('mytitle');
  vtitle.style.display = 'block';
  setmysub(stthis);
  var vcontent = document.getElementById('mycontent');
  iwidth = $(window).width();
  iheight = $(window).height() - $(vtitle).height() - iminus;
  vcontent.style.display = 'none';
  var myrgroup=document.getElementById('myradiogroup');
  myrgroup.style.display = 'none';
  var rbcheck=document.getElementsByName('rgplayer');
  if (rbcheck[0].checked) {
    var vid1 = document.getElementById('player1');
    vid1.style.display = 'block';
    jwplayer('player1').setup({ 
      autostart: true,
      file: sturl, 
      width: iwidth,
      height: iheight,
      modes: [ 
        { type: "html5" }, 
        { type: "flash", src: "../js/player.swf" }, 
        { type: "download" } 
      ]  
    }); 
  } else if (rbcheck[1].checked) {
    var vid2 = document.getElementById('player2');
    vid2.style.display = 'block';
    vid2.style.width = iwidth+'px';
    vid2.style.height = iheight+'px';
    vid2.src = sturl;
  } else if (rbcheck[2].checked) {
    var fram = document.getElementById('subframe');
    fram.style.display = 'block';
    setmysub(stthis);
    $(fram).height(iheight);
    fram.src = sturl;
  }     
  suburltemp = sturl;
}
function checkrbplay() {
  var rbcheck=document.getElementsByName('rgplayer');
  var lab1 = document.getElementById('lab1');
  var lab2 = document.getElementById('lab2');
  var lab3 = document.getElementById('lab3');
  if (rbcheck[0].checked) {
    $(lab1).addClass('bcheck');
    $(lab2).removeClass('bcheck');
    $(lab3).removeClass('bcheck');
  } else if (rbcheck[1].checked) {
    $(lab1).removeClass('bcheck');
    $(lab2).addClass('bcheck');
    $(lab3).removeClass('bcheck');
  } else if (rbcheck[2].checked) {
    $(lab1).removeClass('bcheck');
    $(lab2).removeClass('bcheck');
    $(lab3).addClass('bcheck');
  }     
}
function gosubvidurl() {
  window.location.href = subpage;
  setmysub('');
  var vtitle = document.getElementById('mytitle');
  vtitle.style.display = 'none';
  var vid1 = document.getElementById('player1');
  vid1.style.display = 'none';
  jwplayer('player1').remove();  
  var vid2 = document.getElementById('player2');
  vid2.style.display = 'none';
  vid2.src = '';
  var fram = document.getElementById('subframe');
  fram.style.display = 'none';
  fram.src = '';
  var myrgroup=document.getElementById('myradiogroup');
  myrgroup.style.display = 'block';
  var vcontent = document.getElementById('mycontent');
  vcontent.style.display = 'block';
  vcontent.style.height = '';
}
function gosuburl() {
  window.location.href = subpage;
  setmysub('');
  var vtitle = document.getElementById('mytitle');
  vtitle.style.display = 'none';
  var vcontent = document.getElementById('mycontent');
  vcontent.style.display = 'block';
  vcontent.style.height = '';
  var fram = document.getElementById('subframe');
  fram.style.display = 'none';
  fram.src = '';
}
function gosubimgurl() {
  window.location.href = subpage;
  setmysub('');
  var vtitle = document.getElementById('mytitle');
  vtitle.style.display = 'none';
  var vcontent = document.getElementById('mycontent');
  vcontent.style.display = 'block';
  vcontent.style.height = '';
  var fram = document.getElementById('subframe');
  fram.style.display = 'none';
  fram.src = '';
  var vdiv = document.getElementById('subdiv');
  vdiv.style.display = 'none';
  var vimg = document.getElementById('subimg');
  vimg.src = '';
}
function refreshsubframe() {
  var fram = document.getElementById('subframe');
  if ($(fram).css('display') == 'block') {
    setsubheight();
    fram.src = suburltemp;
  }
}
function refreshvid() {
  var iwidth = 480;
  var iheight = 360;
  var vtitle = document.getElementById('mytitle');
  iwidth = $(window).width();
  iheight = $(window).height() - $(vtitle).height() - iminus;
  var rbcheck=document.getElementsByName('rgplayer');
  if (rbcheck[0].checked) {
   jwplayer('player1').remove();  
   jwplayer('player1').setup({ 
      autostart: true,
      file: suburltemp, 
      width: iwidth,
      height: iheight,
      modes: [ 
        { type: "html5" }, 
        { type: "flash", src: "../js/player.swf" }, 
        { type: "download" } 
      ]  
    }); 
  } else if (rbcheck[1].checked) {
    var vid2 = document.getElementById('player2');
    vid2.style.width = iwidth+'px';
    vid2.style.height = iheight+'px';
    vid2.src = suburltemp;
  } else if (rbcheck[2].checked) {
    var fram = document.getElementById('subframe');
    $(fram).height(iheight);
    fram.src = suburltemp;
  }     
}
