/**
 * wSlide 0.1 - http://www.webinventif.fr/wslide-plugin/
 * 
 * News Slider
 *
 * Copyright (c) 2008 Julien Chauvin (webinventif.fr)
 * Licensed under the Creative Commons License:
 * http://creativecommons.org/licenses/by/3.0/
 *
 * Date: 2008-07-03
 * Developer: Elemer Szatmari
 * 
 */
this.imagePreview = function(){	
	/* CONFIG */
		
		xOffset = -40;
		yOffset = 50;
		
		// these 2 variable determine popup's distance from the cursor
		// you might want to adjust to get the right result
		
	/* END CONFIG */
	$("img.preview").hover(function(e){
		this.t = this.title;
		this.title = "";	
		var c = (this.t != "") ? "<br/>" + this.t : "";
		$("body").append("<p id='preview'><img src='"+ this.src.substr(0, this.src.indexOf('.gif')) + "_normal.jpg" +"' alt='Image preview' />"+ c +"</p>");		
		if(xmas == false)
		{
			$("#preview")
			.css("top",(e.pageY - xOffset) + "px")
			.css("left",(e.pageX + yOffset) + "px")
			.css("width", "300px")	
			.fadeIn("fast");						
		}
		else
		{

		$("#preview")
			.css("top",(e.pageY - xOffset) + "px")
			.css("left",(e.pageX + yOffset ) + "px")
			.css("width", "300px")	
			.css("backgroundColor", "#9E0F23")
			.css("text-align", "center")
			.fadeIn("fast");						

		}
    },
	function(){
		this.title = this.t;	
		$("#preview").remove();
    });	
	$("img.preview").mousemove(function(e){

		if(xmas == false)
		{
			$("#preview")
			.css("top",(e.pageY - xOffset) + "px")
			.css("left",(e.pageX + yOffset) + "px");
		}
		else
		{
			$("#preview")
			.css("top",(e.pageY - xOffset) + "px")
			.css("left",(e.pageX + yOffset) + "px");
		}

	});			
};

      $.fn.cycle.defaults.timeout = 2000;
      $(function() {
          
          $('#NewsFader') 
          .cycle({ 
			  cleartype:  1	,
              fx:     'fade', 
              speed:   1000, 
              timeout: 4500, 
              pause:   1, 
              pager:  '#NewsFader_menu',
			  cssBefore:{  
        display: 'block' 
    }
			  //		  
          });
			
	$('#tena_gallery').cycle({ 
	cleartype:  1	,
    fx:     'fade', 
    speed:  'fast', 
    timeout: 0, 
    next:   '#gallery_next', 
    prev:   '#gallery_prev' 
	});

      });
	  		
			
$(document).ready(function(){
		$("#messageBox").append($(".messageContainer").html()).show().fadeOut(5000);
		imagePreview();
		
		//hide the all of the element with class hitBody
		$(".hitBody").hide();
		//toggle the componenet with class hitBody
		$(".hitHead").click(function()
		{
			$(this).next(".hitBody").slideToggle();
		});

		$("#headerLogin").height($("#headerAd").height()-1);
		//alert($("#headerAd").height());
		if($("#headerAd").height() == 120)$("#headerBoxContent").css("margin-top","10px");
		
		$('.articleFontLarge').bind('click', function() {
			$('.expBoxContent').removeClass('expTextSmall');
			$('.expBoxContent').removeClass('boxAnswerContent');
			$('.expBoxContent').removeClass('boxQuestionContent');
			$('.expBoxContent').removeClass('expTextLarge');
			$('.expBoxContent').addClass('expTextLarge');
		});
	
		$('.articleFontNormal').bind('click', function() {
			$('.expBoxContent').removeClass('expTextSmall');
			$('.expBoxContent').removeClass('boxAnswerContent');
			$('.expBoxContent').removeClass('boxQuestionContent');
			$('.expBoxContent').removeClass('expTextLarge');
			$('.expBoxContent').addClass('boxAnswerContent');
		});
	
		$('.articleFontSmall').bind('click', function() {
			$('.expBoxContent').removeClass('expTextSmall');
			$('.expBoxContent').removeClass('boxAnswerContent');
			$('.expBoxContent').removeClass('boxQuestionContent');
			$('.expBoxContent').removeClass('expTextLarge');	
			$('.expBoxContent').addClass('expTextSmall');
		});
});

