//görsel boyutlandırıcısı
var originalImageHeight,
    originalImageWidth,
    initialScreenHeight,
    initialScreenWidth,
    ratio,
    queryString = function() {
      var qs = location.search.substring(1, location.search.length).replace(/(%20|\+)/g, " ");
      if (arguments.length == 0 || qs == "") return qs; else qs = "&" + qs + "&";
      if (qs.indexOf(arguments[0]) == -1) return null;
      return qs.substring(qs.indexOf("=", qs.indexOf("&" + arguments[0] + "=") + 1) + 1, qs.indexOf("&", qs.indexOf("&" + arguments[0] + "=") + 1));
    },
    goToURL = function(direction) {
      var galleryId = queryString('galleryId');
      var position = queryString('position') == null || queryString('position') == '' ? 0 : parseInt(queryString('position'));
      switch (direction) {
          case 'p':
              position--;
              break;
          case 'n':
              position++;
              break;
          default:
              position;
              break;
      }
      var lastPosition = parseInt($('#Slide-Numbers li:last').text()) - 1;
      var baseUrl = window.location.pathname.substring(0, 12).toLowerCase() == '/galeri.aspx' ? '/galeri.aspx?galleryId=' + galleryId + '&position=' + position : window.location.pathname + '?position=' + position;
      var url = position > lastPosition ? ('/istasyon.aspx?gallery' + (queryString('galleryId') == null || queryString('galleryId') == '' ? 'Name=' + window.location.pathname.replace('/', '').replace('.html', '') : 'Id=' + galleryId)) : baseUrl;
      window.location = url;
    },
    setBounds = function() {
      initialScreenHeight = $(window).height();
      initialScreenWidth = $(window).width();

      ratio = originalImageHeight / originalImageWidth;
      var maximumImageHeight = initialScreenHeight - 90 - 110;
      var maximumImageWidth = initialScreenWidth - 260 - 200;
      initialImageHeight = originalImageHeight;
      initialImageWidth = originalImageWidth;


      if (originalImageHeight > originalImageWidth) {
          initialImageHeight = originalImageHeight > maximumImageHeight ? maximumImageHeight : originalImageHeight;

          if (initialImageHeight / ratio > maximumImageWidth) {
              initialImageWidth = maximumImageWidth;
              initialImageHeight = initialImageWidth * ratio;
          }
          else {
              initialImageWidth = initialImageHeight / ratio;
          }
      }
      else {
          initialImageWidth = originalImageWidth > maximumImageWidth ? maximumImageWidth : originalImageWidth;
          if (initialImageWidth * ratio > maximumImageHeight) {
              initialImageHeight = maximumImageHeight;
              initialImageWidth = initialImageHeight / ratio;
          }
          else {
              initialImageHeight = initialImageWidth * ratio;
          }
      }
      var initialContainerWidth = initialImageWidth + 330;

      $('#hylPicture img, #Photo').height(initialImageHeight);
      $('#hylPicture img, #Photo').width(initialImageWidth - 6);
      $('#PhotoWrapper').width(initialContainerWidth + 2);

      var paddingBottomValue = $('#Footer').height();
      $('#Slide').css('padding-bottom', paddingBottomValue);
      $('#Footer').css('margin-top', '-170px');

      $('.BlankPixel img').attr('width', initialImageWidth - 6).attr('height', initialImageHeight);
    };
$(function() {
  setBounds();
  $(window).resize(setBounds);
  $(document)
    .bind('keydown', 'left', function() { goToURL('p') })
    .bind('keydown', 'right', function() { goToURL('n') })
    .bind('keydown', 'up', function() { goToURL('r') });
});

//video galeri açıcı
//function openGameWindow(url) { window.open(url, 'videoWindow', 'status=1,width=994,height=710,resizable=no,menubar=no,location=no,toolbar=no,scrollbars=1'); }
//tarayıcı seçicisi
/*function css_browser_selector(u) { var ua = u.toLowerCase(), is = function(t) { return ua.indexOf(t) > -1; }, g = 'gecko', w = 'webkit', s = 'safari', h = document.getElementsByTagName('html')[0], b = [(!(/opera|webtv/i.test(ua)) && /msie\s(\d)/.test(ua)) ? ('ie ie' + RegExp.$1) : is('firefox/2') ? g + ' ff2' : is('firefox/3') ? g + ' ff3' : is('gecko/') ? g : /opera(\s|\/)(\d+)/.test(ua) ? 'opera opera' + RegExp.$2 : is('konqueror') ? 'konqueror' : is('chrome') ? w + ' ' + s + ' chrome' : is('applewebkit/') ? w + ' ' + s + (/version\/(\d+)/.test(ua) ? ' ' + s + RegExp.$1 : '') : is('mozilla/') ? g : '', is('j2me') ? 'mobile' : is('iphone') ? 'iphone' : is('ipod') ? 'ipod' : is('mac') ? 'mac' : is('darwin') ? 'mac' : is('webtv') ? 'webtv' : is('win') ? 'win' : is('freebsd') ? 'freebsd' : (is('x11') || is('linux')) ? 'linux' : '', 'js']; c = b.join(' '); h.className += ' ' + c; return c; }; css_browser_selector(navigator.userAgent);*/
