$(document).ready(function(){
	$("a.colorbox").colorbox();
	
	slideshow();

	
	$(".menu .mIten").each(function() {
		/*$("ul", this).css({
			"display": "none"
		});*/
		$(this).mouseover(function() {
			$(this).css({
				"color": "#ffffff", 
				"padding-top": "10px", 
				"cursor": "pointer"
			});
			$("ul", this).css({
				"display": "block"
			});
		});
		$(this).mouseout(function() {
			$(this).css({
				"color": "#cccccc", 
				"padding-top": "10px", 
				"border-top": "none"
			});
			$("ul", this).css({
				"display": "none"
			});
		});
	});
	
	$(".sliper").each(function() {
		$(this).click(function(){
			
			$(".moretext", this).slideToggle("fast");
			
			$(this).toggleClass('expand');
			return false;
		});
		
		$(this).mouseover(function() {
			$(this).css({
				"cursor":"pointer"});
		});
		$(this).mouseout(function() {
			$(this).css({
				"cursor":"normal"
			});
		});
	});
	//map
	$(".map").click(function(){
		var href = $(this).attr("href");
		$.colorbox({
			href:href,
			iframe:true,
			scrolling: false,
			innerWidth: 850,
			innerHeight: 480
		});
		return false;
	});
	//popup
	$('div.popup_layer').css('opacity', 0.2);
	$('div.popup_box #popup_close').bind('click', function () {
		$('div.popup_layer, div.popup_box').fadeOut(200);
		return false;
	});
});
var timer = null;     //az idozíto létrehozás a képváltáshoz  
function slideshow() {
	if(timer)  clearInterval(timer); //idozíto törlése
	var picnum =  $("div.homepics div.thumbnails a").size();
	var actnum = 1;
	var prevnum = 1;
	
	var REL = $("div.homepics .image img").attr('rel');
	keplink(REL);
	 
	$("div.homepics div.thumbnails a").click( function() {
		if(timer)  clearInterval(timer);
		prevnum = actnum;
		var ID = parseInt($(this).attr('id'));
		var TITLE = $(this).html();
		REL = parseInt($(this).attr('rel'));
		actnum = ID
		
		$("div.homepics div.thumbnails span").removeClass('active'); 
		$("div.homepics div.thumbnails span a#"+actnum).parent().addClass('active'); 
		$("div.homepics .image").prepend("<img src='/images/homepics/"+actnum+".jpg' alt='' id="+actnum+" title='"+ TITLE +"' />");
		$("div.homepics .image img#"+prevnum).animate({'opacity':0}, 600, null, function(){
			$('div.homepics .image img#'+prevnum).remove();
			keplink(REL);
		}); 
		timer = setInterval( function() {
			
			prevnum = actnum;
			if(actnum == picnum){
				actnum = 1;
			}else{
				actnum = actnum + 1;
			}
			REL = $("div.homepics div.thumbnails span a#"+actnum).attr('rel');
			var TITLE = $("div.homepics div.thumbnails span a#"+actnum).html();
			
			$("div.homepics div.thumbnails span").removeClass('active'); 
			$("div.homepics div.thumbnails span a#"+actnum).parent().addClass('active'); 
			$("div.homepics .image").prepend("<img src='/images/homepics/"+actnum+".jpg' alt='' id="+actnum+" title='"+ TITLE +"' />");
			$("div.homepics .image img#"+prevnum).animate({'opacity':0}, 600, null, function(){
				$('div.homepics .image img#'+prevnum).remove();
				keplink(REL);
			}); 
			
		}, 5*1000 );
		return false;
	});		
	
	timer = setInterval( function() {
		prevnum = actnum;
		if(actnum == picnum){
			actnum = 1;
		}else{
			actnum = actnum + 1;
		}
		REL = $("div.homepics div.thumbnails span a#"+actnum).attr('rel');
		var TITLE = $("div.homepics div.thumbnails span a#"+actnum).html();
		
		$("div.homepics div.thumbnails span").removeClass('active'); 
		$("div.homepics div.thumbnails span a#"+actnum).parent().addClass('active'); 
		$("div.homepics .image").prepend("<img src='/images/homepics/"+actnum+".jpg' alt='' id="+actnum+" title='"+ TITLE +"' />");
		$("div.homepics .image img#"+prevnum).animate({'opacity':0}, 600, null, function(){
			$('div.homepics .image img#'+prevnum).remove();
			keplink(REL)
		}); 
	}, 5*1000 );
	//az animáció vége        
	
}

function keplink(link) {
	
	$('div.homepics .image img').live('mouseover mouseout', function(event) {
	  if (event.type == 'mouseover') {
		$(this).css({
			"cursor": "pointer"
		});
	  } else {
		$(this).css({
			"cursor": "normal"
		});
	  }
	});
	$('div.homepics .image img').live('click', function() {
		window.location = link;
	});
	
}



