$(document).ready(function(){ 
	$('.loginShow').click(function(){
		$('.loginNoDp').fadeIn("fast", function(){
			$('.loginFormCont').fadeIn("fast");
		})
		return false;
	})
	$('.loginNoDp, .formContent .close, #forgot-password-link').click(function(){
		$('.loginFormCont').fadeOut("fast", function(){
			$('.loginNoDp').fadeOut("fast");
		})
		return false;
	})
	
	function activateSubcategories() {
		$('.subcategories li').hover(
			function(){
				if(!$(this).children('.txt').is(':animated')) {
					$(this).children('.txt').slideDown('fast');	
				}
			},
			function() {
					$(this).children('.txt').slideUp('fast');
			}	
		);
	}
	
	activateSubcategories();
	
	var subcategories = $('.szeriak .subcategories li');
	
	var showSubcategories = function(page) {
		page = parseInt(page);
		if(!page) {
			page = 1;
		} 
		subcategories.remove();
		$('.szeriak .subcategories').empty();
		var newSubcategories = subcategories.clone();
		var offset = page * 9 - 9;
		newSubcategories = newSubcategories.slice(offset, 9 + offset);
		newSubcategories.hide().appendTo('.szeriak .subcategories').fadeIn(1000);
		activateSubcategories();
	}
	
	if(subcategories.length > 9) {
		var maxPage = Math.ceil(subcategories.length / 9);
		var hash = document.location.hash;
		var patt = /page:([\d]+)/;
		var page = patt.exec(hash);
		if(!page) {
			page = 1;
		} else {
			page = page[1];
		}
		showSubcategories(page);
		var pager = $('<div class="pager"><span class="prev" style="display:none;" title="Előző oldal">&laquo;</span> <span class="pageCount">'+page+' / '+maxPage+'</span> <span class="next" title="Következő oldal">&raquo;</span></div>');
		$('.szeriak').append(pager);
		pager.find('.prev').css('cursor', 'pointer').click(function() {
			$('html, body').animate({scrollTop:550}, 1000);
			page--;
			if(page <= 1) {
				page = 1;
				$(this).hide();
			}
			pager.find('.next').show();
			pager.find('.pageCount').html(page + ' / ' +maxPage);
			showSubcategories(page);
			return false;
		});
		pager.find('.next').css('cursor', 'pointer').click(function() {
			$('html, body').animate({scrollTop:550}, 1000);
			page++;
			if (page >= maxPage) {
				page = maxPage;
				$(this).hide();
			}
			pager.find('.prev').show();
			pager.find('.pageCount').html(page + ' / ' +maxPage);
			showSubcategories(page);
			return false;
		});
	}
	/*
	if($('.bCCont .banner').length == 1) {
		var el = $($('.bCCont .banner'));
			el.show();
			if(el.find('.btText').text().length > 100) {
				function getHeight() {
					var height 	= el.find('.btTitle').outerHeight() 
						+ el.find('.btSTitle').outerHeight()
						+ el.find('.btLink').outerHeight()
						+ el.find('.btText').outerHeight();
					return height;
				}
				while(getHeight() > 280) {
					var oldText = el.find('.btText').text();
					var newText = oldText.substring(0, oldText.lastIndexOf(' ')) + '...';
					el.find('.btText').text(newText);
				}
				
			}
	}
	*/
	$('.bCCont').cycle({
		timeout: 8000,
		before: function(currSlideElement, nextSlideElement, options, forwardFlag) {
			var el = $(nextSlideElement);
			if(el.hasClass('processed')) {
				return;
			}
			el.addClass('processed');
		//	el.show();
			/*		
			*/
			if(!el.find('.btText').hasClass('shortened') && el.find('.btText').text().length > 50) {
				el.find('.btText').addClass('shortened');
				function getHeight() {
					var hidden = false;
					if(el.is(':hidden')) {
						hidden = true;
						el.show();
					}
					var height 	= el.find('.btTitle').outerHeight() 
						+ el.find('.btSTitle').outerHeight()
						+ el.find('.btLink').outerHeight()
						+ el.find('.btText').outerHeight();
					if(hidden) {
						el.hide();
					}	
					return height;
				}
		
				while(getHeight() > 280) {
					var oldText = el.find('.btText').text();
					if(oldText.length < 50) {
						break;
					}	
					var newText = oldText.substring(0, oldText.lastIndexOf(' ')) + '...';
					el.find('.btText').text(newText);
				}
				
			}
		},
		after: function(currSlideElement, nextSlideElement, options, forwardFlag) {
		//	$(currentSlideElement).hide();
		}
	});
	
	$('.bannerCont .bannerTxt').css('opacity', 0.8);
	
	$('.bannerCont .banner .btCont').each(function(){
		
	});
})

