if(typeof(EVERYZING) == 'undefined') { EVERYZING = {}; }

// Collect full transcript text
var fullTranscriptText = "";

// actual clipping function
EVERYZING.clipText = function(obj,maxLen) {
	fullTranscriptText = obj.innerHTML;
	jQuery(obj).truncate(maxLen, {
        chars: / /,
        leave: false,
        trail: [true, "...\"", ""]
    });
}

EVERYZING.truncate_to = function(target, maxLen){
    maxLen = parseInt(maxLen);
    if (isNaN(maxLen) || maxLen <= 0){ return; }    
    var target = jQuery(target);    
    target.each(function(){
		EVERYZING.clipText(this,maxLen);
    });
};

// opens faq pop
EVERYZING.openFaq = function(url){
	var pWidth = 520; // width of popup
	var pHeight = 520; // width of popup
	var leftPos = screen.width - pWidth - 100; // 100px from right of screen
	var topPos = (screen.height - pHeight)/2; // vertically centered
	var win = window.open(url, "Transcript", "left=" + leftPos + ",top=" + topPos + ",width=" + pWidth + ",height=" + pHeight + ",resizable,scrollbars");
}

//copy text to clipboard
EVERYZING.copyToClipboard = function(inElement, path) {
    var flashcopier = 'flashcopier';
    if(!document.getElementById(flashcopier)) {
      var divholder = document.createElement('div');
      divholder.id = flashcopier;
      document.body.appendChild(divholder);
    }
    document.getElementById(flashcopier).innerHTML = '';
    var divinfo = '<embed src="' + path + 'clipboard.swf" FlashVars="clipboard='+encodeURIComponent(inElement.value)+'" width="0" height="0" type="application/x-shockwave-flash"></embed>';
    document.getElementById(flashcopier).innerHTML = divinfo;
	inElement.className = "ez-copied";
}

// display or clip full transcript on media lander
EVERYZING.displayTranscript = function(tObj, tBtn, tClipLength) {
	tObj = document.getElementById(tObj);
	tBtn = document.getElementById(tBtn);
	if (tBtn.innerHTML == "+") { // expand
		//tObj.innerHTML = fullTranscriptText;
		tObj.className = "ez-full";
		tBtn.innerHTML = "-";
	} else { // clip
		//EVERYZING.clipText(tObj, tClipLength);
		tObj.className = "ez-clipped";
		tBtn.innerHTML = "+";
	}
}

//blank out the searchbox value
EVERYZING.emptySearchBox = function() {
	var sObj = document.getElementById("ezsearch-string")
	sObj.value = "";
	sObj.className = "ezsearch-string ezsearch-string-active";
}

// validate search
EVERYZING.validateSearch = function() {
	var bool = false;
	var str = document.getElementById("ezsearch-string");
	str.value = jQuery.trim(str.value);
	if (str.value.length > 0) {
		bool = true;
	}
	return bool;
}

// these overwrite foundation functions to use local images for media thumbs
EVERYZING.snippetVideoImgError = function(source){
    source.src = EVERYZING.themeUrl + "/images/ez_video_icon.jpg";
    source.onerror = null;	
    return true;
}
EVERYZING.snippetAudioImgError = function(source){
    source.src = EVERYZING.themeUrl + "/images/ez_audio_icon.jpg";
    source.onerror = null;	
    return true;
}

// resize logo images in snippets to maintain proper dimensions
EVERYZING.resizeLogos = function() {
	var arrImg = document.getElementsByTagName("img");
	for (var i = 0; i < arrImg.length; i++) {
		if (arrImg[i].id.indexOf("thumb_") != -1 &&	
		arrImg[i].src.indexOf("tbologo80x60.jpg") != -1) {
			arrImg[i].className = "ez-logoThumb";
		}
	}
}

// write out today's date
EVERYZING.todaysDate = function() {
	var d = new Date;
	var arrMo = new Array("January", "February", "March", "April", "May", "June", "July", "August", "September", "October", "November", "December");
	document.write(arrMo[d.getMonth()] + " " + d.getDate() + ", " + d.getFullYear());
}
