jQuery(document).ready(function(){
	// Homepage Tab panel	
	jQuery("ul#tabs-text").find("li").each(function(i) {
		
		jQuery(this).mouseover(function(event){
			
			jQuery('#content ul#tabs li[class!="tab-current"]').removeClass('tab-current');
			jQuery('#content ul#tabs-text li[class!="tab-current"]').removeClass('tab-current');
			
			jQuery('#content div[class!="content-tab' + i +'"]').removeClass('active');			
			
			jQuery(this).addClass('tab-current');
			jQuery('#content div.content-tab' + i).addClass('active');
			
			clearInterval($intervalid);
			event.preventDefault();
		});
	});
	
	
	
	jQuery("#ec_phone").keypress(function(e){
		
		if (e.which > 31 && (e.which < 48 || e.which > 57)){
			if (e.which != 40 && e.which != 41 && e.which != 43 && e.which != 44 && e.which != 45 && e.which != 32 && e.which != 37 && e.which != 39 && e.which != 46 && e.which != 35 && e.which != 36)
				e.preventDefault();
		}
		
	});	
	
	
		jQuery("#contactfrm").submit(function(event){		  
			dataString = jQuery("#contactfrm").serialize();			

			jQuery.ajax({
		   	type: "POST",
		   	url: "/wp-content/plugins/easy-contact/contactsend.php",
		   	data: dataString,
		   	success: function(msg){
		   		if(msg == 'invalid'){		   			
		   			return false;
		   		}
		    	jQuery('#infotext').html(msg);
		    	jQuery('#contactfrm').hide();
		   	}
		 });
		event.preventDefault();
		
		});
	
});

function slideSwitch() {
    var $active = jQuery('#slideshow DIV.active');
	var $tabactive = jQuery('ul#tabs li.tab-current');
	
    if ( $active.length == 0 ){
    	$active = jQuery('#slideshow DIV:last');    	
    }
	if ($tabactive.length== 0){
		$tabactive = jQuery('ul#tabs li:last');
	}
    // use this to pull the images in the order they appear in the markup
    var $next =  $active.next().length ? $active.next():jQuery('#slideshow DIV:first');
	var $tabnext = $tabactive.next().length ? $tabactive.next():jQuery('ul#tabs li:first');
	
	
    // uncomment the 3 lines below to pull the images in random order
    
    // var $sibs  = $active.siblings();
    // var rndNum = Math.floor(Math.random() * $sibs.length );
    // var $next  = $( $sibs[ rndNum ] );


    $active.addClass('last-active');
	$tabactive.addClass('tab-last');
	
	
    $next.css({opacity: 0.0})
        .addClass('active')
        .animate({opacity: 1.0}, 1000, function() {
            $active.removeClass('active last-active');
        });
    
	$tabnext.css({opacity: 0.0})		
        .addClass('tab-current')        
        .animate({opacity: 1.0}, 1000, function() {
            $tabactive.removeClass('tab-current tab-last');
        });

	$tabactive.css({opacity: 1.0})
        .animate({opacity: 0.0}, 1000, function() {
        //    $tabactive.removeClass('tab-currenttest');
        });

}
var $intervalid;
jQuery(function() {
    $intervalid = setInterval( "slideSwitch()", 5000 );
});	

