﻿// JavaScript Document
var BASE_PATH = "http://www.szunari.hu/";
var d = new Date();
var year=d.getFullYear(); //aktuális év
var month=d.getMonth()+1; //aktuális hónap
var parentClass;
var mw=true;
var firstScroll=true;
var refresh=false;
var mouseOverChat=false;

//Snow
/*
$(function() {
    $().jSnow({
            flakes:7,
            flakeMaxSize:30,
            flakeMinSize:20,
            flakeCode:[BASE_PATH + "Design/01/Snow_imgs/small/1.png", BASE_PATH + "Design/01/Snow_imgs/2.png", BASE_PATH + "Design/01/Snow_imgs/small/3.png", BASE_PATH + "Design/01/Snow_imgs/4.png"],
            flakeColor:["#f00","#00f","#fff"],
            interval:30
            });
}); */

/*OLDAL NYITÁSKOR BETÖLTŐDŐ SCRIPTEK------------------------------------------------------------------------------------*/
    $(document).ready(
				   function(){
				    WhoIsOnline();
				    menu();
                    moc();
                    $('.send_hsz').click(function(){
                        chat_be();
                        $('.chat_post').val('');

                    });
                    $(".tut_img").tooltip({ position: "bottom center", opacity: 1, tipClass : 'tooltip_tut', tip: '#mytip_' + 22 });
        
                       /*
                        Az események előugró ablakját állítja nem láthatóra
                       */
                       $('.esemenyDiv').css('display', 'none');
                       eventboxClose();
                       //datemask();
    
                       $(".regform").validationEngine();
                 
                 $('.hszek').localScroll('p:last');  
                 
                 $('.adatlap').click(function(){
                    id=this.name;
                     $('.esemenyDiv').css('display', 'block');
                     $.ajax({
                         type: 'POST',
                         data: 'id='+id,
                         url: BASE_PATH + '/Modules/Adatlap/adatlap.php',
                         beforeSend:  function() {
                         $(".edc").empty().html('<img src="' +BASE_PATH+ '/Design/01/IMG/loading_w.gif"  alt="loadingimg" class="loadingimg"/>');},
                         success: function (response) {      
                         $('.edc').html(response);}
                         });
                    
                 })     
              /* NAGYGOMBOK------------------------------------------------------------------------------------------*/         
                $('.log_reg li img').css('display', 'none');
                $('.log_reg li').mouseover(function(){
                    $(this).children('img').css('display', 'block');
                });
                $('.log_reg li').mouseout(function(){
                    $(this).children('img').css('display', 'none');
                });
              
              
              
              $('.chat_head').click(function(){
                 h=$('.chat_body').height()
                 if(h==0) 
                 {
                    $('.chat_body').animate({height: 460+'px'},400);
                    refresh=true;
                    chat_ki();
                    
                 }
                 else
                 {
                    $('.chat_body').animate({height: 0+'px'},400);
                    refresh=false;
                 }
                
               })
              
              /* HIBA ÜZENETEK------------------------------------------------------------------------------------------*/         
              if ($('.ex_text').text()!='') 
               {
                 $('.exceptions').css('display', 'block');
                 $('.exceptions').animate({height: 200+'px'},800).delay(5000).animate({height: 0+'px'},800);
               }  
              /*NAPTÁR SCRIPTEK---------------------------------------------------------------------------------------------*/
                      
                     
                    calend_left();
                    calend_right();
                    calend_hover();
                    eventboxOpen();
                    eventboxClose();
                    has_esemeny_meghivo();
                    $(".nn").tooltip({ position: "bottom center", opacity: 0.9});
                    toolsEffect();
                    
             /*NAPTÁR VÉGE-------------------------------------------------------------------------------------------------*/
			 
              
              
              /* LOGIN_INPUT--------------------------------------------------------------------------------------------*/
              
                       $('.log_input').focus(function(){
                              $(this).val('');
                       });
                       
                       $('.input_name').blur(function(){
                              if($(this).val()=='') $(this).val('Név...');
                       });

                       $('.input_pass').blur(function(){
                              if($(this).val()=='') $(this).val('Jelszó...');
                       });
             $('.reg').click(function(){
                $('.esemenyDiv').css('display', 'block');
                $.ajax({
                         url: BASE_PATH + '/Main_Content/LatReg.php',
                         beforeSend:  function() {
                            $(".edc").empty().html('<center><img src="'+BASE_PATH+'/Design/01/IMG/loading_w.gif"  alt="loadingimg" class="loadingimg" /></center>');},
                         success: function (response) {      
                         $('.edc').html(response);}
                         });
                        // datemask();
                         eventboxClose();
    
                       $(".regform").validationEngine();});
                                                                                            
            
             $('.log').click(function(){
                $('.esemenyDiv').css('display', 'block');
                $.ajax({
                                                            url: BASE_PATH + '/Modules/login.php',
                                                            beforeSend:  function() {
                                                             $(".edc").empty().html('<center><img src="'+BASE_PATH+'/Design/01/IMG/loading_w.gif"  alt="loadingimg" class="loadingimg" /></center>');},
                                                            success: function (response) {
                                                                      
                                                                      $('.edc').html(response);
                                                                                             $('.log_input').focus(function(){
                              $(this).val('');
                       });
                       nm=$('.input_name').val();
                       p=$('.input_pass').val();
                       $('.input_name').blur(function(){
                              
                              if($(this).val()=='') $(this).val(nm);
                       });

                       $('.input_pass').blur(function(){
                              if($(this).val()=='') $(this).val(p);
                       });
                                                                      }})
             })
             
            });
             
