$(document).ready(function() {
	
	$("#services_nav ul li").hover(function() {
		
		$(this).animate({ "color": "#d5edff" }, 300);
		
	}, function() {
		
		$(this).animate({ "color": "#0090ff" }, 300);
		
	});
	
	var windowHeight = $(window).height();
	var windowWidth = $(window).width();
	
	$("#services_bg").css("height", windowHeight + "px").css("width", windowWidth + "px");
	
	$("#navigator a").css("padding-right", "30px");
	
	$("#navigator a").hover(function() {
		
		$(this).stop(true, true).animate({ "padding-right": "40px" }, 350);
		
	}, function() {
		
		$(this).stop(true, true).animate({ "padding-right": "30px" }, 350);
		
	});
	
	$("h2.dropper").toggle(function() {
		
		$(this).siblings(".dropper_content").slideUp(1000);
		
		$(this).addClass("dropped");

	}, function() {

		$(this).removeClass("dropped");
		
		$(this).siblings(".dropper_content").slideDown(1000);
		
	});
	
	var isDragging = false;
	
	$("#ui_name").focus(function() {
		
		if ($(this).val() != "Your Name") {
			
		} else {
			
			$(this).val("");
			
		}

	}).blur(function() {
		
		if ($(this).val().length > 0) {
			
		} else {
			
			$(this).val("Your Name");
			
		}
		
	});
	
	$("#ui_company").focus(function() {
		
		if ($(this).val() != "Your Company") {
			
		} else {
			
			$(this).val("");
			
		}

	}).blur(function() {
		
		if ($(this).val().length > 0) {
			
		} else {
			
			$(this).val("Your Company");
			
		}
		
	});
	
	$("#ui_phone").focus(function() {
		
		if ($(this).val() != "Your Digits (Phone)") {
			
		} else {
			
			$(this).val("");
			
		}

	}).blur(function() {
		
		if ($(this).val().length > 0) {
			
		} else {
			
			$(this).val("Your Digits (Phone)");
			
		}
		
	});
	
	$("#ui_email").focus(function() {
		
		if ($(this).val() != "Your Email") {
			
		} else {
			
			$(this).val("");
			
		}

	}).blur(function() {
		
		if ($(this).val().length > 0) {
			
		} else {
			
			$(this).val("Your Email");
			
		}
		
	});
	
	$("#ui_message").focus(function() {
		
		if ($(this).val() != "Your Message/Thoughts/Ideas") {
			
		} else {
			
			$(this).val("");
			
		}

	}).blur(function() {
		
		if ($(this).val().length > 0) {
			
		} else {
			
			$(this).val("Your Message/Thoughts/Ideas");
			
		}
		
	});
	
	$("#ui_rname").focus(function() {
		
		if ($(this).val() != "Your Name") {
			
		} else {
			
			$(this).val("");
			
		}

	}).blur(function() {
		
		if ($(this).val().length > 0) {
			
		} else {
			
			$(this).val("Your Name");
			
		}
		
	});
	
	$("#ui_remail").focus(function() {
		
		if ($(this).val() != "Your Email") {
			
		} else {
			
			$(this).val("");
			
		}

	}).blur(function() {
		
		if ($(this).val().length > 0) {
			
		} else {
			
			$(this).val("Your Email");
			
		}
		
	});
	
	$("#ui_rrname").focus(function() {
		
		if ($(this).val() != "Referree's Name") {
			
		} else {
			
			$(this).val("");
			
		}

	}).blur(function() {
		
		if ($(this).val().length > 0) {
			
		} else {
			
			$(this).val("Referree's Name");
			
		}
		
	});
	
	$("#ui_rremail").focus(function() {
		
		if ($(this).val() != "Referree's Email") {
			
		} else {
			
			$(this).val("");
			
		}

	}).blur(function() {
		
		if ($(this).val().length > 0) {
			
		} else {
			
			$(this).val("Referree's Email");
			
		}
		
	});
	
	$("#ui_rrphone").focus(function() {
		
		if ($(this).val() != "Referree's Phone") {
			
		} else {
			
			$(this).val("");
			
		}

	}).blur(function() {
		
		if ($(this).val().length > 0) {
			
		} else {
			
			$(this).val("Referree's Phone");
			
		}
		
	});
	
	$("#ui_rrmessage").focus(function() {
		
		if ($(this).val() != "Basic description of the project. (example: company, what they need, who they are, etc)") {
			
		} else {
			
			$(this).val("");
			
		}

	}).blur(function() {
		
		if ($(this).val().length > 0) {
			
		} else {
			
			$(this).val("Basic description of the project. (example: company, what they need, who they are, etc)");
			
		}
		
	});
	
	$(".block_item").hover(function() {
		
		$(this).children(".overlay").stop(true, true).animate({ "opacity": "0" }, 250);
		$(this).children(".overlay").stop(true, true).animate({ "z-index": "1" }, 10);
		$(this).find(".type_bar").stop(true, true).animate({ "right": "0px" }, 400);
		
		$(this).find(".bottom_slider").stop(true, true).animate({ "opacity": ".96", "bottom": "0px" }, 400, 'easeOutExpo');
		
	}, function() {
		
		$(this).children(".overlay").stop(true, true).animate({ "z-index": "1004" }, 10);
		$(this).children(".overlay").stop(true, true).animate({ "opacity": "1" }, 400);
		
		//var typebarWidth = $(this).children(".type_bar").width;
		
		$(this).find(".type_bar").stop(true, true).animate({ "right": "-100%" }, 400);

		$(this).find(".bottom_slider").stop(true, true).animate({ "opacity": "1", "bottom": "-25%" }, 400, 'easeInExpo');
		
	});
	
	$("#nav li a").hover(function() {
		
		navChange($(this), "23%", "0090ff");
		
	}, function() {
		
		navChange($(this), "5%", "333333");
		
	});
	
	function navChange(item, padding, color) {
		
		$(item).stop(true, true).animate({ "padding-left": padding, "background-color": "#" + color, "display": "inline" }, 250);
		
	}
	
    Boxes = {
        init: function(){
            var self = this;
            
            this.main = $('#blocks');
            
            if ( ! this.main.length ) return;
            
            this.sideBar = $('#sidebar');
            this.item = $('.block_item', this.main);
            this.image = $('.block_item img');
            //this.itemName = $('.block_item', this.main);
            this.scrollBarWidth = $.getScrollbarWidth();
            this.itemWidth = 320;
            this.win = $(window);
      
            this.resize();
            this.win.resize(function(event) {
                self.resize();
            });
        },
        resize: function(){
            // if ( this.win.width() <= 1024 ) return;
            var newSize = this.win.width() - 40; // 32 - this.sideBar.width(),
                boxSize = (newSize-this.scrollBarWidth)/( Math.floor(this.win.width()/this.itemWidth) );
                
            this.main.width(newSize);
            this.item.width(boxSize);
            this.image.width(boxSize);
            this.image.height(boxSize);
            //this.itemName.width(boxSize);
            this.item.height(boxSize);
        }
    }
    
    Boxes.init();
    
    BoxesDetalhe = {
        init: function(){
            var self = this;
            this.main = $('#blocks');
            
            if ( ! this.main.length ) return;
            
            this.sideBar = $('#sidebar');
            this.scrollBarWidth = $.getScrollbarWidth();

            this.win = $(window);
            
            this.resize();
            this.win.resize(function(event) {
                self.resize();
            });
        },
        resize: function(){
            var newSize = this.win.width(); // - this.sideBar.width();
            this.main.width(newSize);
        }
    }
    
    //BoxesDetalhe.init();
    
    

    Sidebar = {
    	
    	init: function() {
    		
    	this.sideBar = $("#sidebar");
    	
    	this.locked = false;
    	
    	this.out = true;
    		
    	},
    	slideIn: function() {
    		
    		
    		
    	if (this.locked != true) {
    		
	    	this.sideBar.stop().animate({ "margin-left": "-165px" }, 300);
	    	
	    	this.sideBar.children("#arrow").animate({ "opacity": 1 }, 200);
	    	
	    	$("#corner_icon").animate({ "opacity": "1" }, 300);
	    	
	    	this.out = false;
	    	
	    	blink(false);
	    	
	    }

    	},
    	slideOut: function() {
  		
    	if (this.out != true) {
    			
	    	if (this.locked != true) {
	    		
	    		this.sideBar.stop().animate({ "margin-left": "0px" }, 300);
	    	
	    		this.sideBar.children("#arrow").stop().animate({ "opacity": 0 }, 200);	
	    		
	    		$("#corner_icon").animate({ "opacity": "0" }, 300);
	    		
	    	}
	    	
	    	 this.out = true;
 
	    }
	    
	    blink(true);
	    
		},
		lock: function() {
    	
    	$("#arrow").stop(true, true);
			
		this.sideBar.stop().animate({ "margin-left": "0px" }, 300);
		
		this.locked = true;
			
		},
		unlock: function() {
			
		this.locked = false;
			
		}
    	
    }
    
    Sidebar.init();
    	
	$("#sidebar").hover(function() {
	
		Sidebar.slideOut();
	
	}, function() {
		
		Sidebar.slideIn();
		
	});

    setTimeout("Sidebar.slideIn()", 3000);
    
    $(".panel").css("left", "-300px");
    
    $("#launch_contact").click(function() {
    	
    	$("#referral_panel").css("left", "-300px");
    	
    	Sidebar.lock();
    	
    	$("#contact_panel").animate({ "left": "205px" }, 450, "easeOutExpo");

    	return false;
    	
    });
    
    $("#launch_referral").click(function() {
    	
    	$("#contact_panel").css("left", "-300px");
    	
    	Sidebar.lock();
    	
    	$("#referral_panel").animate({ "left": "205px" }, 450, "easeOutExpo");

    	return false;
    	
    });
    
    $("button.exit").hover(function() {
		
		$(this).stop(true, true).animate({ "opacity": "1" }, 100);
		
	}, function() {
		
		$(this).stop(true, true).animate({ "opacity": ".7" }, 200);
		
	});
	
	$(".panel button.exit").click(function() {
		
		Sidebar.unlock();
		
		$(this).parent('.panel').animate({ "left": "-300px" }, 300);
		
		Sidebar.slideIn();
		
	});
	
	$(".after_success").hide();
	$(".after_failure").hide();
	$("#contact_response").hide();
	
	$("input#send_contact").click(function() {
		
		$("#the_contact_form").fadeOut(200);
		$("#contact_response").fadeIn(200);

	});
	
	$("input#send_referral").click(function() {
		
		$("#the_referral_form").fadeOut(200);
		$("#referral_response").fadeIn(200);
		
	});
	
	
	$("#services_links a").hover(function() {
		
		$(this).stop(true, true).animate({"color": "#62baec"}, 300);
		
	}, function() {
		
		$(this).stop(true, true).animate({"color": "#ffffff"}, 500);
		
	});
	

});

function showContactForm() {
	
	$("#the_contact_form").fadeIn(200);
	$("#contact_response").fadeOut(200);
	
}

function showReferralForm() {
	
	$("#the_referral_form").fadeIn(200);
	$("#referral_response").fadeOut(200);
	
}

    function flashArrow() {
    	
    	$("#arrow").animate({ "opacity": ".45" }, 500).animate({ "opacity": "1" }, 500);
    	
    	
    	
    }
    
    function blink(){
    
    	if (Sidebar.out != true) { $('#arrow').delay(100).fadeTo(300,0.5).delay(100).fadeTo(300,1, blink); }

	}

