﻿var itsIE7 = false;

if (navigator.userAgent.indexOf('MSIE 7.0') != -1) {
  itsIE7 = true;
  //$("div#toppanel").hide();
}

function PrintEMail()
{
  document.write('info');
  document.write('@');
  document.write('july.');
  document.write('com.ua');
}//PrintEMail


function PrintEMailAsLink()
{
  document.write('<a href="mailto:');
  PrintEMail();
  document.write('">');
  PrintEMail();
  document.write('</a>');
}//PrintEMailAsLink


function currentYPosition() {
  // Firefox, Chrome, Opera, Safari
  if (self.pageYOffset) return self.pageYOffset;
  // Internet Explorer 6 - standards mode
  if (document.documentElement && document.documentElement.scrollTop)
      return document.documentElement.scrollTop;
  // Internet Explorer 6, 7 and 8
  if (document.body.scrollTop) return document.body.scrollTop;
  return 0;
}


function elmYPosition(eID) {
  var elm = document.getElementById(eID);
  var y = elm.offsetTop;
  var node = elm;
  while (node.offsetParent && node.offsetParent != document.body) {
      node = node.offsetParent;
      y += node.offsetTop;
  } return y;
}


function smoothScroll(eID, offs) {
  if (!offs) offs = 0;
  var startY = currentYPosition();
  var stopY = elmYPosition(eID) + offs;
  var distance = stopY > startY ? stopY - startY : startY - stopY;
  if (distance < 100) {
      scrollTo(0, stopY); return;
  }
  var speed = Math.round(distance / 100);
  if (speed >= 20) speed = 20;
  var step = Math.round(distance / 25);
  var leapY = stopY > startY ? startY + step : startY - step;
  var timer = 0;
  if (stopY > startY) {
      for ( var i=startY; i<stopY; i+=step ) {
          setTimeout("window.scrollTo(0, "+leapY+")", timer * speed);
          leapY += step; if (leapY > stopY) leapY = stopY; timer++;
      } return;
  }
  for ( var i=startY; i>stopY; i-=step ) {
      setTimeout("window.scrollTo(0, "+leapY+")", timer * speed);
      leapY -= step; if (leapY < stopY) leapY = stopY; timer++;
  }
}


function UpdateTopPanelVisibility()
{
  if (itsIE7) {
    $('#toppanel').hide();
    return;
  }
  if ((!itsIE7) && (document.documentElement.clientWidth > 1155) && ($('#toppanel').is(':hidden'))) {
    $('#toppanel').show();
    return;
  }
  if ((document.documentElement.clientWidth <= 1155) && ($('#toppanel').is(':visible'))) {
    $('#toppanel').hide();
    return;
  }
}//UpdateTopPanelVisibility

$(window).resize(UpdateTopPanelVisibility);

$(document).ready(function() {

  UpdateTopPanelVisibility();

  $("div.panel_button").click(function(){
    $("div#panel").animate({
      width: "280px"
    })
    .animate({
      width: "240px"
    }, "fast");
    $("div.panel_button").toggle();
  });

  $("div#hide_button").click(function(){
    $("div#panel").animate({
      width: "0px"
    }, "fast");
  });

  MyCar = document.getElementById('mycarousel');
  if (MyCar) MyCar.style.width = '4332px';//calculated width + 1px per item for IE  (228 pixels per carousel item)  2288  3648 4104 4332

  //Fix problem in IE6 where menu was incorrectly displayed when a page is loaded.
  document.getElementById('nav').style.display = 'block';

  jQuery('#mycarousel').jcarousel({
    scroll: 1
  });

});
