$(document).ready(function(){
	$("a.zoom").fancybox({ 
		'padding':0,
		'opacity':true,
		'hideOnContentClick': true, 
		'overlayColor' : '#000', 
		'overlayOpacity': 0.4,
		'overlayShow':true,
		'speedIn':400,
		'speedOut':400,
		'titlePosition': 'outside'
	});
	$("a[rel=fancy_group]").fancybox({
		'transitionIn'	: 'none',
		'transitionOut'	: 'none',
		'titlePosition' : 'outside'
	});
	$("#tab").tabs();
	$(".tab_content .mini a").click(function(){
		$('#medium img').attr('src', $(this).attr('href'));
		$('#medium').attr('href', $(this).attr('href').replace('_medium', '_big'));
		$(".tab_content .mini a").removeClass('selected');
		$(this).addClass('selected');
		return false;
	});
	$('a.save').click(function(){
		var parent = $(this).parents('tr.row');
		$('form', parent).submit();
		return false;
	});
	$('a.book').click(function(){
		var ansfer = confirm($(this).attr('rel')); 
		if(ansfer){
			var parent = $(this).parents('tr.row');
			$('form', parent).submit();
		}
		return false;
	});

	$("a.box").not('.disabled').fancybox({ 
		'padding':20,
		'opacity':false,
		'hideOnContentClick': false,
		'overlayColor' : '#011b37',
		'overlayOpacity': 0.5,
		'type':'iframe',
		'overlayShow':true,
		'speedIn':400,
		'speedOut':400,
		'width':600,
		'height':400,
		'autoDimensions':false,
		'transitionIn':'elastic',
		'transitionOut':'elastic',
		'titleShow':false
	});
	$(".boxLogin").fancybox({ 
		'padding':20,
		'opacity':false,
		'hideOnContentClick': false,
		'overlayColor' : '#011b37',
		'overlayOpacity': 0.5,
		'overlayShow':true,
		'speedIn':400,
		'speedOut':400,
		'width':280,
		'height':170,
		'autoDimensions':false,
		'transitionIn':'elastic',
		'transitionOut':'elastic',
		'titleShow':false
	});
	$(".boxElement").fancybox({ 
		'padding':20,
		'opacity':false,
		'hideOnContentClick': false,
		'overlayColor' : '#011b37',
		'overlayOpacity': 0.5, 
		'overlayShow':true,
		'speedIn':400,
		'speedOut':400,
		'width':600,
		'height':400,
		'autoDimensions':false,
		'transitionIn':'elastic',
		'transitionOut':'elastic',
		'titleShow':false
	});
	$('#sort-control').change(function(){
		$.cookie($(this).attr('name'), $(this).val(), { path: '/'});
		var tid = $('#tid').val();
		var tid_str = '';
		if(tid){
			tid_str = 'tid,'+tid+',';
		}
		var lid = $('#lid').val();
		var lid_str = '';
		if(lid){
			lid_str = 'lid,'+lid+',';
		}
		var url = $('#base-url').val()+'/'+tid_str+lid_str+$(this).attr('name')+','+$(this).val()+'.html';
		document.location.href = url;
	});
	$("a.disabled").click(function(){
		return false;
	});
	$(".insert-image").click(function(){
		var rel = $(this).attr('rel')
		var src = $(this).attr('href')
		//CKEDITOR.instances.ew_form_fieldstrona_glowna.insertElement(writer.getHtml());
		var imgHtml = CKEDITOR.dom.element.createFromHtml('<img src="'+src+'" alt=""/>');
              	eval('CKEDITOR.instances.'+rel+'.insertElement(imgHtml)');

		return false;
	});
});

function focusInput(el, txt){
	if(el.value == txt){
		el.value=''
	}
}
function blurInput(el, txt){
	if(el.value == ''){
		el.value=txt;
	}
}
$(window).load(function(){
	equalHeight($(".branze"));
	if($('.page .in').height()<parseInt($(document).height())-550){
		$('.page .in').height(parseInt($(document).height())-550);
	}
});

function equalHeight(group){
	var tallest = 0;
	group.each(function(){
		var thisHeight = $(this).height();
		if(thisHeight > tallest){
			tallest = thisHeight;
		}
	});
	group.height(tallest);
}

