var ww = $(window).width();
var wh = $(window).height();
var bgpr = 1; // hatterkep sz/m aranya
var wpr = ww/wh;
var nw, nh;

$(document).ready(function(){
	
	$("#background > img").load(function() {
		bgResize();   	
    });
    $(window).resize(function(e){
    	bgResize();
    });
    
    // biztonsagbol
    setTimeout(bgResize, 100);
    var str='', split;
    $( "#sortable" ).sortable({
			placeholder: "ui-state-highlight",
			update: function(){
				str='';
				$('ul#sortable li textarea').each(function(i, item){
					split=$(item).attr('name').split('_');
					str+=split[1];
					if(i<$('ul#sortable li textarea').length-1)str+=','; 
				});
				$('input[name=sort]').val(str);
			}
	});
	
});

function bgResize() {
	ww = $(window).width();
	wh = $(window).height();
	wpr = ww/wh;
	
	bgpr = $("#background > img").width() / $("#background > img").height(); // hatterkep aranya
    
    if (bgpr < wpr) {
    	nw = ww+1;
    	nh = (($("#background > img").height()*nw)/$("#background > img").width())+1;
    } else {
    	nh = wh+1;
    	nw = (($("#background > img").width()*nh)/$("#background > img").height())+1;
    }
   	$("#background").css("width",nw);
    $("#background").css("height",nh);
    $("#background > img").css("display","none").css("width",nw);
    $("#background > img").css("display","none").css("height",nh);
    $("#background > img").show();   
}

function fireFancy() {
	$("a.group_fancy").fancybox({
		'zoomSpeedIn': 300, 
		'zoomSpeedOut': 300, 
		'overlayShow': true,
		'imageScale': false,
		'overlayColor': '#000000',
		'padding': 0
	});
}
