$(function(){  $('A[href=#]').click( false );  $.vsModal = {      obj: $('#modal'),      resize: function() {        this.obj.width( $('body').width() ).height( $('#body').height() );      },      show: function( showCallback, hideCallback, opacity, permanent ) {        if (typeof opacity === 'undefined') opacity = 0.5;        permanent = permanent || false;        this.obj.unbind('click');        if (!permanent) this.obj.click( function( e ) {          e.preventDefault();          $.vsModal.hide( hideCallback );        });        this.obj.css({ opacity: opacity }).show();        if ($.type( showCallback ) == 'function') showCallback();      },      hide: function( hideCallback ) {        if ($.type( hideCallback ) == 'function') hideCallback();        this.obj.hide();      },      init: function() {        var self = this;        self.resize();        $(window).resize( function() { self.resize(); } );      }  };  $.vsModal.init();    $.fn.incImgCount = function( inc, e ) {    return this.each( function(){      var o = $(this), c = o.data('imgCount') || 0;      //if (typeof e !== 'undefined') console.log( 'event: ' + e.type );      c = c + (typeof inc === 'undefined' ? 0 : inc);      //if (typeof e.target !== 'undefined') console.log( e.target );      o.data('imgCount', c);    });  };    $('A[href$=".exe"],A[href$=".dmg"],A[href$=".deb"],A[href$=".rpm"]').click(function( e ) {  	if (typeof this.alreadyClicked === 'undefined' || !this.alreadyClicked) {  		e.preventDefault();    	this.alreadyClicked = true;    	    	$.vsModal.show(function(){    	  $('#modal-loader').css('display', 'block');    	}, null, 0.6, true);    	  		var obj = $(this).data('imgCount',0), url = obj.attr('href'), gaCode = obj.data('gaсode'), apTo = $('#hiddenImgs'), to;  		/* GOOGLE ANALYTICS */  		if (typeof gaCode !== 'undefined') pageTracker._trackPageview( gaCode );    	      var rnd = Math.round(Math.random() * 10000000000);      /* Amarena */      obj.incImgCount( 1, { type: 'add Amarena'} );      $('<IMG />')      .attr('src', 'http://www4.smartadserver.com/track/pix2.asp?99505;11936;'+rnd+';0;[transactionid];[reference]')      .attr('width', '1').attr('height', '1')      .bind('load.imgAmarena error.imgAmarena', function( e ) {        obj.incImgCount( -1, e );      }).appendTo( apTo );        		/* ADRIVER */  		var ext = url.substr(-3).toLowerCase(), adR_codes = {        'exe': 'http://ad.adriver.ru/cgi-bin/rle.cgi?sid=175503&sz=windows&bt=2&pz=0&rnd=',        'dmg': 'http://ad.adriver.ru/cgi-bin/rle.cgi?sid=175503&sz=mac&bt=2&pz=0&rnd=',        'deb': 'http://ad.adriver.ru/cgi-bin/rle.cgi?sid=175503&sz=linuxdebian&bt=2&pz=0&rnd=',        'rpm': 'http://ad.adriver.ru/cgi-bin/rle.cgi?sid=175503&sz=linuxrpm&bt=2&pz=0&rnd='  		};  		if (typeof adR_codes[ext] !== 'undefined') {  		  url = adR_codes[ext] + rnd;  		  /*        obj.incImgCount( 1, { type: 'add AdRiver'} );  			$('<IMG />')  			.attr('src', adR_codes[ext] + rnd).attr('width', '1').attr('height', '1').bind('load.imgAdRiver error.imgAdRiver', function( e ) {          obj.incImgCount( -1, e );  			}).appendTo( apTo );  			*/  		}  		  		/* REDIRECT TO DOWNLOAD LOCATION  */  		setTimeout(function(){        to = setInterval(function() {          if (obj.data('imgCount') < 1) {            clearInterval( to );            $.vsModal.hide(function() { $('#modal-loader').hide(); });            window.location = url;          }        }, 250);  		},1000);  		return false;  	}  	return true;  });      if (typeof cuSel !== 'undefined') cuSel({	  changedEl: "select.custom",	  visRows: 5,	  scrollArrows: false  });  $('A.pseudo-link').click( function( e ) {  	e.preventDefault();  	var dest = $ ( $(this).attr('href') );  	$.vsModal.show(   		function(){  			dest.show();  		},  		function(){  			dest.hide();  		}  	);  });  $('A.popup-show').click( function( e ) {  	e.preventDefault();  	var lnk = $(this), dest = $ ( lnk.attr('href') );  	$.vsModal.show(   		function(){  			if (lnk.parent().is('LI')) lnk.parent().toggleClass('active',true);  			var pos = lnk.offset(), h = lnk.height(), w = lnk.width(), ph = dest.height(), pw = dest.width(), wnd = $('html');  			if (dest.hasClass('popup-tl')) {  				pos.top = pos.top - ph;   			} else if (dest.hasClass('popup-tc')) {  				pos.top = pos.top - ph;  				pos.left = pos.left + (w / 2) - ( pw / 2);  			} else if (dest.hasClass('popup-tr')) {  				pos.top = pos.top - ph;  				pos.left = pos.left + w - pw;  			} else {   				// BOTTOM CENTER  				dest.toggleClass('popup-bc', true);  				pos.top = pos.top + h;  				pos.left = pos.left + (w / 2) - ( pw / 2);  			}  			dest.css({ top: pos.top, left: parseInt(pos.left)-1 }).show();  			if ( wnd.scrollTop() > (pos.top - 5) ) wnd.animate({ scrollTop: pos.top - 5}, 'slow');  		},  		function(){  			lnk.parent().removeClass('active');  			dest.hide();  		}  	);  });      $('.help-group-holder').find('DT').find('A').click( function( e ) {  	e.preventDefault();  	$(this).parents('LI').toggleClass('active');  });    $('#demo-popup').click( function( e ) {  	window.open( $(this).attr('href'), 'demopopup', 'width=700,height=700,toolbar=0,location=0,menubar=0,scrollbars=1,resizable=1,status=1,directories=0');  	e.preventDefault();  });    $.mfSelectZ = 20;  $.fn.mfSelect = function() {  	return this.each( function() {  		var o = $(this),   				ns = $('<DIV />').addClass('myselect').css('z-index', $.mfSelectZ--)  						.append('<INS class="back tl" />')  						.append('<INS class="back tr" />')  						.append('<INS class="back bl" />')  						.append('<INS class="back br" />')  						.append('<DL><DT /><DD><UL /></DD></DL>'),  				dt = ns.find('DT').data('init', false).click( function( e ) {  					e.stopPropagation();  					var t = $(this), dd = t.next();  					t.parent().toggleClass('active')  					if (t.data('init') === false) {  						t.data('init', true);  						if (dd.hasClass('select-scrollable')) {  							dd.height(140).jScrollPane({	  							verticalDragMinHeight: 18,	  							verticalDragMaxHeight: 18	  						}).find('.jspTrack').prepend(	  							$('<DIV />').addClass('jspTrackBottom')	  						);  						}  					}  				}),  				ul = ns.find('UL'),  				sel = null,  				i = 0,  				list = [],  				opts = o.children('OPTION');   		  		if (o.hasClass('select-scrollable')) {  			dt.next().addClass('select-scrollable');  		}  		  		opts.each( function() {  			var opt = $(this);  			list[i] = { value: opt.val(), text: opt.text() };  			if (sel === null && opt.is(':selected')) sel = i;  			i++;   		});  		if (list.length) {  			if (sel === null) sel = 0;  			var inp = $('<INPUT />')				.attr('type', 'hidden')				.attr('name', o.attr('name'))				.attr('id', o.attr('id'))				.addClass('select')				.toggleClass('required',o.hasClass('required'))				.val( list[sel].value );  			dt.text( list[sel].text );  			for (i in list) {  				ul.append(						$('<LI />')							.toggleClass('active', i == sel).text( list[i].text )							.data('value', list[i].value )							.css( { cursor: 'pointer' })							.click( function( e ) {								e.stopPropagation();								var li = $(this);								inp.val( li.data('value') ).change();								li.addClass('active').siblings().removeClass('active').parents('DL').removeClass('active').children('DT').text( li.text() );							})							.hover( function() {								$(this).toggleClass('hover');							})  				);  			}  			    		o.after( inp ).after( ns ).remove();  		}  	});  }  $('SELECT.select').mfSelect();    $.mfFeedBack = {	errors: 0,	obj: $('#form-feedback'),	fields: null,	init: function() {		if (this.obj.length) {			this.obj.find('.required').bind( 'change focusout', this.check ); 		}	},	check: function() {		var self = $.mfFeedBack;	  if (self.obj.length) {			self.errors = 0;			self.obj.find('.required').each( function() {				var o = $(this), v = o.val();				if ((o.is('SELECT') || o.hasClass('select')) && (v == '' || v == '0' || v == 0)) {					self.errors++;				} else {					v = $.trim( v );					if (!v.length) {						self.errors++;					}					o.val( v );				}			});			var b = $('#form-feedback-submit').toggleClass('disabled', self.errors > 0); 			if (self.errors > 0) b.attr('disabled','disabled');			else b.removeAttr('disabled');	  }	}  };  $.mfFeedBack.init();  });
