function displayblock(id) {
    
    $('#' + id).toggle();
    
    return;
    
} 

function ShowComments(ID)
{
	
		
	$('.HelloContent').hide();			
		
		$('.BlogItem').each(function (){
			$(this).hide();
		});
		


	$('#lContent'+ID).parent().show();	
	$('#lContent'+ID+'Full').show();
	$('#lContent'+ID+'Short').hide();
	$('#lContent'+ID+'Comments').show();
	
	
}

function BackBlogs()
{
	$('.HelloContent').show();	
	$('.BlogItem').each(function (){
			$(this).show();
		});
	
	$('.ShortContent').each(function (){
			$(this).show();
	});
	
	$('.FullContent').each(function (){
			$(this).hide();
	});
	
	$('.CommentList').each(function (){
			$(this).hide();
	});
		$('.BackLink').each(function (){
			$(this).hide();
	});
	
	$('.CommentsLinkZ').each(function (){
			$(this).show();
	});
	
	
	
	
	return false;
			
		
}
function ShowFull(ID)
{
	
	
	$('.HelloContent').hide();			
		
		$('.BlogItem').each(function (){
			$(this).hide();
		});
		
		
		
	$('#lContent'+ID+'BackLink').show();
	$('#lContent'+ID+'CommentsLinkZ').hide();
	$('#BlogItem'+ID).show();	
	$('#lContent'+ID+'Full').show();
	$('#lContent'+ID+'Short').hide();
	$('#lContent'+ID+'Comments').show();
	
	/*
		$('.HelloContent').hide();
	
		$('.FullContent').each(function (){
			$(this).hide();
		});
		
		
		$('.CommentList').each(function (){
			if( $(this).attr('id') != 'lContent'+ID+'Comments')
			{
				$(this).hide();
			}
		});
		
		
		$('.ShortContent').each(function (){
			$(this).show();
		});
		
	$('#lContent'+ID+'Short').hide();
	$('#lContent'+ID+'Full').slideDown('slow');
*/
	
	
}
function product_change_click(e) {
    
    var input = $(this).parents('tr').find('input[type=text]').get(0);
    
    var id, name;
    
    var part = parseInt($(input).attr('part'));
    var prid = parseInt($(input).attr('prid'));
    var calorie = parseInt($(input).attr('calorie'));
    var fat = parseInt($(input).attr('fat'));
    
    var value = parseInt($(input).val());
    
    if (part >= 0) {
        id = part + '-' + prid;
        name = part + '][' + prid;
    }
    else {
        id = prid;
        name = prid;
    }
    
    switch($(this).val()) {
        case '+':
            value += 1;
            break;
        case '-':
            if (value > 0) {
                value -= 1;
            }
            //$(this).parents('tr').replaceWith('');
            break;
        default:
            break;
    }
    
    $('input#quantity-' + id).val(value);
    $('span#calorie-' + id).html("" + (value * calorie));
    $('span#fat-' + id).html("" + (value * fat));
    
}



