/* Copyright (c) 2007 Onlyweb Studio | http://www.onlyweb.ru/ */
/*


From Russia with love!

Author: Nikola Safin (unlimit@bk.ru)

*/


function get_File(path)
{
  jQuery.get('/form.php',{
        down: path
      }, function(text) {
         $("#Form").html(text);
  });

  //alert("fkthn");
}

var newClass = function() {
	return function() {

		return this.init.apply(this, arguments);
	}
}

// листалка фоток на главной ======== >>>
var ChangeLider = newClass();
ChangeLider.prototype = {
  init: function() {
    var t = this;
    t.people = $('div.People');
    t.text = $('div.Right_body');
    t.imeout_id = window.setInterval(function() { t.changePerson() }, 7000)
  },

  changePerson: function() {
    var t = this;

    curPict = t.people.find("div").not(".BlockNone");

    id = curPict.attr("id").substring(6) * 1;

    t.text.find("#text_"+(id)).hide();
    t.text.find("#text_"+(id)).toggleClass("BlockNone");

    curPict.hide();
    curPict.toggleClass("BlockNone");

    if(id == t.people.find("div").size()-1)
     id = -1;

    t.people.find("#photo_"+(id+1)).fadeIn(500);
    t.text.find("#text_"+(id+1)).fadeIn(500);

    //t.people.find("#photo_"+(id+1)).css("display","block");
    //t.text.find("#text_"+(id+1)).css("display","block");

    //t.text.find("#text_"+(id+1)).toggleClass("BlockNone");
    t.people.find("#photo_"+(id+1)).toggleClass("BlockNone");
    //console.log(id);
  }
}
// <<================== листалка фоток на главной


// JavaScript Для матрицы проектов ===================>>>
var Smena = newClass();
Smena.prototype = {

  init: function() {
	 var t = this;

     t.img = false;
     t.block = false;

	$(".BlockTd img").mouseover(function() {
    	//$(this).parents("table").find(".BlockTd").removeClass("SelectBT");
    	//$(".BlockTdAbs").removeClass("DisplayBlock");
        //$(".BlockTdAbs").fadeIn(200);
    	//$(this).parents(".BlockTd").addClass("SelectBT");
        t.img = true;
        //t.block = true;
        $("div.BlockTdAbs").fadeOut(0);
    	$(this).parents("div.BlockTd").find("div.BlockTdAbs").fadeIn(300);//.addClass("DisplayBlock");
		$(".BlockTd").removeClass("BlockTdPos");
		$(this).parents(".BlockTd").addClass("BlockTdPos");
    });


    // подсветка таблички
	$(".BlockTd").mouseover(function() {
    	var className = $(this).parents("td").attr("class");
    	$(this).parents("table").find("."+className).addClass("SelectBTI");
    	$(this).parents("table").find("th."+className+" img").addClass("SelImgBTI");
        $(this).parents("tr:first").addClass("SelTrProject");
/*    	$(this).parents("table").find("tfoot td."+className+" a").addClass("SelImgBTI");*/
    });
	


	$(".BlockTd").mouseout(function() {
    	$("table td, table th").removeClass("SelectBTI");
        $("table tr").removeClass("SelTrProject");
    });


    $(".BlockTdAbs").mouseover(function() {
       //t.img = true;
       t.block = true;
    });

    // при уходе мыши с блоков и картинки
    $(".BlockTdAbs").mouseout(function() {
	   t.block = false;
       setTimeout(function(){ t.hideTabs(); },500);
    });

    $(".BlockTd img").mouseout(function() {
	   t.img = false;
       setTimeout(function(){ t.hideTabs(); },500);

    });


 },

 hideTabs: function()
 {
   var t = this;
   if((t.img != true) && (t.block != true))
   {
     setTimeout(function(){ $(".BlockTdAbs").fadeOut(200); },100);
   }
 }
};

// <<<========================== JavaScript Для матрицы проектов