/*VÉGE---------------------------------------------------------------------------------------------------------------------*/


 
/*VÉGE---------------------------------------------------------------------------------------------------------------------*/
function moc()
{
    $('.hszek').mouseover(function(){
                        mouseOverChat=true;
                    });
    $('.hszek').mouseleave(function(){
                        mouseOverChat=false;
                    });
}


function hszScroll()
{
    $("#hszek").attr({ scrollTop: $("#hszek").attr("scrollHeight") });
}
function menu()
{
        $("ul.sf-menu").superfish({ 
            animation: {height:'show'},   // slide-down effect without fade-in 
            delay:     10               // 1.2 second delay on mouseout 
        });  
}
/*-------------------------------------------------------------------------------------------------------------------------
  Kiszámolja az éppen megjelenítendő naptári dátumot év-hónap fügvényében
  @param n: 0 esetén az előző hónap 1 esetén a következeő hónap
  -------------------------------------------------------------------------------------------------------------------------*/ 
function dateX(n)
{
    if (n==0)
    {
        month--;
        if (month<1) 
        {
            month=12;
            year--;
            }
    }
    else
    {
        month++;
        if (month>12) 
        {
            month=1;
            year++;
            }
    }
}
/*VÉGE---------------------------------------------------------------------------------------------------------------------*/



/*Az éppen aktuális dátumhoz képest előző hónap eseményeit ada vissza (AJAX)-----------------------------------------------*/

function calend_left()
{
    $('.calend_left').click(
                                          function(){                                          
                                            
                                            dateX(0);
                                            calend_data="honap="+month+"&ev="+year+"&ma=1";
                                            $.ajax({
							
                                                            type: 'POST',
                                                            url: BASE_PATH + '/Modules/naptar/naptar.php',
					                                        data: calend_data,
                                                            beforeSend:  function() {
                                                             $(".calend").empty().html('<img src="'+BASE_PATH+'/Design/01/IMG/loading_w.gif"  alt="loadingimg" class="loadingimg"/>');},
                                                            success: function (response) {
                                                                      
                                                                      $('.calend').html(response);
                                                                      $(".nn").tooltip({ position: "bottom center", opacity: 0.9});
                                                                      toolsEffect();
                                                                      /*$('.nn').tipsy({gravity: 'n', fade: true});*/
                                                                      calend_left();
                                                                      calend_right();
                                                                      calend_hover();
                                                                      eventboxOpen();
                                                                      eventboxClose();
                                                                      has_esemeny_meghivo();
                                                                      
                                                                      //$(".calendar").animate({opacity: 1.0},100);
                                                                      }
                                                            });
                                             
                                          });
}
/*VÉGE----------------------------------------------------------------------------------------------------------------------*/