function ajaxFavouriteUserPost()
{

	var isTopic = ($('#TopicID').val() != "");
	var qs = (isTopic) ? "?TopicID=" + $('#TopicID').val() : "?PageID=" + $('#PageID').val();
	$.ajax(
      {
        url: "/forumtopic.php" + qs + "#post",
        type: "POST",
        data: {
				Command: 'setFavoriteUser',
				UserID: $('#UserID').val(),
				TopicID: $('#TopicID').val(),
                PageID: $('#PageID').val()
              },
        cache: false,
		
		dataType: "json",
        timeout: 60000,
        success: function(jsonObj){
			if (jsonObj.Status == 'OK')
			{
				showAjaxFavouriteUserSuccess(jsonObj.Opt);
			}
			else
			{
					showAjaxMessageError(jsonObj.Messages);
			}
          },
		error: function(XMLHttpRequest, textStatus, errorThrown){
			showAjaxMessageError(new Array('Hiba történt a kommunikációban', XMLHttpRequest.readyState + '-' + XMLHttpRequest.statusText, (textStatus == null) ? 'N/A' : textStatus, (errorThrown) ? errorThrown.description : 'N/A'));
		}
      }
    );
}

function ajaxFavouriteTopicPost(setMode)
{

	var isTopic = ($('#TopicID').val() != "");
	var qs = (isTopic) ? "?TopicID=" + $('#TopicID').val() : "?PageID=" + $('#PageID').val();
	$.ajax(
      {
        url: "/forumtopic.php" + qs + "#post",
        type: "POST",
        data: {
				Command: setMode,
				TopicID: $('#TopicID').val(),
                PageID: $('#PageID').val()
              },
        cache: false,
		
		dataType: "json",
        timeout: 60000,
        success: function(jsonObj){
			if (jsonObj.Status == 'OK')
			{
				showAjaxFavouriteTopicSuccess(setMode);
			}
			else
			{
					showAjaxMessageError(jsonObj.Messages);
			}
          },
		error: function(XMLHttpRequest, textStatus, errorThrown){
			showAjaxMessageError(new Array('Hiba történt a kommunikációban', XMLHttpRequest.readyState + '-' + XMLHttpRequest.statusText, (textStatus == null) ? 'N/A' : textStatus, (errorThrown) ? errorThrown.description : 'N/A'));
		}
      }
    );
}

function ajaxMessagePost()
{

	var isTopic = ($('#TopicID').val() != "");
	var qs = (isTopic) ? "?TopicID=" + $('#TopicID').val() : "?PageID=" + $('#PageID').val();
	$.ajax(
      {
        url: "/forumtopic.php" + qs + "#post",
        type: "POST",
        data: {
				Command: 'SendMessage',
                RecipientMessage: $('#RecipientMessage').val(),
                Subject: $('#Subject').val(),
                RecipientID: $('#RecipientID').val(),
                RecipientMail: $('#RecipientMail').val(),
                RecipientFirstName: $('#RecipientFirstName').val(),
				TopicID: $('#TopicID').val(),
                PageID: $('#PageID').val()
              },
        cache: false,
		
		dataType: "json",
        timeout: 60000,
        success: function(jsonObj){
			if (jsonObj.Status == 'OK')
			{
				showAjaxMessageSuccess();
			}
			else
			{
				
				showAjaxMessageError(jsonObj.Messages);
			}
          },
		error: function(XMLHttpRequest, textStatus, errorThrown){
			showAjaxMessageError(new Array('Hiba történt a kommunikációban', XMLHttpRequest.readyState + '-' + XMLHttpRequest.statusText, (textStatus == null) ? 'N/A' : textStatus, (errorThrown) ? errorThrown.description : 'N/A'));
		}
      }
    );
}

