$(document).ready(function ()
{
	//search
	$("#search")
		.bind("keypress", function(e)
		{
			if(e.which == 13 && $(this).attr("value"))
				document.location.href = "/search/" + encodeURI($(this).attr("value"));
		});
	$('table.search_table tr').hover(function()
		{
			$(' > td:first', this).css({background: "URL('/images/plus_b.gif') no-repeat 5px"});  
			$(' > td', this).css({background: "#eeeeee"});  
		}, function()
		{
			$(' > td', this).css({background: ""});
		})
	$('span.suchen_name').css('background', '#FF4040');
	$('span.suchen').css('background', '#FFFF00');
	$('table.search_table td a').click(function()
	{
		$('form[@name=search]').attr('action', $(this).attr('href')).submit();
		return false;
	});	
		
	//search button
	$('#getform').click
	(
		function() {
			if($('#search').attr('value') && $('#search').attr('value') != '')
				document.location.href = "/search/" + encodeURI($('#search').attr("value"));
		}
	);
	
	//votes
	//$('body').addClass('js-on');
    //$('#vottes input').checkBox();
	$('#votebut').click(
		function() {
			var data = '';
			switch($('input[@name=type]').attr('value'))
			{
				case 'once':
					data = '&value=' + $('input:checked[@name=vote]').attr('value');
					break;
				case 'many':
					var count = 0;
					$('#vottes input:checked').each(
						function() {
							data += '&value'+count+'='+$(this).attr('value');
							count ++;
						}
					);
					data += '&count='+count;
					break;
			}
			if(data != '' && data != '&count=0')
			{
				var voteID = $('#voteID').attr('value');
				$('#votepad').slideUp('normal', 
					function() {
						$(this).html('<div align="center"><img src="/images/ajaxload.gif" alt="Загрузка" /><div>Что-то происходит...</div></div>');
						$(this).slideDown('normal',
							function() {
								$.ajax({
								type: 'POST',
								url: '/modules/votes_panel_2.php',
								data: "type=voting&voteID="+voteID+'&'+data,
								success: function(result){
										$('#votepad').slideUp('normal',
											function() {
												$(this).html(result);
												$('#votepad').inner_slide("#vote", "bottom", {duration: "slow"}, null);
											});
									}
								});	
							}
						);
					});
			}
			return false;
		}
	);	
	//drop-down-menu
	$('#nav').droppy();	
	//reviews
	$('#check').hide();	
	//lightbox
	$('a[@rel=lightbox]').css({textDecoration: "none", margin: "0px"}).lightBox({fixedNavigation:false});
	
	//form.php // reviews.php
	$('#quest_form').formValidation({
		alias     : 'name'
		,required : 'accept'
		,err_list : false
		,callback : 'success_form'
	});	
	
	//site
	$('html').height($('#headers').height());
	$('#nav li').hover(
		function() {
			var w = $(this).width();
			//alert($(this).width());
			if(w>110 && w<120)
				$(this).css('background', 'url(/images/bg_hover2.jpg) no-repeat');	
			else if(w<90 && w>80)
				$(this).css('background', 'url(/images/bg_mmhover2.jpg) no-repeat');	
			else if(w<110 && w>90)
				$(this).css('background', 'url(/images/bg_bhover2.jpg) no-repeat');		
			else if(w<70 && w>60)
				$(this).css('background', 'url(/images/bg_mhover2.jpg) no-repeat');	
			else
				$(this).css('background', 'url(/images/bg_mmmhover2.jpg) no-repeat');	
		}, function() {
			$(this).css('background', 'none');	
		}
	);
});

/*
VOTES
Slider
*/
var ATTR_INNER_SLIDDING = "INNER_SLIDDING";
;(function($) { 
		
	$.fn.inner_slide = function(container, direction, options, callback) {
				  var defaults = {
			duration: "normal", //"slow", "normal", or "fast"
			easing: "linear" //The name of the easing effect that you want to use (plugin required). There are two built-in values, "linear" and "swing".			
		  };
 
		var opts = $.extend({}, defaults, options);
		return this.each(function() {
				$this = $(this);
				var slidding = ($(this).attr(ATTR_INNER_SLIDDING) != undefined && $(this).attr(ATTR_INNER_SLIDDING));
				if (slidding == "false")slidding = false;
				if(slidding){return false;}
				
				var o = $.meta ? $.extend({}, opts, $this.data()) : opts;			
				$(this).hide();
				//$(this).hide("explode", { pieces: 25 }, 1000);
				$(this).css("top", "0px");
				$(this).css("left", "0px");	
				container = $(container);	
				var params = {};
				switch(direction)
				{
					case "right":
						$(this).css("left", 0 - container.width() + "px");
						params.left = "+=" + container.width();
						break;			
					case "left":
						$(this).css("left",  container.width() + "px");
						params.left = "-=" + container.width();
						break;
					case "bottom":
						$(this).css("top",  0 - container.height() + "px");
						params.top = "+=" + container.height();
						break;	
					default:
					case "top":
						$(this).css("top", container.height() + "px");
						params.top = "-=" + container.height() ;
						break;
				}
				$(this).show();	
				$(this).attr(ATTR_INNER_SLIDDING, true);
				var self = $(this);
				$(this).animate(params, o.duration, o.easing, function(){self.attr(ATTR_INNER_SLIDDING, false);if (o.callback)o.callback.call($(this)); });
		});
	};
})(jQuery);
