/*
 * tools.tabs 1.0.2 - Tabs done right.
 * 
 * Copyright (c) 2009 Tero Piirainen
 * http://flowplayer.org/tools/tabs.html
 *
 * Dual licensed under MIT and GPL 2+ licenses
 * http://www.opensource.org/licenses
 *
 * Launch  : November 2008
 * Date: ${date}
 * Revision: ${revision} 
 */
(function(d){d.tools=d.tools||{};d.tools.tabs={version:"1.0.2",conf:{tabs:"a",current:"current",onBeforeClick:null,onClick:null,effect:"default",initialIndex:0,event:"click",api:false,rotate:false},addEffect:function(e,f){c[e]=f}};var c={"default":function(f,e){this.getPanes().hide().eq(f).show();e.call()},fade:function(g,e){var f=this.getConf(),h=f.fadeOutSpeed,j=this.getCurrentPane();if(h){j.fadeOut(h)}else{j.hide()}this.getPanes().eq(g).fadeIn(f.fadeInSpeed,e)},slide:function(f,e){this.getCurrentPane().slideUp(200);this.getPanes().eq(f).slideDown(400,e)},ajax:function(f,e){this.getPanes().eq(0).load(this.getTabs().eq(f).attr("href"),e)}};var b;d.tools.tabs.addEffect("horizontal",function(f,e){if(!b){b=this.getPanes().eq(0).width()}this.getCurrentPane().animate({width:0},function(){d(this).hide()});this.getPanes().eq(f).animate({width:b},function(){d(this).show();e.call()})});function a(f,g,h){var e=this,i;function j(k,l){d(e).bind(k,function(n,m){if(l&&l.call(this,m.index)===false&&m){m.proceed=false}});return e}d.each(h,function(k,l){if(d.isFunction(l)){j(k,l)}});d.extend(this,{click:function(l){var o=e.getCurrentPane();var m=f.eq(l);if(typeof l=="string"&&l.replace("#","")){m=f.filter("[href*="+l.replace("#","")+"]");l=Math.max(f.index(m),0)}if(h.rotate){var n=f.length-1;if(l<0){return e.click(n)}if(l>n){return e.click(0)}}if(!m.length){if(i>=0){return e}l=h.initialIndex;m=f.eq(l)}var k={index:l,proceed:true};d(e).triggerHandler("onBeforeClick",k);if(!k.proceed){return e}if(l===i){return e}m.addClass(h.current);c[h.effect].call(e,l,function(){d(e).triggerHandler("onClick",k)});f.removeClass(h.current);m.addClass(h.current);i=l;return e},getConf:function(){return h},getTabs:function(){return f},getPanes:function(){return g},getCurrentPane:function(){return g.eq(i)},getCurrentTab:function(){return f.eq(i)},getIndex:function(){return i},next:function(){return e.click(i+1)},prev:function(){return e.click(i-1)},onBeforeClick:function(k){return j("onBeforeClick",k)},onClick:function(k){return j("onClick",k)}});f.each(function(k){d(this).bind(h.event,function(l){e.click(k);return l.preventDefault()})});if(location.hash){e.click(location.hash)}else{e.click(h.initialIndex)}g.find("a[href^=#]").click(function(){e.click(d(this).attr("href"))})}d.fn.tabs=function(i,f){var g=this.eq(typeof f=="number"?f:0).data("tabs");if(g){return g}var h=d.extend({},d.tools.tabs.conf),e=this.length;d.extend(h,f);if(d.isFunction(f)){f={onBeforeClick:f}}d.extend(h,f);this.each(function(l){var j=d(this);var k=j.find(h.tabs);if(!k.length){k=j.children()}var m=j.children(i);if(!m.length){m=e==1?d(i):j.parent().find(i)}g=new a(k,m,h);j.data("tabs",g)});return h.api?g:this}})(jQuery);

/* -------------------------------------------------- *
 * Tooltip
** -------------------------------------------------- */

