var modeM = false, isOpenBig = false, nclick = false;
function more() {
	if(nclick != true) {
		if(modeM == false) {
			$("#moreSwit").removeClass("moreHiddenChoices"); $("#moreSwit").addClass("moreShownChoices").queue(function(){
				$(this).slideDown("normal").queue(function(){
					$("#wordsTopMoreF").css("background","url(/images/words/zwin.gif)"); $(this).dequeue(); });
				$(this).dequeue(); });
			modeM = true; return;
		}
		if(modeM == true) {
			$("#moreSwit").slideUp("normal").queue(function(){
				$(this).removeClass("moreShownChoices"); $(this).addClass("moreHiddenChoices");
				$("#wordsTopMoreF").css("background","url(/images/words/rozwin.gif)"); $(this).dequeue(); });
			modeM = false;
		}
	}
}

function initWords() {
	more();
	nclick = true;
	ival = setInterval("stop()",3000);
}

function stop() {
	nclick = false;
	more();
	clearInterval(ival);
}

function showBig(img_path,img_desc) {
	$("#galleryWrdBig").hide().queue(function() {
		$("#galleryWrdBig").empty();
		if(img_desc) { $("#galleryWrdBig").append("<p class='imgDesc'>"+img_desc+"</p>"); imgClass = "bigImg"; }
		else {  imgClass = "bigImgFix"; }
		$("#galleryWrdBig").append("<img class='"+imgClass+"' src='"+img_path+"' alt='' onclick='hideBig()' />").queue(function() {
			
			if(isOpenBig != true) {
				$("#galleryWrdBig").slideDown("normal");
				isOpenBig = true;
				if($('img.bigImg').width()>640)
		{
			$('img.bigImg').width(640);
			clearTimeout(x);
		}
			}
			else { $("#galleryWrdBig").show(); 
			if($('img.bigImg').width()>640)
		{
			$('img.bigImg').width(640);
			clearTimeout(x);
		}
							}
			
			


			$(this).dequeue();
		});
		$(this).dequeue();
	});
	
	if($('img.bigImg').width()>640)
		{
			$('img.bigImg').width(640);
			clearTimeout(x);
		}
	
	
	var x  = setTimeout(function(){ 
		if($('img.bigImg').width()>640)
		{
			$('img.bigImg').width(640);
			clearTimeout(x);
		}
	},3000);
	
}

function hideBig() {
	$("#galleryWrdBig").slideUp("normal");
	isOpenBig = false;
}

$(document).ready(function() {
	
	//$('body,html').animate( { scrollTop: 170 }, 500);

	
	$('.sms_dotpay').livequery(function() {
		$(this).fancybox({
			'transitionIn'	:	'elastic',
			'transitionOut'	:	'elastic',
			'speedIn'		:	600, 
			'speedOut'		:	200, 
			'overlayShow'	:	false
		});
	});
		
	$("#menuHbtn1").css("background","url(/images/header/m1_a.gif)");
	$("#menuHbtn1").unbind();
	initWords();
	
	$('.wordGetMore').bind('click', function() {
	
		$.getJSON('/words/readmore?id='+$(this).attr('id'), function(data) {
			if(data.payment_active) { // zaladuj dalsza tresc
				$('.wordsPtext').html(data.content);
			}
			else { // warstwa platnosci
				//$('#payment_wrapper').addClass('payments');
				$('#payment_wrapper').html( '' );
				$('#payments').appendTo('#payment_wrapper');
				//$('#payments').remove();
				$('#payments').css('display', 'block');
				//$('#wordsTopT').html('');
			}
		});
	});
	
	$('.do_payment').live('click', function() {
		$.ajax({
			url: '/payment/savetransaction',
			type: 'POST',
			data: $(this).parent().serialize(),
			async: false
		});
		$(this).parent().submit();
	});
	
	
});
