var fcklayer = {};
(function($){
	
	$('a[rel*="external"]').live('click',function(e){
		e.preventDefault();
		window.open($(this).attr('href'), '_blank');
	});
	$('a[rel*="goback"]').live('click',function(e){
		e.preventDefault();
		history.go(-1);
	});	
	
	$(document).ready(function() {		
		
		$('.lightbox').lightbox({
			fitToScreen: true,
			imageClickClose: false,
			fileLoadingImage: '/templates/powerpages/js/lightbox/images/loading.gif',
			fileBottomNavCloseImage: '/templates/powerpages/js/lightbox/images/closelabel_hu.gif',
			strings: {
				help: ' \u2190 / P - previous image\u00a0\u00a0\u00a0\u00a0\u2192 / N - next image\u00a0\u00a0\u00a0\u00a0ESC / X - close image gallery',
				prevLinkTitle: 'előző kép',
				nextLinkTitle: 'következő kép',
				prevLinkText:  '&laquo; Előző',
				nextLinkText:  'Következő &raquo;',
				closeTitle: 'kép bezárása',
				image: 'kép ',
				of: ' / '
			}
		});			
		
		$('#main-promo').cycle({
			timeout: 6000,
			delay:2000, 
			speed:600,
			pause: 1,
			pager:'#main-promo-nav',
			pagerEvent:'mouseover',
			pagerAnchorBuilder: function(idx, slide) {
				return '#main-promo-nav a:eq('+idx+')';
			},
			before: function(currSlideElement, nextSlideElement, options, forwardFlag){
				//console.log(forwardFlag);
				var h = $(currSlideElement).find('span').outerHeight();
				$(currSlideElement).find('span').stop().animate({bottom:-h},300,function(){});
			},
			after: function(currSlideElement, nextSlideElement, options, forwardFlag){
				$(nextSlideElement).find('span').stop().animate({bottom:'0'},300,function(){});
			}			
		 }); 	

		$('.section.references li').hover(
		function(){
			var thumbOver = $(this).find('img').attr('src');
			var info = $(this).find('span');
			$(this).find('a').css({'background':'url('+thumbOver+') no-repeat center '+(-$(this).height()+'px')});
			$(this).find('em').stop().fadeTo('normal',0,function(){
				$(this).hide();
				info.stop().animate({bottom:0},300,function(){});
			});
		},
		function(){
			var info = $(this).find('span');
			$(this).find('em').stop().fadeTo('normal', 1).show();
			info.stop().animate({bottom:-info.outerHeight()},300,function(){});
		});
		 
		function contentScrollTo(element) {
			var e = element!=undefined ? element : window.location.href;			
			eObj = $("a[name='"+e.split("#")[1]+"-nojump']");
			$.scrollTo(eObj,800,{onAfter:function(){}});
		}
		//$('div.items a').click(function(){if(window.location.href.split("#")[1]!=undefined)contentScrollTo($(this).attr('href'))});
		if(window.location.href.split("#")[1]!=undefined)contentScrollTo();		 
				
		fcklayer.init()
		
	});	

	jQuery.fn.center = function () {
		this.css('top', (($(window).height() - this.outerHeight(false)) / 2) + $(window).scrollTop() + 'px');
		this.css('left', (($(window).width() - this.outerWidth(false)) / 2) + $(window).scrollLeft() + 'px');
		return this;
	}
	
	/** fcklayer - fckban feltoltott bannerek/kepek elrejtese, linkkel megjelenitese 
		<div class="fcklayer">content</div>
		init@dom ready
	*/	
	var Fcklayer = function(){		
		var popup;
		var stack = [];
		this.show = function(index){			
			$('select:not(:hidden), embed, object',$('#base')).hide();
			$('#fckoverlay').hide().css({width:'100%',height:$(document).height() +'px',opacity:'.7'}).fadeIn(function(){
				$(stack[index]).appendTo('body');
				popup = $('#fcklayer'+index);			
				popup.center();			
			});
		};		
		this.hide = function(){
			popup.remove();
			$('#fckoverlay').fadeOut();
			$('select:not(:hidden), embed, object',$('#base')).show();		
		};
		this.register = function(markup){
			stack.push(markup);
		};
		this.init = function(){
			$('<div id="fckoverlay" title="Bezár"></div>').appendTo('body');
			$('.fcklayer').each(function(index,value){
				$this = $(this);
				fcklayer.register('<div id="fcklayer'+index+'" class="fcklayer-window">'+
					'<div class="fcklayer-window-content"><span class="clickcatcher"></span>'+$this.html().replace(/menu="true"/,"wmode=transparent")+'</div>'+
				'</div>');	
				$this.html('<a onclick="fcklayer.show('+index+')">Banner megtekintése</a>');	
			});
			$('#fckoverlay').click(function(){
				fcklayer.hide();
			});		
		}
	};
	Fcklayer.call(fcklayer);
	
})(jQuery);





	



