// XHTML STRICT method of making a popup window.
// Link formation: <a href="http://www.yourlink.com" onclick="popUp(this.href,'console',400,640);return false;" rel="external">Link Text</a>
// Note: this function requires the externalLinks function above. Pass the appropriate argument (console, fixed, or elastic) for different window types.
function popUp(strURL, strType, strHeight, strWidth) {
	var strOptions="";
	if (strType=="console") {
	    strOptions = "scrollbars,resizable,height=" + strHeight + ",width=" + strWidth;
	}
	if (strType=="fixed") {
	    strOptions = "status,height=" + strHeight + ",width=" + strWidth;
	}
	if (strType=="elastic") {
	    strOptions = "toolbar,menubar,scrollbars,resizable,location,height=" + strHeight + ",width=" + strWidth;
	}
	var new_window = window.open(strURL, 'newWin', strOptions);
    new_window.focus();
}


// Allows for fadeToggle
jQuery.fn.fadeToggle = function(speed, easing, callback) {
   return this.animate({opacity: 'toggle'}, speed, easing, callback);
};

$(document).ready(function(){
	// PNG fix
	$('img[@src$=.png], img.logo').ifixpng();
	
	// Remove border from checkboxes
	$('input:checkbox').css({ border: "none" });
	
	// XHTML STRICT method of targeting blank window using rel tag
	$('a[@rel=external]').attr({'target': '_blank'});
	
	// Size side-by-side boxes if present
	/*if ( ($.browser.name) != "ie" ) { // if browser is IE skip the sizing
		if ( $("#b1").length > 0 && $("#b2").length > 0 ) { // check for the existence of boxes
			var box1 = $('#b1').height();
			var box2 = $('#b2').height();
			if ( box1 > box2 ) {
				$('#b1').css({ minHeight: box1 });
				$('#b2').css({ minHeight: box1 });
			} else {
				$('#b1').css({ minHeight: box2 });
				$('#b2').css({ minHeight: box2 });
			}
		}
	}*/
	
	// Size side-by-side boxes if present
	if ( ($.browser.name) != "ie6" ) { // if browser is IE skip the sizing
		var maxHeight = 0;
    	$('div.box_content ul').each(function() {
        	var height = $(this).height();
			if (height >= maxHeight) {
            	maxHeight = height;
        	}
    	});
		$('div.box_content').css({ minHeight: maxHeight + 36 });
	}
	
	// Sets hover class to function in IE6
	$('#nav ul.tabs li').hover(function() {
		$(this).addClass('current');
	}, function() {
		$(this).removeClass('current');
	});
	
	$('#nav ul.tabs li').hover(
		function() {
			$(this).children('div').fadeIn("fast");
		}, 
		function() {
			$(this).children('div').hide();
	});
	
	$('#tab_container').tabs({ fxFade: true, fxSpeed: 'fast' });
	
	$(".lightbox").lightbox();

    $('a[@rel=popup]').click(function(e) {
        // Keep the link from being followed
        e.preventDefault();
        // Defaults
        var height = 650;
        var width = 700;

        var $this = $(this);
        var classes = $this.attr('class').split(/\s+/);
        for (var i = 0; i < classes.length; i++) {
            if (/\d+x\d+/.test(classes[i])) {
                var match = classes[i].match(/\d+/g);
                width = match[0];
                height = match[1];
            }
        }
        popUp($this.attr('href'), "elastic", height, width);
    });
});
