$(document).ready(function() { 
    
    if (jQuery.browser.msie && jQuery.browser.version.substr(0,1)<7) {
        jQuery("body").html("");
        if(confirm("Ön egy régi Internet Explorert verziót használ. Kérjük frissítse a böngészőjét és látogasson vissza oldalunkra!")){
            //window.location="/";
            window.location="http://www.google.com/chrome/?hl=hu";
        }else{
            window.location="http://www.mozilla-europe.org/hu/firefox/";
        }
    }
													 
	$("a.fancy").fancybox({
		'overlayOpacity'	: 0.8,
		'overlayShow'			: true,
		'zoomSpeedIn'			: 600,
		'zoomSpeedOut'		: 500
	});
        $("a.fancy1").fancybox({
		'overlayOpacity'	: 0.8,
		'overlayShow'			: false,
		'zoomSpeedIn'			: 600,
		'zoomSpeedOut'		: 500, 
                'overlayShow'	:	false, 
                'scrolling' : 'yes'
	});
        $("a.iframe").fancybox({
		'transitionIn'	:	'elastic',
		'transitionOut'	:	'elastic',
		'speedIn'		:	600, 
		'speedOut'		:	200,
		'overlayShow'	:	false, 
                'scrolling' : 'no'
	});
        
        $("a.xframe").fancybox({
		'transitionIn'	:	'elastic',
		'transitionOut'	:	'elastic',
		'speedIn'		:	600, 
		'speedOut'		:	200,
		'overlayShow'	:	false, 
                'scrolling' : 'yes',
                'width' : '500',
                'height' : '500'
	});
        
        $(".youtube").click(function() {
	$.fancybox({
			'padding'		: 0,
			'autoScale'		: false,
			'transitionIn'	: 'none',
			'transitionOut'	: 'none',
			'title'			: this.title,
			'width'		: 680,
			'height'		: 495,
			'href'			: this.href.replace(new RegExp("watch\\?v=", "i"), 'v/'),
			'type'			: 'swf',
			'swf'			: {
                         /*'wmode'		: 'transparent',*/
                        'allowfullscreen'	: 'true'
			}
		});

	return false;
        });

});

jQuery.fn.fadeToggle = function(speed, easing, callback) {
   return this.animate({opacity: 'toggle'}, speed, easing, callback);
};

function yesOrNo(msg){
    if(confirm(msg)){
        return true;
    }else{
        return false;
    }
}

