(function($){
$(document).ready(function() {
  $('.tabs_most_read li').click(function() {
    $('.tabs_most_read li').removeClass('active');
    $(this).addClass('active');
    $('.most_tab').hide();
    $('.'+$(this).attr('id')).show();
  });
    
  $('#fotka-node-form #edit-submit').click(function() {
    $('#fotka-node-form #edit-field-foto-competition-und').removeAttr('disabled');
  });  

  $('.windguru_forecast li').click(function() {
    $('.windguru_forecast li').removeClass('active');
    $(this).addClass('active');
    var rowclass = $(this).attr('id').replace('windguru_forecast_','');
    $('.windguru_forecast .windguru_info').hide();
    $('.windguru_forecast .windguru_info.'+rowclass).show();
  }); 
  
  $(".node .comment_links .comment-reply a.clone_form").click(function() {
    var comment_reply_form_cont = $(this).parents(".comment_form_helper").find(".comment_reply_form");
    if (comment_reply_form_cont.html()=='') {
      $(".comment_reply_form").html("");
      var form = $("#comment-form").clone();
      form.attr("action",$(this).attr("href"));
      var href = $(this).attr("href").split("/");
      form.attr("id",'comment-form-reply-'+href[(href.length-1)]);
      $(this).parents(".comment_form_helper").find(".comment_reply_form").append(form);
    } 
    else {
      $(".comment_reply_form").html("");
    }
    return false;
  });
  
  $("#block-views-forum-news-block .comment_links .comment-reply a").each(function() {
    var href = $(this).parents(".comment").find('.field-name-comment-body a').attr('href');
    $(this).attr('href',href);
  });
  
  $("form.comment-form textarea").keypress(function(e) {
    code = (e.keyCode ? e.keyCode : e.which);
    if (code == 13) {
      $(this).parents('form.comment-form').submit();
      e.preventDefault();
    }
  });
  //a.show_login_modal,
  $('a.show_register_modal').click(function(e) {
		$('#block-custom-modal-custom-modal-login, #block-custom-modal-custom-modal-register, #block-custom-modal-custom-modal-password').hide();
    //Cancel the link behavior
		e.preventDefault();
		//Get the A tag
		if ($(this).hasClass('show_login_modal')) {
      var id = '#block-custom-modal-custom-modal-login';
    }
    else if ($(this).hasClass('show_register_modal')) {
      var id = '#block-custom-modal-custom-modal-register';
    }
    else if ($(this).hasClass('show_password_modal')) {
      var id = '#block-custom-modal-custom-modal-password';
    };

		//Get the screen height and width
		var maskHeight = $(document).height();
		var maskWidth = $(window).width();
	
		//Set heigth and width to mask to fill up the whole screen
		$('#modal_mask').css({'width':maskWidth,'height':maskHeight});
		
		//transition effect		
		$('#modal_mask').fadeIn(500);	
		$('#modal_mask').fadeTo("slow",0.8);	
	
		//Get the window height and width
		var winH = $(window).height();
		var winW = $(window).width();
            
		//Set the popup window to center
		$(id).css('top',  ((winH/2-$(id).height()/2)+$(document).scrollTop()));
		$(id).css('left', winW/2-$(id).width()/2);
	
		//transition effect
		$(id).fadeIn(500); 
		return false;
	});
	
	//if close button is clicked
	$('.modal_close_button, #modal_mask').click(function (e) {
		//Cancel the link behavior
		e.preventDefault();
		
		$('#modal_mask, #block-custom-modal-custom-modal-login, #block-custom-modal-custom-modal-register').hide();
	});

  $('.region-bottom-outside form').attr('action',window.location.href);
  
  $('.views_slideshow_slide.views-row-1 .views-field-field-pictures').each(function(i) {
    _replace_front_pictures($(this));
  });
  
  $(".view-article-gallery").mouseover(function() {
    $(this).find('.views-field-field-pictures').each(function(i) {
      _replace_front_pictures($(this));
    });
    $(this).unbind('mouseover');  
  });
  
  setTimeout(_load_competition_fotos,3500);
}); 

function _replace_front_pictures(parent_node) {
  var new_html = parent_node.html().replace("R_img","<img").replace("R_imge","/>");
  parent_node.html(new_html);  
}

var _load_competition_fotos = function() {
  if ($(".ajax_loading_gallery").length>0) {
    $('.ddblock-cycle-upright60p .slide.clearfix a.imagefield').each(function(i) {
      _replace_front_pictures($(this));
    });
    $('.ddblock-cycle-upright60p .scrollable-pager-inner a.pager-link').each(function(i) {
      _replace_front_pictures($(this));
    });
    setTimeout(function(){$(".ajax_loading_gallery").hide().remove();},1000);
  }
} 
}(jQuery));

;

