// Main JS File

/* Google Analytics */
var gaJsHost = (("https:" == document.location.protocol) ? "https://ssl." : "http://www.");
document.write(unescape("%3Cscript src='" + gaJsHost + "google-analytics.com/ga.js' type='text/javascript'%3E%3C/script%3E"));

$.fn.equalHeights = function(px) {
	$(this).each(function(){
		var currentTallest = 0;
		$(this).children().each(function(i){
			if ($(this).height() > currentTallest) { currentTallest = $(this).height(); }
		});
		if ($.browser.msie && $.browser.version == 6.0) { $(this).children().css({'height': currentTallest}); }
		$(this).children().css({'min-height': currentTallest}); 
	});
	return this;
};

$(window).bind("load", function() {
	/* Google Analytics Code */
	try {
		var pageTracker = _gat._getTracker("UA-10317754-1");
		pageTracker._trackPageview();
	} catch(err) {}
	
	/* Menu */
	//$("#menu>li:hover>ul").css({'display': 'none'});	//override css effect 	//deprecated, since .css on :hover doesn't work on firefox 3.5 and others
	$("head").append("<style type=\"text/css\">#menu>li:hover>ul { display: none; }</style>");	//override css effect
	
	//$("#menu>li>ul").css({'display': 'block'});	//override css effect
	
	//Add a new effect
	$("#menu>li").hoverIntent(function(){
		$(this).children("ul").slideDown("normal");
	},function(){
		$(this).children("ul").slideUp("normal");
	});

	/* External Links Behavoir */
	$("a[href^=\"http://\"]").attr("target","_blank");
	
	/* Images */	
	$("p.images img").css("float","none");
	$("p.images img").addClass("float-left");
	
	$("img.box").wrap("<div class=\"box\"></div>");
	$("img.box.float-left").parent().addClass("float-left");
	$("img.box.float-left").removeClass("float-left");
	$("img.box.float-right").parent().addClass("float-right");
	$("img.box.float-right").removeClass("float-right");
	$("img.box").removeClass("box");
	
	$(".box").each(function(){
		//Copy the title
		var title= $(this).children("img").attr("title");
		if(title) $(this).append("<p>"+title+"</p>");
		
		//Resize stuff
		var width=$(this).children("img").width();
		$(this).children("img").width("100%");
		$(this).width(width);
		
		//URL
		var url=$(this).children("img").attr("src");
		url=url.substring(0,url.lastIndexOf("/")+1)+"full-"+url.substring(url.lastIndexOf("/")+1);
		$(this).children("img").wrap("<a href=\""+url+"\"></a>");
		
		//Give title to a tag too
		$(this).children("a").attr("title",title)
	})
	
	$("p.images").equalHeights();
	
	$(".box a").lightBox({fixedNavigation:true});
	
	//Clear empty p tags
	$.fn.clearEmptyP = function(){
		$(this).each(function(){
			if($(this).parent().hasClass("images")!=true)	{
				$(this).parent().css("margin-bottom","0px");	//make sure the p doesn't have any margin-bottom
				$(this).parent().next().css("margin-top","0px");	//make sure the h after it is not affected by the + selector
			}
		});
		return this;
	}
	$("#content .float-left").clearEmptyP();
	$("#content .float-right").clearEmptyP();
	
	
});