//alert(parseInt($.browser.version));


var browser_not_support_css3 = ($.browser.mozilla || $.browser.safari || ($.browser.opera && $.browser.version >10.5)|| ($.browser.msie && $.browser.version >8.99))?0:1;

jQuery.fn.addCorners = function(){
    $(this).css('position','relative');
    type = "corner cor-" + ($(this).hasClass('gray')?'gray':$(this).hasClass('lightblue')?'lightblue':$(this).hasClass('margenta2')?'margenta2':'margenta');
    if ($(this).hasClass('gray')){
        type = "corner cor-gray";
    }
    border_size = $(this).hasClass('lightblue')?1:$(this).hasClass('margenta2')?0:2
    if ($(this).hasClass('grayblue')){
        type = "corner cor-grayblue";
        border_size = 4;
    }
    $(this).append(
        '<div class="'+type+' topleft'+border_size+'"></div>'
      + '<div class="'+type+' topright'+border_size+'"></div>' 
      + '<div class="'+type+' bottomright'+border_size+'"></div>' 
      + '<div class="'+type+' bottomleft'+border_size+'"></div>');
    return $(this);
}

var current_sub = new Object();
jQuery.fn.slide = function(){  
    current_sub = this;
    
    $('#header ul li.main .sublist-wrapper').each(function(){
      //$(this).attr('isOpened', $(this).css('display') == 'block'?1:0);   
      if ($(this).attr('isOpened') == 1 && current_sub !=this){
        $(this).stop().fadeTo(100,0,function(){
          $(this).attr('isOpened',0);
           if ($.browser.msie){
               $(this).css('display','none');
           } else {
               $(this).hide();
           }
        });
      }
    })
    
    //$(this).attr('isOpened', $(this).css('display') == 'block'?1:0);   
    
    if ($(this).attr('isOpened') == 1){
      $(this).fadeTo(500,0);
      $(this).attr('isOpened',0);
    } else if ($(this).attr('isOpened') == 0) {
      $(this).stop().fadeTo(500,1, function(){
        $(this).fadeTo(25000,0.95,function(){
          if ($(this).attr('isOpened')==1){
            $(this).fadeTo(500,0,function(){
              $(this).attr('isOpened',0);
                if ($.browser.msie){
                    $(this).css('display','none');
                } else {
                    $(this).hide();
                }
            });
          }
        });
      });      
      $(this).attr('isOpened',1);
    }
    return $(this);
}

$(document).ready(function(){
    if ($.browser.opera && parseInt($.browser.version)<10){
    	$('a.gate').css('margin-left','78px');
    	$('a.gate').css('margin-top','0');
/*        $('body').html(' ');
        $('body').css('background','#0202ab url(\'/images/design/tmp/bluescreen.jpg\') center center no-repeat');*/
    }
     

  $('#header ul li.main .sublist-wrapper').each(function(){
    $(this).attr('isOpened',0);
  })

  if (browser_not_support_css3){
    $('.rounded').each(function(){
      $(this).addCorners();
    })
  }
  $('.rounded-always').each(function(){
      $(this).addCorners();
    });
  $('#header ul li h3 > a').click(function(){
    if ($(this).parent().parent().find('.sublist-wrapper').length){
      $(this).parent().parent().find('.sublist-wrapper').slide();
      return false;
    }
  })

  $('a.grey').click(function(){
    $('.alert-message').each(function(){
      $(this).remove();
    });
    $('body').prepend('<div class="alert-message alert-top">Раздел <b>"'+$(this).text()+'"</b> находится в разработке'
    + '<a href="#" class="close" onclick="$(this).parent().stop().slideUp(300,function(){$(this).remove();});return false;">Закрыть</a></div>');
    $('.alert-message').stop().fadeTo(3000,0.9,function(){
      $(this).stop().fadeOut(3000, function(){
        $(this).remove();
      });
    });
    return false;
  });
  
$('a.grey2').click(function(e){
    $('.alert-message').each(function(){
      $(this).remove();
    });
    $('body').prepend('<div class="alert-message 123456" style="top:'+e.pageY
    +'px;left:'+(e.pageX-260)
    +'px">Еще не работает, посмотрите пока остальные разделы :-)'
    + '<a href="#" class="close" onclick="$(this).parent().stop().slideUp(300,function(){$(this).remove();});return false;">Закрыть</a></div>');
    $('.alert-message').stop().fadeTo(1500,0.95,function(){
      $('.alert-message').fadeTo(300,0, function(){
        $('.alert-message').remove();
      });
    });
    return false;  
});
var arPiw = Array();
    if($('img.popup').length){
       $('img.popup').mouseenter(function(e){
           piw = Math.round(Math.random()*100000000);
           popimg = $(this).attr('src').replace('_small','').replace('.','_popup.');
          // alert(popimg);
           offsetX = e.pageX+20;
           offsetY = e.pageY+20;
           $(this).attr('rel', piw);
           arPiw[piw] = 1;

           img = new Image();
           img.myAttr       = new Object();
           img.myAttr.piw   = piw;
           img.myAttr.leftX = offsetX;
           img.myAttr.topY  = offsetY;
           img.onload = function(){
               if (arPiw[img.myAttr.piw] == 1){
                   if ($.browser.msie){
                       $('body').prepend("<div id=\"piw_"+img.myAttr.piw+"\" style=\"left:"+img.myAttr.leftX+"px;top:"+img.myAttr.topY+"px;\" class=\"popup-wrap\"><img src=\""+this.src+"\" /></div>");
                   } else {
                       $('body').prepend('<div id="piw_'+img.myAttr.piw+'" style="left:'+img.myAttr.leftX+'px;top:'+img.myAttr.topY+'px;" class="popup-wrap"></div>');
                       $('#piw_'+img.myAttr.piw+'').append(this);
                   }
               }
           }
           img.src = popimg;
       }).mousemove(function(e){
           if (!$('body').find('#piw_'+$(this).attr('rel')).length){
               return ;
           }
           offsetX = e.pageX+20;
           offsetY = e.pageY+20;
           $('body').find('#piw_'+$(this).attr('rel')).css('top', offsetY+'px').css('left', offsetX+'px');
       }).mouseleave(function(){
           if (!$('body').find('#piw_'+$(this).attr('rel')).length){
               return ;
           }
           arPiw[$(this).attr('rel')] = 0;
           $('body').find('#piw_'+$(this).attr('rel')).remove();
       });
    }

    $('.popup-wrap').live('mouseover',function(){
        $(this).remove();
    })
});
var tmp;







