$.fn.fixPNG = function(){
	return this.each(function () {
		var image = $(this).css('backgroundImage');
		if (image.match(/^url\(["']?(.*\.png)["']?\)$/i)) {
			image = RegExp.$1;
			$(this).css({
				'backgroundImage': 'none',
				'filter': "progid:DXImageTransform.Microsoft.AlphaImageLoader(enabled=true, sizingMethod=" + ($(this).css('backgroundRepeat') == 'no-repeat' ? 'crop' : 'scale') + ", src='" + image + "')"
			}).each(function () {
				var position = $(this).css('position');
				if (position != 'absolute' && position != 'relative')
					$(this).css('position', 'relative');
			});
		}
	});
};

$.fn.fixPNG2 = function(){
	$(this).css({'backgroundImage': 'none'})
};

$(document).ready(function(){
	var isIE = ($.browser.msie && parseInt($.browser.version.substr(0,1)) < 7);
	if (isIE) {
		$(".png").fixPNG();
		$(".png2").fixPNG2();
	}
	
	// umisteni paticky
	var windowHeight = $(window).height();
	var headerHeight = $('#header1').height();
	var $content = $('#content');
	var contentHeight = $content.height();
	var footerHeight = $('#footer').height();
	if (windowHeight > headerHeight+contentHeight+footerHeight) {
		var $text = $('#text');
		var textPadding = 2 * 45;
		$content.css('height', (windowHeight-headerHeight-footerHeight)+'px');
	}
	$('#container').css('height', (headerHeight+contentHeight+footerHeight-35)+'px');
	
	// animace menu
	$('#menu a').hover(function(){
		$(this).stop().animate({backgroundPosition: '0px -29px'}, 150);
	}, function(){
		$(this).stop().animate({backgroundPosition: '0px 0px'}, 1000);
	})
	
	// reference
	var api = $("#gallery").scrollable({
		size: 3,
		speed: 2000,
		clickable: false,
		loop: true
	}).circular().autoscroll({
 		autoplay: true,
 		interval: 4000
 	});
 	
 	// fakturacni adresa
 	$jakopostovni = $('#jakopostovni');
	if ($jakopostovni.attr('checked')) {
		$('#ulice2, #mesto2, #psc2, #zeme2').attr('disabled', 'checked').css('backgroundColor', '#ccc');
	}
	$jakopostovni.change(function(){
		if ($jakopostovni.attr('checked'))
			$('#ulice2, #mesto2, #psc2, #zeme2').attr('disabled', true).css('backgroundColor', '#ccc');
		else
			$('#ulice2, #mesto2, #psc2, #zeme2').attr('disabled', false).css('backgroundColor', '#fff');
	});
 	
 	// form navrh
 	$navrh = $('#navrh');
 	$grafikatr = $('#grafika-tr');
 	if ($navrh.val() != 'ano') $grafikatr.addClass('hidden');
 	$navrh.change(function(){
		if ($navrh.val() != 'ano') $grafikatr.addClass('hidden');
		else $grafikatr.removeClass('hidden');
	});
 	
 	// form button
 	$('#submit').hover(function(){
 		$(this).addClass('hover');
	}, function(){
		$(this).removeClass('hover');
	});
	
	// fancybox
	$('a.fancy').fancybox({
		'transitionIn'	: 'elastic',
		'transitionOut'	: 'elastic',
		'titlePosition'	: 'inside',
		'cyclic': true,
		'centerOnScroll': true
	});

});
