// cleans broken links and spacer gifs
// put a class of keep on your links to keep the text but remove the clickyness
$(document).ready(function(){
	var KEEP_CLASS = "keep";
	$('a').each(function(index) {
		var link = $(this);
		var l = link.attr('href');  
		// if link hrefs are empty hide them
		// or remove the a tag if class is "keep"
		
		if(!l && !$(this).attr('name')){
			if(link.hasClass("keep")){
				link.replaceWith("" + link.html() + "");
			}else{
				$(this).hide();
			}
		}
	});

	//hide spacer gifs from cms
	$('img').each(function(index) {
		var thisItemsClass = $(this).attr('class');
		if (thisItemsClass != KEEP_CLASS) {
			var s = $(this).attr('src');
			if(s.indexOf('spacer.gif') != -1) $(this).remove();
		}
	});
	
	// put a class of ifExists on items with the attribute you are checking for in the rel attribute
	$('.ifExists').each(function() {
		if ((!$(this).attr('rel')) || ($(this).attr('rel') == '/echotools/images/spacer.gif')) {
			$(this).remove();
		}	
	});
	
});

function log(d){
	try{
		console.log(d);
	}catch(e){
		
	}
}

/*
* 	FUNCTION:		stripeMyStuff
* 	DESCRIPTION: 	Will zebra stripe a given set of elements
* 	IN: 			containingID - string of the id for the item containing items to stripe (Ex. '#faqList')
					elementInID - string containing the element to stipe (Ex. 'div')
					stripeClassName - string containing the CSS class name defining the striped elements
* 	OUT: 			n/a
*/
function stripeMyStuff (containingID, elementInID, stripeClassName) {
	var containingID = '#eventDates';
	var elementInID = 'tr';
	var stripeClassName = 'alt';
	$(containingID).find(elementInID + ':odd').addClass(stripeClassName);
}

 function ifExists(val, htmlOut, other)  
{
	if (typeof other=='undefined') other = "";

	if (val.length && val != "false" && val !="/echotools/images/spacer.gif"){
	document.write (htmlOut);
	}else{
		if(other.length)
		{
			document.write (other);
		}
	}
}

/* 
* 	FUNCTION: 		toggleMe
* 	DESCRIPTION: 	Will toggle a given item (showHideItem) on and off.
*					The item that you are turning on and off should default to being hiden with CSS
*	IN:				triggerToggle - the string of the id for the item containing items to turn on and off (Ex. '.tourDates')
*		 			showHideItem - the element within the  container that will turn on and off (Ex. '.tourDateDetails')
*	OUT: 			n/a
*/
function toggleMe (triggerToggle, showHideItem) {
	$(triggerToggle).click(function() {
		$(this).children(showHideItem).toggle();
	});
}

function spawnWindow(url,name,w,h){
	if(w == undefined) w = 320;
	if(h == undefined) h = 240;
	if(name == undefined) name = "popWindow";
	var newWindow = window.open(url,name,"toolbar=0,scrollbars=1,resizable=1,width="+w+",height="+h+"\"");		
 }
 function spawnJukebox(){
	var newWindow = window.open("content/jukebox.php",'jb',"toolbar=0,scrollbars=1,resizable=1,width=350,height=250");		
 }

