// Handling iPhone Visits
var iphone
var current = window.location.href;
var brwsr = navigator.userAgent.toString();

var temp = new Array();
temp = current.split('/');

var site = "http://" + temp[2];
var directory = "/" + temp[3];
var end

if(current.indexOf("comment.php")!=-1)
	{
		end = "/comment.php";
	}
	else if((current.indexOf("index.php")!=-1) || (current.indexOf("index.php/index.php")==-1))
	{
		end = ".php";
	}
	else {
		end = "";
	}
		
var tempUrl = site + "/iphone" + directory + end;
var tempUrl2 = tempUrl.replace(/\/.php/,"");
var newUrl = tempUrl2.replace(/.php.php/,".php");

if((brwsr.match(/iPhone/i)) || (brwsr.match(/iPod/i)))
	{
		iphone = true;
	}
	else {
		iphone = false;
	}

if((iphone == true) && (current.indexOf("?iphone=no")==-1) && (temp[3] == 'gallery'))
	{
		location.replace('http://mjarrell.com/iphone/gallery/index.html');
	}
	else if((iphone == true) && (current.indexOf("?iphone=no")==-1))
		{
			location.replace(newUrl);
		}
	else {
		//
	}
	

// Cache Images for Rollover
$(document).ready(function(){
  $.preloadCssImages();
}); 

// Get Date for Copyright
var now = new Date();
var year= now.getYear();
var mon = now.getMonth() + 1;
var day = now.getDate();



// Hack for Gecko and Web-Kit Y2K  Bug
if (year >= 100 && year <= 1999)
	{ 
		year = year + 1900
	}
	else {
		year = year
	}
	
//Determines which calendar to display
	if ((year == 2009) && (mon < 9))
		{
			var iframe = "<iframe src=\"http://www.google.com/calendar/embed?title=2009%20SEC%20Football%20Schedule&amp;showTitle=0&amp;showPrint=0&amp;showCalendars=0&amp;height=600&amp;wkst=1&amp;bgcolor=%23ffffff&amp;src=t7gncdlefdn3am4iqd73c50vdk3ls2fq%40import.calendar.google.com&amp;color=%235A6986&amp;ctz=America%2FChicago&dates=20090901%2F20091001\" style=\" border-width:0 \" width=\"700\" height=\"600\" frameborder=\"0\" scrolling=\"no\" id=\"sec\"></iframe>";
			$(document).ready(function(){	
				$('#lrgCal').click(function(){
					window.open('http://www.google.com/calendar/embed?title=2009%20SEC%20Football%20Schedule&showTitle=0&showPrint=0&showCalendars=0&height=600&wkst=1&bgcolor=%23ffffff&src=t7gncdlefdn3am4iqd73c50vdk3ls2fq%40import.calendar.google.com&color=%235A6986&ctz=America%2FChicago&dates=20090901%2F20091001','window','menubar=no,width=900,height=600,toolbar=no,resizable=no,scrollbars=no');
					return false;
				  });
			});
		}
		else {
			var iframe = "<iframe src=\"http://www.google.com/calendar/embed?title=2009%20SEC%20Football%20Schedule&amp;showTitle=0&amp;showPrint=0&amp;showCalendars=0&amp;height=600&amp;wkst=1&amp;bgcolor=%23ffffff&amp;src=t7gncdlefdn3am4iqd73c50vdk3ls2fq%40import.calendar.google.com&amp;color=%235A6986&amp;ctz=America%2FChicago\" style=\" border-width:0 \" width=\"700\" height=\"600\" frameborder=\"0\" scrolling=\"no\" id=\"sec\"></iframe>";
			$(document).ready(function(){	
				$('#lrgCal').click(function(){
					window.open('http://www.google.com/calendar/embed?title=2009%20SEC%20Football%20Schedule&showTitle=0&showPrint=0&showCalendars=0&height=600&wkst=1&bgcolor=%23ffffff&src=t7gncdlefdn3am4iqd73c50vdk3ls2fq%40import.calendar.google.com&color=%235A6986&ctz=America%2FChicago','window','menubar=no,width=900,height=600,toolbar=no,resizable=no,scrollbars=no');
					return false;
				  });
			});
		}

$(document).ready(function(){
	$('.fail').click(function(){
		if ($.browser.msie)
		{
			$('#hahaIE').fadeIn(900);
			return false;
		}
	  });
	$('#hahaClose').click(function(){
		$('#hahaIE').fadeOut(900);					   
	});
});



//Calculate Dev Experience
var devExp = year - 2005;

// Hide Email Address from SPAM Bots
/*Usage Example:
<script type="text/javascript">document.write('<a href="' + 'mailto:' + user + '@' + domain + '.' + suffix + '">' + 'Contact</a>');</script>*/
var user = "mike";
var domain = "mjarrell";
var suffix = "com";

//jQuery form validation
$(document).ready(function(){
	$("#commentForm").validate(
		{
		rules: 
			{
    			name: "required",
				email: "required email",
				styled2: "required"
  			}
	});
});

