/*------------------------------------------------------
Site-wide JavaScript 

version:	1.1
author:		joe ardeeser
email:		info@jordancrown.com
website:	http://www.jordancrown.com
------------------------------------------------------*/



/* Load when the document is ready
------------------------------------------------------*/
$(document).ready(

	function() { 
  	// Add the additional structure to the box divs
		$("div.box").wrap(
			'<div class="box_outer">' + 
			'<div class="bd">' + 
			'<div class="c">' + 
			'</div>' + 
			'</div>' + 
			'</div>' 
		);

		$('div.box_outer').prepend(
			'<div class="hd">' +
			'<div class="c"></div>' +
			'</div>'
		).append(
			'<div class="ft">' +
			'<div class="c"></div>' +
			'</div>'
		);

		$('div.box_outer').each( function(i, o) {

			// Copy the classes and id to the top parent
			var classes = $(o).find('.box:first').attr('class');
			$(o).addClass(classes);

			var id = $(o).find('.box:first').attr('id');
			if( id != '' ) {
				$(o).attr('id', id);
			}

			// Override the classes from the inner box and remove the id
			$(o).find('.box:first').attr('class', 's getLayout').removeAttr('id');
		});

		// Prep the buttons
		init_buttons();


		/* Auto fill copyright year 
		------------------------------------------------------*/
		var todays_date = new Date();
		current_year = todays_date.getFullYear();

		$('#ft').ready( function() {

				// Give it some time to load
				window.setTimeout( function() {
					$('.current_year').html( current_year ); 
				}, 100 );
		});
	}
);

// Just for anchors that aren't using the href
function v() {
	// Nothing
}



/* Buttons 
------------------------------------------------------*/
function init_buttons() {

	// Add the additional structure to the buttons 
	$('.button:not(:has("span"))').each( function( i, o ) {
			$(o).wrapInner( '<span class="wrap"><span></span></span>' );

			// Make the buttons go back to their normal state (IE)
			$(o).click( function() {
				$(this).blur();
			});
	});
}



/* Thinkbox Windows
------------------------------------------------------*/
// Closes the open thick box window
function tb_close_window( delay ) {
	if( delay > 0 ) {
		setTimeout( "tb_remove()", delay );
	} else {
		tb_remove();
	}
}



/* Bubbling
------------------------------------------------------*/
function cancelBubbling(e)
{
    if (!e) var e = window.event;
    e.cancelBubble = true;
    if (e.stopPropagation) e.stopPropagation();
}



/* Strings 
------------------------------------------------------*/
String.prototype.trim = function() {
	return this.replace(/^\s+|\s+$/g,"");
}



/* Radio Buttons 
------------------------------------------------------*/
function getSelectedRadio(buttonGroup) {
   // returns the array number of the selected radio button or -1 if no button is selected
   if (buttonGroup[0]) { // if the button group is an array (one button is not an array)
      for (var i=0; i<buttonGroup.length; i++) {
         if (buttonGroup[i].checked) {
            return i
         }
      }
   } else {
      if (buttonGroup.checked) { return 0; } // if the one button is checked, return zero
   }
   // if we get to this point, no radio button is selected
   return -1;
}

function getSelectedRadioValue(buttonGroup) {
   // returns the value of the selected radio button or "" if no button is selected
   var i = getSelectedRadio(buttonGroup);
   if (i == -1) {
      return "";
   } else {
      if (buttonGroup[i]) { // Make sure the button group is an array (not just one button)
         return buttonGroup[i].value;
      } else { // The button group is just the one button, and it is checked
         return buttonGroup.value;
      }
   }
}
