/* Author: 

*/


$(document).ready(function(){
	$.fn.placeholder = function(){

            // quit if there's support  for html5 placeholder
            if (this[0] && 'placeholder' in document.createElement('input')) return;

            return this
            .live('focusin',function(){
                if ($(this).val() === $(this).attr('placeholder')) {
                    $(this).val('');
                }
            }).live('focusout',function(){
                if ($(this).val() === ''){
                    $(this).val( $(this).attr('placeholder') );
                    if($(this).attr('type')==='password') {
                        $(".password-field label").removeClass('hidden');
                        $(".password-field").addClass('needed');
                    }
                }
            }).focusout();
    }
    $('input[placeholder]').placeholder();
	$('form .view-all').click(function(e){
		e.preventDefault();
		$(this).parent().submit();
	});
	$('.video-gallery').append('<a href="#" title="Previous Videos" class="prev-vids"></a><a href="#" title="Next Videos" class="next-vids"></a>');
	$('.video-gallery .prev-vids').css({'opacity':'0.25','cursor':'auto'}).addClass('disabled').click(function(e){
		e.preventDefault();
		if(!$(this).hasClass('disabled')){
			$('.next-vids').css({'opacity':'1','cursor':'pointer'}).removeClass('disabled');
			$('.video-gallery .gallery-slide').animate({'margin-left':(parseFloat($('.video-gallery .gallery-slide').css('margin-left'))+632)+'px'},500,function(){
				if(parseFloat($('.video-gallery .gallery-slide').css('margin-left'))==0) {
					$('.video-gallery .prev-vids').css({'opacity':'0.25','cursor':'auto'}).addClass('disabled');
				}
			});
		}
	});
	$('.video-gallery .next-vids').click(function(e){
		e.preventDefault();
		if(!$(this).hasClass('disabled')){
			$('.video-gallery .prev-vids').css({'opacity':'1','cursor':'pointer'}).removeClass('disabled');
			$('.video-gallery .gallery-slide').animate({'margin-left':(parseFloat($('.video-gallery .gallery-slide').css('margin-left'))-632)+'px'},500,function(){
				if(parseFloat($('.video-gallery .gallery-slide').css('margin-left'))<=-1*(parseFloat($('.video-gallery .gallery-slide').css('width'))-632)) {
					$('.video-gallery .next-vids').css({'opacity':'0.25','cursor':'auto'}).addClass('disabled');
				}
			});
		}
	});
	$('.video-gallery .gallery-slide').css('width',158*$('.video-gallery .video').length+'px');
	$(".video-gallery div object").append('<param value="transparent" name="wmode">');
	$(".video-gallery div embed").attr('wmode','transparent');
	$('.news .video').live('click',function(){
		$('.video-show').html($('.video-show').html());
		$('.video-show').attr('class','video');
		$(this).attr('class','video-show').html($(this).html());
	});
	$('.signup .view-all').click(function(e){
		e.preventDefault();
		$('.signup p').remove();
		var myString = $('#list_email').val(),
			myName = '';
		if($('#list_name').val()!='' && $('#list_email').val()!='Name'){
			myName=$('#list_name').val();
		}
		if(myString.match(/^(([^<>()[\]\\.,;:\s@\"]+(\.[^<>()[\]\\.,;:\s@\"]+)*)|(\".+\"))@((\[[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\])|(([a-zA-Z\-0-9]+\.)+[a-zA-Z]{2,}))$/ ) && myName!=''){
			$.ajax({
				url: "http://kneebody.com.hostbaby.com/list-test.html",
				data: "list_email="+myString+"&list_name="+myName,
				type: "POST",
				success: function(html){
    				$('.signup p').html(myName+', thank you for joining the mailing list with '+myString+'.');
  				}
			});
			$('.signup form').remove();
			$('.signup .view-all').remove();
			$('.signup').append('<p>Please wait while we add you to the list.</p>');
			
		} else if (myName=='') {
			$('.signup form').after('<p>Please enter your name.</p>');
		} else {
			$('.signup form').after('<p>Please enter a valid email address.</p>');
		}	
	});
});




















