var mainmenutimeoutid = 0;var mainmenutimeoutid2 = 0;var sgtimeoutid = 0;var sgCurrentSelection = 0;var sgLastTerm = '';function print_r(arr, level) {    var print_red_text = "";    if(!level) level = 0;    var level_padding = "";    for(var j=0; j<level+1; j++) level_padding += "    ";    if(typeof(arr) == 'object') {        for(var item in arr) {            var value = arr[item];            if(typeof(value) == 'object') {                print_red_text += level_padding + "'" + item + "' :\n";                print_red_text += print_r(value,level+1);		}             else                 print_red_text += level_padding + "'" + item + "' => \"" + value + "\"\n";        }    }     else  print_red_text = "===>"+arr+"<===("+typeof(arr)+")";    return print_red_text;}	$(function() {	//FIX PNG	if($.browser.msie && $.browser.version.substr(0,1)<7)		$('img[@src$=.png],#trailer0 table,#trailer1 table,#trailer2 table,#trailer3 table').ifixpng();		//PANEL SHOW CLOSE	$(document).click(function(e){	    if($(e.target).is(".panel, .panel *"))	    {		   			$('.panel').not(e.target).not($(e.target).parents(".panel")).slideUp(200);	    }		    else	    {	    				$('.panel').slideUp(200);	    }				});		$(".showPanel").click(function(){		panelID=$(this).attr("id");		if($("#panel_"+panelID).is(":visible"))		{			$("#panel_"+panelID).slideUp(200);		}		else		{			$("#panel_"+panelID).slideDown(200);		}		return false;	});	$(".closePanel").click(function(){				$(this).parents(".panel").slideUp(200);		return false;	});			//KINOPKA	$("#kinopka").hover(function(){		mainmenutimeoutid2 = setTimeout(function(){clearTimeout(mainmenutimeoutid);$("#kinopka").addClass("hover");$("#topmenu").show();},150);			},function(){		clearTimeout(mainmenutimeoutid2);		mainmenutimeoutid = setTimeout(function(){$("#topmenu").hide();$("#kinopka").removeClass("hover");},300);			});			$("#topmenu").hover(function(){				clearTimeout(mainmenutimeoutid);		//$("#topmenu").show();	},function(){		//setTimeout(function() { alert('0.5 секунды') }, 500)		mainmenutimeoutid = setTimeout(function(){$("#topmenu").hide();$("#kinopka").removeClass("hover");},300);			});			//SEARCH SUGGESTS	$( "#search_field" ).attr("autocomplete","off")		.keyup(function(){		if(sgLastTerm != $(this).val())		{			if($(this).val()!='')			{			 				sgGetSuggestion();			}			sgLastTerm = $(this).val();		}		}).keydown(function(e) {	      switch(e.keyCode) { 	         // User pressed "up" arrow	         case 38:	        	 $( "#search_field" ).focus();	        	 	        	 sgNavigate('up');	        	 return false;	        	 	            	         break;	         // User pressed "down" arrow	         case 40:	        	 $( "#search_field" ).focus();	        	 	        	 sgNavigate('down');	        	 return false;	         break;	         // User pressed "enter"	         case 13:	        	 	        	 sgGo();       	         break;	      }	      	   })	.keypress(function(e){if((e.keyCode==13)&&($("#suggests div.suggest.hover").size()!=0)){return false;}})   	.blur(function(){sgtimeoutid = setTimeout(function(){$("#suggests").hide()},200);})	.focus(function(){clearTimeout(sgtimeoutid); $(this).keyup();});			$("#suggests").blur(function(){sgtimeoutid = setTimeout(function(){$("#suggests").hide()},200);})	.focus(function(){clearTimeout(sgtimeoutid); $(this).keyup();});			//THUMBS	$(".thumb_up,.thumb_down,.board-block").not('.hover,.disable').hover(function(){$(this).addClass("hover");},function(){$(this).removeClass("hover");});			//SMOOTH SCROLLING		$('a[href*=#]').click(function() {			    if (location.pathname.replace(/^\//,'') == this.pathname.replace(/^\//,'') 	        && location.hostname == this.hostname) {	 	            var $target = $(this.hash);	 	            $target = $target.length && $target || $('[name=' + this.hash.slice(1) +']');	 	            if ($target.length) {	 	                var targetOffset = $target.offset().top;	 	                $('html,body').animate({scrollTop: targetOffset}, 1000);	                	                $target.animate({ backgroundColor: "#ffcc5e" }, "slow",function(){$target.animate({ backgroundColor: "transparent" }, "slow",function(){$target.css("background-color","transparent");});});	 	                return false;	 	            }	 	        }	 	    });		}); //END READYfunction sgGetSuggestion(){	if( typeof sgGetSuggestion.counter == 'undefined' ) {		sgGetSuggestion.counter = 0;    }	sgGetSuggestion.counter++;	var curNum = sgGetSuggestion.counter;	$.getJSON('/scripts/search.php', {term : $("#search_field").val()}, function(json) {		if(curNum == sgGetSuggestion.counter)		{			$("#suggests").html("");			//$("#suggests").html("top:"+$("#search_field").offset().top+"<br>height:"+$("#search_field").height());			$("#suggests").css("top",$("#search_field").offset().top+$("#search_field").height()+2+"px").css("left",$("#search_field").offset().left+"px");			var maxi=0;			$.each(json, function(i,item){								$('<div class="suggest"><img src="'+item.img+'" width="40" align="left"><div><a href="'+item.link+'"><b>'+item.rname+'</b>'+((item.year!=undefined)?' ('+item.year+')':'')+'</a></div><div>'+item.ename+'</div><br clear="both"></div>')				.hover(function(){sgCurrentSelection = i; sgSetSelected(i);},function(){})				.click(function(){sgGo();})				.appendTo("#suggests");				maxi=i;		    });			$('<div class="suggest nosuggest"><a href="/search/?q='+encodeURIComponent($( "#search_field" ).val())+'">Смотреть все результаты для "'+$( "#search_field" ).val()+'"</a>&nbsp;&raquo;</div>')			.hover(function(){sgCurrentSelection = maxi+1; sgSetSelected(maxi+1);},function(){})			.click(function(){sgGo();})			.appendTo("#suggests");			$("#suggests").show();		}		});		}function sgNavigate(direction) {	// Check if any of the menu items is selected	if($("#suggests div.suggest.hover").size() == 0) {		sgCurrentSelection = -1;	}	if(direction == 'up' && sgCurrentSelection != -1) {		if(sgCurrentSelection != 0) {			sgCurrentSelection--;		}	} else if (direction == 'down') {		if(sgCurrentSelection != $("#suggests div.suggest").size() -1) {			sgCurrentSelection++;		}	}	sgSetSelected(sgCurrentSelection);	return false;}function sgSetSelected(menuitem) {	$("#suggests div.suggest").removeClass("hover");	$("#suggests div.suggest").eq(menuitem).addClass("hover");	return false;}function sgGo(){	if($("#suggests div.suggest.hover").size()==1)	{	        		 		window.location = $("#suggests div.suggest.hover a").attr("href");		return false;	} }
