$(function(){
	//alert('Hi');	
	
	 /* indexinio paveiksliuko animacija */
    
    var allbublelis = $('ul.buble li');	
	var all_items = $('#contFlash .item');
    var curent_buble = 1;
    var buble_interval = 3000;
    var inbublet = null;

	$('.buble li').mouseover(function(e){
		$(this).addClass('active');  
	});
	
	$('.buble li').mouseout(function(e){
		$(this).removeClass('active');  
	});
	
	$('.buble a').click(function(e){
		clearTimeout ( inbublet );
		inbublet = null;
        e.preventDefault();
        var id = $(this).attr('href').replace('#','');
		do_buble_step(id);
        setTimeout(function(){
            curent_buble = id;
            start_buble_interval();
        }, 3000);
	});
    
    do_buble_step(1);
    start_buble_interval();

    function start_buble_interval(){
        if(typeof inbublet == 'number'){
            clearTimeout ( inbublet );
        }

        inbublet = setInterval ( function(){
            var next_buble = curent_buble++;

            if(next_buble == 4){
                curent_buble = 1;
            }

           do_buble_step(next_buble);
        }, buble_interval );
    }

    //
    function do_buble_step(id){
        var active_li = $('ul.buble li.buble_li'+id);
		var active_item = $('#contFlash .item'+id);
		
		if(active_li.is('.current')){
			//li is active wtf do you want?
		}else{
			allbublelis.removeClass('current');
			active_li.addClass('current');  
			all_items.css('display', 'none');
			active_item.css('display', 'block');
		}
    }

	
	//2011.07.27 VL spam prevention
	$('.nspm').blur(function() {
	  $('#o1e').val('sc223aze');
	});
	
});

$(document).ready(function() {
	$("a.reply_pict").fancybox({ 'zoomSpeedIn': 300, 'zoomSpeedOut': 300, 'overlayShow': false }); 
	$("a.reply_cpu").fancybox({ 'zoomSpeedIn': 300, 'zoomSpeedOut': 300, 'overlayShow': false }); 
	$("a.feedbackForm").fancybox({ 'zoomSpeedIn': 300, 'zoomSpeedOut': 300, 'overlayShow': false }); 
	//$('#message1Link').click();	
	//alert($("#message1Link").html());
	//$("#message1Link").trigger('click');
	
	var btn_name = "images/button_narsyti.gif";
		
  $("input.browsePicture").filestyle({ 
	  image: btn_name,
	  imageheight : 28,
	  imagewidth : 135,
	  width : 186
  });
	

	$(".onlyNumbers").keydown(function(event) {
        // Allow only backspace and delete
		//alert(event.keyCode);
        if ( event.keyCode == 46 || event.keyCode == 8 || event.keyCode == 107 || event.keyCode == 187 || event.keyCode == 37 || event.keyCode == 39) {
                // let it happen, don't do anything
        }
        else {
                // Ensure that it is a number and stop the keypress
                /*if (event.keyCode < 48 || event.keyCode > 57 ) {
                        event.preventDefault(); 
                } */
			
				if(!((event.keyCode >= 48 && event.keyCode <= 57) || (event.keyCode >= 96 && event.keyCode <= 105))){
					event.preventDefault(); 
				}				
        }
		//alert(event.data);
    });
	
});

function ExecuteOnLoadFunctions(){
	/*ReplaceSelect('kamSkirta');
	ReplaceSelect('laikoIntervalai');	*/
	setForm();//replace all select to <ul>
	
	/*
	$.fancybox(
		'<h2>Hi!</h2><p>Lorem ipsum dolor sit amet, consectetur adipiscing elit. Etiam quis mi eu elit tempor facilisis id et neque</p>',
		{
        		'autoDimensions'	: false,
			'width'         		: 350,
			'height'        		: 'auto',
			'transitionIn'		: 'none',
			'transitionOut'		: 'none'
		}
	);
	*/
	$("#message1Link").trigger('click');
}

function ShowUzsakymoForma(){
	var order_form = $('#orderForm');
	if(order_form.css('display') == 'none'){
		order_form.css('display', 'block');
	}else{
		order_form.css('display', 'none');
	}
}

function ShowUzsakymoForma(){
	var order_form = $('#orderForm');
	if(order_form.css('display') == 'none'){
		order_form.css('display', 'block');
	}else{
		order_form.css('display', 'none');
	}
}


function CheckFeedbackForm(form_id, module_id, message){
	var name = jQuery.trim($('#'+form_id+' input[name='+module_id+'author_name]').val());
	var feedback = jQuery.trim($('#'+form_id+' textarea[name='+module_id+'comment]').val());
	if(name == '' || feedback == ''){
		alert(message);
		return false;
	}
	return true;
}

function ExtendActions(){
	/*
     var elem = document.getElementById("footer_text_id");
     if(elem){
       elem.style.bottom = "88px";
     }
     
     elem = document.getElementById("copyright_id");
     if(elem){
       elem.style.bottom = "30px";
     }*/
   }


function PageExtender(used_height){
    var elemet_id = "page_extender";
	var elem = null;
	if(elem = document.getElementById(elemet_id)){
	  //alert('Your resolution is '+screen.width+'x'+screen.height); 
	  
	  	var w, h;
		if (self.innerHeight) // all except Explorer
		{
			w = self.innerWidth;
			h = self.innerHeight;
		}
		else if (document.documentElement && document.documentElement.clientHeight)
			// Explorer 6 Strict Mode
		{
			w = document.documentElement.clientWidth;
			h = document.documentElement.clientHeight;
		}
		else if (document.body) // other Explorers
		{
			w = document.body.clientWidth;
			h = document.body.clientHeight;
		}
	  //alert("W: "+ w + " H: " + h);
	  var diff = h - used_height;
	  //alert(diff);
	  if(diff < 0) diff = 0;
	  elem.style.height = diff +"px";
	  ExtendActions();
	}
   }




