if ((navigator.userAgent.indexOf('iPhone') != -1) || (navigator.userAgent.indexOf('iPod') != -1)){
	document.location = "http://www.citrussamurai.com/iphone.php";  
}

// jQuery
$(function(){
	
	// external links in new window
	$("a[href^=http]").live("click", function(){
		window.open(this.href); return false;
	});
	
	$(".top-email, .link-email").click(function(){
		location.href = "mailto:" + $(this).attr("rel") + "@gmail.com?subject=I Want To Hire You!";
	});
	
// portfolio thumb click
	$(".portfolio-content .thumb-item img").bind("click",function(e){
		$(e.target).closest(".portfolio-content").find(".container-fade").fadeOut(300,function(){
			$(this).find(".info h5 a").text($(e.target).attr("title")).attr("href", $(e.target).next("div").find(".external").attr("href"));
			$(this).find(".info div").html($(e.target).next("div").html());
			$(this).find(".screenshot").css("background-image",'url(' + $(e.target).attr("src") + ')');
			$(e.target).closest(".portfolio-content").find(".screenshot").attr("href", $(e.target).attr("src").replace("/thumbnails/", "/screenshots/")).attr("title", $(e.target).attr("title")).fancybox({'titlePosition':'inside'});
			$(this).fadeIn(300);
		});
	});
	
// portfolio container tabs
	$("#portfolio-3d").hide();
	$("#portfolio-web .thumb-item img:first").click();
	$("#portfolio-web-link").addClass("selected");
	$("#portfolio-web-link").bind("click",function(e){
		if (!$(e.target).hasClass("selected")){
			$("#portfolio-web .thumb-item img:first").click();
			$(e.target).addClass("selected");
			$("#portfolio-3d-link").removeClass("selected");
			$("#portfolio-3d").hide();
			$("#portfolio-web").show();
		}
	});
	$("#portfolio-3d-link").bind("click",function(e){
		if (!$(e.target).hasClass("selected")){
			$("#portfolio-3d .thumb-item img:first").click();
			$(e.target).addClass("selected");
			$("#portfolio-web-link").removeClass("selected");
			$("#portfolio-web").hide();
			$("#portfolio-3d").show();
		}
	});
	
// twitter plugin
	$.getScript("/js/jquery.twitter.js", function(){
		$("#masthead-container").append('<div id="twitter"></div>');
		$("#twitter").getTwitter({
			userName: "tarvis",
			numTweets: 5,
			loaderText: "",
			slideIn: false,
			showHeading: false,
			showProfileLink: false,
			showTimestamp: true
		});
		$("#twitter").prepend('<div id="twitter-bg-fade"></div>');
	});
	
// contact form
	$('#contact-form .submit-button').wrapInner('<span />');;
	$('#contact-form').append('<input type="hidden" id="avoidbots" name="avoidbots" value="nobot" />');
	
	$('.link-contact').fancybox({ 'titleShow' : false });
	
	$('#contact-form label').each(function(i) {
		if ($(this).next('input').length > 0) {
			$(this).next('input').val($(this).text());
			var a = $(this).next('input').val();
			$(this).next('input').focus(function() {
				$(this).filter(function() {
					return $(this).val() == '' || $(this).val() == a;
				}).val('').addClass('focus');
			}).blur(function() {
				$(this).filter(function() {
					return $(this).val() == '';
				}).val(a).removeClass('focus');
			});
		} else {
			$(this).next('textarea').val($(this).text());
			var b = $(this).next('textarea').val();
			$(this).next('textarea').focus(function() {
				$(this).filter(function() {
					return $(this).val() == '' || $(this).val() == b;
				}).val('').addClass('focus');
			}).blur(function() {
				$(this).filter(function() {
					return $(this).val() == '';
				}).val(b).removeClass('focus');
			});
		}
	}).remove();
	
	$(".submit-button").click(function(){
		if($("#name").val() == "Your Name"){ $("#name").addClass("error"); }else{ $("#name").removeClass("error"); }
		if($("#email").val() == "Email Address"){ $("#email").addClass("error"); }else{ $("#email").removeClass("error"); }
		if(!(($("#email").val().indexOf(".") > 2) && ($("#email").val().indexOf("@") > 0))){ $("#email").addClass("error"); }else{ $("#email").removeClass("error"); }
		if($("#message").val() == "How can I help you?"){ $("#message").addClass("error"); }else{ $("#message").removeClass("error"); }
		if($(".text").hasClass("error")){
			return (false);
		} else {
			$.ajax({
				type: "POST",
				url: "contact.php",
				data: $('#contact-form').serialize(),
				success: function(html) {
					console.log($('#contact-form').serialize());
					$("#contact").html(html);
				}
			});
			return false;
		}
	});
	
});

// Google Analytics
var _gaq = _gaq || [];
_gaq.push(['_setAccount', 'UA-1162892-3']);
_gaq.push(['_trackPageview']);
(function() {
	var ga = document.createElement('script'); ga.type = 'text/javascript'; ga.async = true;
	ga.src = ('https:' == document.location.protocol ? 'https://ssl' : 'http://www') + '.google-analytics.com/ga.js';
	(document.getElementsByTagName('head')[0] || document.getElementsByTagName('body')[0]).appendChild(ga);
})();