var tipApi = null

$(document).ready(function() {

	// textarea //
	
		$('textarea.resizable:not(.processed)').TextAreaResizer();
		$('iframe.resizable:not(.processed)').TextAreaResizer();
	
	// tooltip //
	
	    $(".tip").tooltip({position: 'bottom left',
	                        onShow: function(ev) {
	                            $(this.getTrigger()).addClass('gyorsmenu_active')
	                        },
	                        onHide: function(ev) {
	                            $('.gyorsmenu_active').removeClass('gyorsmenu_active')
	                        }
	
	        });
		tipApi = $(".tip").data("tooltip"); 
	
		$.tools.tooltip.addEffect("toggle",
	
			function(done) {
				var conf = this.getConf(), tip = this.getTip(), o = conf.opacity;
	
	
				if (o < 1) { tip.css({opacity: o}); }
				tip.css({top: '48px', left: '-2px'});
	
	
				tip.show();
				done.call();
			},
	
			function(done) {
				this.getTip().hide();
				done.call();
			}
		);
	
	// select //
	
		$('.selectbox').sSelect({
	        defaultText: '- Válasszon!',
			scrollHeight: '500px',
			showType: 'click',
			isWrap: 'true'
		});
	
	// datepicker //
	
	    curDate = new Date();
	
	    $('.date').datepicker({
	            dateFormat: 'yy-mm-dd',
	            minDate: new Date(curDate.getFullYear(), curDate.getMonth(), curDate.getDate() + 1),
	            maxDate: new Date(curDate.getFullYear()+2, curDate.getMonth()+1, curDate.getDate()),
	            buttonImageOnly: false,
	            changeMonth: true,
	            changeYear: true,
	            showMonthAfterYear: true,
	            showOn: 'both'
	    });
	
	// left menu //
	
		$(".subsub").hide();
		
		$("a.subsublink").click(function(){
			$(this).toggleClass("opened").next().toggle();
		});
	
	// search tab //
	
		$(".tab_content").hide(); 
		$("ul.tabs li:first").addClass("active").show();
		$(".tab_content:first").show();
		
		$("ul.tabs li").click(function() {
			$("ul.tabs li").removeClass("active");
			$(this).addClass("active");
			$(".tab_content").hide();
			var activeTab = $(this).find("a").attr("href");
			$(activeTab).fadeIn();
			return false;
		});
		
		
	// font resizer //	

		var originalFontSize = '11px';										// original font
		// var originalFontSize = $('#content').css('font-size');		// original font
		
		$("#resetfont").click(function(){
    		$('#content').children().css('font-size', originalFontSize);
    		return false;
  		});
  		
		$("#increasefont").click(function(){							// increase font size
			var currentFontSize = $('#content').children().css('font-size');
			var currentFontSizeNum = parseFloat(currentFontSize, 10);
			var newFontSize = currentFontSizeNum*1.2;
			if ( newFontSize < 20 ) {
				$('#content').children().css('font-size', newFontSize);
			}	
			return false;
		});
		
		$("#decreasefont").click(function(){							// decrease font size
			var currentFontSize = $('#content').children().css('font-size');
			var currentFontSizeNum = parseFloat(currentFontSize, 10);
			var newFontSize = currentFontSizeNum*0.8;
			if ( newFontSize > 8 ) {
				$('#content').children().css('font-size', newFontSize);
			}
			return false;
		});
		
		
	// print //
	
		$("#print").click(function() {
			$('#data').printElement({ 
				overrideElementCSS: [{ href:'./resources/css/print.css', 
				media:'screen,print'}], 
				leaveOpen: true, 
				printMode: 'popup' 
			});
		});
		
	// banner //
	/*
		var bannerArr = Array(
							'1|bannerPelikan|pelikan|swf|155|250|', 
							'1|bannerSunset|sunset|swf|155|250|', 
							'1|bannerCity|city_cafe|img|155|151|http://www.citycafe.hu/',
							'1|bannerArkadent|arkadent|img|155|250|http://www.arkadent.hu/fooldal-hu.html',
							'2|bannerParkolas|parkolas|img|155|149|http://www.belvarosikorzo.hu/',
							'2|bannerLiget|liget|swf|155|257|'
						);
	
		for (i = 0; i < bannerArr.length; i++) {

			str = bannerArr[i].split('|');
			folder = './userfiles/ads/';
			
			$('<div id="' + str[1] + '" style="padding: 10px 0;z-index: -9999;"></div>').appendTo("#ads"+ str[0]);
			
			
			
			switch(str[3]) {
				
				case 'swf':
					$('#' + str[1]).flash({
					
						src: 		folder + str[2] + '.swf',
						width: 		str[4],
						height: 	str[5],
						wmode: 		'opaque',
						version:  	8
				
					});
						break;
				
				case 'img':
					$('#' + str[1]).html(((str[6] != '') ? '<a href="' + str[6] + '" target="_blank">' : '') + '<img src="' + folder + str[2] + '.jpg" width="' + str[4] + '" height="' + str[5] + '" />' + ((str[6] != '') ? '</a>' : ''));
						break;
						
			}
			
		}
		
	*/	
	// map1 //
	
		$('#map1').mouseover(function(e) { changeImg(1, $(this).attr('href')) });		
		
	// map2 //
	
		$('#map2').mouseover(function(e) { changeImg(2, $(this).attr('href')) });
	
	// map3 //
	
		$('#map3').mouseover(function(e) { changeImg(3, $(this).attr('href')) });
		
	// change map image //
	
		function changeImg(number, url) {
			
			$('#mapImg').attr('src', './resources/img/body/img_map' + number + '.jpg');
			$('#mapHref').attr('href', url);
			
			for (i = 1; i <= 3; i++) {
				
				if (i == number) {
					
					$('#map' + i).addClass('active');
					
				}
				
				else {
					
					$('#map' + i).removeClass('active');
					
				}
				
			}
			
		}	

	// show hide div
		$("#ptext").click(function(e) {
			
			e.preventDefault(); 
			var id = $(this).attr('rel');
			
			if ($('#pdate'+id).is(':visible')) {
				$('#ptext').html('További dátumok megjelenítése');	
				$('#pdate'+id).hide();
			}
			else {
				$('#ptext').text('További dátumok elrejtése');
				$('#pdate'+id).show();
			}
		});
		
});





// search box //

	function searchDown() {
		$(".search_details").animate({height: "240px"}, 200, function(){
			$(".search_details_in").css({display: 'block'});
			$("#searchOn").css({display: 'none'});
			$("#searchOff").css({display: 'block'});
		});
	}
	function searchUp() {
		$(".search_details").animate({height :"0"}, 200, function(){
			$(".search_details_in").css({display: 'none'});
			$("#searchOff").css({display: 'none'});
			$("#searchOn").css({display: 'block'});
		});
	}
	
	
// time //

	function timeDisplay() {
		display = document.getElementById('time');
		var digital = new Date();
		var hours = digital.getHours();
		var minutes	= digital.getMinutes();
		var seconds	= digital.getSeconds();

		if (minutes <= 9) { minutes = '0' + minutes; }	
		if (seconds <= 9) { seconds = '0' + seconds; }	

		display.innerHTML = hours + ':' + minutes + ':' + seconds
		setTimeout('timeDisplay()', 1000);
	}
