(function($){$.fn.extend({limit:function(limit,element){var interval,f;var self=$(this);$(this).focus(function(){interval=window.setInterval(substring,100)});$(this).blur(function(){clearInterval(interval);substring()});substringFunction="function substring(){ var val = $(self).val();var length = val.length;if(length > limit){$(self).val($(self).val().substring(0,limit));}";if(typeof element!='undefined')substringFunction+="if($(element).html() != limit-length){$(element).html((limit-length<=0)?'0':limit-length);}";substringFunction+="}";eval(substringFunction);substring()}})})(jQuery);

$(function(){


$.fn.textDropShadow = function(ShdwClass){
    $(this).css('position','relative').html('<span class='+ShdwClass+'>'+$(this).html()+'</span><span style="position:relative;">'+$(this).html()+'</span>');
	return $(this);
}

 $.fn.fadeIn2 = function (speed, callback) {
 return this.animate({
 opacity: 'show'
 }, speed, function () {
 if ($.browser.msie) {
 this.style.removeAttribute('filter');
 }
 if ($.isFunction(callback)) {
 callback.call(this);
 }
 });
 };
 
 $.fn.fadeOut2 = function (speed, callback) {
 return this.animate({
 opacity: 'hide'
 }, speed, function () {
 if ($.browser.msie) {
 this.style.removeAttribute('filter');
 }
 if ($.isFunction(callback)) {
 callback.call(this);
 }
 });
 };
 
 $.fn.fadeTo2 = function (speed, to, callback) {
 return this.animate({
 opacity: to
 }, speed, function () {
 if (to == 1 && $.browser.msie) {
 this.style.removeAttribute('filter');
 }
 if ($.isFunction(callback)) {
 callback.call(this);
 }
 });
 };




});


$(document).ready(function(){

		$('#show').fadeIn2("slow", function() {
			$('#horizon').fadeOut2("fast");
		});
		
		$('ul.sub_menu').hide();
		$('.main_menu').find("a.first_active").next("ul.sub_menu").addClass('open').show();
		$('.main_menu').find("a.second_active").next("ul.sub_menu").addClass('open').show();
		
		$(".main_menu li a").click(function(){
		var href = $(this).attr("href");
			if(href == "javascript:void(0);"){
				$('.le2').css({height:($('#cont2').height()-130)});
				$('.re2').css({height:($('#cont2').height()-130)});
				
				if($(this).next(".sub_menu").is(":visible")){
					$(this).next("ul.sub_menu").removeClass('open');
					$(this).removeAttr("style");
				}
				
				if($(this).next(".sub_menu").is(":hidden")){
					$('.main_menu').find("a").css({'border-bottom':'none'});
					$(this).next("ul.sub_menu").addClass('open');
					$(this).css({'border-bottom':'1px #5e5e5e dashed'});
					
					//console.log($(this).parents("ul.sub_menu"));
					$('.main_menu').find("ul.open").not($(this).next("ul.sub_menu")).not($(this).parents("ul.sub_menu")).slideToggle().removeClass('open');
				}
				$(this).next(".sub_menu").slideToggle();
			}
		});   
	
		$("#toggle-forms").click(function(){
			var forms = $("#forms");
			forms.toggle();
			if ($('#forms').is(':hidden')){
				$('#toggle-forms').css({'background':'url(/templates/ave/images/switch_m.gif) no-repeat 0% 50%'});
			}else {
				$('#toggle-forms').css({'background':'url(/templates/ave/images/switch_p.gif) no-repeat 0% 50%'});
			} 
			$('.le2').css({height:($('#cont2').height()-130)});
			$('.re2').css({height:($('#cont2').height()-130)});
			
		});		
		
		$('.le2').css({height:($('#cont2').height()-130)});
		$('.re2').css({height:($('#cont2').height()-130)});

		$(".carousel").jCarouselLite({ btnNext: ".news_home_block .next", visible:1, speed:500,circular: true});

		$('.block_menu').each(function(el, i) {
			var bsel = $(i).children('div.sb');
			$(i).bind({
				 mouseenter: function() {
					if(bsel.hasClass('active')) { return false; }
					bsel.animate({top:"-80px"}, 200).addClass('active');
				},
				mouseleave: function() {
					if(bsel.hasClass('active2')) { return false; }
					bsel.animate({top:"0px"}, 200).removeClass('active');
				}
			});
		});	

});




function getCaptha(){
	now = new Date();
	$('#captcha img').attr('src','/inc/captcha.php?cd='+now);
};