jQuery(document).ready(function(){
    
   jQuery(".iamenu").click(function(e){
       e.preventDefault();       
   });
    
   //alert("ok");
   jQuery("#navigation li a").hover(
    function(){
        jQuery(this).next("span").addClass("csillanas");
    },
    function(){
        jQuery(this).next("span").removeClass("csillanas");
    }
   );
       
  //menü elrejtése
  jQuery("#navigation li a.menu-item, #container-main, #wrapper, #cserelheto-kep, #header-image, body, header").hover(function(){
        jQuery("div.submenu").hide();
  });
       
   jQuery(".submenu").hide();
   jQuery(".submenu-parent, .submenu").hover(
    function(){
        tmp = jQuery(this).attr("class");
        c = tmp.split(" ");
        if(c[0]=="submenu-parent"){
            jQuery(".submenu").hide(); 
            jQuery(this).next(".submenu").show();
        }
    },
    function(){
        tmp = jQuery(this).attr("class");
        c = tmp.split(" ");
        //console.log(c);
        if(c[0]!="submenu-parent"){            
            //ha nem submenu
            jQuery(this).next(".submenu").hide();
        }
        
    }
   );
       
  jQuery( "#accordion-meccsek" ).accordion({
      clearStyle: true, collapsible: true, active: true
  });
  
  jQuery('.box_skitter_etokc').skitter({interval: 3500,hideTools:true, navigation:true, numbers:true});
  jQuery('.box_skitter_member').skitter({interval: 2500,hideTools:false, navigation:true, numbers:false});
  
  //[0, 0, 0, 80, 9, 32, 50]
  function everyFive(periods) { 
    nap = periods[3];
    ora = periods[4];
    perc = periods[5];
    ms = periods[6];
        
    //console.log(nap, ora, perc, ms);
    
    if(ms>=0 && ms<6){
        jQuery(".t4").show();
    }else{
        jQuery(".t4").hide();
    }
    
    if(perc>=0 && perc<2){
        jQuery(".t3").show();
    }else{
        jQuery(".t3").hide();
    }
    
    if(ora>=0 && ora<2){
        jQuery(".t2").show();
    }else{
        jQuery(".t2").hide();
    }
    
    if(nap>=0 && nap<2){
        jQuery(".t1").show();
    }else{
        jQuery(".t1").hide();
    }
    
    if($.browser.msie && $.browser.version.substring(0) < "8") {
        //ie7 zindex fix
        jQuery(".t1, .t2, .t3, .t4").css({"zIndex":-1});
    }
    
   }
  
  var newYear = new Date(); 
  newYear = new Date(newYear.getFullYear() + 1, 1 - 1, 1);
  
  newYear = new Date(akt_meccs.ev, akt_meccs.ho-1, akt_meccs.nap, akt_meccs.ora, akt_meccs.perc, 0);
  //console.log(newYear);
  //console.log(akt_meccs);
  //newYear = "Wed Oct 12 2011 14:50:22 GMT+0200 (CEST)";
  jQuery.countdown.setDefaults($.countdown.regional[langid]);
  //{until: liftoffTime, format: 'HMS', onTick: everyFive, tickInterval: 5}
  jQuery(".aktualias-merkozes-timer").countdown({format: 'DHMS', until: newYear, onTick: everyFive, tickInterval: 1},$.countdown.regional[langid]);  
  jQuery(".datepicker").datepicker();
  jQuery(".datepicker").datepicker( jQuery.datepicker.regional[ langid ] );
  jQuery(".external").attr("target", "_blank");  
  //jQuery('a.tooltip').tipsy({fade: true, gravity: 'n'});
  
  
  //Calendar
  (function($){
      function a_click() {
          //Gombokról leveszi az eseménykezelőket
          $('#calendar-container .head a').unbind('click');
          
          //Paraméterek kinyerése
          $this = $(this);
          href = $this.attr('href').split('?');
          
          //Kérés indítása
          $.ajax({
                 url: "controllers.php",
                 data: "do=updatecalendar&"+href[1],
                 async: false,
                 success: function(html){
                    //Naptár frissítés
                    $("#calendar-container").html(html);
                    //Gombok visszaállítása
                    $('#calendar-container .head a').click(a_click);
                  }
               });
          return false; 
      }
      //Init
      $('#calendar-container .head a').click(a_click);
      
  })(jQuery);
  //\Calendar
  
  //Sidebar poll
  (function($){
      $('#szavazas-form').validate(
          {
             rules: {
               sidebar_poll_answerid: "required"
             },
             messages: {
               sidebar_poll_answerid: ""
             },
             submitHandler: function(form) {
                  $.ajax({
                      url:"controllers.php",
                      type:"POST",
                      async:false,
                      dataType:"json",
                      data: 'do=can_vote&sidebar_pollid='+$('#sidebar_poll_id').val(),
                      success : function (data) {
                          if (data.result===true) {
                              //$('#sidebar-szavazas-body').slideUp();
                              //poll
                              $.ajax({
                                  url:"controllers.php",
                                  type:"POST",
                                  async:false,
                                  dataType:"html",
                                  data: 'do=vote&sidebar_pollid='+$('#sidebar_poll_id').val()+'&sidebar_poll_answerid='+$('input:radio[name=sidebar_poll_answerid]:checked').val(),
                                  success : function (html) {
                                      //$('#sidebar-szavazas-body').slideDown();
                                      $('#sidebar-szavazas-body').html(html);
                                  }
                              });
                          }
                          else {
                              $.fancybox("<div style='width:200px;height:50px;'>Már szavazott</div>");
                          }
                      }
                  });
                  return false;
             }
          }
      );
          
      if ($(".poll-background").length>0) {
          $(".poll-background").each(function(){
              $this = $(this);
              width = $this.find(".poll-line-background").attr("rel");
              $this.find(".poll-line-background").animate({width:width+'px'}, {queue:false, duration:1000, easing:"quintEaseInOut"});
              width = $this.find(".poll-percentage").attr("rel");
              $this.find(".poll-percentage").animate({left:width+'px'}, {queue:false, duration:1000, easing:"quintEaseInOut"});
          });
      }
      
      if ($("#sidebar_show_poll_results").length>0) {
          $("#sidebar_show_poll_results").click(function() {
             $.ajax({
                  url:"controllers.php",
                  type:"GET",
                  async:false,
                  dataType:"html",
                  data: 'do=sidebar_showresult&sidebar_showresult=true&sidebar_pollid='+$('#sidebar_poll_id').val(),
                  success : function (html) {
                      $('#sidebar-szavazas-body').html(html);
                  }
             });
             return false;
          });
      }
                 
  })(jQuery);
  //\Sidebar poll
  
  
  $(".csapat-tooltip").simpletip({fixed: true,  position: 'left',
   onBeforeShow: function(e){
      // Note this refers to the API in the callback function
      var itemid = this.getParent().attr("rel");
      this.load('/'+ langid + '/csapatok/ajax/'+itemid);      
      
      
    }
  });
  
    $(".csapat-tooltip1").simpletip({fixed: true,  position: [0,0],
   onBeforeShow: function(e){
      // Note this refers to the API in the callback function
      var itemid = this.getParent().attr("rel");
      this.load('/'+ langid + '/csapatok/ajax/'+itemid);      
     
    }
  });
  
  
});