;function simple_tooltip(target_items,name){
$(target_items).each(function(i){$("body").append("<div class='"+name+"' id='"+name+i+"'><iframe src='about:blank' scrolling='no' frameborder='0' class='f-frame'></iframe><div><p>"+$(this).attr('title')+"</p></div><i></i></div>");var my_tooltip=$("#"+name+i);$(this).removeAttr("title").mouseover(function(){my_tooltip.css({display:"block"});}).mousemove(function(kmouse){
offPage = 0;
if(kmouse.pageX+my_tooltip.width() > $(window).width()) {
	offPage = my_tooltip.width();
}
else {
	offPage = 0;
}
my_tooltip.css({left:kmouse.pageX-offPage+10,top:kmouse.pageY+10});}).mouseout(function(){my_tooltip.hide();});});}

/*
 * Alternate Select Multiple (asmSelect) 1.0.4a beta - jQuery Plugin
 * http://www.ryancramer.com/projects/asmselect/
 * 
 * Copyright (c) 2009 by Ryan Cramer - http://www.ryancramer.com
 * 
 * Dual licensed under the MIT (MIT-LICENSE.txt)
 * and GPL (GPL-LICENSE.txt) licenses.
 *
 */

(function($) {

	$.fn.asmSelect = function(customOptions) {

		var options = {

			listType: 'ol',						// Ordered list 'ol', or unordered list 'ul'
			sortable: false, 					// Should the list be sortable?
			highlight: false,					// Use the highlight feature? 
			animate: false,						// Animate the the adding/removing of items in the list?
			addItemTarget: 'bottom',				// Where to place new selected items in list: top or bottom
			hideWhenAdded: false,					// Hide the option when added to the list? works only in FF
			debugMode: false,					// Debug mode keeps original select visible 

			removeLabel: 'remove',					// Text used in the "remove" link
			highlightAddedLabel: 'Added: ',				// Text that precedes highlight of added item
			highlightRemovedLabel: 'Removed: ',			// Text that precedes highlight of removed item

			containerClass: 'asmContainer',				// Class for container that wraps this widget
			selectClass: 'asmSelect',				// Class for the newly created <select>
			optionDisabledClass: 'asmOptionDisabled',		// Class for items that are already selected / disabled
			listClass: 'asmList',					// Class for the list ($ol)
			listSortableClass: 'asmListSortable',			// Another class given to the list when it is sortable
			listItemClass: 'asmListItem',				// Class for the <li> list items
			listItemLabelClass: 'asmListItemLabel',			// Class for the label text that appears in list items
			removeClass: 'asmListItemRemove',			// Class given to the "remove" link
			highlightClass: 'asmHighlight'				// Class given to the highlight <span>

			};

		$.extend(options, customOptions); 

		return this.each(function(index) {

			var $original = $(this); 				// the original select multiple
			var $container; 					// a container that is wrapped around our widget
			var $select; 						// the new select we have created
			var $ol; 						// the list that we are manipulating
			var buildingSelect = false; 				// is the new select being constructed right now?
			var ieClick = false;					// in IE, has a click event occurred? ignore if not
			var ignoreOriginalChangeEvent = false;			// originalChangeEvent bypassed when this is true

			function init() {

				// initialize the alternate select multiple

				// this loop ensures uniqueness, in case of existing asmSelects placed by ajax (1.0.3)
				while($("#" + options.containerClass + index).size() > 0) index++; 

				$select = $("<select></select>")
					.addClass(options.selectClass)
					.attr('name', options.selectClass + index)
					.attr('id', options.selectClass + index); 

				$selectRemoved = $("<select></select>"); 

				$ol = $("<" + options.listType + "></" + options.listType + ">")
					.addClass(options.listClass)
					.attr('id', options.listClass + index)
					.hide();

				$container = $("<div></div>")
					.addClass(options.containerClass) 
					.attr('id', options.containerClass + index); 

				buildSelect();

				$select.change(selectChangeEvent)
					.click(selectClickEvent); 

				$original.change(originalChangeEvent)
					.wrap($container).before($select).before($ol);

				if(options.sortable) makeSortable();

				// if($.browser.msie && $.browser.version < 8) $ol.css('display', 'inline-block'); // Thanks Matthew Hutton
			}

			function makeSortable() {

				// make any items in the selected list sortable
				// requires jQuery UI sortables, draggables, droppables

				$ol.sortable({
					items: 'li.' + options.listItemClass,
					handle: '.' + options.listItemLabelClass,
					axis: 'y',
					update: function(e, data) {

						var updatedOptionId;

						$(this).children("li").each(function(n) {

							$option = $('#' + $(this).attr('rel')); 

							if($(this).is(".ui-sortable-helper")) {
								updatedOptionId = $option.attr('id'); 
								return;
							}

							$original.append($option); 
						}); 

						if(updatedOptionId) triggerOriginalChange(updatedOptionId, 'sort'); 
					}

				}).addClass(options.listSortableClass); 
			}

			function selectChangeEvent(e) {

				// an item has been selected on the regular select we created
				// check to make sure it's not an IE screwup, and add it to the list

				if($.browser.msie && $.browser.version < 7 && !ieClick) return;
				var id = $(this).children("option:selected").slice(0,1).attr('rel'); 
				addListItem(id); 	
				ieClick = false; 
				triggerOriginalChange(id, 'add'); // for use by user-defined callbacks
			}

			function selectClickEvent() {

				// IE6 lets you scroll around in a select without it being pulled down
				// making sure a click preceded the change() event reduces the chance
				// if unintended items being added. there may be a better solution?

				ieClick = true; 
			}

			function originalChangeEvent(e) {

				// select or option change event manually triggered
				// on the original <select multiple>, so rebuild ours

				if(ignoreOriginalChangeEvent) {
					ignoreOriginalChangeEvent = false; 
					return; 
				}

				$select.empty();
				$ol.hide().empty();
				buildSelect();

				// opera has an issue where it needs a force redraw, otherwise
				// the items won't appear until something else forces a redraw
				if($.browser.opera) $ol.hide().fadeIn("fast");
			}

			function buildSelect() {

				// build or rebuild the new select that the user
				// will select items from

				buildingSelect = true; 

				// add a first option to be the home option / default selectLabel
				$select.prepend("<option>" + $original.attr('title') + "</option>"); 

				$original.children("option").each(function(n) {

					var $t = $(this); 
					var id; 

					if(!$t.attr('id')) $t.attr('id', 'asm' + index + 'option' + n); 
					id = $t.attr('id'); 

					if($t.is(":selected")) {
						addListItem(id); 
						addSelectOption(id, true); 						
					} else {
						addSelectOption(id); 
					}
				});

				if(!options.debugMode) $original.hide(); // IE6 requires this on every buildSelect()
				selectFirstItem();
				buildingSelect = false; 
			}

			function addSelectOption(optionId, disabled) {

				// add an <option> to the <select>
				// used only by buildSelect()

				if(disabled == undefined) var disabled = false; 

				var $O = $('#' + optionId); 
				var $option = $("<option>" + $O.text() + "</option>")
					.val($O.val())
					.attr('rel', optionId);

				if(disabled) disableSelectOption($option); 

				$select.append($option); 
			}

			function selectFirstItem() {

				// select the firm item from the regular select that we created

				$select.children(":eq(0)").attr("selected", true); 
			}

			function disableSelectOption($option) {

				// make an option disabled, indicating that it's already been selected
				// because safari is the only browser that makes disabled items look 'disabled'
				// we apply a class that reproduces the disabled look in other browsers

				$option.addClass(options.optionDisabledClass)
					.attr("selected", false)
					.attr("disabled", true);

				if(options.hideWhenAdded) $option.hide();
				if($.browser.msie) $select.hide().show(); // this forces IE to update display
			}

			function enableSelectOption($option) {

				// given an already disabled select option, enable it

				$option.removeClass(options.optionDisabledClass)
					.attr("disabled", false);

				if(options.hideWhenAdded) $option.show();
				if($.browser.msie) $select.hide().show(); // this forces IE to update display
			}

			function addListItem(optionId) {

				// add a new item to the html list

				var $O = $('#' + optionId); 

				if(!$O) return; // this is the first item, selectLabel

				var $removeLink = $("<a></a>")
					.attr("href", "#")
					.addClass(options.removeClass)
					.prepend(options.removeLabel)
					.click(function() { 
						dropListItem($(this).parent('li').attr('rel')); 
						return false; 
					}); 

				var $itemLabel = $("<span></span>")
					.addClass(options.listItemLabelClass)
					.html($O.html()); 

				var $item = $("<li></li>")
					.attr('rel', optionId)
					.addClass(options.listItemClass)
					.append($itemLabel)
					.append($removeLink)
					.hide();

				if(!buildingSelect) {
					if($O.is(":selected")) return; // already have it
					$O.attr('selected', true); 
				}

				if(options.addItemTarget == 'top' && !buildingSelect) {
					$ol.show().prepend($item); 
					if(options.sortable) $original.prepend($O); 
				} else {
					$ol.show().append($item); 
					if(options.sortable) $original.append($O); 
				}

				addListItemShow($item); 

				disableSelectOption($("[rel=" + optionId + "]", $select));

				if(!buildingSelect) {
					setHighlight($item, options.highlightAddedLabel); 
					selectFirstItem();
					if(options.sortable) $ol.sortable("refresh"); 	
				}

			}

			function addListItemShow($item) {

				// reveal the currently hidden item with optional animation
				// used only by addListItem()

				if(options.animate && !buildingSelect) {
					$item.animate({
						opacity: "show",
						height: "show"
					}, 100, "swing", function() { 
						$item.animate({
							height: "+=2px"
						}, 50, "swing", function() {
							$item.animate({
								height: "-=2px"
							}, 25, "swing"); 
						}); 
					}); 
				} else {
					$item.show();
				}
			}

			function dropListItem(optionId, highlightItem) {

				// remove an item from the html list
				
				if($ol.find('li').length === 1){
					$ol.hide()
				}

				if(highlightItem == undefined) var highlightItem = true; 
				var $O = $('#' + optionId); 

				$O.attr('selected', false); 
				$item = $ol.children("li[rel=" + optionId + "]");

				dropListItemHide($item); 
				enableSelectOption($("[rel=" + optionId + "]", options.removeWhenAdded ? $selectRemoved : $select));

				if(highlightItem) setHighlight($item, options.highlightRemovedLabel); 

				triggerOriginalChange(optionId, 'drop'); 

			}

			function dropListItemHide($item) {

				// remove the currently visible item with optional animation
				// used only by dropListItem()
				

				if(options.animate && !buildingSelect) {

					$prevItem = $item.prev("li");

					$item.animate({
						opacity: "hide",
						height: "hide"
					}, 100, "linear", function() {
						$prevItem.animate({
							height: "-=2px"
						}, 50, "swing", function() {
							$prevItem.animate({
								height: "+=2px"
							}, 100, "swing"); 
						}); 
						$item.remove(); 
					}); 

				} else {
					$item.remove();
				}
			}

			function setHighlight($item, label) {

				// set the contents of the highlight area that appears
				// directly after the <select> single
				// fade it in quickly, then fade it out

				if(!options.highlight) return; 

				$select.next("#" + options.highlightClass + index).remove();

				var $highlight = $("<span></span>")
					.hide()
					.addClass(options.highlightClass)
					.attr('id', options.highlightClass + index)
					.html(label + $item.children("." + options.listItemLabelClass).slice(0,1).text()); 

				$select.after($highlight); 

				$highlight.fadeIn("fast", function() {
					setTimeout(function() { $highlight.fadeOut("slow"); }, 50); 
				}); 
			}

			function triggerOriginalChange(optionId, type) {

				// trigger a change event on the original select multiple
				// so that other scripts can pick them up

				ignoreOriginalChangeEvent = true; 
				$option = $("#" + optionId); 

				$original.trigger('change', [{
					'option': $option,
					'value': $option.val(),
					'id': optionId,
					'item': $ol.children("[rel=" + optionId + "]"),
					'type': type
				}]); 
			}

			init();
		});
	};

})(jQuery);

