/*
 * jQuery custom scripts for CNX
 * http://www.cnxcorp.com/
 *
 * Dual licensed under the MIT and GPL licenses.
 * http://docs.jquery.com/License
 *
 * Date: 2010-11-05 (Fri, 5 November 2010)
 * Revision: 2
 */





/* Custom functions
------------------------------------------------- */
Array.prototype.max = function() {return Math.max.apply(Math, this);};
Array.prototype.min = function(){return Math.min.apply(Math, this);};

function maxHeight() {
	var heights = new Array();
	$(".twocolumn .main, .twocolumn .sidebar").each(function(i) {
		heights[i] = $(this).height();
	});
	return heights.max();
}

jQuery.fn.selectRange = function(start, end) {
	return this.each(function() {
		if(this.setSelectionRange) {
			this.focus();
			this.setSelectionRange(start, end);
		}
		else if(this.createTextRange) {
			var range = this.createTextRange();
			range.collapse(true);
			range.moveEnd("character", end);
			range.moveStart("character", start);
			range.select();
		}
	});
};

jQuery.fn.autoTab = function(event, len, next_field) {
	var phone_field_length = 0;
	if(event == "down") {
		phone_field_length = this.val().length;
	}
	else if(event == "up") {
		if(this.val().length != phone_field_length) {
			phone_field_length = this.val().length;
			if(phone_field_length == len) {
				next_field.focus();
			}
		}
	}
};
/* -------------------------------------------------
                             end custom functions */





/* UI Candy
------------------------------------------------- */
$(document).ready(function(){
	
	/////////////////////
	// rounded corners //
	/////////////////////
	if($.browser.msie) {
		$("#home div.box").prepend('<div class="corner" id="bl"></div><div class="corner" id="br"></div><div class="corner" id="tl"></div><div class="corner" id="tr"></div>');
	}
	
	///////////////////////
	// add class for IE6 //
	///////////////////////
	$(":last-child").addClass("last-child");
	
	////////////////////
	// external links //
	////////////////////
	$('a[rel="external"]').attr("target","_blank");
	
	if($.fancybox) {
		// screenshots
		$("a[rel=screenshots]").fancybox({
			"overlayColor"		: "#333",
			"overlayOpacity"	: .8,
			"transitionIn"		: "fade",
			"transitionOut"		: "fade",
			"titlePosition" 	: "inside",
			"titleFormat"       : function(title, currentArray, currentIndex, currentOpts) {
				return '<strong>' + title + "</strong><br />Image " + (currentIndex + 1) + " of " + currentArray.length;
			}
		});
	}
});
/* -------------------------------------------------
                                     end UI Candy */







