$(document).ready(function(){

	//$("header nav.menu").shadow();
	var location = window.location.href,
		location = (location.indexOf("http://localhost") > -1)? "http://localhost:85/portfolio":"";
	
	$.cassioPopup.DefaultSettings = {ImgSRC:location + "/javascript/cassioPopup/images/"};
	
	$("header nav.share").share();
	
	$.stickyFooter({
			content : ".allContent > div",
			footer : "footer"		   
		});
	
	$.InputEmbededTitle({
			fn : null
		});
	
	$(".email").email();
	
	/*
	if( window.location.href == "http://darlesson.com/" || window.location.href == "http://www.darlesson.com/" ){
		$.cassioPopup({
				Title : "Welcome to My Website",
				Type : "HTML",
				Content : "<div style='padding:10px 10px;'><p>This website is in construction and it is being done in HTML5. You may \
							find it incomplete or not working well with Internet Explorer. I recommend a better browser to check \
							it out.</p> \
							<p>If you are interested to see the final result, go to Contact page and send me a message. \
							I will gladly invite you to check it again.</p> \
							<p>Thank you</p> \
							</div>",
				Modal : true,
				Minimize : false,
				OnCreate : function(){ // Fecha o popup quando o fundo é clicado
					var $bg = $("[id*='_modalBG']");
					var bgId = $bg.attr("id");
					var popupName = bgId.substring(0, bgId.lastIndexOf("_"));
					
					$bg.click(function(){
						$.cassioPopup.Remove( popupName );
					});
					
					//$("#" + popupName).shadow();
				}
			});
	}
	*/
						   
});

// E-mail
(function($){

	$.fn.email = function(){
		
		this.each(function(){
			var $this = $(this),
				$this = ( $this.attr("[href]") != undefined )? $this:$this.find("a"),
				emailAddress = "mailto:";
				
			$this.children("img").each(function(){
					emailAddress += $(this).attr("alt");							 
				});
			
			$this
				.click(function(){
					window.location = emailAddress;
					return false
				});
		
		});
		return this
	
	};

})(jQuery);

// Validade Contact Form
(function($){
		  	
	$.validateContact = function(){   
		var $form = $("form[name=\'contactForm\']"),
			$submit = $form.find(":submit");
		
		$submit.click(function(){
							   
				if( $.validateContact.Validate( $form ) ){   
					$form.submit();
				}else{
					$("h2").scrollTo();
					return false
				};
				
			});
		
		// Refresh captcha
		$("[href*='#capctha']").click(function(){							   
			var $img = $("img[src*='captcha_code_file.php']"),
				src = $img.attr("src");
			
			$img.attr( "src", src.substring(0,src.lastIndexOf("?"))+"?rand="+Math.random()*1000 );
			
			return false
		
		});
		
	};
	
	$.extend( $.validateContact, {
			
			Validate : function( $form ){
				var $name = $form.find("[name='name']"),
					$email = $form.find("[name='email']"),
					$message = $form.find("[name='message']"),
					$error = $form.find(".error");
					
				var validEmailFormat = /^([a-zA-Z0-9_.-])+@(([a-zA-Z0-9-])+.)+([a-zA-Z0-9]{2,4})+$/;
					
				if( $name.val() == "" || $name.val().toLowerCase() == "name" || $email.val() == "" || $email.val().toLowerCase() == "e-mail" || $message.val() == "" || $message.val().toLowerCase() == "message" ){
					$error
						.html("All fields are required")
						.slideFadeShow();
					return false
				}else if( !validEmailFormat.test( $email.val() ) ){
					$error
						.html("Invalid e-mail")
						.slideFadeShow();;
					return false
				};
				return true
			}
			
		});

})(jQuery);

// Input Embeded Title
(function($){

	$.InputEmbededTitle = function( options ){
		
		var defaults = {
				fn : function(){
					alert("Preencha o campo para buscar");
				}
			},
			settings = $.extend({}, defaults, options);
		
        $("input[type='text'][initialValue], textarea[initialValue]").each(function() {
            var $this = $(this);
            var cssColor = $this.css("color");
            var ColorInheritance = (!$.browser.msie) ? "inherit" : $this.parents("body").css("color");
            if ($this.attr("attributed") == undefined) {

                // Verifica se existe algum evento validando a busca
                var $button = $this.parents("tp_busca").find(":image, :button, :submit");
                var $form = $this.parents("form");
                if ($button.attr("onclick") == undefined || $form.attr("onsubmit") == undefined) {
                    $form.submit(function() {
                        if ($this.val() == $this.attr("initialValue")) {
							if( typeof settings.fn == "function" ){
								$(settings.fn);
							};
                            return false
                        }
                    });
                }

                $this.focus(function(e) {
                    if ($this.val() == $this.attr("initialValue")) {
                        $this
							.val("")
							.css("color", ColorInheritance);
                    };
                })
				.attr("attributed", "true");
                $this.blur(function(e) {
                    if ($this.val() == "") {
                        $this
							.val($this.attr("initialValue"))
							.css("color", cssColor);
                    };
                });
            };
        });
	
	};

})(jQuery);