function css_browser_selector(u){var ua = u.toLowerCase(),is=function(t){return ua.indexOf(t)>-1;},g='gecko',w='webkit',s='safari',o='opera',h=document.getElementsByTagName('html')[0],b=[(!(/opera|webtv/i.test(ua))&&/msie\s(\d)/.test(ua))?('ie ie'+RegExp.$1):is('firefox/2')?g+' ff2':is('firefox/3.5')?g+' ff3 ff3_5':is('firefox/3')?g+' ff3':is('gecko/')?g:is('opera')?o+(/version\/(\d+)/.test(ua)?' '+o+RegExp.$1:(/opera(\s|\/)(\d+)/.test(ua)?' '+o+RegExp.$2:'')):is('konqueror')?'konqueror':is('chrome')?w+' chrome':is('iron')?w+' iron':is('applewebkit/')?w+' '+s+(/version\/(\d+)/.test(ua)?' '+s+RegExp.$1:''):is('mozilla/')?g:'',is('j2me')?'mobile':is('iphone')?'iphone':is('ipod')?'ipod':is('mac')?'mac':is('darwin')?'mac':is('webtv')?'webtv':is('win')?'win':is('freebsd')?'freebsd':(is('x11')||is('linux'))?'linux':'','js']; c = b.join(' '); h.className += ' '+c; return c;}; css_browser_selector(navigator.userAgent);

