jQuery(document).ready(function() {

var buves_width=win_width();
var buves_height=win_height();


(function($) {
    $.fn.fullBg = function(options) {
        var bgImg = $(this);

        bgImg.addClass('fullBg');
        function resizeImg(force_reload) {

	
//skaiciuojame pirma bet kokiu atveju ***************
			var winwidth = win_width();
            var winheight = win_height();
			
			
			var imgwidth = 1300;
            var imgheight = 550;
			
			  var widthratio = winwidth/imgwidth;
			var heightratio=winheight/imgheight;
            var widthdiff = winwidth-17;
			
			
			if (winwidth==1280 && screen.height==1024) {
				heightdiff = winheight-300;
			} else if (screen.height==1126 && screen.width==1408) {
			//alert('spauskite ok');
				heightdiff = winheight-325;
			} else {
				heightdiff = winheight-212;
			}
			//perskaiciuojame width
			naujas_width=1300*heightdiff/550;
			marginas=(winwidth-naujas_width)/2;
			
		var bg_style_pirmas='width:'+	naujas_width + 'px;height:'+heightdiff + 'px;margin-left:'	+marginas + 'px';
		var wrapper_pirmas='height:'+heightdiff + 'px;';
			//if (defaults.pirmas_psl==1){
			
			bgImg.css({
                    width:naujas_width + 'px'
                    ,height:heightdiff + 'px'
					,marginLeft:marginas + 'px'
                });
				//svarbu
				
				var left_id=document.getElementById("leftarr");
				if (left_id != null)
					left_id.style.top = (heightdiff -34) + 'px';

				
				var right_id=document.getElementById("rightarr");
				if (right_id != null) {
					right_id.style.left = (win_width() -115) + 'px';
					right_id.style.top = (heightdiff -33) + 'px';
				}

				
				var wrapper=document.getElementById("wrapper");
				if (wrapper != null) 
					wrapper.style.height = heightdiff + 'px';
				
				var car_id=document.getElementById("car");
				if (car_id != null) 
					car_id.style.width = (win_width() -500) + 'px';
				var burbulai=document.getElementById("burbulai");
				burbulai.style.display = "inline";

				var url= 'burbulai.php?width='+naujas_width+'&height='+heightdiff+'&foto='+fotoarr[selected_idx]+'&margin='+marginas;
				$.get(url,
					function(data){
						$('#burbulai').html(data);
					});
	
				if (force_reload==1) { 	window.location.reload(); 	}		
              
           
			
        }
		resizeImg(0);
			
        $(window).resize(function() {
		if ((buves_width!=win_width()) &&  (buves_height!=win_height())){
		buves_width=win_width();
		buves_height=win_height();

			resizeImg(1);
			
			}
        });
    };
})(jQuery);





}); //jquery ready


function win_width(){
var winwidth = $(window).width();
if (winwidth<1024) {winwidth=1024; }
return winwidth;

}

function win_height(){
var winheight = $(window).height();
if (winheight<768) {winheight=768; }
return winheight;

}