function ajaxForumPost()
{

	var isTopic = ($('#TopicID').val() != "");
	var qs = (isTopic) ? "?TopicID=" + $('#TopicID').val() : "?PageID=" + $('#PageID').val();
	$.ajax(
      {
        url: "/forumtopic.php" + qs + "#post",
        type: "POST",
        data: {
				Command: 'Post',
                Message: $('#Message').val(),
                ReplytoPostID: $('#ReplytoPostID').val(),
                ReplytoPostCreatorID: $('#ReplytoPostCreatorID').val(),
                TopicID: $('#TopicID').val(),
                PageID: $('#PageID').val()
              },
        cache: false,
		
		dataType: "json",
        timeout: 60000,
        success: function(jsonObj){
			if (jsonObj.Status == 'OK')
			{
				location.reload();
			}
			else
			{
				
				showAjaxError(jsonObj.Messages);
			}
          },
		error: function(XMLHttpRequest, textStatus, errorThrown){
			showAjaxError(new Array('Hiba történt a kommunikációban', XMLHttpRequest.readyState + '-' + XMLHttpRequest.statusText, (textStatus == null) ? 'N/A' : textStatus, (errorThrown) ? errorThrown.description : 'N/A'));
		}
      }
    );
}

function ajaxExpertQuestionPost()
{

	$.ajax(
      {
        url: "/tanacsado.php?id=" + $('#ExpertID').val() + '&kerdes=1' ,
        type: "POST",
        data: {
		        Message: $('#Message').val(),
		        CreatorNick: $('#CreatorNick').val(),
		        CreatorEmail: $('#CreatorEmail').val(),
		        QuestionSubject: $('#QuestionSubject').val(),
                CreatorID: $('#CreatorID').val(),
                registered: $('#registered').val(),
                ExpertID: $('#ExpertID').val()
              },
        cache: false,
		
		dataType: "json",
        timeout: 60000,
        success: function(jsonObj){
			if (jsonObj.Status == 'OK')
			{
				showAjaxExpertQuestionSuccess();
			}
			else
			{
				
				showAjaxExpertQuestionError(jsonObj.Messages);
			}
          },
		error: function(XMLHttpRequest, textStatus, errorThrown){
			showAjaxError(new Array('Hiba történt a kommunikációban', XMLHttpRequest.readyState + '-' + XMLHttpRequest.statusText, (textStatus == null) ? 'N/A' : textStatus, (errorThrown) ? errorThrown.description : 'N/A'));
		}
      }
    );
}

function ajaxTenaSurveyPost()
{

	$.ajax(
      {
        url: "/inkontinencia_kerdoiv.php" ,
        type: "POST",
        data: {
		        q1: $('input[name=q1]:checked').val(),
		        q2: $('input[name=q2]:checked').val(),
		        q3: $('input[name=q3]:checked').val(),
		        q4: $('input[name=q4]:checked').val(),
		        q5: $('input[name=q5]:checked').val(),
		        q6: $('input[name=q6]:checked').val(),
		        q7: $('input[name=q7]:checked').val(),
				submitted: 'true'
              },
        cache: false,
		
		dataType: "json",
        timeout: 60000,
        success: function(jsonObj){
			if (jsonObj.Status == 'OK')
			{
				showAjaxTenaSurveySuccess();
			}
			else
			{
				showAjaxExpertQuestionError(jsonObj.Messages);
			}
          },
		error: function(XMLHttpRequest, textStatus, errorThrown){
			showAjaxError(new Array('Hiba történt a kommunikációban', XMLHttpRequest.readyState + '-' + XMLHttpRequest.statusText, (textStatus == null) ? 'N/A' : textStatus, (errorThrown) ? errorThrown.description : 'N/A'));
		}
      }
    );
}