/*Az éppen aktuális dátumhoz képest következő hónap eseményeit ada vissza (AJAX)--------------------------------------------*/
function calend_right()
{
     $('.calend_right').click(
                                          function(){                                          
                                            
                                            dateX(1);
                                            calend_data="honap="+month+"&ev="+year+"&ma=1";
                                            $.ajax({
							
                                                            type: 'POST',
                                                            url: BASE_PATH + '/Modules/naptar/naptar.php',
					                                        data: calend_data,
                                                            beforeSend:  function() {
                                                             $(".calend").empty().html('<center><img src="'+BASE_PATH+'/Design/01/IMG/loading_w.gif" alt="loadingimg" class="loadingimg"/></center>');},
                                                            success: function (response) {
                                                                      $('.calend').html(response);
                                                                      $(".nn").tooltip({ position: "bottom center", opacity: 0.9});
                                                                      toolsEffect();
                                                                      /*$('.nn').tipsy({gravity: 'n', fade: true});*/
                                                                      calend_right();
                                                                      calend_left();
                                                                      calend_hover();
                                                                      eventboxOpen();
                                                                      eventboxClose();
                                                                      has_esemeny_meghivo();
                                                                      
                                                                      //$(".calendar").animate({opacity: 1.0},100);
                                                                      }
                                                            });
                                             
                                          });
}
/*VÉGE----------------------------------------------------------------------------------------------------------------------*/
function meghivo()
{
    $('.visszaigazolo_gomb').click(function(){
    vdata='vi='+$(this).attr('alt')+'&cid='+$(this).parent().attr('alt');
    $.ajax({
							
                        type: 'POST',
                        url: BASE_PATH + '/Modules/naptar/visszaigazolas.php',
                        data: vdata,
                        success: function (response) {
                                 $('.ol').html(response);}
                                                                      
                                                            });
                
              }); 
}
function has_esemeny_meghivo()
{
    if($('.nn').hasClass('naptar-m naptar-m2'))
    {
        $(this).removeClass('naptar-m naptar-m2').addClass('naptar-em');
    }
}

function  calend_hover()
{
    $('.nn').mouseenter(function(){
        $(this).addClass('naptar-h');});
        
    $('.nn').mouseleave(function(){
        $(this).removeClass('naptar-h');
    })
    }

function eventboxOpen()
{
    $('.nn').click(function() {
        $('.esemenyDiv').css('display', 'block');
        date='date=' + $(this).children('.day').attr('title');
        $.ajax({
							
                                                            type: 'POST',
                                                            url: BASE_PATH + '/Modules/naptar/esemeny_ki.php',
					                                        data: date,
                                                            beforeSend:  function() {
                                                             $(".edc").empty().html('<center><img src="' +BASE_PATH+ '/Design/01/IMG/loading_w.gif" /></center>');},
                                                            success: function (response) {
                                                                      $('.edc').html(response);
                                                                      meghivo();
                                                                      }});
    })
}
function eventboxClose()
{
    $('.closebox').click(function(){
        $(this).parent().css('display', 'none').stop();
        $('.edc').empty();
    })
}

function datemask()
{
    $(".datemask").mask("9999-99-99");
}

function chat_ki()
{
    if(refresh)
            $.ajax({
							
                                                            url: BASE_PATH + '/Modules/chat/chat_ki.php',
                                                            
                                                            success: function (response) {
                                                                      $('.hszek').html(response);
                                                                      moc();
                                                                      if(firstScroll)
                                                                      {$("#hszek").attr({ scrollTop: $("#hszek").attr("scrollHeight") });
                                                                       firstScroll=false;
                                                                      }
                                                                      else
                                                                      {
                                                                        moc();
                                                                       if(!mouseOverChat){
                                                                      //$('.hszek').mouseleave(function(){
                                                                         $("#hszek").attr({ scrollTop: $("#hszek").attr("scrollHeight") });
                                                                      
                                                                         }
                                                                       }
                                                                      setTimeout('chat_ki();', 2000);
                                                                      }});
         
         
       
       
       
           
}

function chat_be()
{
    $.ajax({
							
                                                            type: 'POST',
                                                            url: BASE_PATH + '/Modules/chat/chat_be.php',
					                                        data: 'text='+$('.chat_post').val(),
                                                            
                                                            success: function (response) {
                                                                      firstScroll=true;
                                                                      }
                                                                      });
}

function toolsEffect(){
    $(".nn").tooltip({

	// change trigger opacity slowly to 0.8
	onShow: function() {
		this.getTrigger().fadeTo("slow", 0.8);
	}

});
}

/*---TUTORIALOK---*/
//Tooltip

