(function($){
/*
function openBigImage(url,w,h,hwin) {
  var ztop = ((screen.availHeight-h)/2)-80;
  var zleft = ((screen.availWidth-w)/2);
  parem='status=0,menubar=0,resizable=1,copyhistory=no,directories=no,scrollbars=1,width='+Number(w+25)+',height='+Number(hwin+25)+',top='+ztop+',left='+zleft+'';
  window2=window.open('','window2',parem);
  window2.document.open("text/html","replace");
  window2.document.writeln("<html><head><title>agrarunio.hu</title></head><body bgcolor=white style='margin:0 0 0 0'>");
  window2.document.writeln("<a href='javascript:self.close()'><img src="+url+" width="+w+" height="+h+" border=0></a>");
  window2.document.writeln("</body></html>");
  window2.document.close();
  window2.focus();
}
*/
	$.confirm2 = function(title, msg, url){

		var markup = [
			'<div id="confirmOverlay">',
			'<div id="confirmBox">',
			'<h3>'+title+'</h3>',
			'<p>'+msg,
			'<div id="confirmButtons"><a id="button_ok" class="orange awesome">törlés</a> <a id="button_cancel" class="awesome">mégse</a></div>',
      '</div></div>'
		].join('');
		
		$(markup).hide().appendTo('body').fadeIn();
		//$(markup).appendTo('body');
		toppos = $('#confirmBox').css('top');
		$('#confirmBox').css('top', 0);
		$('#confirmBox').animate({top: toppos},"fast");

	}
					
	$.confirm2.hide = function(){
		$('#confirmOverlay').fadeOut(function(){
			$(this).remove();
		});
	}
	
	$('#button_cancel').live('click', function(){
		$('#confirmOverlay').fadeOut(function(){
			$(this).remove();
			return false;
		});
	});
	
	$('#button_ok').live('click', function(){
			window.location=url;
			return false;
	});
})(jQuery);


var IE = /*@cc_on!@*/false;
var IE6 = (IE && (navigator['appVersion'].indexOf('MSIE 6') > 0)) ? true : false;



function modalBox(what) {
	if(!content){
		$('#ntz_modal').remove();
		$('#ntz_overlay').fadeOut(function(){$(this).remove();});
		try{if(IE6){$('body').find('select.unhideThis').removeClass('unhideThis').visibility('visible');}}catch(err){};
		$('embed.unhideThis, object.unhideThis').removeClass('unhideThis').css('visibility', 'visible');
		return false;
	}
	try{if(IE6){$('body').find('select:visible').addClass('unhideThis').visibility('hidden');}}catch(err){};
	$('embed:visible, object:visible').addClass('unhideThis').css('visibility', 'hidden');
	$('body').append('<div id="ntz_overlay"></div>');
	$('#ntz_overlay').css({
		width		:	'100%',
		height		:	$(document).height(),
		position	:	'absolute',
		left		:	0,
		top		:	0,
		backgroundColor	:	'#FFFFFF',
		zIndex		:	9990,
		opacity		:	0
	}).fadeTo(200, 0.5);
	$('body').append('<div id="ntz_modal"></div>');
	$('#ntz_modal').css({
		border		:	'1px solid #2d7abb',
		width		:	width ? width : 350,
		backgroundColor	:	'#FFFFFF',
		position	:	'absolute',
		left		:	'50%',
		top		:	$(document).scrollTop(),
		zIndex		:	9995,
		marginLeft	:	-(Math.ceil((width ? width : 800)/2))
	}).append(content);
	$('#ntz_modal a:eq(0), #ntz_modal input, #ntz_modal textarea').focus();
	try{
		callback.call();
	}catch(err){};
	$(document).bind('scroll', function(){
		$('#ntz_modal').css({
			top:$(document).scrollTop()
		});
	});
};



var site = function() {

	$(document).ready(function() {


  // LOGIN
		$('a#login_button').click(function(){
    $('#overlay').css({display: 'block'}).fadeTo(200, 0.8);
      $('#login').fadeTo(300, 1);
      $('#username').focus();
      return false;
    });
    
		$('#overlay').click(function(){
		  $('#login').fadeOut(200, function(){
        $('#overlay').fadeOut(200, function(){
          $('#overlay').css({display: 'none'});
          $('#username').focus();
          return false;
        })
      })
    });
    
// Teaser

// === Cikk teaser ===
 var gtHidden=true;
 var showTeaser = function () {
   $("#gtTeaser").animate({
     right: 0
     }, 300);
     gtHidden=false;
 };
 
 var hideTeaser = function () {
   $("#gtTeaser").animate({
     right: "-400px"
     }, 500);
     gtHidden=true;
 };

$(window).scroll(function () {
  var offset = $("#pagebottom").offset();

  if($("#tartalom_vege").length) offset = $("#tartalom_vege").offset();

  var bingo = $(window).scrollTop()+$(window).height()-offset.top;

 if (bingo > 0 && gtHidden) {
   showTeaser();
 }
 else if((bingo < 0 || $(window).scrollTop()==0) && !gtHidden) {
   hideTeaser();
 }
});

// === Cikk teaser end...
  
// Confirm box

	$('.confirmthis').click(function(){
    url = $(this).attr("href");
    var title = 'Figyelem!';
    var msg = $(this).attr("title");
    
		$.confirm2(title, msg, url);
    return false;
	});

// Galéria
$("a[rel^='galeria']").prettyPhoto({overlay_gallery: false, show_title: false});

// Táblázatok rendezése
$("table.sortable").tablesorter();

// Tooltip (Pl. fotóknál)
//$('.tt').betterTooltip();

// Klikkelhető táblázatsorok
$("tbody.klikk tr").click(function(){
	  window.location=$(this).find("a").attr("href"); return false;
});

		site.initialize();
	});

return {

		// IE fixes
		IEfix: function() {
			if (IE) {
				setTimeout(function() {
				}, 10);
			}
			return false;
		},

		initialize: function() {

			var a = null;
			var obj = null;
			var tmp = null;

		} // /init

	}
	// /return


}();
// /site

