
$(document).ready(function(){
		Calendar.setup({
		inputField:  'f_date1',
		ifFormat:    '%d%m%Y',
		displayArea: 'f_date_show1',
		daFormat:    '%d %B %Y',
		button:      'f_date_trigger1',
		firstDay:    1,
		weekNumbers: false,
		range:       [2002, CDate.y],
		dateStatusFunc: dateStatus
	});
	
	$('a').focus(function(){$(this).blur()});
	$('.sidemenu li').mouseenter(function(){
		$(this).children('ul').css('visibility', 'visible');
		if(jQuery.browser.msie!=true)$(this).children('ul').animate({ 
        opacity: 1
      }, {queue:false,duration:160} );
	});
	$('.sidemenu li').mouseleave(function(){
		$(this).children('ul').css('visibility', 'hidden');
		if(jQuery.browser.msie!=true)$(this).children('ul').animate({        
        opacity: 0.01
      }, {queue:false,duration:160} );
	});
	$('#search .submit').mouseenter(function(){
		$('#search').css('backgroundPosition', 'left -90px');	
	});
	$('#search .submit').mouseleave(function(){
		$('#search').css('backgroundPosition', 'left top');	
	});
//	$('.sidemenu a').click(function(){
//		if($(this).parent().children('ul').html()!=null){
//			return false;
//		}else {
//
//		}
//	});
	$('.sub').mouseenter(function(){
		$(this).css('backgroundPosition', 'left -65px');
	});
	$('.sub').mouseleave(function(){
		$(this).css('backgroundPosition', 'left top');
	});
	$('.pmiddle').mouseenter(function(){
		$(this).css('backgroundPosition', '-70px -58px');
	});
	$('.pmiddle').mouseleave(function(){
		$(this).css('backgroundPosition', '-70px top');
	});
	$('.ptop').mouseenter(function(){
		$(this).css('backgroundPosition', '-70px -59px');
	});
	$('.ptop').mouseleave(function(){
		$(this).css('backgroundPosition', '-70px top');
	});
	$('.pbottom').mouseenter(function(){
		var a = $(this).height()-100;
		$(this).css('backgroundPosition', '-70px '+a+'px');
	});
	$('.pbottom').mouseleave(function(){
		$(this).css('backgroundPosition', '-70px bottom');
	});
	var inputheight = 50;
	var inputheight2 = 24;
	var duration = 8; 
	$(".dropdown div input").click(function(){		
		var h = $(this).parent().children("ul");
		//alert(h);
		$(this).parent().animate({
	 		'height' : inputheight + h.height() +3
	 	}, { queue:false, duration: duration*h.children("li").length, easing: 'linear'});
	 	$(".dropdown div ul").css("z-index", 3);
	});
	$(".dropdown div").mouseleave(function(){
		var h = $(this).children("ul");
		if($(this).parent().parent().attr('id')=='calform'){
		$(this).animate({
	 		'height' : inputheight 
	 	}, { queue:false, duration:duration*h.children("li").length, easing: 'linear'});
		}else{
	 	$(this).animate({
	 		'height' : inputheight2
	 	}, { queue:false, duration:duration*h.children("li").length, easing: 'linear'});
	 	}
	});
	$(".dropdown input").focus(function(){$(this).blur()});
	$(".dropdown div ul li").click(function(){
		$(this).parent().parent().children("input").attr("value",$(this).html());
		//alert($(this).parent().parent().parent().parent().attr('id'));
			if($(this).parent().parent().parent().parent().attr('id')=='calform'){
				$(this).parent().parent().height(inputheight);
			}
			else{
				$(this).parent().parent().height(inputheight2);
			}
			
			ff($(this));
		}
	);
	$('.freeinput').children('input').each(function(){
		$(this).attr('title',$(this).attr('value'));
		
	});
	$('.freeinput input').click(function(){
		if($(this).attr('value')==$(this).attr('title')){
			$(this).attr('value','');			
		}
	});
	$('.freeinput input').blur(function(){
		if($(this).attr('value')==''){
			$(this).attr('value',$(this).attr('title'));
		}
	});
		$('#valcal').click(function(){
		var fw = $(window).width();
		fw = (fw - 400)/2;
		
		var xxx = $(window).scrollTop();
		var fh = $(window).height();
			fh = xxx+(fh - 307)/2;
				$('.cl').css('display','block');
				$('.cl').css('height',306);
				$('.cl').css('width',367);		
				$('.cl').css('top',fh);		
				$('.cl').css('left',fw);				

		return false;
		
	});
	$('.cl').draggable();
	$('#x').click(function(){
		$('.cl').css('display','none');
	});
	$('.stcontent table tr:first-child').attr('class','first');
	$('.stcontent table tr:last-child').attr('class','last');
	$('.stcontent table tr td:first-child').attr('class','first');
	$('.stcontent table tr td:last-child').attr('class','last');
	if(($('.stcontent table tr.first').children().length)>8){
		$('.stcontent table').attr('class','long');
	}
	$('#button').focus(function(){$(this).blur()});
		if(langid != 'undefined'){
		var holdme = '<tr class="first">' + $('#rate .first').html() + '</tr>';
		$('#rate').html('');
		$('#rate').append(holdme);
		var getme = $.ajax({
		 url: 'ajax/table.php?lang='+langid+'&date=' + $("#f_date").attr('value'),
		 async: false
		 }).responseText;
		 $('#rate').append(getme);
		}
		
		function ff(el){
			var ds = el.parent().parent().parent().parent().attr('id');
			var rat4e = $.ajax({
				 url: 'ajax/koef.php?valuta='+el.html(),
				 async: false
				 }).responseText;
			
			$('#x'+ds).attr('value',rat4e);
//			$('#x'+ds).attr('value',1);
			//alert(el.html());
//			ds.attr('value',1);
		}
		$('a.izchisli').click(function(){
			var tmp = $('#amountt').attr('value');
			tmp = tmp.replace(',','.');
			tmp = tmp*($('#xdvaluta').attr('value')/$('#xtdvaluta').attr('value'));
			$('#rezultattxt').attr('value', (Math.round(100* tmp ))/100);
			return false;
		});
		$('#formsubmitx').click(function(){
//			alert($('#ttime').attr('value'));
//			return false;			
			if($('#tcredit').attr('value')==creditq){
				alert($.ajax({url: 'ajax/translate.php?word=credita&lang='+langid, async: false}).responseText);
				return;
			}
			if(isNaN(parseFloat($('#tsuma').attr('value')))){
				alert($.ajax({url: 'ajax/translate.php?word=sumata&lang='+langid, async: false}).responseText);
				return;
			}
			if($('#ttime').attr('value')>300||$('#ttime').attr('value')<1||isNaN(parseFloat($('#ttime').attr('value')))){
				alert($.ajax({url: 'ajax/translate.php?word=sroka&lang='+langid, async: false}).responseText);
				return;
			}
			if($('#tproc').attr('value')>100||$('#tproc').attr('value')<1||isNaN(parseFloat($('#tproc').attr('value')))){
				alert($.ajax({url: 'ajax/translate.php?word=lihvata&lang='+langid, async: false}).responseText);
				return;
			}
			$('#calform').submit();
		});
		if($('#here').html()!=''&&baneri.length>0){
			var loop4e = Array();
			var i=0;
			loop4e[0] =$('#here').html();//alert(baneri.count);
			for(i=0; i<baneri.length; i++){
			loop4e[i+1] = baneri[i];
			}
//			alert(i);
			var y = 0;
			var y2 =0;
				$(this).everyTime(11000, function() {
					 
					 while(y==y2){
					 	y2 = rand(0,i);
//					 	alert(y2);
					 }					 					 
					 $('#here').fadeOut(600, function(){$('#here').html(loop4e[y2]);});			   		 
			   		 $('#here').fadeIn(600);
			   		 y=y2;
//			   		 alert('guz');
			 	 });
		}
		$('#f_date').change(function(){
		ajcall()
		});
});
function rand (min, max) {
    // Returns a random number 
    //
    // version: 909.322
    // discuss at: http://phpjs.org/functions/rand
    // +   original by: Leslie Hoare
    // +   bugfixed by: Onno Marsman
    // %          note 1: See the commented out code below for a version which will work with our experimental (though probably unnecessary) srand() function)
    // *     example 1: rand(1, 1);
    // *     returns 1: 1
     
    var argc = arguments.length;
    if (argc === 0) {
        min = 0;
        max = 2147483647;
    } else if (argc === 1) {
        throw new Error('Warning: rand() expects exactly 2 parameters, 1 given');
    }
    return Math.floor(Math.random() * (max - min + 1)) + min;
}
function ajcall(){
			if(langid != 'undefined'){
			var holdme = '<tr class="first">' + $('#rate .first').html() + '</tr>';
			$('#rate').html('');
			$('#rate').append(holdme);
			var getme = $.ajax({
			 url: 'ajax/table.php?lang='+langid+'&date=' + $("#f_date").attr('value'),
			 async: false
			 }).responseText;
			 $('#rate').append(getme);
			}			
		}