$(document).ready(
    
    function() {
		
		if ($('li').hasClass('MenuCurrent') == false && $('li').hasClass('LeftMenuLink') == false) 
		{		
			$('#SecondaryContentCentralDiv').css({'width': '750px'});
		}

			$('.Accordion a').click(function (){
										
										divID = 'ContentDiv'+$(this).attr('href').replace('http://www.slim.ru/?Module=pages&IdItem=', '');


										
										if($('#'+divID).html() == null)
										{
										$('.info').slideDown('fast', function(){
											
										$('.info').remove();	
										});
										 $(this).parent().append('<div class="info" style="display: none" id="'+ divID+'"><div>')
										 $('#'+divID).load($(this).attr('href') + ' .InnerContentHolder', function(){
																																			
																														$('#'+divID).fadeIn('slow');						
																																			});
										}
										/*
										else{
											if($('#'+divID).attr('style') == 'display: none;')
											{
												$('#'+divID).fadeIn('slow', function(){

																$('.info').each(function(){
																 if($(this).attr("id") != divID)
																 {
																 $(this).hide(); 
																 }
																 });
																					 
																					 });
											}
											else{
												
												
																$('.info').each(function(){
																 if($(this).attr("id") != divID)
																 {
																 $(this).hide(); 
																 }
																 });
											//	$('#'+divID).fadeOut('slow');
											}
											//$('#'+divID)
										}*/
										
										
										 return false;
										 
										 
										// $(this).attr(
										 // $(this).attr({'href' : 'javascript:void(0)'});
										  //console.log($(this).attr('href');
										
										  
							//	SecondaryContentCentralDiv		  
										  });	
		


        //$(document).pngFix({'blankgif':'/templates/user/img/blank.gif'});
		
        
        //$('a.product-add').parent().after('<div class="dn">' + $('#product-add').html() + '</div>');
        
        /*
        XBB.path = '/templates/user/js/bbcode';
        XBB.textarea_id = 'bbcode';
        XBB.area_width = '100%';
        XBB.area_height = '250px';
        XBB.state = 'plain';
        XBB.lang = 'ru_utf8';
        
        XBB.init();
        */
        
        /*tinyMCE.init({
	        theme : "advanced",
	        mode : "textareas",
	        plugins : "bbcode",
	        editor_selector : "tinymce",
	        theme_advanced_buttons1 : "bold,italic,underline,undo,redo,link,unlink,image,forecolor,styleselect,removeformat,cleanup,code",
	        theme_advanced_buttons2 : "",
	        theme_advanced_buttons3 : "",
	        theme_advanced_toolbar_location : "bottom",
	        theme_advanced_toolbar_align : "center",
	        theme_advanced_styles : "Code=codeStyle;Quote=quoteStyle",
	        //content_css : "bbcode.css",
	        entity_encoding : "raw",
	        add_unload_trigger : false,
	        remove_linebreaks : false
        });*/
        
        $('.datepicker').datepicker({'dateFormat':'yy-mm-dd','dayNamesMin':['Вс','Пн','Вт','Ср','Чт','Пт','Сб'],'firstDay':1,'monthNames':['Январь','Февраль','Март','Апрель','Май','Июнь','Июль','Август','Сентябрь','Октябрь','Ноябрь','Декабрь']});
        
        $('#block-r-slim-club').click(
									  
									
            function() {
				/*
                if ($('#block-r-login').size()) {
                    $('#block-r-login').toggle();
                    //$('#block-r-login:visible').animate({'opacity':'hide'}, 'slow');
                    //$('#block-r-login:hidden').animate({'opacity':'show'}, 'slow');
                    return false;
                }}*/
				if ($('#block-r-login').attr('style') == 'display: block;')
				{
					$('#block-r-login').hide();
				}
				else{
					$('#block-r-login').fadeIn('slow');
				}
	}
               
            
        );
        
        $('a.product-add').click(
            function() {
                $(this).parent().nextAll('div').toggle();
                return false;
            }
        );
        
        $('.item-name').click(
            function() {
                $(this).parent().toggleClass('selected');
            }
        );
        
        $('a.toggle').click(
            function() {
                $(this).parents('p').nextAll().toggle();
                return false;
            }
        );
        
		if (FlashDetect.minorAtLeast(0) == true)
		{
					
	       // $('#logo').flashembed({'src':'/templates/user/img/logo_new.swf', 'width':'220', 'height':'130', 'wmode':'transparent', 'version':[9,0]});
		
			$('#colaj').flashembed({'src':'/colaje.swf', 'width':'1000', 'height':'280', 'wmode':'transparent', 'version':[9,0]});
			
			//$('#colaj').flashembed({'src':'/spring_high.swf', 'width':'1000', 'height':'372', 'wmode':'transparent', 'version':[9,0]});
		}
		
        
     
        
        $('.scrollable').scrollable({'size':4,'nextPage':'.news-next','prevPage':'.news-prev','clickable':false,'speed':1000});
        
        $('input[name=product-add]').click(
            
            function() {
                
                var select = $(this).parents('.item-items').find('select').get(0);
                
                if (select == null) {
                    return false;
                }
                
                var option = select.options[select.selectedIndex];
                
                if (option == null) {
                    return false;
                }
                
                var id, name;
                
                var part = parseInt($(option).attr('part'));
                var prid = parseInt($(option).attr('prid'));
                var calorie = parseInt($(option).attr('calorie'));
                var fat = parseInt($(option).attr('fat'));
                
                if (part >= 0) {
                    id = part + '-' + prid;
                    name = part + '][' + prid;
                }
                else {
                    id = prid;
                    name = prid;
                }
                
                var value = 1;
                
                if ($('input#quantity-' + id).size()) {
                    value = parseInt($('input#quantity-' + id).val()) + 1;
                    $('input#quantity-' + id).val(value);
                    $('span#calorie-' + id).html("" + (value * calorie));
                    $('span#fat-' + id).html("" + (value * fat));
                }
                else {
                    $(this).parents('.products').parent().find('.calorie tr:first').after('<tr><td width="40%">' + $(select).val() + '</td><td>&nbsp;</td><td nowrap="nowrap"><img src="/templates/user/img/button-side.gif" width="1" height="20" border="0" alt="" align="top" /><input type="button" value="-" name="product-edit" class="form-button" /><img src="/templates/user/img/button-side.gif" width="1" height="20" border="0" alt="" align="top" /></td><td><input type="text" id="quantity-' + id + '" name="quantity[' + name + ']" prid="' + prid + '" part="' + part + '" calorie="' + calorie + '" fat="' + fat + '" readonly="readonly" value="' + value + '" size="2" style="text-align:center;" /></td><td nowrap="nowrap"><img src="/templates/user/img/button-side.gif" width="1" height="20" border="0" alt="" align="top" /><input type="button" value="+" name="product-edit" class="form-button" /><img src="/templates/user/img/button-side.gif" width="1" height="20" border="0" alt="" align="top" /></td><td>&nbsp;</td><td width="60%">' + $(option).attr('metage') + ', <span id="calorie-' + id + '">' + $(option).attr('calorie') + '</span> ккал <span id="fat-' + id + '">' + $(option).attr('fat') + '</span> г. жира</td></tr>');
                }
                
                $('input[name=product-edit]').bind('click', product_change_click);
                
            }
            
        );
        
        $('input[name=product-edit]').bind('click', product_change_click);
        
        $('#search-in-input input').each(
            function() {
                $(this).attr('default', $(this).val());
            }
        );
        
        $('#search-in-input input').focus(
            function() {
                if ($(this).val() == $(this).attr('default')) {
                    $(this).val('');
                }
            }
        );

        $('#search-in-input input').blur(
            function() {
                if ($(this).val() == '') {
                    $(this).val($(this).attr('default'));
                }
            }
        );  

      


        $('#block-r-search input').each(
            function() {
                $(this).attr('default', $(this).val());
            }
        );
        
        $('#block-r-search input').focus(
            function() {
                if ($(this).val() == $(this).attr('default')) {
                    $(this).val('');
                }
            }
        );

        $('#block-r-search input').blur(
            function() {
                if ($(this).val() == '') {
                    $(this).val($(this).attr('default'));
                }
            }
        );  

        

        $('#newreply').submit(
            function() {
                var val = $(this).find('textarea[name=message]').val();
                $('#forum-frame').load(
                    function() {
                        if (this.contentDocument && this.contentDocument.location.href.match(/showthread/g)) {
                            $('#newreply-success').show();
                            $('#newreply-submit').hide();
                            $('#newreply-success-link').attr('href', this.contentDocument.location.href);
                        }
                    }
                );
                $('#forum-frame').contents().find('form[name=vbform]').each(
                    function() {
                        $(this).find('textarea[name=message]').val(val);
                        $(this).submit();
                    }
                );
                return false;
            }
        );
        
    }
    
);




function Set_Cookie( name, value, expires, path, domain, secure )
{
// set time, it's in milliseconds
var today = new Date();
today.setTime( today.getTime() );

/*
if the expires variable is set, make the correct
expires time, the current script below will set
it for x number of days, to make it for hours,
delete * 24, for minutes, delete * 60 * 24
*/
if ( expires )
{
expires = expires * 1000 * 60 * 60 * 24;
}
var expires_date = new Date( today.getTime() + (expires) );

document.cookie = name + "=" +escape( value ) +
( ( expires ) ? ";expires=" + expires_date.toGMTString() : "" ) +
( ( path ) ? ";path=" + path : "" ) +
( ( domain ) ? ";domain=" + domain : "" ) +
( ( secure ) ? ";secure" : "" );
}


function Delete_Cookie( name, path, domain ) {
if ( Get_Cookie( name ) ) document.cookie = name + "=" +
( ( path ) ? ";path=" + path : "") +
( ( domain ) ? ";domain=" + domain : "" ) +
";expires=Thu, 01-Jan-1970 00:00:01 GMT";
}