/* Success - Error handling functions */

function showAjaxError(messages)
{
  var tpl = "<div class=\"errors\"><div class=\"c1\"><div>Nem sikerült létrehozni a bejegyzést, mivel:</div><ul>(0)</ul></div></div>";
  var msgs = "";
 
  for(i=0;i<messages.length;i++){
	msgs += '<li>'+messages[i] +'</li>';
  }
	
  $('#ajaxErrorMessageDiv').empty().append($(tpl.replace('(0)', msgs))).show();
}

function showAjaxMessageError(messages)
{
  var tpl = "<div class=\"errors\"><div class=\"c1\"><div>Nem sikerült elküldeni az üzenetet, mivel:</div><ul>(0)</ul></div></div>";
  var msgs = "";
 
  for(i=0;i<messages.length;i++){
	msgs += '<li>'+messages[i] +'</li>';
  }
	
  $('#ajaxErrorMessageDiv').empty().append($(tpl.replace('(0)', msgs))).show();
}

function showAjaxMessageSuccess(){
	
	$.scrollTo("#messageBox",{offset:-200});
	$("#messageBox").empty().append($("#successMessageContainer").html()).show().fadeOut(6000);
	$("#Subject").val('');
	$("#RecipientMessage").val('');
	$("#RecipientID").val('');
	$("#RecipientMail").val('');
	$("#RecipientFirstName").val('');
	$("#uzenet").hide();
}

function showAjaxFavouriteTopicSuccess(setMode){
	
	$.scrollTo("#messageBox",{offset:-200});
	if(setMode == 'setFavoriteTopic')
	{
		$("#messageBox").empty().append($("#successSetFavouriteTopic").html()).show().fadeOut(6000);
		$("#setToFavouriteTopic").hide();
		$("#unSetToFavouriteTopic").show();
	}
	else if(setMode == 'unsetFavoriteTopic')
	{
		$("#setToFavouriteTopic").show();
		$("#unSetToFavouriteTopic").hide();
		$("#messageBox").empty().append($("#successUnSetFavouriteTopic").html()).show().fadeOut(6000);
	}
}
function showAjaxFavouriteUserSuccess(opt){
	
	$.scrollTo("#messageBox",{offset:-200});
	if(opt == 'already')
	{
		$("#messageBox").empty().append($("#successAlreadyFavouriteUser").html()).show().fadeOut(6000);
	}
	else if(opt == 'new')
	{
		$("#messageBox").empty().append($("#successNewFavouriteUser").html()).show().fadeOut(6000);
	}
}

function showAjaxExpertQuestionError(messages)
{
  var tpl = "<div class=\"errors\"><div class=\"c1\"><div>Nem sikerült elküldeni a kérdést, mivel:</div><ul>(0)</ul></div></div>";
	
  $('#ajaxErrorMessageDiv').empty().append($(tpl.replace('(0)', messages))).show();
}

function showAjaxExpertQuestionSuccess(){
	
	$.scrollTo("#messageBox",{offset:-200});
	$("#ajaxErrorMessageDiv").hide();
	$("#messageBox").empty().append($("#successExpertQuestionContainer").html()).show().fadeOut(6000,function(){location.replace('http://'+window.location.host+'/tanacsadas.php')});
	/*
	$("#Message").val('');
	$("#QuestionSubject").val('');
	if($("#CreatorID").val()==0){
		$("#CreatorNick").val('');
		$("#CreatorEmail").val('');
	}*/
	
}

function showAjaxTenaSurveySuccess(){
	
	$("#surveyForm").hide();
	$("#tenaDataForm").show();
	$.scrollTo("#tenaDataForm");
	
}
