jQuery.preloadImage = function(i)
{
    jQuery("<img>").attr("src", i);
}

jQuery.fixDiv = function(maxsize, p, f, ispad)
{
	size = $('div#c div' + p).height();
	if ( (size + 22) < maxsize ) $('div#c div' + p).append('<div id="' + f + '"></div>');

	$('div#c div#' + f).css('background-color', '#d4cba8');
	$('div#c div#' + f).css('margin-top', '8px');
	$('div#c div#' + f).height(maxsize - size);
	if (p == '#c_l') {
		$('div#c div#' + f).height(maxsize - (size + 14));
		$('div#c div#' + f).css('width', '128px');
	}
	if (p == '#c_r') {
		$('div#c div#' + f).height(maxsize - (size + 14));
		$('div#c div#' + f).css('width', '131px');
		$('div#c div#' + f).css('margin-left', '1px');
		$('div#c div#' + f).css('position', 'relative');
		$('div#c div#' + f).css('top', '-6px');
	}
	if (p == '.smenubox') {
		$('div#c div#' + f).css('margin-top', '0px');
		$('div#c div#' + f).css('width', '129px');
		$('div#c div#' + f).css('margin-left', '7px');
		$('div#c div#' + f).height(maxsize - (size + 9));
	}
}

jQuery.fixScreen = function()
{
		var kulso = [ 'c_r', 'c_l', 'c_c' ];
		var belso = [ '.cl', '.smenubox' ];
		var fix_kulso = { '#c_r':'c_r_fix', '#c_l':'c_l_fix' };
		var fix_belso = { '.cl':'c_cl_fix', '.smenubox':'smenubox_fix' };

		$.each(fix_kulso, function(p, f) { $('div#c div#' + f).remove() })
		$.each(fix_belso, function(p, f) { $('div#c div#' + f).remove() })

		var max_kulso = 0
		var max_belso = 0

		$.each(kulso, function() {
			if ( $('#' + this).height() > max_kulso ) max_kulso = $('#' + this).height();
		})

		if ( $('div#c_c > .cl').height() > $('div#c_c > .smenubox').height() ) {
			max_belso = $('div#c_c > .cl').height();
			$.fixDiv(max_belso, '.smenubox', 'smenubox_fix', 0);
		}
		
		$.each(belso, function() {
			if ( $('div#c_c > ' + this).height() > max_belso ) max_belso = $('div#c_c > ' + this).height();
		})

		$.each(fix_kulso, function(p, f) { $.fixDiv(max_kulso, p, f, 1); })
/*
		$.each(fix_belso, function(p, f) { $.fixDiv(max_belso, p, f, 0); })
*/
}

jQuery(document).ready(function() {
	
	$('img').each(function() {
		$.preloadImage( $(this).attr("src") );
	})

	var jqzoom_options = {
		title: false,
		zoomWidth: 430,
		zoomHeight: 334,
		xOffset: 26,
		yOffset: -55,
		preloadText: 'Kép betöltése...',
		position: "right"
	};

	$('.termekkep').jqzoom(jqzoom_options);
/*
	$('ul.lmenu1 > li > ul').each(function() {
		if ( $(this).parent().hasClass("opened") ) {
			$(this).parent().addClass('li2');
			$(this).parent().show();
			$.fixScreen();
		} else {
			$(this).parent().addClass('li1');
			$(this).hide();			
		}
	});
	
	$('ul.lmenu1 > li').click(function() {
		var p = $(this);
		$(this).children('ul:visible').hide('slow', function() {
			$(this).parent().removeClass('li2');
			$(this).parent().addClass('li1');
			$.fixScreen();
		});
		$(this).children('ul:hidden').show('slow', function() {
			$(this).parent().removeClass('li1');
			$(this).parent().addClass('li2');
			$.fixScreen();
		});
	});
*/
//	setTimeout("$.fixScreen();", 1000);
});


/*	
var hasab = [ 'c_r', 'c_l', 'c_c' ];
var hasab2 = [ '.cl', '.cr' ];
var fixdivs1 = { '#c_r':'c_r_fix', '#c_l':'c_l_fix' };
var fixdivs2 = { '.cl':'c_cl_fix', '.cr':'c_cr_fix' };

function fixdiv(maxsize, p, f, ispad) {
	if ( $('div#c div' + p).height() < maxsize ) $('div#c div' + p).append('<div id="' + f + '"></div>');

	$('div#c div#' + f).css('background-color', '#d4cba8');
	if (ispad == 1) $('div#c div#' + f).css('margin-top', '8px');
	$('div#c div#' + f).height(maxsize - $('div#c div' + p).height());		
}

function fixscreen() {
	$.each(fixdivs1, function(p, f) {
		$('div#c div#' + f).remove()
	})

	$.each(fixdivs2, function(p, f) {
		$('div#c div#' + f).remove()
	})

	var maxsize = 0
	var maxsize2 = 0
	$.each(hasab, function() {
		if ( $('#' + this).height() > maxsize ) maxsize = $('#' + this).height();
	})

	$.each(hasab2, function() {
		if ( $('div#c_c > ' + this).height() > maxsize2 ) maxsize2 = $('div#c_c > ' + this).height();
	})

	$.each(fixdivs1, function(p, f) {
		fixdiv(maxsize, p, f, 1);
	})

	if ( $('div#c_c > div.cl > div.cbox').height() > 0 ) {
		$.each(fixdivs2, function(p, f) {
			fixdiv(maxsize2, p, f, 0);
		})
	}
	
	if ( $('div#c_c > div.cbox').height() > 0 ) {
		fixdiv(maxsize, '#c_c', 'c_c_fix', 1);
	} else {
		fixdiv(maxsize, '.cl', 'c_cl_fix', 1);
		$('div#c div#c_cl_fix').css('margin-left', '8px');
		fixdiv(maxsize, '.cr', 'c_cr_fix', 1);
	}
}
*/	


