// Standard jQuery header
(function($) {

  var cache = [];
  
	// Arguments are image paths relative to the current page.
	$.preLoadImages = function() {
		var args_len = arguments.length;
		for (var i = args_len; i--;) {
		  var cacheImage = document.createElement('img');
		  cacheImage.src = arguments[i];
		  cache.push(cacheImage);
		}
	}


    $.fadeCanvasOut = function() {
		
		if ($.browser.msie) {
			//$("#canvas").css('filter', 'alpha(opacity=33)');
		} else {
			$("#canvas").fadeTo("slow", 0.33);	
		}
		
	}
	
	
    $.fadeCanvasIn = function() {
		
		if ($.browser.msie) {
			//$("#canvas").css('filter', 'alpha(opacity=100)');
		} else {
			$("#canvas").fadeTo("slow", 1);	
		}
		
	}
	
	// vertically center something in the viewport
	// thanks to Andreas Lagerkvist - http://andreaslagerkvist.com/jquery/center/#jquery-plugin-source
	$.fn.center = function (absolute) {
		
		return this.each(function () {
			var t = jQuery(this);
	
			t.css({
				position:    absolute ? 'absolute' : 'fixed', 
				left:        '50%', 
				top:        '50%', 
				zIndex:        '99'
			}).css({
				marginLeft:    '-' + (t.outerWidth() / 2) + 'px', 
				marginTop:    '-' + (t.outerHeight() / 2) + 'px'
			});
	
			if (absolute) {
				t.css({
					marginTop:    parseInt(t.css('marginTop'), 10) + jQuery(window).scrollTop(), 
					marginLeft:    parseInt(t.css('marginLeft'), 10) + jQuery(window).scrollLeft()
				});
			}
		});
	};
	
	$(document).ready(function() {  
		
		$(".closeThis").click( function (e) {
			e.stopPropagation();
			$(this).parent().hide();
		});
		
		if($("#foreground .layout .left-col").height() > $("#foreground .layout .main-col .mid").height()){
			the_height = $("#foreground .layout .left-col").height() + 30;
			$("#foreground .layout .main-col .mid").css("height",  the_height );
		}
		if($("#foreground .layout .right-col").height() > $("#foreground .layout .main-col .mid").height()){
			the_height = $("#foreground .layout .right-col").height() + 30;
			$("#foreground .layout .main-col .mid").css("height",  the_height );
		}
		
		$("#tweets .widget-title-box").click(function(){	
			$("#lastfm .widget-text-box").hide(1000);
			$("#lastfm .widget-title-box .widget-expand").removeClass('widget-expand widget-collapse').addClass('widget-expand');
		});
		$("#lastfm .widget-title-box").click(function(){	
			$("#tweets .widget-text-box").hide(1000);
			$("#tweets .widget-title-box .widget-expand").removeClass('widget-expand widget-collapse').addClass('widget-expand');
		});
		
		// toggles tweet and lastfm widgets and flips down/up arrow
		$(".widget-text-box").hide();
		var ztop = 210;
		$(".widget-title-box").click(function(){
			ztop=ztop+1;
			$(this).next(".widget-text-box").css("z-index", ztop);
			$(this).next(".widget-text-box").slideToggle(600);			
			$(this).find(".widget-expand").toggleClass('widget-collapse');
		});
		
		// toggles shop affiliate icons over products
		$(".shop-item").mouseover(function(){
			$(this).find(".shop-item-top").addClass('show-item');
		});
		$(".shop-item").mouseout(function(){
			$(this).find(".shop-item-top").removeClass('show-item');
		});
		
		// toggles text boxes on homepage and flips down/up arrow
		$(".home-text-box").hide();
		$(".home-title-box").click(function(){
			$(this).next(".home-text-box").slideToggle(600);
			$(this).find(".home-expand").toggleClass('home-collapse');
		});
		
		// toggles wide text boxes on other pages and flips down/up arrow
		$(".pages-text-box").hide();
		$(".pages-title-box").click(function(){
			$(this).next(".pages-text-box").slideToggle(600);
			$(this).find(".pages-expand").toggleClass('pages-collapse');
		});
	
		//IE Fix, set background height to 100% - IE as usual doesnt do what it should
		if ($.browser.msie) { $("#background").height($("#foreground").height()); }
		//console.log($("#background").height());
		
		$("#latest-activity a.close").click(function() { 
			
			wrapper = $(this).parents("#latest-activity")[0];
			$(wrapper).remove();
			
		});
		
		
	});
 
// Standard jQuery footer
})(jQuery);