	var rot_state = 0; // состояние поворотак картинки

	function rot(pic,win){
	  if (rot_state == 0){
	    dot = document.getElementById("work_img"+win).style.width.substr(0,document.getElementById("work_img"+win).style.width.indexOf("px")) - 0;
	    dot1 = document.getElementById("work_img"+win).style.marginLeft.substr(0,document.getElementById("work_img"+win).style.marginLeft.indexOf("px")) - 0;
      document.getElementById("work_img"+win).style.width = (dot-10)+"px";
	    document.getElementById("work_img"+win).style.marginLeft = (dot1+5)+"px";
      if (document.getElementById("work_img"+win).style.width.substr(0,document.getElementById("work_img"+win).style.width.indexOf("px"))>0)
	      window.setTimeout("rot('"+pic+"','"+win+"')",10);
	    else{
	      rot_state = 1;
	      //$("#work_img").attr("src",'images/portfolio/'+pic);

       	 document.getElementById("work_img"+win).src='images/portfolio/'+pic;
         document.getElementById("work_a"+win).href='images/portfolio/big_'+pic.substr(0,pic.indexOf(".png"))+'.jpg';
		  fixPNG(document.getElementById("work_img"+win));
		  window.setTimeout("rot('"+pic+"','"+win+"')",10);
	    }
	  }
	  else{
	    dot = document.getElementById("work_img"+win).style.width.substr(0,document.getElementById("work_img"+win).style.width.indexOf("px")) - 0;
	    dot1 = document.getElementById("work_img"+win).style.marginLeft.substr(0,document.getElementById("work_img"+win).style.marginLeft.indexOf("px")) - 0;
	    document.getElementById("work_img"+win).style.width = (dot+10)+"px";
	    document.getElementById("work_img"+win).style.marginLeft = (dot1-5)+"px";
	    if (document.getElementById("work_img"+win).style.width.substr(0,document.getElementById("work_img"+win).style.width.indexOf("px"))<200)
	      window.setTimeout("rot('"+pic+"','"+win+"')",10);
	    else{
	      rot_state = 0;
	    }
	  }
	}

  function absolute_pos(obj){
  	offset = obj.offsetLeft;
    while (obj.offsetParent.tagName != 'BODY'){
    	obj = obj.offsetParent;
      offset += obj.offsetLeft;
    }
    return offset;
  }

  // реализация ниспадающего меню
  function show_menu(id, state, dop){
    if (state){
    	document.getElementById('menu_'+id).style.visibility='visible';
      if (dop != null){
		    document.getElementById('menu_'+id).style.left = absolute_pos(dop) - 5 +'px';
     isOpera = window.opera //Opera 5+
     if (document.all && document.all.item && !isOpera) //Microsoft Internet Explorer 4+
		 	{
			document.getElementById('menu_'+id).style.left = absolute_pos(dop) + 10 +'px';
			document.getElementById('menu_'+id).style.top = 142 +'px';
			}
      }
    }
    else
      document.getElementById('menu_'+id).style.visibility='hidden';
  }

  var x; // Зазмер клиентской области окна

  function mod_x(){
	  if (self.innerWidth) // all except Explorer
	    x = self.innerWidth;
	  else if (document.documentElement && document.documentElement.clientWidth)
	    // Explorer 6 Strict Mode
	    x = document.documentElement.clientWidth;
	  else if (document.body) // other Explorers
	    x = document.body.clientWidth;
    document.getElementById("contWin"+act).style.left=(absolute_pos(document.getElementById("bg1"))+60) + "px";
  }

  function down_win(){

//  	i = 2;
//    while (document.getElementById("contWin"+i)){
//    	document.getElementById("contWin"+i).style.left = x+"px";
//      i++;
//    }

    document.getElementById("contWin1").style.left = (absolute_pos(document.getElementById("bg1"))+60) + "px";
    show_form('contWin1');
  }


	var state = 0;
  var href;// адрес для перехода
  var act = 1; // номер активной страницы

  var counter = 0; // счетчик для просчета циклов сдвижения окна в Opera


	function show_form(name){
  	mod_x();
		if (state == 0){
	    dot = document.getElementById(name).style.top.substr(0,document.getElementById(name).style.top.indexOf('px')) - 0;
	    document.getElementById(name).style.top = (dot+30)+'px';
	    if (document.getElementById(name).style.top.substr(0,document.getElementById(name).style.top.indexOf('px'))<150)
	      window.setTimeout("show_form('"+name+"')",30);
      else{
      	document.getElementById(name).style.top = "160px";
      	state = 1;
        $("#contWin1 > div.content_window > div.container_img > div.digit > a").each(
        	function (){
            a = new Image;
            a.src = "/images/portfolio/"+this.href.substr(16,(this.href.indexOf('"',16)-16));
          }
        );
      }
    }
    else{
//      alert(document.getElementById("doc_html").scrollHeight);
//      alert(document.getElementById("doc_html").clientHeight);
//      alert(document.getElementById("doc_html").style.overflowY);// = "hidden";

      if (navigator.appName=="Netscape")  // FF
      	if (document.getElementById("doc_html").scrollHeight<=document.getElementById("doc_html").clientHeight)
          document.getElementById("doc_html").style.overflowY = "hidden";

      if (window.opera){  // Opera
      	if ((counter == 0) && (document.getElementById("doc_html").scrollHeight>document.getElementById("doc_html").clientHeight))
      		document.getElementById("doc_html").style.overflow = "hidden";
        counter++;
      }

      dot = document.getElementById(name).style.top.substr(0,document.getElementById(name).style.top.indexOf('px')) - 0;
	    document.getElementById(name).style.top = (dot+30)+'px';
	    if (document.getElementById(name).style.top.substr(0,document.getElementById(name).style.top.indexOf('px'))<document.body.clientHeight)
	      window.setTimeout("show_form('"+name+"')",10);
      else{
      	state = 0;
		document.getElementById(name).style.visibility = "hidden";
        top.location.href = href;
      }
    }
  }

  function ch_page (obj,e){
  	if(!e) e = window.event;
		if(e.preventDefault) e.preventDefault();
		else e.returnValue = false;
    href = obj.href;
    show_form('contWin'+act);
  }

	function onAjaxSuccess(data)
	{
    $("#container").append(data);
	}


  function s_nextj(num,n_num){
  	i = 1;
  	while (document.getElementById("contWin"+i))
    	i++;
    $.get("create_contWin.php",{work: n_num, win_num: i, act_win: num},onAjaxSuccess);//append("<div id='contWin"+i+"' style='position:absolute; top:160px; visibility:hidden' class='contWin'><div class='title_window'>Создание сайтов</div><div class='content_window'><p>Компания CView была основана в 2005 году. За время своей работы довольно нехило прокачалась. Работники нашей компании постоянно обрастают опытом, прошариваются в самые последние технологии которые потом применяются при создании МеГА-сайтов!</p><p>Основные направления деятельности:</p><a href='javascript:s_next(1,\"kjl\")'>Создание сайтов</a><br /><a href='javascript:s_next(1,3)'>Дизайн</a><br />- всех видов полиграфии<br />- Web-сайтов<br />- упаковки<br />- наружной рекламы<br />- логотипов<br />Разработка фирменного стиля<br />3D визуализация<br /><p>Кстати цены у нас нормальные, много не берем, только на еду и хватает.</p></div><div class='bot_window'><div class='button_place'></div></div>");
    n_num = i;
    window.setTimeout("dop_f("+num+","+n_num+")",50);
  }

  // дополнительная функция для включения lightbox в окнах сгенерированных ajax
  function dop_f(num, n_num){
  	if (document.getElementById("contWin"+n_num)){
    	$("#contWin"+n_num+" > div.content_window > div.container_img > div.zoom > a").lightBox();
    	s_next(num,n_num);
    }
    else
      window.setTimeout("dop_f("+num+","+n_num+")",50);
  }

  function s_next(num,n_num){
	    win_state = 1;
      ////////// для подгруженных окон
     // $("a[@rel*=lightbox]").lightBox();
      //////////
	    i = 0;
	    document.getElementById("contWin"+n_num).style.left = x+"px";
	    document.getElementById("contWin"+n_num).style.visibility = "visible";
	    document.getElementById("doc_html").style.overflowX = "hidden";
	    next_win(num,n_num);
	    act = n_num;
  }

  function s_prev(num,p_num){
  	win_state = 1;
    document.getElementById("contWin"+(p_num)).style.left = (0-document.getElementById("contWin"+(p_num)).clientWidth)+"px";
  	prev_win(num,p_num);
    document.getElementById("doc_html").style.overflowX = "hidden";
    act = p_num;
  }

  var win_state = 0;

  function next_win(num,n_num){
    if (win_state == 1){
    	if (document.getElementById("contWin"+(n_num)).style.left.substr(0,document.getElementById("contWin"+(n_num)).style.left.indexOf('px'))>(absolute_pos(document.getElementById("bg1")) + 120)){
      	dot = document.getElementById("contWin"+num).style.left.substr(0,document.getElementById("contWin"+num).style.left.indexOf('px')) - 0;
        document.getElementById("contWin"+num).style.left = (dot-60)+'px';

        if (document.getElementById("contWin"+num).style.left.substr(0,document.getElementById("contWin"+num).style.left.indexOf('px'))<0){
        	dot = document.getElementById("contWin"+(n_num)).style.left.substr(0,document.getElementById("contWin"+(n_num)).style.left.indexOf('px')) - 0;
        	document.getElementById("contWin"+(n_num)).style.left = (dot-60)+'px';
        }
        window.setTimeout("next_win("+num+","+n_num+")",5);
      }
      else{
      	document.getElementById("contWin"+(n_num)).style.left = (absolute_pos(document.getElementById("bg1"))+60) + "px";
      	win_state = 0;
        document.getElementById("doc_html").style.overflowX = "auto";

        $("#contWin"+n_num+" > div.content_window > div.container_img > div.digit > a").each(
        	function (){
            a = new Image;
            a.src = "/images/portfolio/"+this.href.substr(16,(this.href.indexOf('"',16)-16));
          }
        );


      }
    }
  }

  function prev_win(num,p_num){
  	if (win_state == 1){
    	if (document.getElementById("contWin"+(p_num)).style.left.substr(0,document.getElementById("contWin"+(p_num)).style.left.indexOf('px'))<(absolute_pos(document.getElementById("bg1")) - 120)){
      	dot = document.getElementById("contWin"+num).style.left.substr(0,document.getElementById("contWin"+num).style.left.indexOf('px')) - 0;
        document.getElementById("contWin"+num).style.left = (dot+60)+'px';

        dot = document.getElementById("contWin"+num).style.left.substr(0,document.getElementById("contWin"+num).style.left.indexOf('px'))-0;
        if ((dot+document.getElementById("contWin"+num).clientWidth)>x){
	        dot = document.getElementById("contWin"+(p_num)).style.left.substr(0,document.getElementById("contWin"+(p_num)).style.left.indexOf('px')) - 0;
	        document.getElementById("contWin"+(p_num)).style.left = (dot+60)+'px';
        }
        window.setTimeout("prev_win("+num+","+p_num+")",5);
      }
      else{
      	document.getElementById("contWin"+(p_num)).style.left = (absolute_pos(document.getElementById("bg1"))+60) + "px";
      	win_state = 0;
        document.getElementById("contWin"+num).style.visibility = "hidden";
        document.getElementById("contWin"+num).style.left = "0px";
        document.getElementById("doc_html").style.overflowX = "auto";
      }
    }
  }