Cufon.replace('.regular', { fontFamily: 'PlumbC'} );
Cufon.replace('.bold', { fontFamily: 'PlumbBlackC'});
	
var $top, $bottom, $content, $sized, ht, hb, 
$cases_holder;

$(document).ready(function() {
	
	if(document.location.hash=='#print') setPrintCSS(true); 
	else {
	
	
		if($.browser.webkit) {
			$('li.top').width('33.34%')
		}
			
		$top = $('#top').css({position: 'absolute'});
		ht = $top.outerHeight();
		
		$bottom = $('#bottom').css({position: 'absolute'});
		hb = $bottom.outerHeight();
		
		$sized = $('div.navigation');
	
		$cases_holder = $('div.cases-holder');
		
		$content = $('#content').css({position: 'absolute', top: ht, overflow: 'hidden'});
		
		$('li.top').find('a.menu-navigation,div.menu-navigation').each(function() {
			var dragging = false,
				visible = false,
				$self = $(this),
				$parent = $(this).parent(),
				interval,
				$nav = $(this).next();		
			
			$(this).mouseover(function(){
				if(!visible) {
					$nav.css({display:'block',opacity:0});				
					$parent.addClass('top-hover').find('div.scrollable-nav').scrollPane({
						onStart: function(e) {
							dragging = true;
						},
						onEnd: function(e) {
							dragging = false;;
						}
					});			
					statTime = (new Date).getTime()
					$nav.stop(true).animate({opacity: 1}, 500);	
					visible = true;
				}
			})		
			$parent.mouseleave(function() {
				if(!dragging) {
					interval = setTimeout(function() {
						$parent.removeClass('top-hover')
						$nav.css({display:'none'});
						visible = false;
					}, 150);
					
				}
			});
		})
		
		$(window).resize(resize).trigger("resize");
		
		$('div.login').find("input").defaultValue();
		$('#login').click(function() {
			$('div.login').toggle();
			$(this).toggleClass('hover');
			return false;
		})
		
		$("a.submit").click(function(){
			$(this).parents("form").submit();
			return false;
		});

	}
});
	
function resize() {
	var w = top.innerWidth || document.documentElement.clientWidth || document.body.clientWidth;
	var h = top.innerHeight || document.documentElement.clientHeight || document.body.clientHeight;
	
	h = Math.max(h,565);
	w = Math.max(w,800);
	$cases_holder.css({width: w,height: Math.min(h-hb-ht,542)})
	
	$content.css({ width: w, height:  h-hb-ht });
	$sized.css({ height: h-hb-ht });
	$bottom.css({ top:  h-hb });	
	
	if( typeof onResize == 'function') {
		onResize(w, h-hb-ht);
	}
}

(function() {
	jQuery.fn.defaultValue = function() {
		return this.each(function() {	
			var _default = $(this).attr("default");
			$(this).val(_default).addClass("default")		
			.bind("focus", function() {
				
				
				if($(this).val() == _default)
					$(this).val("").removeClass("default").removeClass("error");
				
			
			})
			.bind("blur", function() {
				if($(this).val()=="")
					$(this).val(_default).addClass("default").addClass("error");
			});
		});
	}
})(jQuery);

function setPrintCSS(isPrint) {
// Определяем поддержку нужного нам элемента в броузерах
  if (document.getElementsByTagName)
      x = document.getElementsByTagName('link');
  else if (document.all)
      x = document.all.tags('link');
  else
  {
      alert('Простите, этот скрипт не работает в вашем браузере');
      return;
  }
  
// Пробегая по всем элементам LINK в HTML  - включаем и отключаем нужные нам стили
// идентифицируя их по атрибуту title
// параметр isPrint - отвечает просто за вариант стилей для печти или монитора
  for (var i=0;i<x.length;i++) {
      if(x[i].title == 'printview'){x[i].disabled = !isPrint;}
      if(x[i].title == 'screenview'){x[i].disabled = isPrint;}
  }
}
