(function($) {
    /**
     * Register jQuery plugin functions here
     */
    $.fn.equalHeights = function(minHeight, maxHeight) {
	tallest = (minHeight) ? minHeight : 0;
	this.each(function() {
	    if($(this).height() > tallest) {
		tallest = $(this).height();
	    }
	});
	if((maxHeight) && tallest > maxHeight) tallest = maxHeight;
	return this.each(function() {
	    $(this).height(tallest);
	});
    }
})(jQuery);

var width = null;
function gridify() {
    if(width == null) {
	width = 1024;
    }
    var resolutions = [
    1920,
    1280,
    1680,
    1600,
    1440,
    1152,
    1024
    ]
                
    function compareResolution(a, b) {
	var result = 0;
	if (a > b) {
	    result = -1;
	}
	if (a < b) {
	    result = 1;
	}
	return result;
    }
                
    resolutions.sort(compareResolution);

    try {
	if(document.body.clientWidth >= 1024) {
	    width = document.body.clientWidth;
	}
    } finally {
	if(width == null) {
	    /*
	     * @todo subtract appropriate amount based on common viewing
	     * areas per browser & version
	     */
	    if(screen.width >= 1024) {
		width = screen.width -100;
	    } else {
		width = 1024;
	    }
	}
    }
    for(idx = 0; idx < resolutions.length; idx++) {
	if(compareResolution(resolutions[idx], width) != -1 || idx == resolutions.length - 1) {
	    $.stylesheetSwitch("xBlocks" + resolutions[idx]);
	    break;
	}
    }
}
            

$(function() {
    $.stylesheetInit();
});
function showPanel(panel) {
    $(panel).siblings("div").stop().fadeOut('fast',function(){
	$(this).hide();
	$(this).parent().find(panel).fadeIn(200);
    });
}
function equalHeight(group) {
    tallest = 0;
    group.each(function() {
	thisHeight = $(this).height();
	if(thisHeight > tallest) {
	    tallest = thisHeight;
	}
    });
    group.height(tallest);
}


//i.e. issue, use window.load instead
$(document).ready(function() {
    gridify();

    
    /*
     * Info hover for inputs with a title attribute. 
     */
//    $(".tooltip:parent").fadeTo("fast",1.0,function(){
//	alert("Boo");
//	$(this).parent("div").find("input[type=text").tooltip({
//	    api:true,
//	    position:"center right",
//	    relative:true,
//	    opacity:0.8,
//	    effect:"slide",
//	    bounce:true,
//	    slideFade:true,
//	    slideInSpeed:350
//	});
//    });
});
function refresh() {
    $(".roundableSmall").liquidCanvas(
	"[shadow{width:2;color:rgba(25,25,25,0.8);shift:2;}] => roundedRect{radius:5}"
	);

    $(".roundableBig").liquidCanvas(
	"[fill{color:#fff}] => roundedRect{radius:30}"
	);
    //	    gradient{from:rgba(255, 255, 255, 1.0); to:rgba(50,50,55,0.9);}
/*    $(".titleBar").liquidCanvas(
	"[fill{color:#A5A5A5}] => top_roundedRect{radius:15}"
	);
   $(".footerBar").liquidCanvas(
	"[fill{color:#ffc82f}] => bottom_roundedRect{radius:20}"
	);
*/    $(".rightRound").liquidCanvas(
	"[fill{color:#dddddd}] => right_roundedRect{radius:20}"
	);
    $(".leftRound").liquidCanvas(
	"[fill{color:#dddddd}] => left_roundedRect{radius:20}"
	);
/*	$(".sideMenuItem:hover").liquidCanvas(
	"[fill{color:#F00}] => left_roundedRect{radius:10}"
	);
*/
    $(".roundable").liquidCanvas(
	//    gradient{from:rgba(255, 255, 255, 1.0); to:rgba(50,50,55,0.9);}shadow{width:2;color:rgba(25,25,25,0.8);shift:2;}
	"[ fill{color:#dddddd} ]=> roundedRect{radius:15}"
	);
/*    $(".input").liquidCanvas(
	"[shadow{width:1;color:rgba(80,80,80,0.8);shift:-1;} fill{color:#eee}] => roundedRect{radius:5}"
	);
*/
	
    //    gradient{from:rgba(255, 255, 255, 1.0); to:rgba(50,50,55,0.9);} shadow{width:1;color:rgba(80,80,80,0.8);shift:1;} border{color:rgba(20,20,20,0.7);width:1;}




    /* draws outline of blocks */
    $(".debug > .x1").liquidCanvas(
	"border{color:rgba(255,0,0,0.5); width:1;} => rect"
	);

    
}
$(window).load(function() {
    refresh();
	
	
	
/*  Do Not Use for sideMenu Items.  SUCKS!  




$("#sideMenu a").liquidCanvas(
	//    gradient{from:rgba(255, 255, 255, 1.0); to:rgba(50,50,55,0.9);}
	"[gradient{from:rgba(255, 255, 255, 0.0);  to:rgba(255, 255, 255, 0.0);} ]=> left_roundedRect{radius:15}"
	
	);

				var sideDefault = "[fill{color:#dddddd}] => left_roundedRect{radius:10}";
				var sideHover = "[linearGradient{colors:[rgb(0,0,0), rgb(255,255,255)]; stops:[0.0, 0.11];} ] => left_roundedRect{radius:15}";
				var sideCurrent = "[linearGradient{colors:[rgb(4,104,192), rgb(102,165,219), rgb(0,47,121)]; stops:[0.2, 0.5 , 0.9];} ] => left_roundedRect{radius:15}";

				$(".sideMenuItem").liquidCanvas(sideDefault);
				$(".sideMenuItem").hover(function() {
					$(this).liquidCanvas(sideHover);
				},function() {
					$(this).liquidCanvas(sideDefault);
				});
*/		
});

$(window).resize(function() {
    gridify();
});


    /**
     * May need a better name for this function. It actually hides all sibling
     * .panel elements as well as showing a panel.
     */