$(function () {
    if (!$.browser.msie || ($.browser.msie && $.browser.version.substr(0, 1) != '6'))
        $('.b-search .btn,.loginbar .btn, .btn input, td>input.btn').hover(function () { $(this).addClass('hovered') }, function () { $(this).removeClass('hovered').removeClass('mousedown') }).mousedown(function () { $(this).addClass('mousedown') }).mouseup(function () { $(this).removeClass('mousedown') });

    if ($('#table-view').size() > 0) {
        function tableview() {
            var wi = $('#table-view').width();
            var col = parseInt(wi / 179);
            col > 5 ? (col = 5) : (col = col);
            var size = $('#table-view .item').size();
            var left = size % col; //- (col > 3 ? col : 5 - col);
            $('#table-view.disks .noborder').removeClass('noborder');
            if (col == size)
            { $('#table-view.disks .item').addClass('noborder'); }
            else {
                var lastindex = 0;
                if (left == 0)
                    lastindex = size - col - 1;
                else lastindex = size - left - 1;
                $('#table-view.disks .item:gt(' + lastindex + ')').addClass('noborder');
            }
            var ww = parseInt(wi / col - 3);

            //$('#table-view.disks .item:gt(' + left + ')').addClass('noborder');
            $('#table-view .it,#table-view .item,#table-view .em-hover').css('width', ww + 'px');
        } tableview();
        $(window).resize(function () { tableview() });
    }
    $('#tabsbar #block1 .b2').click(function () {
        $('#pricebar .art a').addClass('act');
        $('ul.names').find('.active').removeClass('active');
        $('ul.names').find('a[href=#block2]').parent().addClass('active');
        $('#block1').hide();
        $('#block2').show();
        return false
    });

    $('#tabsbar .names a').click(function () {
        if (!$(this).parent().hasClass('active')) {
            if ($(this).attr('href') == '#block1') { $('#fromsellers').addClass('act') } else { $('#fromsellers').removeClass('act') }
            if ($(this).attr('href') == '#block2') { $('#pricebar .art a').addClass('act') } else { $('#pricebar .art a').removeClass('act') }
            opentab($(this).attr('href'), $(this));
        }
        return false
    });
    function opentab(id, el) {
        if (arguments.length > 1) {
            $('ul.names').find('.active').removeClass('active');
            el.parent().addClass('active').parent().parent().children('div').hide();
            $(id).show();
        }
        else {
            $('ul.names').find('.active').removeClass('active').end().parent().children('div').hide();
            $('ul.names').find('a[href=' + id + ']').parent().addClass('active');
            $(id).show();
        }
    }
    $('#fromsellers').click(function () {
        $(this).addClass('act'); $('#pricebar .art a').removeClass('act');
        opentab('#block1');
        return false
    });
    $('#pricebar .art a').click(function () {
        $(this).addClass('act'); $('#fromsellers').removeClass('act')
        opentab('#block2');
        return false
    });
    $('td.order a').mouseleave(function () { $(this).removeClass('down') }).mousedown(function () { $(this).addClass('down') }).mouseup(function () { $(this).removeClass('down') });

    function mousePageXY(e) {
        var x = 0, y = 0;
        if (!e) e = window.event;
        if (e.pageX || e.pageY) {
            x = e.pageX;
            y = e.pageY;
        }
        else if (e.clientX || e.clientY) {
            x = e.clientX + (document.documentElement.scrollLeft || document.body.scrollLeft) - document.documentElement.clientLeft;
            y = e.clientY + (document.documentElement.scrollTop || document.body.scrollTop) - document.documentElement.clientTop;
        }
        return { "x": x, "y": y };
    }
    $('#block1 .pay img').hover(function () {
        $('<div id="toolt">' + $(this).attr('alt') + '</div>').appendTo('body');
        $(document).bind('mousemove', function (e) {
            var pos = mousePageXY(e);
            $('#toolt').css('left', pos.x + 12 + 'px').css('top', pos.y + 3 + 'px');
        });
    }, function () {
        $('#toolt').remove();
        $(document).unbind('mousemove');
    });

    if ($('#modelbar').size() > 0) {
        if ($('body').width() > 1002) { $('body').addClass('bodybig') } else { $('body').removeClass('bodybig') }
        $(window).resize(function () {
            if ($('body').width() > 1002) { $('body').addClass('bodybig') } else { $('body').removeClass('bodybig') }
        });
    }

    $('#dsize tr.ln').hover(function () { $(this).addClass('hovered') }, function () { $(this).removeClass('hovered') });

    $('.disks .item:not(".hovered")').mouseenter(function () {
        $(this).clone().addClass('hovered').prependTo($(this)); hovered();
    }).mouseleave(function () {
        $(this).find('.item').remove();
    });

    function hovered() {
        $('.item.hovered').add($('.item.hovered').find('.it,.em-hover')).animate({ "width": "+=40px" }, 0).end().css('margin-left', '-20px');
        $('.item.hovered').mouseleave(function () {
            $(this).remove();
        });
    }

    $('.seldrop').mouseleave(function () {
        $(this).hide();
    }).find('a').click(function () {
        var value = $(this).attr('rel');
        var txt = $(this).text();
        var $im = $(this).find('img').clone();

        $(this).parent().prev().find('div').text(txt).prepend($im);
        $('#color').val(value);
        $(this).parent().hide();

        return false
    });
    $('.selbar').click(function () {
        $(this).next().show();
        return false
    });

    if ($('div.b-site-map').size() > 0) {
        function mapsort() {
            var par = '#' + $('div.mapbar .show-on .active').attr('rel') + ' ';
            $(par + 'div.b-site-map').clone().hide().appendTo(par);
            $(par + 'div.b-site-map:first').show();
            var xx = $(par + 'div.b-site-map:first').width();
            var col = parseInt(xx / 220);
            $(par + 'div.b-site-map:first >.item').each(function () {
                var el = $(this);
                var array = $(this).find('li');
                var inone = Math.ceil(array.size() / col);
                for (var i = 0; i < array.size(); i += inone) {
                    var push = $('<ul></ul>');
                    for (var j = i; j < i + inone; j++) {
                        push.append(array.eq(j));
                    }
                    push.appendTo(el);
                }
            }).find('ul:first').remove();
        }
        mapsort();
        var timer;
        $(window).resize(function () {
            clearTimeout(timer);
            timer = setTimeout(function () {
                var par = '#' + $('div.mapbar .show-on .active').attr('rel') + ' ';
                $(par + 'div.b-site-map:first').remove();
                mapsort();
            }, 200);
        });
    }

    if ($('#lefttime').size() > 0) {
        function ProcessDays(digit) {
            digit = ProcessDigits(digit);
            var textelement = $('.timeleft').find('#daystext');
            switch (digit) {
                case 0:
                    textelement.text("дней");
                    break;
                case 1:
                    textelement.text("день");
                    break;
                case 2:
                    textelement.text("дня");
                    break;
                default:
                    textelement.text("дней");
            }
        }

        function ProcessHours(digit) {
            digit = ProcessDigits(digit);
            var textelement = $('.timeleft').find('#hourtext');
            switch (digit) {
                case 0:
                    textelement.text("часов");
                    break;
                case 1:
                    textelement.text("час");
                    break;
                case 2:
                    textelement.text("часа");
                    break;
                default:
                    textelement.text("часов");
            }
        }

        function ProcessMinutes(digit) {
            digit = ProcessDigits(digit);
            var textelement = $('.timeleft').find('#minutestext');
            switch (digit) {
                case 0:
                    textelement.text("минут");
                    break;
                case 1:
                    textelement.text("минута");
                    break;
                case 2:
                    textelement.text("минуты");
                    break;
                default:
                    textelement.text("минут");
            }
        }

        function ProcessSeconds(digit) {
            digit = ProcessDigits(digit);
            var textelement = $('.timeleft').find('#secondtext');
            switch (digit) {
                case 0:
                    textelement.text("секунд");
                    break;
                case 1:
                    textelement.text("секунда");
                    break;
                case 2:
                    textelement.text("секунды");
                    break;
                default:
                    textelement.text("секунд");
            }
        }

        function ProcessDigits(digit) {
            if (digit == 11 || digit == 12 || digit == 13 || digit == 14)
                return 0;
            if (digit > 10) {
                digit = digit - parseInt(digit / 10, 10) * 10;
            }
            if (digit == 0) {
                return 0;
            }
            else if (digit == 1) {
                return 1;
            }
            else if (digit <= 4) {
                return 2;
            }
            else {
                return 0;
            }
        }

        function showdate() {
            var now = new Date();
            var date = new Date(2010, 5, 30, 23, 59, 59, 999);
            var totalRemains = (date.getTime() - now.getTime());
            if (totalRemains > 1) {
                var RemainsSec = (parseInt(totalRemains / 1000));
                var RemainsFullDays = (parseInt(RemainsSec / (24 * 60 * 60)));
                var secInLastDay = RemainsSec - RemainsFullDays * 24 * 3600;
                var RemainsFullHours = (parseInt(secInLastDay / 3600));
                var secInLastHour = secInLastDay - RemainsFullHours * 3600;
                var RemainsMinutes = (parseInt(secInLastHour / 60));

                ProcessDays(RemainsFullDays);
                ProcessHours(RemainsFullHours);
                ProcessMinutes(RemainsMinutes);
                if (RemainsMinutes < 10) { RemainsMinutes = "0" + RemainsMinutes };
                if (RemainsFullHours < 10) { RemainsFullHours = "0" + RemainsFullHours };
                var lastSec = secInLastHour - RemainsMinutes * 60;
                ProcessSeconds(lastSec);

                if (lastSec < 10) { lastSec = "0" + lastSec };
                $('#leftdays > span').text(RemainsFullDays);
                $('#lefttime > span').text(RemainsFullHours + ":" + RemainsMinutes + ":" + lastSec);
                setTimeout(function () { showdate(); }, 1000);
            }
            else { $('#timeleft').text('Сайт открыт') }
        }
        showdate();
    }

    $('#byfirm,#byalphabet').attr('ww', $('#byfirm').width());
    $('div.mapbar .show-on a').click(function () {
        if (!$(this).hasClass('active')) {
            $('div.mapbar .show-on a').removeClass('active');
            $(this).addClass('active');
            $('#byfirm,#byalphabet').hide();
            var el = $('#' + $(this).attr('rel'));
            el.show();

            if (el.hasClass('firstload')) {
                el.removeClass('firstload');
                mapsort();
            }
            if (el.width() != el.attr('ww')) {
                $('#' + $(this).attr('rel') + ' div.b-site-map:first').remove();
                mapsort()
            }

        }
        return false
    });

    $('div.text table tr:even').addClass('dark');

    $('.adv th a').hover(function () { $('#' + $(this).attr('class')).css('visibility', 'visible') }, function () { $('#' + $(this).attr('class')).css('visibility', 'hidden') }).click(function () { return false });

    if ($('#sell').size() > 0) {
        var ww = $('#sell .lf .war1').width();
        var cols = parseInt(ww / 18);
        $('#sell .lf .war1 input').attr('size', cols);
        $(window).resize(function () {
            var ww = $('#sell .lf .war1').width();
            var cols = parseInt(ww / 18);
            $('#sell .lf .war1 input').attr('size', cols);
        });
    }

    $('.gonextstep input').click(function () {
        isValid = true;
        $(this).parents('form').find('.need').each(function () {
            if (!$(this).val() || $(this).hasClass('default')) {
                if ($(this).hasClass('number')) { $(this).parents('table').parents('table').find('em.error').css('display', 'block'); }
                else { $(this).parents('table').find('em.error').css('display', 'block'); }
                isvaliddel();
                isValid = false
            }
        });
        if ($('select#PhoneOperators').length > 0 && $('select#PhoneOperators').find(':selected').val() == '') {
            $('select#PhoneOperators').parents('table').parents('table').find('em.error').css('display', 'block');
            $('select#PhoneOperators').bind('change', function () {
                if ($(this).find(':selected').val() != '')
                    $(this).parents('table').parents('table').find('em.error').css('display', 'none');
            });
            isValid = false;
        }
        if (isValid) {
            if ($('input:text#Login').length == 1 && $('input:text#Email').length == 1) {
                if (!$.register.validPasswords($('input:password#Password').val(), $('input:password#RePassword').val(), $('input:text#Login').val())) {
                    $.register.showPasswordError($('.regform-pass'));
                    return false;
                }
                $.register.checkForExist($('input:text#Login'), $('input:text#Email'), $(this));
            }
            else
                $(this).parents('form').submit();
        }
    });
    function isvaliddel() { $('.regform input').one('keyup', function () { $('.regform em.error').hide() }) }

    $('#addtel').click(function () {

        $('<table><col width="220" /><col width="305" /><col width="425" /><tr class="bigpadding"><td></td><td><span class="kbel">+375</span><table class="tel"><tr><td><input type="text need" name="PhoneCode" class="tx kod" /><span class="dp">код</span></td><td><input type="text" name="PhoneNumber" class="tx number need" /><span class="dp">номер</span></td><td><select id="PhoneOperators" name="PhoneOperators"><option>Оператор</option><option value="0">Velcom</option><option value="1">MTS</option><option value="2">Life:)</option><option value="3">Стационарный</option></select></td></tr></table></td><td><a href="#" class="deltel">Удалить</a></td></tr></table>').insertAfter($(this).parents('table'));
        $('a.deltel').click(function () {
            $(this).parents('table').remove();
            return false
        });
        $('.regform .tel input:text').keypress(function (e) { var cc = (e.which) ? e.which : event.keyCode; if (cc > 31 && (cc < 48 || cc > 57)) { return false } });
        return false
    });

    $('#jur').click(function () {
        if ($(this).find(':checked').size() > 0) {
            $('input.city:last').val($('input.city:first').val());
            $('input.zipcode:last').val($('input.zipcode:first').val());
            $('input.address:last').val($('input.address:first').val());
        }
        else {
            $('input.city:last,input.zipcode:last,input.address:last').val('');
        }
    });

    $('.regform .tel input:text').keypress(function (e) { var cc = (e.which) ? e.which : event.keyCode; if (cc > 31 && (cc < 48 || cc > 57)) { return false } });

    $('input.default').each(function () {
        $(this).attr('value', $(this).attr('title'));
        $(this).attr('def', $(this).attr('title'));
    }).focus(function () {
        if ($(this).val() == $(this).attr('def')) {
            $(this).val('').removeClass('default');
        }
    }).blur(function () {
        if ($(this).val() == '') {
            $(this).val($(this).attr('def')).addClass('default');
        }
    });

    if ($('.sizefix .tbar .item .brandtitle').length == 1) {
        if ($('.sizefix .tbar .item .brandtitle').text().length > 17) {
            $('.sizefix .tbar .item .brand').css('background-position', 'left center');
        }
    }

});




