
jQuery(document).ready(function(){
 
 var urlSubscribe = '/wp-content/themes/judobc/scripts/mailchimp/mc_subscribe.php';
 
 jQuery('#submitSubscribe').click(function () {
    var response = jQuery.ajax({
      type: "GET",
      url: urlSubscribe,
      data: "email_address=" + jQuery('#emailSubscribe').val() + '&fname=' + jQuery('#nameSubscribe').val(),
      success: function (html) {
        jQuery('#error-message').html(html);
		jQuery('#error-message').show();
      },
      beforeSend: function () {
        jQuery('#submitSubscribe').hide();
        jQuery('#formstatus2').show();
      },
      complete: function (html) {
        jQuery('#formstatus2').hide();
        jQuery('#submitSubscribe').show();
      }
    });
  });
  
 

	jQuery('#newsletterform .text, #submitSubscribe').click(function(){
	
		jQuery('#error-message').hide();
		jQuery('#subscription .err').hide();									  
	});
	
	
	jQuery('#contactform').ajaxForm({
        url: '/wp-admin/admin-ajax.php?action=contact_us',
        //iframe: true,
        success: function(data) {

            jQuery('#contactform').hide();
            jQuery('#thanks').show();
            return true;
        },
        beforeSubmit: function() {

			isValid = formValidation('contactform', 'email');
			if ( isValid ) {
                jQuery('#submitForm').hide();
                jQuery('#formstatus').show();
                return true;
            } else {
                return false;
            }

        }
    });

    jQuery('.text, .select, .txtArea').click(function(el){
        jQuery('.err').css('display','none');
    }).focus(function(el){
        jQuery('.err').css('display','none');
    });
  
	jQuery('li:even').addClass('odd');

});


function formValidation(formId, emailId) {
	

            var isValid = true;

            var reg = /^([A-Za-z0-9_\-\.])+\@([A-Za-z0-9_\-\.])+\.([A-Za-z]{2,4})$/;
            var address = jQuery('#'+emailId).val();
            jQuery('.err').hide();

            jQuery('#'+formId+' .required').each(function(){

             checkVal = jQuery(this).val();
             if (checkVal.length<2) {
                    isValid = false;
                    jQuery('#'+jQuery(this).attr('id')).focus();
					jQuery('#'+jQuery(this).attr('id')+'Err').show();
					alert(jQuery('#'+jQuery(this).attr('id')+'Err').text());
                    return false;
                }
            });

            if ( isValid ) {
                if ( reg.test(address) == false ) {
                    isValid = false;
                    jQuery('#'+emailId).focus();
                    jQuery('#'+emailId+'Err').html('Invalid email address!');
					alert(jQuery('#'+emailId+'Err').text());
					jQuery('#'+emailId+'Err').show();
                }
            }

	
return isValid;
}



function initMenu(){
	var nodes = document.getElementById("nav").getElementsByTagName("li");
	for (var i=0; i<nodes.length; i++)
	{
		nodes[i].onmouseover = function()
		{
			this.className += " hover";
		}
		nodes[i].onmouseout = function()
		{
			this.className = this.className.replace(" hover", "");
		}
	}
}
if (document.all && !window.opera) attachEvent("onload", initMenu);

