
//
// prototype-like functions
//

function $(myid) {
  if (document.getElementById(myid)) {
	  return document.getElementById(myid);
	}
	return false;
}

function changeClass(myid, myClass) {
  if ($(myid)) {
	  $(myid).className = myClass;
	}
}

// check form input, return false if value is in arguments
// checkInputValue(inputObj, value1, value2, ...)
function checkInputValue() {
  var args = checkInputValue.arguments;
  var inputObj = args[0];
  for (var j = 1; j < args.length; j++) {
    if (args[j] == inputObj.value) return false;
  }
  return true;
}

// check form input, clear default value from input
// checkInputValue(inputObj, defaultValue1, defaultValue2, ...)
function clearDefaultValue() {
  var args = clearDefaultValue.arguments;
  var inputObj = args[0];
  for (var j = 1; j < args.length; j++) {
    if (args[j] == inputObj.value) inputObj.value = '';
  }
}

var displayingMore = false;

function displayMore() {
  displayingMore = (displayingMore) ? false : true;
  $('more').innerHTML = (displayingMore) ? 'back' : 'more';
	try {
	  $('more').blur(); // remove the grey focus border
	} catch (e) {}
	if (displayingMore) {
	  $('textContentTeaser').style.display='none';
		$('textContent').style.display='block';
	} else {
	  $('textContentTeaser').style.display='block';
		$('textContent').style.display='none';
	}
}

//
// open video in a new window
//

function popPlayVideoFromPlayer(artworkId) {
  try {
	  if (document.qtPlayWindow) document.qtPlayWindow.Stop();
	} catch(e) {}
  popPlayVideo(artworkId);
}

function popPlayVideo(artworkId) {
  window.open("playVideo.php?artwork="+artworkId, "playvideo","menubar=no,toolbar=no,resizable=yes,status=no,scrollbars=no,location=no,width=340,height=210");
}

//
// document.write audio embed.  This is to support IE7's object/embed mess.
// open audio in a new window
//

function writeAudioEmbed(mySrc, autoplay) {
  var isAutoPlay = 'false';
  if (autoplay == '1') isAutoPlay = 'true';
  document.write('<object id="nonStreamAudio" class="objectAudio" width="330" height="42">');
  document.write('<param name="src" value="'+mySrc+'">');
  document.write('<param name="autoplay" value="'+isAutoPlay+'">');
  document.write('<param name="controller" value="true">');
  document.write('<param name="bgcolor" value="#EEEEEE">');
  document.write('<embed name="nonStreamAudio" src="'+mySrc+'" class="objectAudio" autostart="'+isAutoPlay+'" loop="false" width="330" height="42" controller="true" bgcolor="#EEEEEE"></embed>');
  document.write('</object>');
}

function popPlayAudio(artworkId) {
 try {
   document.nonStreamAudio.Stop();
 }
 catch (e) {
 	 try {
		 document.getElementById('nonStreamAudio').Stop();
	 }
	 catch (e) {}
 }
  window.open("playAudio.php?artwork="+artworkId, "playaudio","menubar=no,toolbar=no,resizable=yes,status=no,scrollbars=no,location=no,width=340,height=160");
}

//
// media detection
// TODO: this will grow to include Flash when we move to that format for streaming content
//

// detect quicktime

function getQuickTime() {
	
  var plugInFound = getPlugIn("QuickTime");
	return plugInFound;
	
}

function getPlugIn(plugIn) {

  var plugInFound = false;

  plugInsCollection = navigator.plugins
	
	if ((navigator.userAgent.indexOf('MSIE') != -1) && (navigator.userAgent.indexOf('Win') != -1) ) {

	  return true; // would rather have broken link than activeX dialogue box ... (IE 7 support)
	
		try {
		
			testObject = new ActiveXObject("QuickTimeCheckObject.QuickTimeCheck.1");

			activeXFound = testObject.IsQuickTimeAvailable(0);
			if (activeXFound) plugInFound = true;
			
		} catch(e) {}
	
	} else {
	
  	for (i=0;i<plugInsCollection.length;i++) {
  
      plugInDescription = " " + plugInsCollection[i].description
  		plugInName = " " + plugInsCollection[i].name
  		
  		if (plugInDescription.indexOf(" " + plugIn) != -1 || plugInName.indexOf(" " + plugIn) != -1) plugInFound = true;
  			
  	}
		
	}
		
  return plugInFound;

}