var pageLoaded = false;
var showsLoaded = false;
var extraLoaded = false;
var orderSent = false;
var mainPic = 1;
var mainPicB = 1;
var mainPicLast = 1;
var lyrics = new Array();

$(document).ready(function () {
	loadFancyBox();
	setTimeout("changeMainPic()",5500);
	setTimeout("chatRefresh(0)",8500);
});

function pageModule(m) {
	if (m==3) loadExtra();
	for (var i=1;i<=3;i++) {
		if (i==m) $('div#contentMod'+i).show();
		else $('div#contentMod'+i).hide();
	}
}

function loadFancyBox() {
	$("a.bioPics").fancybox({
		'transitionIn'	:	'elastic',
		'transitionOut'	:	'elastic',
		'speedIn'		:	600, 
		'speedOut'		:	200, 
		'overlayShow'	:	false,
		'titlePosition'	:	'inside',
		'opacity'		:	true
	});
}

function changeMainPic() {
	var o = $('div#pagebg').offset();
	if (pageLoaded && o.top<400) {
		while (mainPic == mainPicLast) {
			mainPic = Math.floor(Math.random()*maxMainPic)+1;
		}
		mainPicLast = mainPic;
		if (mainPicB==1) {
			$('div#mainpic div#mp2 img').attr("src", "gfx/ribogzi_main_"+mainPic+".jpg");
			$('div#mainpic div#mp2').fadeIn(1500);
			$('div#mainpic div#mp1').fadeOut(1500);
			mainPicB = 2;
		}
		else {
			$('div#mainpic div#mp1 img').attr("src", "gfx/ribogzi_main_"+mainPic+".jpg");
			$('div#mainpic div#mp1').fadeIn(1500);
			$('div#mainpic div#mp2').fadeOut(1500);
			mainPicB = 1;
		}
	}
	setTimeout("changeMainPic()",o.top<500?7500:2500);
}

function showAllShows() {
	$('div#all_shows').show('slow');
	if (!showsLoaded) $.ajax({
        type        : 'GET',
        url         : 'ajax_all_shows.php',
        success     : function (ret) {
			$('div#all_shows_content').html(ret);
			showsLoaded = true;
        }
    });
}

function scrollToDiv(d,topmore) {
	$('html,body').animate({
		scrollTop: $('div#'+d).offset().top-topmore
		}, 900
	);
}

function chatRefresh(dontrepeat) {
	$.ajax({
        type        : 'GET',
        url         : 'ajax_chat.php',
        success     : function (ret) {
			if (ret) {
				$('#chatbox').html(ret);
			}
			if (!dontrepeat) setTimeout("chatRefresh(0);",7000);
        }
    });
}

function chatSend() {
	$.ajax({
        type        : 'POST',
        url         : 'ajax_chatsend.php',
        data        : 'name=' + encodeURIComponent($('#chat_name').val()) + '&msg=' + encodeURIComponent($('#chat_message').val()),
        success     : function (ret) {
			if (ret) {
				$('#uzenoform').fadeOut('slow');
				//$('#chat_name').val('');
				$('#chat_message').val('');
			}
			chatRefresh(1);
			scrollToDiv('chat',35);
        }
    });
}

function sendOrder(i) {
	if ($('div#kene'+i+' .rend_nev').val() != '' && $('div#kene'+i+' .rend_cim').val() != '') {
		if (!orderSent) {
			orderSent = true;
			$.ajax({
		        type        : 'POST',
		        url         : 'ajax_order.php',
		        data        : 'nev=' + encodeURIComponent($('div#kene'+i+' .rend_nev').val()) + '&cim=' + encodeURIComponent($('div#kene'+i+' .rend_cim').val()) + '&msg=' + encodeURIComponent($('div#kene'+i+' .rend_megj').val()) + '&ar=' + encodeURIComponent($('div#kene'+i+' .rend_penz').val()),
		        success     : function (ret) {
					$('div#keneazalbum'+i).fadeOut('slow');
					$('div#kene'+i).html('<br /><br /><b>Köszönjük!</b><br /><br /><br />');
					setTimeout("$('div#kene"+i+"').fadeOut('slow');",2000);
					
		        }
		    });
		}
	} else alert('Kérjük add meg legalább a neved és az e-mail címed!');
}

function loadExtra() {
	extraLoaded = true;
	$.ajax({
        type        : 'GET',
        url         : 'ajax_extra.php',
        success     : function (ret) {
			$('div#extra').html(ret);
			loadFancyBox();
        }
    });
}

function showLyrics(i) {
	$('div.lyrics').fadeOut('fast');
	$('div#ly'+i).fadeIn('slow');
	$('div.lyricsLink').css({'font-weight': 'normal'});
	$('div#lyricsLink'+i).css({'font-weight': 'bold'});
}
