//--- SERG ---
jQuery.cookie = function(name, value, options) {
    if (typeof value != 'undefined') {
        options = options || {};
        if (value === null) {
            value = '';
            options.expires = -1;
        }
        var expires = '';
        if (options.expires && (typeof options.expires == 'number' || options.expires.toUTCString)) {
            var date;
            if (typeof options.expires == 'number') {
                date = new Date();
                date.setTime(date.getTime() + (options.expires * 24 * 60 * 60 * 1000));
            } else {
                date = options.expires;
            }
            expires = '; expires=' + date.toUTCString();
        }
        var path = options.path ? '; path=' + (options.path) : '';
        var domain = options.domain ? '; domain=' + (options.domain) : '';
        var secure = options.secure ? '; secure' : '';
        document.cookie = [name, '=', encodeURIComponent(value), expires, path, domain, secure].join('');
    } else {
        var cookieValue = null;
        if (document.cookie && document.cookie != '') {
            var cookies = document.cookie.split(';');
            for (var i = 0; i < cookies.length; i++) {
                var cookie = jQuery.trim(cookies[i]);
                if (cookie.substring(0, name.length + 1) == (name + '=')) {
                    cookieValue = decodeURIComponent(cookie.substring(name.length + 1));
                    break;
                }
            }
        }
        return cookieValue;
    }
};
//--- /SERG ---

$(document).ready(function(){
		$(".mark-list .a-show-all").click(
			function(){
				$(".mark-list").toggleClass("show-all");
				return false;
			}
		);
		$(".marka-cars .a-show-all").click(
			function(){$(".marka-cars").toggleClass("show-all");return false;}
		);

		$(".copy-to-block .a-show-all").click(
			function(){$(".copy-to-block").toggleClass("show-all");return false;}
		);
		$(".comments .a-show-all").click(
//--- SERG ---
//			function(){$(".comments").toggleClass("show-all");return false;}
			function(){$(".comments").toggleClass("show-all"); $.cookie ('showComments', $('.comments').hasClass ('show-all') ? 1 : 0); return false;}
//--- /SERG ---
		);
		$(".add-msg .a-add").click(
//--- SERG ---
//			function(){$(".add-msg").toggleClass("show-all");return false;}
			function(){$(".add-msg").toggleClass("show-all"); $.cookie ('showForm', $('.add-msg').hasClass ('show-all') ? 1 : 0); return false;}
//--- /SERG ---
		);

//--- SERG ---
	   	if ($.cookie ('showComments') == 1) $(".comments .a-show-all").click();
	   	if ($.cookie ('showForm') == 1) $(".add-msg .a-add").click();
//--- /SERG ---

		$('dl.tabs dt').click(function(){
		$(this).siblings().removeClass('selected').end().next('dd').andSelf().addClass('selected');
		});

//--- SERG ---
//   $(".show-register").click(function(){  
//   		$(".pelena").fadeIn();
//      $("#login").fadeOut();
//      $("#register").fadeIn();  
//      return false;  
//   });
	$('.show-register').bind ('click', showRegister);
//--- /SERG ---
   $("#register .close").click(function(){  
//--- SERG ---
	if ($('.add-msg').hasClass ('show-all'))
		$('.add-msg .a-add').click ();
//--- /SERG ---
      $("#register").fadeOut();  
   		$(".pelena").fadeOut();
      return false;  
   });  
//--- SERG ---
//   $(".show-login").click(function(){  
//   		$(".pelena").fadeIn();
//      $("#login").fadeIn();  
//      return false;  
//   });  
	$('.show-login').bind ('click', showLogin);
//--- /SERG ---
   $("#login .close").click(function(){
//--- SERG ---
	if ($('.add-msg').hasClass ('show-all'))
		$('.add-msg .a-add').click ();
//--- /SERG ---
      $("#login").fadeOut();  
   		$(".pelena").fadeOut();
      return false;  
   });
   	
   $(".show-options").click(function(){  
   		$(".pelena").fadeIn();
      $("#options").fadeIn();  
      return false;  
   });  
   $("#options .close").click(function(){  
      $("#options").fadeOut();  
   		$(".pelena").fadeOut();
      return false;  
   });
   $("#options .a-btn").click(function(){  
      $("#options").fadeOut();  
   		$(".pelena").fadeOut();
      return false;  
   }); 

   if ($("#textareaFull").length) {
			$("#textareaFull").wysiwyg({			
				controls : {
				bold : { visible : true, tags : ["b", "strong"], css : { fontWeight : "bold" } },
				italic : { visible : true, tags : ["i", "em"], css : { fontStyle : "italic" } },
				strikeThrough : { visible : true },
				underline : { visible : true },
				separator00 : { visible : true },
				justifyLeft : { visible : true },
				justifyCenter : { visible : true },
				justifyRight : { visible : true},
				justifyFull : { visible : true },
				separator01 : { visible : true},
				indent : { visible : true },
				outdent : { visible : true },
				separator02 : { visible : true },
				subscript : { visible : true },
				separator03 : { visible : true },
				undo : { visible : true },
				redo : { visible : true }
			}
			});
	};

   	if ($(".rating").length) {$(".rating").rating('www.url.php', {maxvalue:5, curvalue:3});  }
		
	  if ( $('#trackbar').length){
	   $('#trackbar').trackbar({
			onMove : function() {
				$('.trackbar #leftBlock span').prepend('РѕС‚&nbsp;');
				$('.trackbar #rightBlock span').prepend('РґРѕ&nbsp;');
			},
			width : 424, // px
			leftLimit : 0, // unit of value
			leftValue : 200000, // unit of value
			rightLimit : 3000000, // unit of value
			rightValue : 850000 // unit of value
		});
		}
			if ($('.slide').length){	    
	    $('.slide').slideShow({
	        slideEl:'div.img-holder img',
	        linkNext:'a.next',
	        linkPrev:'a.prev',
	        linkPause:'a.play',
	    		numElementLink:'.med a',		
	        duration:500,
	        autoSlideShow:false,
	        switchTime:3000,
	        event:'click',
	        currentEl:'span.current',
	        allEl:'span.all'
	    });
	   	}
	});
//--- SERG ---
function showLogin () {
	$(".pelena").fadeIn();
	$("#login").fadeIn();  
	return false;  
}

function showRegister () {
	$(".pelena").fadeIn();
	$("#login").fadeOut();
	$("#register").fadeIn();  
}

function redirect (u) {
	var pos, url = u ? u : document.location.href;
	if ((pos = url.indexOf ('#')) >= 0) url = url.substr (0, pos);
	if ((pos = url.indexOf ('?tm=')) >= 0) url = url.substr (0, pos);
	document.location = url + '?tm=' + (new Date).getTime ();
}
//--- /SERG ---