// Sticky Footer
(function($){
		  
	$.stickyFooter = function( options ){
		
		var defaults = {
				content : "body > div:first-child > div",
				footer : "body > div:last-child",
				spacer : 40
			},
			settings = $.extend({}, defaults, options);
			
		var $content = $(settings.content),
			$footer = $(settings.footer);
			
		var footerHeight = $footer.outerHeight();
		
		$content.css("padding-bottom", (footerHeight + settings.spacer) + "px");
		$footer.css("margin-top", "-" + footerHeight + "px");
		
	};

})(jQuery);

// Box image
(function($){
		  
	$.fn.boxImage = function(){
		
		this.each(function(){
			var $this = $(this)
				$img = $this.find("img");
				
			$(window).ready(function(){
				var width = $img.outerWidth(),
					height = $img.outerHeight();
				
				$this.append("<div/>");
	
				$this.find("div")
					.css({
						width : width - 20,
						height : height - 20
					});

			})
			
		});
		return this;
	
	};

})(jQuery);

// Share
(function($){
	
	$.fn.share = function(){
		
		var timer;
	
		this.each(function(){
			var $this = $(this),
				$a = $this.children("a");
			
			$a.each(function(){
				var $a = $(this),
					$img = $a.children("img");
				
				$a.mouseenter(function(){
					
					timer = window.setTimeout(function(){
						$a.animate({
							width : "38px",
							height : "38px",
							top : "-4px"
						}, 200);
					}, 250);
					
				}).mouseleave(function(){
					
					window.clearTimeout( timer );
					$a.animate({
						width : "30px",
						height : "30px",
						top : "0px",
						left : "0px"
					}, 200);
					
				});
			});
			
		})
		
	};
	
})(jQuery);

// Add shadow
(function($){
	
	$.fn.shadow = function(options){
		  
		this.each(function(){
			var $this = $(this);
			var navHeight = $this.outerHeight();
			var html = '\ <div class="top"><div class="topLeft"></div><div class="topMiddle"></div><div class="topRight"></div></div> \
			<div class="bottom"><div class="bottomLeft"></div><div class="bottomMiddle"></div><div class="bottomRight"></div></div> \
			<div class="middle"><div class="middleLeft" style="height:' + (navHeight - 16) + 'px;"></div><div class="middleRight" style="height:' + (navHeight - 16) + 'px;"></div></div>';
			
			$this.prepend("<shadow>" + html + "</shadow>")
		
		});
		return this;
	};
	
})(jQuery);

(function($){
		  
	$.SyntaxHighlighter = function(){
		
		var $code = $(".dp-highlighter");
		
		$code.each(function(){
			var $this = $(this),
				width = $this.outerWidth(),
				scrollWidth = $this.get(0).scrollWidth;

				
			$this.hover(function(){
				
				if( scrollWidth > width ){
					$this
						.animate({
							"width": scrollWidth + "px"
						});
				}
				
		   	}, function(){
				
				if( scrollWidth > width ){
					$this
						.animate({
							"width": width			  
						});
				}
				
		   	});
		});
		
	};

})(jQuery);

// Effects
$.fn.slideFadeToggle = function(easing, callback) {
        return this.animate({ opacity: 'toggle', height: 'toggle' }, "fast", easing, callback);
    };
$.fn.slideFadeShow = function(easing, callback) {
        return this.animate({ opacity: 'show', height: 'show' }, "fast", easing, callback);
    };
$.fn.slideFadeHide = function(easing, callback) {
        return this.animate({ opacity: 'hide', height: 'hide' }, "fast", easing, callback);
    };
	
(function($){
		  
	$.fn.scrollTo = function(){
		$("html, body").animate({
			scrollTop : $(this).offset().top
		}, 500);
		return this;
	};
	
})(jQuery);

	
