$(document).ready(function() {
	
	
	Cufon.replace('h3, h4, .module h5', { fontFamily: 'Myriad Pro Light' });
	Cufon.replace('h2', { fontFamily: 'Myriad Pro' });

	$('#note').hide().css('visiblity', 'visible');
	$('#note-newsletter').hide().css('visibility', 'visible');
	
	function isValidEmailAddress(emailAddress) {
				var pattern = new RegExp(/^(("[\w-\s]+")|([\w-]+(?:\.[\w-]+)*)|("[\w-\s]+")([\w-]+(?:\.[\w-]+)*))(@((?:[\w-]+\.)*\w[\w-]{0,66})\.([a-z]{2,6}(?:\.[a-z]{2})?)$)|(@\[?((25[0-5]\.|2[0-4][0-9]\.|1[0-9]{2}\.|[0-9]{1,2}\.))((25[0-5]|2[0-4][0-9]|1[0-9]{2}|[0-9]{1,2})\.){2}(25[0-5]|2[0-4][0-9]|1[0-9]{2}|[0-9]{1,2})\]?$)/i);
				return pattern.test(emailAddress);
			}		

	$('#ContactSend').click(function() {

		$('#contactForm input:text, #contactForm textarea').each(function() {

			var usedinput = $(this);		
			var usedinputtitle = $(this).attr('title');
			
			if(usedinput.val() == "" || usedinput.val() == usedinputtitle) {
				$(this).val(usedinputtitle);
				$(this).addClass('formError')
			} else {
				if(usedinput.attr('id') == 'ContactEmail') {
					var email = $('#ContactEmail').val();
					if(isValidEmailAddress(email)) {
						$(this).removeClass('formError');
					} else {
						$(this).val(usedinputtitle);
						$(this).addClass('formError')
					}
				} else {
					$(this).removeClass('formError')
				}
			}

			function remove() {
				if(usedinput.val() == usedinputtitle) {
					$(this).val("");
				}
			}
	
			$(this).blur(function() {
				if(usedinput.val() == "") {
					$(this).val(usedinputtitle);
					$(this).addClass('formError')
				} else {
					$(this).removeClass('formError')
				}
			}).focus(remove)
			
		
		});
		
		
		if($('.formError').size()) {
			return false;
		} else {
			var str = $("#contactForm").serialize();
			   $.ajax({
			   type: "POST",
			   url: "http://www.rainfall.ro/style/js/contact.php",
			   data: str
			 });
			 $('#contactForm').slideUp("slow", function() { $('#note').slideDown("slow") })
		   
		return false;
		}

	});

	$('#newsletter-submit').click(function() {

		$('#newsletterForm input:text').each(function() {

			var usedinput = $(this);		
			var usedinputtitle = $(this).attr('title');
			
					var email = $('#newsletter-input').val();
					if(isValidEmailAddress(email)) {
						$(this).removeClass('newsletterError');
					} else {
						$(this).val(usedinputtitle);
						$(this).addClass('newsletterError')
					}

			function remove() {
				if(usedinput.val() == usedinputtitle) {
					$(this).val("");
				}
			}
	
			$(this).blur(function() {
				if(usedinput.val() == "") {
					$(this).val(usedinputtitle);
					$(this).addClass('newsletterError')
				} else {
					$(this).removeClass('newsletterError')
				}
			}).focus(remove)
			
		
		});
		
		
		if($('.newsletterError').size()) {
			return false;
		} else {
			var str = $("#newsletterForm").serialize();
			   $.ajax({
			   type: "POST",
			   url: "http://www.rainfall.ro/style/js/newsletter.php",
			   data: str
			 });
			 $('#newsletterForm').slideUp("slow", function() { $('#note-newsletter').slideDown("slow") })
		   
		return false;
		}

	});
    
    $('#main-navigation li a span').fadeTo(0,0);
    $('#twitter-icon span').fadeTo(0,0).css('visibility', 'visible');
    
    // latest news element
    
    $('#sidebar p:last').addClass('last');
    
    // set equal height

    $col = $('.col .equal');
    $colAlt = $('.col.alt .equal');
    
    if($col.height() > $colAlt.height()) {
        $colAlt.height($col.height())
        }
    else {
        $col.height($colAlt.height())
    }
    
    // make slide feat proj
    
    $('.featured-project').each(function (i){
        $(this).hover(function() {
            $(this).find('span').stop().animate({ 'bottom': '0px'  }, 400); }
                , function() {
            $(this).find('span').stop().animate({ 'bottom': '-34px'  }, 400);
        });
    });
    
    // nav :)

    $('#main-navigation li a').each(function (i){
        $(this).hover(function() {
            $(this).children().stop().fadeTo(600, 1);                       
        },
            function() {
                $(this).children().stop().fadeTo(600, 0);                       
        });                                              
    });
	
        $('#twitter-icon').hover(function() {
            $(this).children().stop().fadeTo(600, 1);                       
        },
            function() {
                $(this).children().stop().fadeTo(600, 0);                       
        });                                              
    
    // adding the border
    
    $('.project .project-image').prepend('<span class="border"></span>');
    
    // scrollTop
    
    $('.back-top').each(function (i) {
        $(this).click(function() {
      		$('html, body').animate({scrollTop:0}, 'slow', "easeOutExpo"); return false;
        });          
    });
    
    // the hiper super scroll to project
    
    $('.project-nav a').each(function (i) {
        $(this).click(function() {
            var rel = $(this).attr("rel");
            var goTo = '#' + rel;
            var offset = $(goTo).offset();
            $('html, body').animate({scrollTop: offset.top - 20}, 'slow', "easeOutExpo"); return false;       
        });
    });
    
    // making the sidebar nav moooooooooooooove
    
    $('#sidebar ul a, .module ul a, #BlogSidebar ul a').each(function (i) {
        $(this).hover(function() {
            $(this).stop().animate({ paddingLeft: '7px' }, 100); }
                , function() {
            $(this).stop().animate({ paddingLeft: '0px' }, 100);
        });
    });

	
    
}); 








