jQuery(function($){
	// reset css from JavaScript disabled defaults
	if(jQuery.browser.msie && parseInt(jQuery.browser.version) == 6){
		$(".feature-left").css({
			"margin-right": "40px"
		});
	} else {
		$(".feature-left").css({
			"margin-right": "80px"
		});
	}
	
	$("#featured").css({		// when JS is off, Features scroll inside their view
		"overflow-x": "hidden",
		"overflow-y": "hidden"
	});
	
	// apply custom fonts
	Cufon.replace("#menu a,h3,h2,h1", { fontFamily: 'Anivers' });
	
	// menu mouseover
	$("#menu li").hover(function(){
		$(this).addClass("selected");
		Cufon.replace("#menu .selected a", { fontFamily: 'Anivers' }); // recufonize texts
	}, function(){
		$("#menu li").removeClass("selected");
		Cufon.replace("#menu a", { fontFamily: 'Anivers' }); // recufonize texts
	});
	
	// tooltips
	$("a").each(function(i){
	 	$("body").append("<div class='tooltip' id='tooltip"+i+"'><p>"+$(this).attr('title')+"</p></div>");
	 	var my_tooltip = $("#tooltip"+i);
	 	if($(this).attr("title") != ""){ // checks if there is a title
	 		$(this).removeAttr("title").mouseover(function(){
	 				my_tooltip.css({opacity:0.8, display:"none"}).fadeIn(400);
	 		}).mousemove(function(kmouse){
	 				my_tooltip.css({left:kmouse.pageX+15, top:kmouse.pageY+15});
	 		}).mouseout(function(){
	 				my_tooltip.fadeOut(400);
	 		});
	 	}
	 });
	     
	// top drawer
	// set different heights for the drawer based on the browser
	if($.browser.msie){
		if(parseInt($.browser.version) == 6){
			window.drawerHeight = 201;
		} else {
			window.drawerHeight = 179;
		}
	} else {
		window.drawerHeight = 159;
	}
	$("#hire-me-drawer").css({"top": "-"+window.drawerHeight+"px", "display": "block"});//display it
	$("#drawer-button").click(function(){
		if(parseInt($("#hire-me-drawer").css("top")) == 0){
			$("#hire-me-drawer").animate({"top": "-"+window.drawerHeight+"px"}, 1200, "easeOutQuart");
			$(this).html("hire me");
		} else {
			$("#hire-me-drawer").animate({"top": "0px"}, 1000, "easeOutBounce");
			$(this).html("close");
		}
	}).focus(function(){
		$(this).blur();// this removes focus border that looked awful
	});
	
	// crossfades for service icons
	$(".service-icon").each(function (i, element) {
		var src = $(element).find("img").attr("src").replace(".png", "-hover.png");
		$(element).css({background: "url("+src+") no-repeat 1px 1px"});
		$(element).hover(function(){
			$(this).find("img").animate({opacity: 0}, 700);
		}, function(){
			if($(this).find("img:animated").size() == 0){
				$(this).find("img").animate({opacity: 1}, 700);
			} else {
				$(this).find("img").stop().animate({opacity: 1}, 300);
			}
		});
	});
	
	// crossfades for buttons
	// main short buttons
	$(".main-button-short").each(function(i, element){
		var hover = $(element).clone().css({
			"background": "url(images/main-button-short-hover.jpg) no-repeat",
			"position": "relative", 
			"left": "-120px", 
			"z-index": "5", 
			"opacity": "0", 
			"margin-right": "-120px"
		});
		$(element).after(hover);
		$(element).next().hover(function(){
			$(this).animate({opacity: 1}, 300);
		}, function(){
			if($(this).is(":animated")){
				$(this).stop().animate({opacity: 0}, 100);
			} else {
				$(this).animate({opacity: 0}, 300);
			}
		});
	});
	
	// buttons in features
	$(".feature-buttons a").each(function(i, element){
		var hover = $(element).clone().css({
			"background": "url(images/feature-button-hover.jpg) no-repeat",
			"position": "relative", 
			"left": "-120px", 
			"z-index": "5", 
			"opacity": "0", 
			"margin-right": "-120px"
		});
		if($(element).hasClass("feature-button-next")){
			hover.css({"margin-right": "-100px", "left": "-100px"});
		}
		$(element).after(hover);
		$(element).next().hover(function(){
			$(this).animate({opacity: 1}, 300);
		}, function(){
			if($(this).is(":animated")){
				$(this).stop().animate({opacity: 0}, 100);
			} else {
				$(this).animate({opacity: 0}, 300);
			}
		});
	});
	
	// long buttons in main
	$(".main-button-long").each(function(i, element){
		var hover = $(element).clone().css({
			"background": "url(images/main-button-long-hover.jpg) no-repeat",
			"position": "relative", 
			"top": "-65px", 
			"z-index": "5", 
			"opacity": "0", 
			"margin-bottom": "-65px"
		});
		
		$(element).after(hover);
		$(element).next().hover(function(){
			$(this).animate({opacity: 1}, 300);
		}, function(){
			if($(this).is(":animated")){
				$(this).stop().animate({opacity: 0}, 100);
			} else {
				$(this).animate({opacity: 0}, 300);
			}
		});
	});
	
	// register features cycler
	$("#featured").cycle({
		fx: "scrollDown",
		next: ".feature-button-next",
		prev: ".feature-button-prev",
		timeout: 0,
		cleartype:  true,
    	cleartypeNoBg:  true,
		easing: "easeOutBounce",
		speed: 1000
	});
});