function ajax_get_premov(tut_id)
{
    $.ajax({
                         url: BASE_PATH + '/Modules/Tutorial/ajax_get_tutorial.php',
                         data: ({tut_id: tut_id}),
                         dataType: "json",
                         type: 'POST',
                         
                         success: function(response){
                            //$(".tooltip_tut").html("asd");
                            $(".tooltip_tut").html('<div id="media' + tut_id + '"></div>');
                            
                            var so = new SWFObject(BASE_PATH + '/Main_Content/Player/player.swf','mpl','250','180','9');
                            so.addParam('allowfullscreen','false');
                            so.addParam('allowscriptaccess','always');
                            so.addVariable('controlbar','none');
                            so.addVariable('autostart','true');
                            so.addVariable('icons','false');
                            so.addVariable('mute','true');
                            so.addVariable('repeat','always');
                            so.addParam('wmode','opaque');
                            so.addVariable('author',response.u_id);
                            so.addVariable('description','tutorial');
                            so.addVariable('file', BASE_PATH + response.premov_path);
                            so.addVariable('image', BASE_PATH + response.avatar_path);
                            so.addVariable('title', response.nev);
                            so.write('media' + tut_id);
                         },
                    
                         beforeSend:  function() {
                            $(".tooltip_tut").empty().html('<center><img src="' +BASE_PATH+ '/Design/01/IMG/loading_w.gif" /></center>');
                            
                    }
                     });     
}

$(function () {
    $('.tut_img').mouseenter(function() {                                                       
        $(".tut_img").tooltip({ position: "bottom center", opacity: 1, tipClass : 'tooltip_tut', tip: '#mytip_' + this.id});
        ajax_get_premov(this.id);
        });
});

$(function () {                                                      
        $(".thumb").tooltip({ position: "top center", opacity: 0.9, tipClass : 'tooltip_tut_head' });
});

//Lejátszás
$(function() {
    $('#play_butt').click(function() {
        $('.esemenyDiv').css('display', 'block');
                $.ajax({
                         url: BASE_PATH + '/Modules/Tutorial/ajax_get_tutorial.php',
                         data: ({tut_id: $('#tut_id').val()}),
                         dataType: "json",
                         type: 'POST',
                         
                         success: function(response){
                            $(".esemenyDiv .edc").html("<h2>" + response.nev + "</h2>");
                            $(".esemenyDiv .edc").append("<div id=\"media\"></div>");
                            
                            var so = new SWFObject(BASE_PATH + '/Main_Content/Player/player.swf','mpl','620','480','9');
                            so.addParam('allowfullscreen','true');
                            so.addParam('allowscriptaccess','always');
                            so.addParam('wmode','opaque');
                            so.addVariable('author',response.u_id);
                            so.addVariable('description','tutorial');
                            so.addVariable('file', BASE_PATH + response.tutorial_path);
                            so.addVariable('image',BASE_PATH + response.avatar_path);
                            so.addVariable('title', response.nev);
                            so.addVariable('backcolor','0a0a0a');
                            so.addVariable('frontcolor','FFFFFF');
                            so.addVariable('lightcolor','FFFFFF');
                            so.write('media');
                         },
                    
                         beforeSend:  function() {
                            $("edc").empty().html('<center><img src="' +BASE_PATH+ '/Design/01/IMG/loading_w.gif" /></center>');
                    }
                });
    });
    
});

//Who is Online AJAX
function WhoIsOnline() {
    $.ajax({
            url: BASE_PATH + '/Modules/users_online/online_user.php',
                         dataType: "html",
                         type: 'POST',
                         
                         success: function(response){
                            $("#whoisonline").html(response);
                            setTimeout('WhoIsOnline();', 5000);
                         }
            });
}

//DEBUG
/**
 * Function : dump()
 * Arguments: The data - array,hash(associative array),object
 *    The level - OPTIONAL
 * Returns  : The textual representation of the array.
 * This function was inspired by the print_r function of PHP.
 * This will accept some data as the argument and return a
 * text that will be a more readable version of the
 * array/hash/object that is given.
 * Docs: http://www.openjs.com/scripts/others/dump_function_php_print_r.php
 */
function dump(arr,level) {
	var dumped_text = "";
	if(!level) level = 0;
	
	//The padding given at the beginning of the line.
	var level_padding = "";
	for(var j=0;j<level+1;j++) level_padding += "    ";
	
	if(typeof(arr) == 'object') { //Array/Hashes/Objects 
		for(var item in arr) {
			var value = arr[item];
			
			if(typeof(value) == 'object') { //If it is an array,
				dumped_text += level_padding + "'" + item + "' ...\n";
				dumped_text += dump(value,level+1);
			} else {
				dumped_text += level_padding + "'" + item + "' => \"" + value + "\"\n";
			}
		}
	} else { //Stings/Chars/Numbers etc.
		dumped_text = "===>"+arr+"<===("+typeof(arr)+")";
	}
	return dumped_text;
}
