// JavaScript Document

function sBanner() {
	var div = $("#sbanner");
	div.css({"position":'absolute', "left":'0', "top": '0', "z-index": '999', "overflow": 'hidden', "display": 'block'});
	var cont = $('.global, .footer, #minWidth');
	cont.css({"visibility":'hidden'})
	var h = $(window).height(); 
	var w = $(window).width();
	div.css({"width":w+'px', "height":h+'px',"left":-w+'px', "top": $(document).scrollTop()+'px', "visibility": 'visible'});
	div.animate({"left":0+'px'},1000, function(){
		setTimeout(function(){
			cont.css({"visibility":'visible'});
			div.css({"left":'auto', "right":'0'});
			div.animate({"width":0+'px'},1000, function(){div.hide()});
		},6000)
	});						  
}


function iPops() {
	im = $("div.imore");
	ip = $("div.ipop");
	if (im.length) {
		im.mouseenter(function(){
			var t = $(this);
			var p = $("#"+t.attr("id")+"-pop");
			ip.hide();
			p.css({"visibility":'hidden',"display":'block'});			
			var top = t.position().top;
			var left = t.position().left-p.outerWidth();
			if (top-p.outerHeight()>0) {
				top = top - p.outerHeight() + 30;
			}
			p.css({"top":top+'px',"left":left+'px',"visibility":'visible'});
		});
		im.mouseleave(function(){
			ip.hide();				   
		});
	}
}

function debug(vsr) {
	$("body").append('<div id="debug" style="position:fixed; z-index: 999; left:50%; top: 20px; width:300px; margin: 0 0 0 -150px; padding: 8px 12px 10px; background: #fff; border: 1px solid #666; font-size: 12px;">'+vsr+'</div>');	
}

function topMenuOver() {
	var tm = $("div.mit");	
	if (tm.length) {
		
			
		tm.bind("mouseenter", function(){
			var t = $(this);
			var vm = t.find("div.mit-d");
			var vp = t.find("div.b-ssmenu");
			var md = t.find("div.m-dets");
			var ml = t.find("div.mbline");
			t.css({"z-index":'9'});
			md.hide();
			vm.addClass("mit-a");
			ml.show();
			vp.show();
		});
		tm.bind("mouseleave", function(){
			$("div.mit").css({"z-index":'3'});
			$("div.mit-d").removeClass("mit-a");
			$("div.b-ssmenu").hide();
			$("div.mbline").hide();
			$("div.m-dets").show();
		})
		
		
	}
}


(function($) {
	$.fn.vote = function() {
		return this.each(function(){
			var im = $("div.img",$(this));
			var tim = $("td",$(this));
			var sRate = function(rate) {
				var rmax = 0;
				for (j=0; j<im.length; j++) {
					irate = parseInt(im.eq(j).find("img").attr("rel"));
					if (rmax<irate) {
						rmax = irate;
					}	
				}			
				var tw, tm;
				if (rmax>0) {
					var pcent = (rate/rmax)*100;
					if (pcent>=100) {
						tw = 100;					
					}
					else if(pcent<100&&pcent>=75) {
						tw = 85;	 
					}
					else if(pcent<75&&pcent>=50) {
						tw = 70;
					}
					else if(pcent<50&&pcent>=25) {
						tw = 55;
					}
					else {
						tw = 45;	
					}					
					
				}
				else {
					tw = 100;
				}
				tm = (100-tw)/2;
				return {"w":tw, "m":tm};
			}
			im.each(function(){
				
				
				
				
				var t = $(this);
				var trate = parseInt(t.find("img").attr("rel"));
				t.css({height: sRate(trate).w+"%", width: sRate(trate).w+"%", paddingTop: sRate(trate).m*2+"%"});
				
				var td = $(this).parent().parent();
				td.mouseenter(function(){
					//$("img",$(this)).stop().animate({height: sRate(trate).w+10+"%", width: sRate(trate).w+10+"%", marginLeft: sRate(trate).m-5+"%"}, 200);				
					$("p:last",$(this)).html(trate+'+1');
				});
				td.mouseleave(function(){					
					//$("img",$(this)).stop().animate({height: sRate(trate).w+"%", width: sRate(trate).w+"%", marginLeft: sRate(trate).m+"%"}, 200);
					
					///alert($("p:last",td).html());
					$("p:last",$(this)).html(trate);
				});
				td.click(function(){	

					var cur_id = $("p:last",$(this)).attr("id");
					var arr = cur_id.split('_');

					
					trate = trate + 1;
					$("img",$(this)).attr({"rel": trate});
					$("p:last",$(this)).html(trate-1+'+1');
					im.each(function(){
						erate = $(this).find("img").attr("rel");	
						$(this).css({height: sRate(erate).w+"%", width: sRate(erate).w+"%", paddingTop: sRate(erate).m*2+"%"});				 
					})
					tim.css({"cursor":'text'}).unbind("mouseleave").unbind("mouseenter").unbind("click");
					//$("img, p",tim).css({"opacity": '0.4'});
					//$("img, p",$(this)).css({"opacity": '1.0'});
					$("p",$(this)).css({"font-weight": 'bold'});
					$("span",tim).removeClass("adott");
					AjaxNewsRate(arr[0],arr[1]);
				})
			});		
			
		});
	};
})(jQuery);


(function($) {
	$.fn.sAbout = function(o) {
		var defaults = {line: 1, pshow: 'См. продолжение', phide: 'Свернуть'};
    	var o = $.extend(defaults, o);
		return this.each(function(){
			var tt = $(this);
			var tx = tt.find("div.stx")
			var lnk = tt.find("div.showhide");
			var aa = lnk.find("a");
			var line = tt.find("div.aline");
			if (tx.children().height()<=tx.height()) {
				lnk.hide();
				line.hide();
			} else {
				lnk.show();
				line.show();	
			}
			var sh = function() {
				if (tx.css("height")=='auto') {
					tx.css({"height":o.line*1.2+'em'});
					line.css({"top":'auto',"bottom":'4px',"height":'15px',"background-position":'-15px 0'});
					aa.html(o.pshow);
				} else {
					tx.css({"height":'auto'});
					hh = tx.height()+18;
					line.css({"top":'0',"bottom":'auto',"height":hh+'px',"background-position":'0 0'});
					aa.html(o.phide);
				}
			}
			line.click(function(){
				sh();
			});
			aa.click(function(){
				sh();
				return false;
			});
		});
	};
})(jQuery);
