function pngFix(element){
	var src = element.currentStyle.backgroundImage.match(/url\("(.+\.png)"\)/i);
	if(src){
		element.runtimeStyle.backgroundImage = 'none';
		element.runtimeStyle.filter = 'progid:DXImageTransform.Microsoft.AlphaImageLoader(src="' + src[1] + 
		'", sizingMethod = "scale")';
	}
}
function calendar(){
	var c = $('#maincol .calendar');
	if(c.length){
		var a = $('#maincol .calendar td div p a');
		a.hover(
			function(){
				var div = $(this).parent('p').prev('div');
				var h = div.children('h4');
				var p = div.children('p');
				var hs = h.text().length;
				var ps = p.text().length;
				if(div.is('.fix'));
				else{
					if(hs > 61 * 4){h.text(h.text().substr(0,61 * 5) + ' [ ... ]');p.text(' ')}
					else if(hs > 61 * 3) p.text(' ');
					else if(hs > 61 * 2 && ps > 82 * 2) p.text(p.text().substr(0,82 * 2) + ' [ ... ]');
					else if(hs > 61 * 1 && ps > 82 * 3) p.text(p.text().substr(0,82 * 3) + ' [ ... ]');
					else if(hs > 61 * 0 && ps > 82 * 5) p.text(p.text().substr(0,82 * 5) + ' [ ... ]');
					div.addClass('fix');
				}
				$(this).parent('p').prev('div').fadeIn(400)
			},
			function(){$(this).parent('p').prev('div').fadeOut(200)}
		);
	}
}
function subscribe(){
	var inp = $('.subscribe input:text');
	if(inp.length){
		inp.focus(function(){if(this.value == this.defaultValue) this.value = ''})
		.blur(function(){if(!this.value) this.value = this.defaultValue});
	}
}
function partners(){
	var ul = $('#onecol .subcont .partners .panel ul');
	if(ul.length){
		var scr = '#onecol .subcont .partners .scroll ';
		var over = ul.children('li').length - 3;
		if(over > 0){
			var pos = 0;
			var lt = $(scr + '.lt a');
			var rt = $(scr + '.rt a');
			var w = ul.children('li').width();
			lt.addClass('end');
			lt.click(function(){
				if(pos > 0){pos--; move(ul,'+',1,w)}
				return false;
			});
			rt.click(function(){
				if(pos <= over - 1){pos++; move(ul,'-',1,w)}
				return false;
			});
		}
		else $(scr + 'li a').addClass('end');
		function move(node,side,step,len){
			node.animate({'marginLeft': side + '=' + len * step + 'px'},400,function(){
				$(scr + 'li a').removeClass('end');
				if(pos == over) rt.addClass('end');
				else if(pos == 0) lt.addClass('end');
			});
		}
	}
}
function subheader(){
	var panel = $('#maincol .subheader .panel');
	if(panel.length){
		var li = $('#maincol .subheader .panel li');
		if(li.length > 1){
			var pos = 0;
			var scr = $('#maincol .subheader .scroll');
			scr.css('display','inline');
			panel.children('li').css('position','absolute').siblings(':first-child').addClass('active')
			.siblings('li').not(':first-child').css('display','none');
			for(var i = 0, b = 0; i < li.length; i++){
				$(li[i]).css('background-position', '0 -' + b + 'px');
				b += 212;
			}
			scr.children('.rt').click(function(){
				if(pos < li.length - 1){change(panel,'+',false); pos++}
				else{change(panel,'+',true); pos = 0}
				return false;
			});
			scr.children('.lt').click(function(){
				if(pos > 0){change(panel,'-',false); pos--}
				else{change(panel,'-',true); pos = li.length - 1}
				return false;
			});
			function change(node,side,end){
				var pr = node.children('li.active').removeClass('active');
				if(side == '+'){
					if(!end) var li = pr.next('li');
					else var li = pr.siblings('li:first-child');
				}
				else{
					if(!end) var li = pr.prev('li');
					else var li = pr.siblings('li:last-child');
				}
				node.children('li:visible').fadeOut(1000);
				li.fadeIn(1000).addClass('active');
			}
		}
	}
}
function menu(){
	var m = $('#sidecol .sitepanel .menu');
	if(m.length){
		var li = m.children('li');
		li.hover(function(){ulOut(li);ulIn($(this))},function(){ulOut(li)});
		function ulOut(li){li.removeClass('cur').children('ul').hide()}
		function ulIn(li){li.addClass('cur').children('ul').show()}
	}
}
$(document).ready(function(){
	menu(); subheader(); partners(); subscribe(); calendar();
});