// Change href attribures for iPhone users
if((iphone == true) && (current.indexOf("?iphone=no")!=-1)) {
	$(document).ready(function(){
			$("#linkHome").click(function(){
				$(this).attr({href: "../index.php?iphone=no"});
			});
			$("#linkHome2").click(function(){
				$(this).attr({href: "../index.php?iphone=no"});
			});
			$("#linkAbout").click(function(){
				$(this).attr({href: "../about/index.php?iphone=no"});
			});
			$("#linkContact").click(function(){
				$(this).attr({href: "../contact/index.php?iphone=no"});
			});
			$("#linkContact2").click(function(){
				$(this).attr({href: "../contact/index.php?iphone=no"});
			});
			$("#linkResume").click(function(){
				$(this).attr({href: "../resume/index.php?iphone=no"});
			});
			$("#linkGallery").click(function(){
				$(this).attr({href: "../gallery/index.php?iphone=no"});
			});
			$("#linkLinks").click(function(){
				$(this).attr({href: "../links/index.php?iphone=no"});
			});
			$("#iphone").css("display","inline");
	});
}

var url = window.location.href.replace('?iphone=no','');

var tempArray = new Array();
tempArray = url.split('/');

var newLink = "../iphone/" + tempArray[3] + ".php";
var newLink2 = newLink.replace('.php.php','.php');

var iphoneLink = "<a href=\"" + newLink2 + "\">iphone version</a>";
	
//Rollover for Social Images
$(document).ready(function(){
	$("#delicious").hover(function(){
		$(this).attr({src: "/images/delicious_bw2.png"});},function(){$(this).attr({src: "/images/delicious2.png"});
	});
	$("#digg").hover(function(){
		$(this).attr({src: "/images/digg_bw2.png"});},function(){$(this).attr({src: "/images/digg2.png"});
	});
	$("#facebook").hover(function(){
		$(this).attr({src: "/images/facebook_bw2.png"});},function(){$(this).attr({src: "/images/facebook2.png"});
	});
	$("#foursquare").hover(function(){
		$(this).attr({src: "/images/foursquare_bw2.png"});},function(){$(this).attr({src: "/images/foursquare2.png"});
	});
	$("#last").hover(function(){
		$(this).attr({src: "/images/last_bw2.png"});},function(){$(this).attr({src: "/images/last2.png"});
	});
	$("#linkedin").hover(function(){
		$(this).attr({src: "/images/linkedin_bw2.png"});},function(){$(this).attr({src: "/images/linkedin2.png"});
	});
	$("#picasa").hover(function(){
		$(this).attr({src: "/images/picasa_bw2.png"});},function(){$(this).attr({src: "/images/picasa2.png"});
	});
	$("#reader").hover(function(){
		$(this).attr({src: "/images/reader_bw2.png"});},function(){$(this).attr({src: "/images/reader2.png"});
	});
	$("#twitter").hover(function(){
		$(this).attr({src: "/images/twitter_bw2.png"});},function(){$(this).attr({src: "/images/twitter2.png"});
	});
	$("#links-digg").hover(function(){
		$(this).attr({src: "/images/links_digg_over.jpg"});},function(){$(this).attr({src: "/images/links_digg.jpg"});
	});
	$("#links-twitter").hover(function(){
		$(this).attr({src: "/images/links_twitter_over.jpg"});},function(){$(this).attr({src: "/images/links_twitter.jpg"});
	});
	$("#links-facebook").hover(function(){
		$(this).attr({src: "/images/links_facebook_over.jpg"});},function(){$(this).attr({src: "/images/links_facebook.jpg"});
	});
	$("#links-random").hover(function(){
		$(this).attr({src: "/images/links_random_over.jpg"});},function(){$(this).attr({src: "/images/links_random.jpg"});
	});
	$("#links-nettuts").hover(function(){
		$(this).attr({src: "/images/links_nettuts_over.jpg"});},function(){$(this).attr({src: "/images/links_nettuts.jpg"});
	});
	$("#links-smashing").hover(function(){
		$(this).attr({src: "/images/links_smashing_over.jpg"});},function(){$(this).attr({src: "/images/links_smashing.jpg"});
	});
	$("#links-wtf").hover(function(){
		$(this).attr({src: "/images/links_wtf_over.jpg"});},function(){$(this).attr({src: "/images/links_wtf.jpg"});
	});
	$("#links-consumerist").hover(function(){
		$(this).attr({src: "/images/links_consumerist_over.jpg"});},function(){$(this).attr({src: "/images/links_consumerist.jpg"});
	});
	$("#links-jquery").hover(function(){
		$(this).attr({src: "/images/links_jquery_over.jpg"});},function(){$(this).attr({src: "/images/links_jquery.jpg"});
	});
	$("#links-last").hover(function(){
		$(this).attr({src: "/images/links_last_over.jpg"});},function(){$(this).attr({src: "/images/links_last.jpg"});
	});
	$("#links-delicious").hover(function(){
		$(this).attr({src: "/images/links_delicious_over.jpg"});},function(){$(this).attr({src: "/images/links_delicious.jpg"});
	});
});

//Rollover for Navigation
$(document).ready(function(){
	$(".navItem").hover(function(){
		$(this).css("background-image","url(../images/navButton_over.png)");
	}, function() {
		$(this).css("background-image","url(../images/navButton.png)");
	});
});

//Add target attribute to Twitter links
$(document).ready(function(){
	$('#twitterFeed a').attr('target','_blank');
});


// Some Stuff for the Contact Form
$(document).ready(function(){
	$('#name').focus();
	if(current.indexOf("contact/index.php?Subject=CalendarFAIL")!=-1) {
		$('#styled').attr({value: 'Calendar FAIL! Way to go.'});
	}
});

