/**
	cssua.js
	User-agent specific CSS support

	Created: 2006-06-10-1635
	Modified: 2011-01-10-1101

	Copyright (c)2006-2011 Stephen M. McKamey
	Distributed under The MIT License.
*/

var cssua = (function(html, userAgent) {

	/*const string*/ var PREFIX = " ua-";

	/*jslint regexp: false, browser: true */

	var R_All = /[\w\-\.]+[\/][v]?\d+(\.\d+)*/g,
		R_AOL = /\b(aol|america online browser)[\s\/]*(\d+(\.\d+)*)/,
		R_MSIE = /\b(msie|microsoft internet explorer)[\s\/]*(\d+(\.\d+)*)/,
		R_Gecko = /rv[:](\d+(\.\d+)*).*?\bgecko[\/]\d+/,
		R_Opera = /\bopera[\s\/]*(\d+(\.\d+)*)/,
		R_Android = /\bandroid[\s]+(\d+(\.\d+)*)/,
		R_iOS = /\bos[\s]+(\d+(\_\d+)*) like mac os x/,
		R_WinPhone = /\bwindows phone os (\d+(\_\d+)*)/,
		R_MSPIE = /\b(mspie|microsoft pocket internet explorer)[\s\/]*(\d+(\.\d+)*)/,
		R_iCab = /\bicab[\s\/]*(\d+(\.\d+)*)/,
		R_BlackBerry = /\bblackberry\w*[\s\/]+(\d+(\.\d+)*)/,
		R_mobile = /(\bandroid\b|\bipad\b|\bipod\b|\bblackberry|\bwebos\b|\bwindows ce\b|\bwindows phone os\b|\bwindows ce\b|\bpalm|\bsymbian|\bj2me\b|\bdocomo\b|\bpda\b|\bchtml\b|\bmidp\b|\bcldc\b|\w*?mobile\w*?|\w*?phone\w*?)/;

	var cssua = {

		/*Map<string,string>*/ parse : function(/*string*/ uaStr) {
			/*Map<string,string>*/ var ua = {};

			uaStr = (""+uaStr).toLowerCase();
			if (!uaStr) {
				return ua;
			}

			// do this first for all (covers generic user-agents)
			var raw = uaStr.match(R_All);
			if (raw) {
				for (var i=0; i<raw.length; i++) {
					var s = raw[i].indexOf('/'),
						b = raw[i].substring(0, s);
					if (b && b !== "mozilla") {
						// shorten this common engine
						if (b === "applewebkit") {
							b = "webkit";
						}
						ua[b] = raw[i].substr(s+1);
					}
				}
			}

			// aol uses multiple engines so continue checking
			if (R_AOL.exec(uaStr)) {
				ua.aol = RegExp.$2;
			}

			// order is important as user-agents spoof each other	
			if (R_Opera.exec(uaStr)) {
				ua.opera = RegExp.$1;
			} else if (R_iCab.exec(uaStr)) {
				ua.icab = RegExp.$1;
			} else if (R_MSIE.exec(uaStr)) {
				ua.ie = RegExp.$2;
			} else if (R_MSPIE.exec(uaStr)) {
				ua.mspie = RegExp.$2;
			} else if (R_Gecko.exec(uaStr)) {
				ua.gecko = RegExp.$1;
			} else if (R_Android.exec(uaStr)) {
				ua.android = RegExp.$1;
			} else if (R_iOS.exec(uaStr)) {
				ua.ios = RegExp.$1.split('_').join('.');
			} else if (R_WinPhone.exec(uaStr)) {
				ua.winphone = RegExp.$1;
			}

			// ensure that mobile devices have indication
			if (!ua.blackberry && R_BlackBerry.exec(uaStr)) {
				ua.blackberry = RegExp.$1;
			}
			if (R_mobile.exec(uaStr)) {
				ua.mobile = RegExp.$1;
			}

			// version standardization
			if (ua.safari) {
				if (ua.chrome || (ua.mobile && !ua.ios)) {
					delete ua.safari;

				} else if (ua.version) {
					ua.safari = ua.version;

				} else {
					ua.safari = ({
						"419": "2.0.4",
						"417": "2.0.3",
						"416": "2.0.2",
						"412": "2.0",
						"312": "1.3",
						"125": "1.2",
						"85": "1.0"
					})[parseInt(ua.safari, 10)] || ua.safari;
				}

			} else if (ua.opera && ua.version) {
				ua.opera = ua.version;
			}

			if (ua.version) {
				delete ua.version;
			}

			return ua;
		},

		/*string*/ format : function (/*Map<string,string>*/ ua) {
			/*string*/ function format(/*string*/ b, /*string*/ v) {
				b = b.split(' ').join('_').split('.').join('-');
				/*string*/ var css = PREFIX+b;
				if (v) {
					v = v.split(' ').join('_').split('.').join('-');
					var i = v.indexOf('-');
					while (i > 0) {
						// loop through chopping last '-' to end off
						// concat result onto return string
						css += PREFIX+b+'-'+v.substring(0, i);
						i = v.indexOf('-', i+1);
					}
					css += PREFIX+b+'-'+v;
				}
				return css;
			}

			var	uaCss = "";
			for (var b in ua) {
				if (b && ua.hasOwnProperty(b)) {
					uaCss += format(b, ua[b]);
				}
			}

			// user-agent classNames
			return uaCss;
		},

		/* Encodes parsed userAgent object as a compact URI-Encoded key-value collection */
		/*string*/ encode : function(/*Map<string,string>*/ ua) {
			var query = "";
			for (var b in ua) {
				if (b && ua.hasOwnProperty(b)) {
					if (query) {
						query += "&";
					}
					query += encodeURIComponent(b)+"="+encodeURIComponent(ua[b]);
				}
			}
			return query;
		}
	};

	// calculate userAgent
	cssua.userAgent = cssua.ua = cssua.parse(userAgent);

	// append CSS classes to HTML node
	var ua = cssua.format(cssua.ua);
	if (html.className) {
		html.className += ua;
	} else {
		html.className = ua.substr(1);
	}

	return cssua;
})(document.documentElement, navigator.userAgent);
;
function vgrad(s){
	var a=s.substring(1,s.length-1).split(", ");
	var output="";
// opera	
	s='';
	s+='<svg xmlns="http://www.w3.org/2000/svg" version="1.0">';
	s+='<defs>';
	s+='<linearGradient id="gradient" x1="0%" y1="0%" x2="0%" y2="100%">';
	for (i=0;i<a.length;i++)
	s+='<stop offset="'+Math.round(i*100/(a.length-1))+'%" style="stop-color:'+a[i]+';"/>';
	s+='</linearGradient>';
	s+='</defs>';
	s+='<rect fill="url(#gradient)" height=\'100%\' width=\'100%\' />';
	s+='</svg>';
	output+="url(data:image/svg+xml,"+escape(s)+");\n"	
// webkit	
//	output+="background: -webkit-gradient(linear, left top, left bottom, ";
//	output+="from("+a[0]+"), ";
//	output+="to("+a[a.length-1]+")";
// тут промежуточные
//	for (i=1;i<a.length-1;i++)
//	output+=", color-stop(0."+Math.round(i*100/(a.length-1))+", "+a[i]+")";
//	output+=");\n";

/**
 * moz	
 */
	output+="background:";
	output+="-moz-linear-gradient("+a.join(", ")+");\n";
// opera in future	
	output+="background: -o-linear-gradient("+a.join(", ")+");\n";
// webkit	
	output+="background: -webkit-linear-gradient("+a.join(", ")+");\n";
// normal	
	output+="background: linear-gradient("+a.join(", ")+");\n";
// ie
	output+="-pie-background:linear-gradient("+a.join(", ")+");\n";
	output+="behavior:url(/PIE.htc)\n";	
	return output;
}


(function ($) {
function go(){
	less.refresh(true);	
	setTimeout("go()",15000);
}
$(function(){
/**
 * расстановка точек над ё
 */	
	$('ul.menu').each(function(){$(this).children("li").each(function(i){$(this).addClass("element-"+i);});});
	$('ul.menu').each(function(){$(this).addClass("level-"+$(this).parents("ul.menu").length);});
	$('ul.menu>li').each(function(){$(this).addClass("level-"+($(this).parents("ul.menu").length-1));});
/**
 * достройка
 */
 
$(".node-webform .fieldset-description").each(function(){
	$(this).appendTo($(this).parent().prev()).addClass("description");
});
 
$(".node-webform .description").each(function(){
	$(this).CreateBubblePopup({ 
	position : 'top',
	align	 : 'center',
	width:250,
	innerHtmlStyle: {'text-align':'center'},
	themeName: 	'all-black',
	themePath: 	Drupal.settings.basePath+Drupal.settings.jqBubbleThemePach,
	innerHtml: $(this).html() });
});


/**
 * расстановка событий
 */

/**
 *  отладочное
 */
	less.env = 'development';
	less.refresh(true);	
/*	setTimeout("go()",15000);
*/	
});
})(jQuery, less);;

