/*------------------------------------------------------
Site-wide JavaScript 

version:	1.1
author:		joe ardeeser
email:		info@jordancrown.com
website:	http://www.jordancrown.com
------------------------------------------------------*/




/* Sophietta Functions
------------------------------------------------------*/
 
function Preloader( dirPath, arrImagePaths ) {
	this.dirPath = 'images/products/' + dirPath;
	this.arrImagePaths = arrImagePaths;
	this.arrImages = new Array();

	a = 0;
	for( var i in this.arrImagePaths ) {
		this.arrImages[a] = new Image(); 
		this.arrImages[a].src = this.dirPath + '/full_' + arrImagePaths[i] + '.jpg';
		a++;
	}

	this.getImageSource = function( index ) {
		return this.arrImages[index].src;
	};
}

function loadBigImage( path ) {
	$('#main_image img').attr('src', path);
}	




/* Generic Functions
------------------------------------------------------*/

// 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;
      }
   }
}

/* Get Vars 
------------------------------------------------------*/
function getQuerystring(key, default_)
{
  if (default_==null) default_="";
  key = key.replace(/[\[]/,"\\\[").replace(/[\]]/,"\\\]");
  var regex = new RegExp("[\\?&]"+key+"=([^&#]*)");
  var qs = regex.exec(window.location.href);
  if(qs == null)
    return default_;
  else
    return qs[1];
} 
