$(document).ready(function(){
        $('a.re-write').each(function(){
                url = $(this).html();
                if (url.substr(0,7) != 'http://')
                        url = 'http://' + url;
                $(this).attr('href', url);
        });

//        $('#show-map').click(function(){
//                showbig('/images/design/travelScheme.jpg')
//        });
        $('#portfolio').click(function(){
                        location.href = '/portfolio/';
        });



        $('#we-can ul li').click(function(){
                location.href = $(this).find('a').attr('href');
                });


				$('a.prove_comment').click(function(){
					var obj = $(this);
					var objParent = $(this).parent();
					
					$.post("/index.php5?module=coolstuff&class=comment",  { commentId: $(this).attr('value'), action: $(this).attr('name') },
					  function(data){
					  	if (data == 'a'){
				  		 	obj.remove();
					  	}
					  	if (data == 'd'){
				  		 	objParent.remove();
					  	}
					  }
					);
				});
				
        $('#click-me').dblclick(function(){
                if ($('#comma-text').hasClass('visible')) {
                        $('#switcher').css('display','block');
                        $('#contacts_address').css('display','block');
                        $('#comma-text').removeClass('visible');
                        $(this).parent().css('background-image', 'url("/images/design/rightBottom.gif")');
                } else {
                        $('#switcher').css('display','none');
                        $('#contacts_address').css('display','none');
                        $('#comma-text').addClass('visible');
                        $(this).parent().css('background-image', 'url("/images/design/rightBottomDot.gif")');
                }
        });
        $('#commentator_name').focus(function(){
        	$('#wrong_name').css('display', 'none');
        	this.value = '';
        });
         $('#comment_text').focus(function(){
         	$('#wrong_comment').css('display', 'none');
        	this.innerHTML = '';
        });
        
        $('a[rel=external]').click(function(){
            window.open("http://"+this.innerHTML);
            return false;
        }).mouseover(function(){
          this.href='http://'+this.innerHTML;
          window.status='http://'+this.innerHTML;
            return false;
        }).mouseout(function(){
          this.href='/';
          window.status='';
            return false;
        });
        $('a[@rel=external2]').click(function(){
            window.open('http://yandex.ru/yandsearch?rpt=rad&text='+this.title);
            return false;
        }).mouseover(function(){
          this.href='http://yandex.ru/yandsearch?rpt=rad&text='+this.title;
          window.status='http://yandex.ru/yandsearch?rpt=rad&text='+this.title;
            return false;
        }).mouseout(function(){
          this.href='/';
          window.status='';
            return false;
        }); 
        if (($('body').css('width').replace("px",'')<1100)&&($('#contacts_img').length>0))
          $('#contacts_img')[0].src="/images/map_contacts_small.jpg";
          
       /* if (jQuery('#we-can > div.ul-wrapper > ul >li').length>0)
        {
          $('#we-can > div.ul-wrapper > ul >li').mouseover(function(){
            jQuery(this).css('opacity','0.4');
          });
          $('#we-can > div.ul-wrapper > ul >li:last').mouseover(function(){
            jQuery(this).css('opacity','1');
          }); 
          $('#we-can > div.ul-wrapper > ul >li').mouseout(function(){
            jQuery(this).css('opacity','1')
          });
        }*/
          $('#we-can ul li:not(:last)').mouseover(function(){
          		$(this).stop();
          		$(this).fadeTo("slow",0.4);//animate({opacity:0.4},{ queue:false, duration:500 } )//css('opacity', 0.4);
          	}).mouseout(function(){
          		$(this).stop();
          		$(this).fadeTo("slow",1);//animate({opacity:1},{ queue:false, duration:500 } );//css('opacity', 1);
          	});
          	
          
         
          $('body').css('visibility','visible');
       
});



