$(document).ready(addHoverHandlers);
$(document).ready(xpand);

function xpand() {
    $(".module").each(function() { // find specific elements
 			var _startHeight = $(this).height(); // store current height
			var showmore = (_startHeight>119)?'<div class="ceexpand more">See more</div>':'<div class="ceexpand">&nbsp;</div>';
        //var _startHeight = parseInt($(this).css("height")); // store current height
        $(this).css("height", "105px")  // set height to 105px
            .wrap("<div class=\"wrap hide\"></div>") // add a div to group new elements
            .parents("div.wrap") // Select previously added div
            // add new child for clickable area
            .append(showmore)
            .find("div.ceexpand") // select new child
            .hover( // add a hover class
                function() { $(this).toggleClass("cehover") },
                function() { $(this).toggleClass("cehover") }
            )
            .toggle( // toggle the click action of the div
            // Position Closed -> Open It
            //alert(_startHeight);
            function () { 
                // swap the class and change the HTML
                $(this).toggleClass("cecollapse").html("Collapse") 
                // select the pre and animate it open
                .siblings("div").animate({height: _startHeight});
            },
            // Position Open -> Close It
            function () { 
                // swap the class and change the html
                $(this).toggleClass("cecollapse").html("See more")
                // select the pre and animate it closed
                .siblings("div").animate({height: 105}); 
            }
        );
    });
		$("#bottom_cols .two_col .wrap:eq(0)").show('on');
}
function addHoverHandlers() {
    $("#content_banner li a").mouseover(swap);
}
function swap(){
	// Image
    $("#content_banner").find("img.show").show('off');
    $("#content_banner").find("img:eq("+ digit($(this).attr('id'))+")").show('on');
    // Module
    $("#bottom_cols .two_col .show").show('off');
    $("#bottom_cols .two_col .wrap:eq("+digit($(this).attr('id'))+")").show('on');
}
function digit(string){
	return string.replace(/^.*?([0-9]+)$/,"$1");
}
$.fn.show = function(mode) {
    var mode = mode || 'off'; // if mode is undefined, use 'off' as default
    this.each(function() {
        switch(mode) {
        case 'on':
            $(this).removeClass("hide");
            $(this).addClass("show");
            break;
        case 'off':
            $(this).removeClass("show");
            $(this).addClass("hide");
            break;
        }
    });
};	