// JavaScript Document

// Jtables

function Jtables(header, myClassID)
{
$( myClassID +" TR:lt("+ (header) +")").children("TD").css({ 'text-align':'center', 'padding':'6px', 'font-size':'12px', 'font-weight':'bold' });

$( myClassID +" TR:eq("+ (header) +") TD").each(
					function(index)
					{
						$(this).attr({ 'h':'0' }).css({ 'cursor':'pointer' }).bind(
					{
							dblclick: function()
							{
									
									if( $(this).attr('h') != '1' )
									{
									$( myClassID +" TR:gt("+ (header-1) +")").each(
														  
									function()
												{
													$("TD:eq("+ index +")", this).attr({ 'h':'1' }).css({ 'background-color':'#FFFFEE' });	
												}														  
														  );
								}
								else
								{
									$( myClassID +" TR:gt("+ (header-1) +")").each(
														  
									function()
												{
													$("TD:eq("+ index +")", this).attr({ 'h':'0' }).css({ 'background-color':'' });	
												}														  
														  );
								}
							}							
						}
						);
					}
);

$(myClassID +" TR:gt("+ (header-1) +")").each(
	function(index) {
		if( (index%2)==0 )
		{
			$(this).css({ 'background':'#F4F4F4' });	
		}
		$(this).attr({ 'c':$(this).css('background-color'), 't':'0' });
		
		$(this).hover(
					  function() { if( $(this).attr('t') != '1') { $(this).css({ 'background':'#CDE0F1' }); } },
					  function() { if( $(this).attr('t') != '1') { $(this).css({ 'background':$(this).attr('c') }); } }
					  );
		
		$(this).toggle(
					 function()
					 {
							$(this).css({ 'background':'#CDE0F1' }).attr({ 't':'1' });
					 },
					 function()
					 {
							$(this).css({ 'background':$(this).attr('c') }).attr({ 't':'0' });
					 }
		);
		
		$("TD", this).each(
							function()
			{
					if($(this).html() == '<p>-</p>' || $(this).html() == '-' || $(this).html() == '<P>-</P>')
					{
						$(this).css({ 'text-align':'center' });
					}
			}
		);
	}
					  
);
$(myClassID).append("<div class='jtable_tools'><div><a href='#' class='jtable_tools_link' inverttoolWith='"+ myClassID +"'>Инвертировать выделение</a></div><div>|</div><div><a href='#' class='jtable_tools_link' printtoolWith='"+ myClassID +"'>Отправить выбранное на печать</a></div><div style='clear:left; float:none;'>&nbsp;</div></div>");

$("A[inverttoolWith='"+ myClassID +"']").bind({ click: function() {
			
			$( myClassID +" TR:gt("+ (header-1) +")").each( function() { $(this).click(); });
			return false;								  
						} });

$("A[printtoolWith='"+ myClassID +"']").bind({ click: function() {
			$(".jtable_print_container").remove();
			$("BODY").append("<div class='jtable_print_container'><table border='1' cellpadding='5'></table></div>")
			
			$(myClassID +" TR:lt("+ (header) +")").each( function() { var jtable_printTable = $(this).html(); $(".jtable_print_container TABLE").append("<tr>"+ jtable_printTable +"</tr>"); } );
			
			$(myClassID +" TR:gt("+ (header-1) +")").each( function() { 
						
						if($(this).attr('t') == '1')
						{
						 var jtable_printTable = $(this).html();
						$(".jtable_print_container TABLE").append("<tr>"+ jtable_printTable +"</tr>");
						}
																	 
																	 });
						
			open_jtable_printWindow = open("", "displayWindow", "status=no, resizable=yes, scrollbars=yes, toolbar=no, menubar=no, width="+($(myClassID + " TABLE").width()+30));
			open_jtable_printWindow.document.open();
			open_jtable_printWindow.document.write("<html><head><title>Печать выбранного из таблицы</title><style>TABLE { font-family:Arial; font-size:11px; border:1px solid #000; border-collapse:collapse; } TD { border:1px solid #000; border-collapse:collapse; }</style></head>");
			open_jtable_printWindow.document.write("<body><h1>"+ ($(myClassID).parent().children('.price_title').html() ? $(myClassID).parent().children('.price_title').html() : '') + "</h1>" + $(".jtable_print_container").html() +"<br><input type='button' value='Печатать' onClick='print();'></html>");
			open_jtable_printWindow.document.close();

			return false;								  
						} });



}

$(document).ready(function(){
				
				$('.price_title').bind({
					   
					   click: function() 
					   		{
							$(this).parent().children('.price_out').slideToggle().css({'width': $('.price_title').width()+20 });   
					   		}
					   
					   });

$('.menuCon SPAN').last().addClass('last');

$('.usef_con').click( function(){ $('DIV', this).toggle(100); 

var checkArrow = $(this).hasClass('usef_con_down');

if(checkArrow == false)
{
$(this).addClass('usef_con_down');
}
else
{
$(this).removeClass('usef_con_down');
}
 });

if(location.hash)
{
var priceTab = location.hash;
$(priceTab).slideToggle().css({'width': $('.price_title').width()+20 });
}

$('.addReplies').bind({
					  click: function()
					  		{
							$.post('/replies/add_replies.html?template=80',{'my_sub':1},function(data){ $('.makeReview').prepend("<div class='addReplyCon'><h4>Добавить отзыв</h4>"+data+"</div>"); $('.addReplyCon').delay(50).fadeIn('fast'); $('.addReplyCon INPUT[type="submit"]').css({'width':120}); });
							return false;
							}
					  });

 });