var agt=navigator.userAgent.toLowerCase();
var is_ie = ((agt.indexOf("msie") != -1) && (agt.indexOf("opera") == -1));
if(is_ie){

  window.fixPNG = function (imgName) {

    var img = new Image();
    img.src = imgName;
    return "<img src='"+imgName+"' width='"+img.width+"' height='"+img.height+"' style='filter:progid:DXImageTransform.Microsoft.AlphaImageLoader(src="+'"'+img.src+'"'+");') />";
  }
}else {
  window.fixPNG = function (imgName) {
    return "<img style='cursor:hand;' src='"+imgName+"' alt='' />";
  }
}
  

  function preSubmit(){
  	if (document.getElementById('commentator_name').value == '' || document.getElementById('commentator_name').value == 'Меня зовут...') {
  		document.getElementById('wrong_name').style.display = 'block';
  		return false;
  	}
  	if (document.getElementById('comment_text').value == '' || document.getElementById('comment_text').value == 'Я думаю...') {
  		document.getElementById('wrong_comment').style.display = 'block';
  		return false;
  	}
  	document.getElementById('submitForm').submit();
  }
  
  function showbig(picname){
    window.open('/includes/foto.php5?pic='+picname,'_blank','scrollbars=yes,taskbar=no,resizeable=no,status=no,menubar=no,top=30,left=30,width=30,height=30');
  }

  function PreLoad(source){
    var NewImage = new Image();
    NewImage.src = source;
  }

  function prepareSubmit(frm){
    var len = frm.all("editbox").length; if (!len) len = 1;
    for (var i=0; i<len; i++)
      frm.all("codebox", i).innerText = frm.all("codebox", i).style.display ? borderOn(frm.all("codebox", i).innerText) : borderOn(frm.all("editbox", i).innerHTML);
  }

 function menuProcess(menuId){
          if(menuId.style.display == 'none'){
     menuId.style.display = 'block';
   }else{
            menuId.style.display = 'none';
   }
 }

 function btShowFunctionArguments(name){
         btChangeFunctionArgumentsBlock(name,'none','block','block');
 }

 function btHideFunctionArguments(name){
         btChangeFunctionArgumentsBlock(name,'block','none','none');
 }

 function btChangeFunctionArgumentsBlock(name,plus,minus,arguments){
          document.getElementById('backtrace_img_plus_'+name).style.display = plus;
          document.getElementById('backtrace_img_minus_'+name).style.display = minus;
          document.getElementById('backtrace_arguments_'+name).style.display = arguments;
 }

  function processTree(elementId,isTop){
          tbl = document.getElementById('dir_'+elementId);
          img = document.getElementById('img_'+elementId);

          if(tbl.style.display != 'none'){
                   tbl.style.display = 'none';
                   img.alt = 'Раскрыть';
                   if(isTop)
                     img.src = '/images/design/tree_plus.gif';
                   else
                     img.src = '/images/design/tree_sub_plus.gif';
          }else{
                   tbl.style.display = 'block';
                   img.alt = 'Закрыть';
                   if(isTop)
                     img.src = '/images/design/tree_minus.gif';
                   else
                     img.src = '/images/design/tree_sub_minus.gif';
          }
 }

 /**
 * Преобразует многомерный обьект данных в строковое представление
 */
 function Dump(d,l) {
    if (l == null) l = 1;
    var s = '';
    if (typeof(d) == "object") {
        s += typeof(d) + " {\n";
        for (var k in d) {
            for (var i=0; i<l; i++) s += "    ";
            s += k+": " + Dump(d[k],l+1);
        }
        for (var i=0; i<l-1; i++) s += "  ";
        s += "}\n"
    } else {
        s += "" + d + "\n";
    }
    return s;
 }
 function  print_r(arr){
        alert(Dump(arr));
 }

 /**
 * Создаёт копию обьекта (для передачи не по ссылки)
 */
 function clone(d) {
        var s = new Array();
        if(typeof(d) == "object"){
                for (var k in d)
                        s[k] = clone(d[k]);
        }else
                s = d;
        return s;
 }

 /** v 1.1
 * Выдаёт окончание
 *
 * @param int $count - Количество элементов
 * @param str $word - название элемента в ед. числе
 * @return str - название в указанном количестве
 */
function rus_case(count, word){
        var sp_count = (1 * count % 100 - 1 * count % 10) == 10;
        var count = 1 * count % 10;
        var mod = word.substr(word.length-1, 1);
        if(count == 1 && !sp_count)
                return word;
        switch (mod){
                case 'а' :
                        if((count==2 || count==3 || count==4) && !sp_count)
                                return word.substr(0, word.length-1) + 'ы';
                        else
                                return word.substr(0, word.length-1);
                case 'ь' :
                        if((count==2 || count==3 || count==4) && !sp_count)
                                return word.substr(0, word.length-1) + 'я';
                        else
                                return word.substr(0, word.length-1) + 'ей';
                case 'е' :
                        if((count==2 || count==3 || count==4) && !sp_count)
                                return word.substr(0, word.length-1) + 'я';
                        else
                                return word.substr(0, word.length-1) + 'й';
                default:
                        if((count==2 || count==3 || count==4) && !sp_count)
                                return word + 'а';
                        else
                                return word + 'ов';
        }
 }