(function(jQuery){
	
	jQuery.fn.scrollGallery = function(options) {
	
		var settings = {
			delay:2000,
			interval:5000,
			speed: 200,
			paneC: "slidesPane",
			slideC: "slide",
			pagingRowCl : 'galleryNav',
			pagingCl: 'galleryNavItem',
			playBtnCl: 'playBtnCl',
			playBtn:1,
			pagingNums: 0,
			enablePaging :1,		
			enableArrows: 0,
			keyActions:0,
			circular:0,
			scrollNum:1,
			auto:1
		};
		
		if ( options ) { 
			jQuery.extend( settings, options );
		}
		
		return this.each(function(){			
			var obj;		
			obj = jQuery(this);
			obj.pane  = obj.children("."+settings.paneC);
			obj.slides = obj.find("img");
			obj.current = 0;
			
			init(jQuery(this)); 
			
			
			
			function init(el){
				settings.auto==1 ? obj.stopped = 0 : obj.stopped = 1;
				
			    obj.Parent = el.parent();
				obj.slidesQ = obj.slides.length;
				obj.slideWidth = obj.slides.width();
				var slidesWidth = obj.slideWidth*obj.slidesQ;
				obj.sceneWidth = obj.Parent.width();
				obj.margin = (obj.sceneWidth-obj.slideWidth)/2;
				obj.way = obj.slideWidth+obj.margin;
 
				
				if(settings.enablePaging) {
					obj.Parent.append('<div class="'+settings.pagingRowCl+'"></div>');
					obj.pagingRow = obj.Parent.find('.'+settings.pagingRowCl);
					
					n = 0;
					obj.slides.each(function(el){
						if(n==0) 
						{
							active = "active";
							jQuery(this).addClass('active');
						} else {
							active = "";
							jQuery(this).fadeTo(0,0);
						}	
						
						pn = settings.pagingNums ? pn = n+1 : '';
						obj.pagingRow.append('<span class="'+settings.pagingCl+' '+active+'">'+pn+'</span>');
						n++;
					});
					
					obj.pages = obj.pagingRow.find('.'+settings.pagingCl);
					
					obj.pages.click(function(){
							n = jQuery(this).index();
								changeSlide(n);
								if(!obj.stopped) addChangingDelay(); 
						
					});
					
					
					if(settings.playBtn==1)
					{
						obj.pagingRow.append('<span class="'+settings.playBtnCl+'"></span>');
						obj.playBtn = obj.pagingRow.find('.'+settings.playBtnCl);
						obj.playBtn.toggle(
							function(){
								jQuery(this).addClass('stopped');
								//changeSlide(obj.current+1); 
								runAutoChange();
								obj.stopped = 0;
							},
							function(){
								jQuery(this).removeClass('stopped');		
								stopAutoChange();
								obj.stopped = 1;
							}
						);
						if(!obj.stopped) {
							obj.playBtn.click();
						}
						
					}
					
					
					
				}
 
 
			}	
			 
		
		function addChangingDelay(){
		
				if(obj.tmout){
					  clearTimeout(obj.tmout);
				}
				if(obj.invl){
					  clearInterval(obj.invl);	
				}
				obj.tmout = setTimeout(function(){ 
					runAutoChange();
				}, settings.delay);
					
		
		}
		
		function stopAutoChange(){
		
			if(obj.tmout){
				  clearTimeout(obj.tmout);
			}
			if(obj.invl){
				  clearInterval(obj.invl);	
			}
		
		}
		
		function runAutoChange(){
			
			obj.invl  = setInterval( function() {
						changeSlide(obj.current+1); 
					}, settings.interval); 

		}
		
		function checkCirclesState(n){								
			obj.pages.removeClass('active');
			obj.pages.eq(n).addClass('active');
		}
		
		function checkCurrent(n){	
				if(n>=obj.slidesQ){
					n = 0;			
				}
				obj.current=n; 
		}
 
		
		 	function changeSlide(n){
				
				if(obj.current!=n) {	
				checkCurrent(n);
				obj.slides.fadeTo(settings.speed,0,function(){}).removeClass('active');		 
				obj.slides.eq(obj.current).fadeTo(settings.speed,1,function(){}).addClass('active');
				checkCirclesState(obj.current);
				}
				
 		
			} 
	 
		});
		
	}
	
	
	
	jQuery(document).ready(function() {
		jQuery('#slides').scrollGallery();		
	}); 

var newImg = new Image();
newImg.src = 'http://www.judobc.ca/wp-content/themes/judobc/images/bg-drop-down-dot.png';
	
})( jQuery );