// JavaScript Для прокрутки логотипов на главной странице сайта ===================>>>
var logoList = newClass();
logoList.prototype = {
  init: function() {
	 var t = this;

     t.ElementGL = $("div.ElementGL");
     t.GaleryList = $("div.GaleryList");
     t.ContGalery = $("div.ContGalery");
     t.dellayTime = 0;
     t.flag = false;

     $('.linkLogo').mouseover(function(){
       $(this).find("img.Grey").addClass("DisplayNone");
       $(this).find("img.Colour").removeClass("DisplayNone");
     });

     $('.linkLogo').mouseout(function(){
       $(this).find("img.Grey").removeClass("DisplayNone");
       $(this).find("img.Colour").addClass("DisplayNone");
     });

     t.documentWidth = document.documentElement.clientWidth || document.body.clientWidth;


     $('document').ready(function(){
        //setInterval(function(){ t.move() }, 500);
        t.changeSpeed();
        t.createInterval();

        t.ContGalery.mousemove(function(e){
          var pageCoords = e.pageX;
          var clientCoords = e.clientX;
          //document.documentElement.clientWidth || document.body.clientWidth


          percentSpeed = (100 * (e.pageX - t.documentWidth/2)) / (t.ContGalery.width() / 2);
          percentSpeedNormal = 100 - Math.abs(percentSpeed);

          t.motionTime = Math.ceil(percentSpeedNormal * 100 / 100) ;

          //t.Offset =  Math.ceil((100 - percentSpeedNormal)/50);

          //console.log(t.motionTime);

          //t.restartInterval();

          if(percentSpeed < 0)
            t.direction = -1;
          else
            t.direction = 1;
        });

        t.ContGalery.mouseout(function(){
          //t.motionTime = 10;
          //t.Offset = 1;
          //t.restartInterval();
        });
     });

  },

  changeSpeed: function()
  {
    var t = this;

    t.direction = 1;
    t.widthDiv = 128;
    t.Offset = 1;
    t.motionTime = 10;

    t.replaceTime = t.motionTime * t.widthDiv / t.Offset;

    t.countOffset = null;
  },

  createInterval: function()
  {
    var t = this;

    leftPosition = t.GaleryList.css("left").replace('px', '') * 1 - ((t.Offset) * t.direction);
    t.GaleryList.css("left", leftPosition);

    //console.log(t.countOffset)
    if((Math.abs(t.countOffset) >= t.widthDiv - 1) || t.countOffset == 0) {
      t.replace();
      t.countOffset = null;
    } else {
      t.countOffset = t.countOffset + ((t.Offset ) * t.direction );
    }



    t.inter = setTimeout(function(){ t.createInterval(); }, t.motionTime);

  },

  replace: function()
  {
    //var start = new Date();

    var t = this;

    n = t.GaleryList.css("left").replace('px', '') * 1 + t.widthDiv * t.direction;
    t.GaleryList.css("left", n);

      if(t.direction > 0) {
        k = $("div.ElementGL:last").attr('id');
        $("div.ElementGL:first").insertAfter("#" + k);
      } else {
        k = $("div.ElementGL:first").attr('id');
        $("div.ElementGL:last").insertBefore("#" + k);
      }
    //var now = new Date();
    //if(t.motionTime != 0)
    //t.dellayTime = (now - start) * t.Offset / t.motionTime;

    //console.log("Время выполнния функции: " + (now - start));
    //console.log("Время интервала: " + t.motionTime);

  }
};
// <<<=================== JavaScript Для прокрутки логотипов на главной странице сайта

var Response = newClass();
Response.prototype = {
  init: function() {
    var t = this;
    t.flag = false;
    t.OtzivBlock = $("div.OtzivBlock");

    //$("body").click(function(){
     //console.log($(".ImgCont"));

    //  if($(".ImgCont").length > 0)
    //    t.imgHide();
    //});
  },

  imgShow: function(obj, width, height) {
    var t = this;
    t.flag = true;
    var urlImg = $(obj).attr("name");
    var block = '<div class="ImgCont"><img onclick="response.imgHide();" src="'+urlImg+'"/></div>';
    var com = $(obj).parent("div");
    $(block).prependTo(com);
    return false;
  },

  imgHide: function() {
    var t = this;
    t.flag = false;
    $("div.ImgCont").remove();
  }
};

var getScrollTop = function() {
	y = (window.scrollY) ? window.scrollY : document.documentElement.scrollTop ? document.documentElement.scrollTop : document.body.scrollTop;
	return y;
}

var ProgrammPanel = newClass();
ProgrammPanel.prototype = {

	init: function() {
		var t = this;

		t.portfolioPanel = $('#menu_scroll');

		t.top = 200;

		//
		// We have already done work for IE6 in main_ie_6.css
		// top: expression(
		//   eval('document.documentElement.scrollTop') <= 215 ? '215px' : (eval('document.documentElement.scrollTop') + 'px')
		// );
		//
		if (!($.browser.msie && $.browser.version == 6)) {
			$(window).scroll(function(){
				t.windowScroll();
			});
		}

        t.li = t.portfolioPanel.find("li")
         t.li.click(function(){
          t.li.removeClass("ChangePM");
         $(this).addClass("ChangePM");
        });


	},

	windowScroll: function() {
		var t = this;
		if (getScrollTop() > t.top) {
			t.portfolioPanel.addClass('FixedMenu');
			t.portfolioPanel.removeClass('NormalMenu');
		} else {
			t.portfolioPanel.removeClass('FixedMenu');
			t.portfolioPanel.addClass('NormalMenu');
		}
	}

};

var ReportPanel = newClass();
ReportPanel.prototype = {

	init: function() {
		var t = this;

		t.portfolioPanel = $('#report_scroll');
        t.panelHeight = t.portfolioPanel.height();
        t.contentHeight = $("#other_page").height();
        t.documentHeight = document.documentElement.clientHeight || document.body.clientHeight;
		t.top = 200;

		//
		// We have already done work for IE6 in main_ie_6.css
		// top: expression(
		//   eval('document.documentElement.scrollTop') <= 215 ? '215px' : (eval('document.documentElement.scrollTop') + 'px')
		// );
		//
		if (!($.browser.msie && $.browser.version == 6)) {
			$(window).scroll(function(){
				t.windowScroll();
			});
		}

        t.li = t.portfolioPanel.find("li")
         t.li.click(function(){
          t.li.removeClass("ChangePM");
         $(this).addClass("ChangePM");
        });


	},

	windowScroll: function() {
		var t = this;
        //console.log("Позиция блока: " + getScrollTop() + " Высота контента" + t.contentHeight);
		if (getScrollTop() > t.top)   {
            if((getScrollTop() + t.documentHeight + 85) < t.contentHeight) {
                t.portfolioPanel.addClass('FixedMenu');
			    t.portfolioPanel.removeClass('NormalMenu');
                t.portfolioPanel.removeClass('FixedMenuBottom');
            } else {
                t.portfolioPanel.addClass('FixedMenuBottom');
			    t.portfolioPanel.removeClass('FixedMenu');
            }
		} else {
			t.portfolioPanel.removeClass('FixedMenu');
            t.portfolioPanel.removeClass('FixedMenuBottom');
			t.portfolioPanel.addClass('NormalMenu');
		}
	}

}

