$(document).ready(function(){

	$("#accordion").accordion({
		active: '.selected', 
	    active: 0,
		autoHeight: false }
	);

	$("#home #nav li a").hover(
  		function () {
  			var test = $(this).parent().hasClass('current');
   			if (!test) $(this).css("color","#cc7815");
  		},
  		function () {
  			var test = $(this).parent().hasClass('current');
   			if (!test) $(this).css("color","#cc7815");
  		}
	);


 	var l = $("#logo_1");
 

	var arrsections = new Array();

/*	EZ VOLT ideiglenesen 
	arrsections[0] = new Array('#logo_1','felhivas');
	arrsections[1] = new Array('#logo_2','a_fesztival');
	arrsections[2] = new Array('#logo_3','programok');
	arrsections[3] = new Array('#logo_4','facebook');
	arrsections[4] = new Array('#logo_5','galeriak');
	*/

	
	arrsections[0] = new Array('#logo_1','a_fesztival');
	arrsections[1] = new Array('#logo_2','programok');
	arrsections[2] = new Array('#logo_3','facebook');
	arrsections[3] = new Array('#logo_4','utcazeneszek');
	arrsections[4] = new Array('#logo_5','galeriak');
	arrsections[5] = new Array('#logo_6','informaciok');
	arrsections[6] = new Array('#logo_7','terkep');
	
	
	$("#logo_2").hide();
	$("#logo_3").hide();
	$("#logo_4").hide();
	$("#logo_5").hide();
	$("#logo_6").hide();
	$("#logo_7").hide();
	
	var gloaded = 0;
	var mloaded = 0;
	function animateMenuLogo(logo, menu) {
		var scrollposition = $(window).scrollTop();
		var top = $("."+ menu +"").offset().top;
		var sectionheight = $("."+ menu +"").next().outerHeight();
		
		if (((top-30) < scrollposition) && ((top+sectionheight-200) > scrollposition)) {
			$(logo).fadeIn(500);
			$("a[href='#"+ menu +"']").css({ backgroundColor: "#cc7815", color: "#ffffff" });
			$("a[href='#"+ menu +"']").parent().addClass("current");
			if (menu == "galeriak" && gloaded == 0) {
				gloaded = 1;
				loadGallery();
			} else if (menu == "terkep" && mloaded == 0) {
				mloaded = 1;
				loadMap();
			}
		} else {
			$(logo).fadeOut(100);
			$("a[href='#"+ menu +"']").css("background-color","transparent");
			$("a[href='#"+ menu +"']").css("color","#cc7815");$("a[href='#"+ menu +"']").parent().removeClass("current");
		}		
	}

    
    $(window).scroll(
    	function() {
    		
    		var top = 0;
    		
    		top = $(window).scrollTop();
    		
            if (top > 0) {
               $("#home #nav").css("top", 205);
            } else {
           	   $("#home #nav").css("top", 235-top);
            } 

            for (var i = 0; i < arrsections.length; i++) {
            	animateMenuLogo(arrsections[i][0],arrsections[i][1]);
            }
            
    	}
   	);  
   
	
	$(document).everyTime(6000,						   
		function () { 
			selected_item++;
			if (!(selected_item < count_items))
				selected_item = 0;
			animation();
		}					
	);

	
	$(document).oneTime(1000,						   
		function () { 
				$("#footer").stop().animate({ bottom: "-60px" }, 3000, function() {});
			}					
	);
	
	$("#footer").mouseover(
		function() {
			$("#footer").stop().animate({bottom: "-55px" }, {duration:250});
		}
	);
			
	$("#footer").mouseout(
		function() {
			$("#footer").stop().animate({ bottom: "-60px" }, {duration:2000});
		}
	);
 

	$("#nav ul a").click(
		function(event) {
			event.preventDefault();
			var loc = $(this).attr("href");   

			var loc = loc.substring(1);

			//alert(loc);

			var dest = 0;
			if (loc == "") {
				dest = 0;
			} else {
				dest = $("."+loc+"").offset().top;
			}
			$("body, html").stop().animate({scrollTop: dest}, {duration:1000});
		}
	);

});

/*  ---------------  Szpemellenzo  ------------------ */
var uccadress='info_at_utcazene_dot_hu';
function get_uccadress()
{
	var re= /_at_/gi;
	uccadress = uccadress.replace(re,'@');
	var re= /_dot_/gi;
	uccadress = uccadress.replace(re,'.');
	var the_link="mai" + "lto" +":"+uccadress+"?subject=&body=" ;
	window.location=the_link;
}

var fskdress='info_at_fsk.co_dot_hu';
function get_fskdress()
{
	var re= /_at_/gi;
	fskdress = fskdress.replace(re,'@');
	var re= /_dot_/gi;
	fskdress = fskdress.replace(re,'.');
	var the_link="mai" + "lto" +":"+fskdress+"?subject=&body=" ;
	window.location=the_link;
}

/*  ---------------  Cufon fontgeneráló  ------------------ */

Cufon.replace('h1', { color: '-linear-gradient(#CAB165, 0.75=#B59A57, 0.25=#CAB165, #B59A57)' })('h2', { color: '-linear-gradient(#ce761d, 0.75=#8f4613, 0.25=#ce761d, #b45c1b)' })('h3')('h4')('h5')('h6')

var load = '<div align="center"><img src="pix/loading.gif" alt="" border="0" /></div>';

function loadGallery() {
	$('#galeriakDiv').html(load);
	$.get('galeriak.htm?123', function(data) {
		$('#galeriakDiv').html(data);
	});
}

function loadMap() {
	$('#terkepDiv').html(load);
	$.get('terkep.htm', function(data) {
		$('#terkepDiv').html(data);
	});
}
