/* 	BEGIN
	goSammy specific Javascript 
	written by: Sam Lu (http://samlu.ca || http://www.gosammy.com)
	Last Updated: February 2008
*/

var BrowserCheck = {
	init: function(){
		if($.browser.msie) {
			$("#msieflag").prepend("It's been detected that you are surfing onto my blog with Internet Explorer. You really ought to check out <a href='http://getfirefox.com' title='Mozilla Firefox' target='_blank'>Mozilla Firefox</a>. It's a much more robust and secure browser.<br />");
			BrowserCheck.displayIEFlag();
		}
	},
	displayIEFlag: function(){
		$("#msieflag").show();
	}
};

var currentView;

var Navigator = {
	init: function(){
		$("#containerBox").css({width:"990px", overflow:"hidden"})
		$("#wideBox").before('<ul><li id="btn-popular" class="tab"><a href="javascript:;">Popular</a></li><li id="btn-latest" class="tab"><a href="javascript:;">Latest</a></li><li id="btn-categories" class="tab"><a href="javascript:;">Categories</a></li></ul><br class="clear" />');
		$(".archiveTitle").remove();
		$("#btn-popular").click(function() {
			if(currentView != "popular") {
				$("#btn-popular").toggleClass("selectedView");
				Navigator.changeTabStyle();
			}
			Navigator.goToPopular();
			currentView = "popular";
		});
		
		$("#btn-latest").click(function() {
			if(currentView != "latest") {
				$("#btn-latest").toggleClass("selectedView");
				Navigator.changeTabStyle();
			}
			Navigator.goToLatest();
			currentView = "latest";
		});
		
		$("#btn-categories").click(function() {
			if(currentView != "categories") {
				$("#btn-categories").toggleClass("selectedView");
				Navigator.changeTabStyle();
			}
			Navigator.goToCategories();
			currentView = "categories";
		});
		
		$("#btn-popular").toggleClass("selectedView");
		currentView = "popular";
	},
	changeTabStyle: function(){
		if(currentView == "latest") {
			$("#btn-latest").toggleClass("selectedView");
		}
		else if(currentView == "categories") {
			$("#btn-categories").toggleClass("selectedView");
		}
		else if(currentView == "popular") {
			$("#btn-popular").toggleClass("selectedView");
		}
	},
	goToPopular: function(){
		$("#containerBox").animate({ 
        marginLeft: "0px"
      }, 500 );
	},
	goToLatest: function(){
		$("#containerBox").animate({
		marginLeft: "-285px"
	  }, 500 );
	},
	goToCategories: function(){
		$("#containerBox").animate({
		marginLeft: "-570px"	
	  }, 500 );
	}
};

var PortfolioLink = {
	init: function(){
		$("#portfoliohover").append('<img src="/wp-content/themes/gosammy3/images/portfoliohover.png" alt="Portfolio" width="74" height="74" class="noborder" />');
		var portfolioconfig = {
			sensitivity: 3,
			interval: 100,
			over: PortfolioLink.AnimateOver,
			timeout: 500,
			out: PortfolioLink.AnimateOut
		}
		$("#portfolioli").hoverIntent(portfolioconfig);
	},
	AnimateOver: function() {
		$("#portfoliohover").fadeIn("fast");
	},
	AnimateOut: function() {
		$("#portfoliohover").animate({
			marginTop: "-5px"
		}, 500).fadeOut("fast");
		$("#portfoliohover").animate({
			marginTop: "0"
		}, 0);
	}
}

var Content = {
	init: function(){
		var dates = [];
		var ahrefs = [];
		var atitles = [];
		var counter = 0;
		$(".overlay h3").each(function(){
			dates.push($(this).text());
		});
		$(".overlay h2 a").each(function(){
			ahrefs.push($(this).attr("href"));
			atitles.push($(this).attr("title"));
		});
		$(".overlay").each(function(){
			$(this).replaceWith('<a href="' + ahrefs[counter] + '" title="' + atitles[counter] + '" style="text-decoration:none;"><div class="overlay"><h3 class="jsdate">' + dates[counter] + '</h3><h2 class="jstitle">' + atitles[counter] + '</h2><h2 class="jstitle inset">' + atitles[counter] + '</h2></div></a>');
			counter++;
		});
	}
}

var HoverIntent = {
	init: function() {
		var config = {
			sensitivity: 3,
			interval: 50,
			over: HoverIntent.AnimateOver,
			timeout: 300,
			out: HoverIntent.AnimateOut
		}
		$(".image-wrapper").hoverIntent(config);
	},
	AnimateOver: function() {
		$(this).children().children(".overlay").animate({
			opacity: 1,
			paddingLeft: "5px"
		}, 500);
	},
	AnimateOut: function() {
		$(this).children().children(".overlay").animate({
			opacity: 0.8,
			paddingLeft: "0px"
		}, 500);
	}	
}

$(document).ready(function(){
	HoverIntent.init();
	BrowserCheck.init();
	Navigator.init();
	if(!$.browser.msie) {
		PortfolioLink.init();
		Content.init();
	}
});