(function(d){var k=d.scrollTo=function(a,i,e){d(window).scrollTo(a,i,e)};k.defaults={axis:'xy',duration:parseFloat(d.fn.jquery)>=1.3?0:1};k.window=function(a){return d(window)._scrollable()};d.fn._scrollable=function(){return this.map(function(){var a=this,i=!a.nodeName||d.inArray(a.nodeName.toLowerCase(),['iframe','#document','html','body'])!=-1;if(!i)return a;var e=(a.contentWindow||a).document||a.ownerDocument||a;return d.browser.safari||e.compatMode=='BackCompat'?e.body:e.documentElement})};d.fn.scrollTo=function(n,j,b){if(typeof j=='object'){b=j;j=0}if(typeof b=='function')b={onAfter:b};if(n=='max')n=9e9;b=d.extend({},k.defaults,b);j=j||b.speed||b.duration;b.queue=b.queue&&b.axis.length>1;if(b.queue)j/=2;b.offset=p(b.offset);b.over=p(b.over);return this._scrollable().each(function(){var q=this,r=d(q),f=n,s,g={},u=r.is('html,body');switch(typeof f){case'number':case'string':if(/^([+-]=)?\d+(\.\d+)?(px|%)?$/.test(f)){f=p(f);break}f=d(f,this);case'object':if(f.is||f.style)s=(f=d(f)).offset()}d.each(b.axis.split(''),function(a,i){var e=i=='x'?'Left':'Top',h=e.toLowerCase(),c='scroll'+e,l=q[c],m=k.max(q,i);if(s){g[c]=s[h]+(u?0:l-r.offset()[h]);if(b.margin){g[c]-=parseInt(f.css('margin'+e))||0;g[c]-=parseInt(f.css('border'+e+'Width'))||0}g[c]+=b.offset[h]||0;if(b.over[h])g[c]+=f[i=='x'?'width':'height']()*b.over[h]}else{var o=f[h];g[c]=o.slice&&o.slice(-1)=='%'?parseFloat(o)/100*m:o}if(/^\d+$/.test(g[c]))g[c]=g[c]<=0?0:Math.min(g[c],m);if(!a&&b.queue){if(l!=g[c])t(b.onAfterFirst);delete g[c]}});t(b.onAfter);function t(a){r.animate(g,j,b.easing,a&&function(){a.call(this,n,b)})}}).end()};k.max=function(a,i){var e=i=='x'?'Width':'Height',h='scroll'+e;if(!d(a).is('html,body'))return a[h]-d(a)[e.toLowerCase()]();var c='client'+e,l=a.ownerDocument.documentElement,m=a.ownerDocument.body;return Math.max(l[h],m[h])-Math.min(l[c],m[c])};function p(a){return typeof a=='object'?a:{top:a,left:a}}})(jQuery);










var qTipTag = "img,a,label,input,div,strike,option,h2";
var qTipX = 0;
var qTipY = 15;
tooltip = {name : "qTip",offsetX : qTipX,offsetY : qTipY,tip : null}


var myWidth = 0, myHeight = 0;

if( typeof( window.innerWidth ) == 'number' ) {
	myWidth = window.innerWidth;
	myHeight = window.innerHeight;
}else if( document.documentElement && ( document.documentElement.clientWidth || document.documentElement.clientHeight ) ) {
	myWidth = document.documentElement.clientWidth;
	myHeight = document.documentElement.clientHeight;
} else if( document.body && ( document.body.clientWidth || document.body.clientHeight ) ) {
	myWidth = document.body.clientWidth;
	myHeight = document.body.clientHeight;
}
tooltip.init = function () {var tipNameSpaceURI = "http://www.w3.org/1999/xhtml";if(!tipContainerID){ var tipContainerID = "qTip";}
var tipContainer = document.getElementById(tipContainerID);if(!tipContainer) {tipContainer = document.createElementNS ? document.createElementNS(tipNameSpaceURI, "div") : document.createElement("div");
tipContainer.setAttribute("id", tipContainerID);document.getElementsByTagName("body").item(0).appendChild(tipContainer);}if (!document.getElementById) return;this.tip = document.getElementById (this.name);
if (this.tip) document.onmousemove = function (evt) {tooltip.move (evt)};
var a, sTitle, elements;
var elementList = qTipTag.split(",");for(var j = 0; j < elementList.length; j++){elements = document.getElementsByTagName(elementList[j]);if(elements){for (var i = 0; i < elements.length; i ++){a = elements[i];

sTitle = a.getAttribute("klerol");

if(sTitle){
	a.setAttribute("tipname", sTitle);
	a.onmouseover = function() {
		tooltip.show(this.getAttribute('tipname'), this.getAttribute('k_width'))
	};
	a.onmouseout = function() {
		tooltip.hide()
	};
}
}}}}
tooltip.move = function (evt) {var x=0, y=0;
if (document.all) {
x = (document.documentElement && document.documentElement.scrollLeft) ? document.documentElement.scrollLeft : document.body.scrollLeft;
y = (document.documentElement && document.documentElement.scrollTop) ? document.documentElement.scrollTop : document.body.scrollTop;
x += window.event.clientX;y += window.event.clientY;} 
else {x = evt.pageX;y = evt.pageY;}

cont = $('#qTip').innerWidth();
if(x + cont > myWidth){
	this.tip.style.left = (x - ((x+cont)-myWidth+25)) + "px";
}else{
	this.tip.style.left = (x + this.offsetX) + "px";
}
this.tip.style.top = (y + this.offsetY) + "px";
}

tooltip.show = function (text, swidth) {
	if (!this.tip) return;
	this.tip.innerHTML = text;
	this.tip.style.display = "block";
	if(swidth)this.tip.style.width = swidth+'px';
}
tooltip.hide = function () {
	if (!this.tip) return;
	this.tip.innerHTML = "";
	this.tip.style.display = "none";
	this.tip.style.width = '';
}

window.onload = function () {tooltip.init ();}



function textCounter(field, countfield, maxlimit)
{
	if (field.value.length > maxlimit)
	{
		field.value = field.value.substring(0, maxlimit);
	} else {
		countfield.value = maxlimit - field.value.length;
	}
}

