$(document).ready(function(){

	Cufon.replace(".cu");
	Cufon.replace("#menu-main .l0", {hover: true});
	

	jQuery.fn.whenLoaded = function(fn){
	  return this.each(function(){
	
	    if (this.complete || this.readyState == 'complete'){
	      fn.call(this);
	    } else {
	      $(this).load(fn);
	    }
	  });
	}

	$("input.defaultText").focus(function() {
		
		    if (this.value == $(this).attr('defvalue')) {
		
				this.value = '';
		    }
	
		    $(this).blur(function() {
		
				if (this.value == '') {
		
					this.value = $(this).attr('defvalue');
				}
		    });
	});


	var navOver = function() { $(this).addClass('hover'); };
	var navOut = function() { $(this).removeClass('hover'); };	
		
	var config = {    
	     over: navOver,
	     timeout: 300,
	     out: navOut
	};
	
	$("#header ul.nav li").hoverIntent( config );
	$("#menu-main ul li").hoverIntent( config );
	$("#menu-main ul li ul li").hoverIntent( config );
/*
	var zIndexNumber = 1000;
	$('ul').each(function() {
		$(this).css('zIndex', zIndexNumber);
		zIndexNumber -= 10;
	});
*/	
	
	$('.spoiler-button').click(function() {
	
		$(this).toggleClass('head-button-active');
		$(this).next().toggleClass('spoiler-show');		

		return false;

	});
	
	$('#print').click(function() {
		
		openPrintVersion();
		return false;
	});
	
	function openPrintVersion() {
		
		var currentUrl=document.location.href;
		openPrintVersionUrl(currentUrl);	
	}
	
	function openPrintVersionUrl(url) {
		
		var printUrl = "";
		if (url.indexOf("?") != -1){
			
			printUrl=url+"&print=true";
		}
			else {

			if (url.substr(-1) != "/") {

				printUrl = url + "/";
			}
			
			printUrl=url+"?print=true";		

		}
		window.open(printUrl,'','width=1011,height=700,scrollbars=yes,menubar=yes');		
	}
});
