$(document).ready (function(){
	if (navigator.userAgent.match(/iPhone/i)==null) {
		var showFirst = function(){
			$(".cssProject").load('templates/ryan_jackson.html .template', function(){
				$(".imageDiv").attr("title", "Turn on lightbox");
			});
			$('.tabNav li:first').addClass('active');
			$("#portfolio h1:first").toggleClass("active");
			$(".cssSite").show();
		}();
	} else {
		$('#about h3').click(function(){
			var aboutContent = $('#about img, #about p');
			$("div.inside, #twitter_update_list").hide();
			if (aboutContent.is(":hidden")) {
				aboutContent.show();	
			} else {
				aboutContent.hide();
			}
		});
		$('#twitter_div h3').click(function(){
			var tweets = $('#twitter_update_list');
			$("div.inside, #about img, #about p").hide();
			if (tweets.is(":hidden")) {
				tweets.show();	
			} else {
				tweets.hide();	
			}
		});
	}
	var accordion = function(){
		$("#portfolio h1").click(function(){
			var slidingDiv = $(this).next("div");
			if (slidingDiv.is(":hidden")) {
				$("div.inside").slideUp();
				$("#portfolio h1").removeClass("active");
				$(slidingDiv).slideDown();
      		} else {
        		$(slidingDiv).slideUp();
      		}
			$(this).toggleClass("active");
		});	
	}();
	
	var slideShow = function(){
		$("span.pagination").live('click', function(){
			$(this).addClass("active").siblings("span.pagination").removeClass("active");
			if ($(this).attr("page") == "one") {
				$(this).siblings(".imageDiv").children("img").animate({marginLeft:"0px"}, 300);
			}else if ($(this).attr("page") == "two") {
				$(this).siblings(".imageDiv").children("img").animate({marginLeft:"-600px"}, 300);
			}else if ($(this).attr("page") == "three") {
				$(this).siblings(".imageDiv").children("img").animate({marginLeft:"-1200px"}, 300);
			}
		});	
	}();
	
	var tab = function(){
		/*$("a.tab").each(function(){
			var idStr = $(this).attr("id"); 
			var tabNum = String(idStr.charAt(idStr.length-1));
			$(this).click(function(){
				$(".cssProject").hide();
				$(".tabNav li").removeClass("active");
				$("div#tabContent" + tabNum).show();
				$(this).parent().addClass("active");
				return false;
			});
		});*/
		$("a.tab").click(function(evt){
			evt.preventDefault();
			$(".tabNav li").removeClass('active');
			var loadContent = $(this).attr('href') + ' .template';
			$(".cssProject").empty().load(loadContent, function(){
				$(".imageDiv").attr("title", "Turn on lightbox");
			});
			$(this).parent().addClass("active");
		});
	}();

	var contactTab = function(){
		var slideUp,
			slideDown,
			arrowBlue,
			arrowGray;
		var blueArrow = function(){
			$('#contact h6').removeClass('up');
			$('#contact h6').addClass('down');	
		}

		var grayArrow = function(){
			$('#contact h6').removeClass('down');
			$('#contact h6').addClass('up');
		}
		
		$("#contact").hover(function(){
			clearTimeout(slideDown);
			clearTimeout(arrowBlue);
			slideUp = setTimeout(function(){
				$('#contact').animate({top:'-9em'}, 600);
			}, 400);
			arrowGray = setTimeout(function(){
				grayArrow();
			}, 1200);
			$(this).toggleClass("up");
			}, function(){
				clearTimeout(slideUp);
				clearTimeout(arrowGray);
				slideDown = setTimeout(function(){
					$('#contact').animate({top:'0'}, 600);
				}, 600);
				arrowBlue = setTimeout(function(){
					blueArrow();
				}, 1400);
				$(this).toggleClass("up");
		});
	}();
	
	var lightBox = function(){
		var maskOn = 0;
		$(".imageDiv").live('click', function(){
			var docHeight = $(document).height();
			$("#mask").height(docHeight);
			if(!maskOn) {
				$("#mask").show();
				maskOn = 1;
				$(this).attr("title", "Turn off lightbox");
			}else {
				$("#mask").hide();
				maskOn = 0;
				$(".imageDiv").attr("title", "Turn on lightbox");
			}
		});	
	}();
});
