matchColumns=function(){
     var divs,contDivs,maxHeight,divHeight,d;
     // get all <div> elements in the document
     divs=document.getElementsByTagName('div');
     contDivs=[];
     // initialize maximum height value
     maxHeight=0;
     // iterate over all <div> elements in the document
     for(var i=0;i<divs.length;i++){
          // make collection with <div> elements with class attribute 'border'
          if(/\bborder\b/.test(divs[i].className)){
                d=divs[i];
                contDivs[contDivs.length]=d;
                // determine height for <div> element
                if(d.offsetHeight){
                     divHeight=d.offsetHeight;                     
                }
                else if(d.style.pixelHeight){
                     divHeight=d.style.pixelHeight;                    
                }
                // calculate maximum height
                maxHeight=Math.max(maxHeight,divHeight);
          }
     }
     // assign maximum height value to all of container <div> elements
     for(var i=0;i<contDivs.length;i++){
          contDivs[i].style.height=maxHeight+300 + "px";
     }
}

function switchVideo(vidID) {
	var aj = new Ajax.Request("/actions/switch_video.php",{method: 'post',parameters: "id=" + vidID,
						onSuccess: function(response) {
							$('featurevideo').innerHTML = response.responseText;
							$$('.current').each(function(elem){ elem.removeClassName('current')});
							$('fvid_'+vidID).addClassName('current');
						}
					});
	return false;
}

function switchVideoB(vidID) {
	var aj = new Ajax.Request("/actions/switch_video_new.php",{method: 'post',parameters: "id=" + vidID,
						onSuccess: function(response) {
							var fields = response.responseText.split("}|{");
							$('featurevideo').innerHTML = fields[0];
							$$('.current').each(function(elem){ elem.removeClassName('current')});
							$('fvid_'+vidID).addClassName('current');
							
							$('ad_lb').update(fields[1]);
							$('ad_sq1').update(fields[2]);
							$('ad_sq2').update(fields[3]);
							//$$('.contentad').each(function(elem){ elem.update(fields[4]); });
							$('ad_c1').update(fields[4]);
							$('ad_c2').update(fields[5]);
							$('ad_c3').update(fields[6]);
							$('ad_c4').update(fields[7]);
							$('ad_c5').update(fields[8]);
							$('ad_c6').update(fields[9]);
						}
					});
	return false;
}

 /*-----------------------------------------------------------
    Toggles element's display value
    Input: any number of element id's
    Output: none 
    ---------------------------------------------------------*/
	function toggleDisp() {
	    for (var i=0;i<arguments.length;i++){
		var d = $(arguments[i]);
		if (d.style.display == 'none')
		    d.style.display = 'block';
		else
		    d.style.display = 'none';
	    }
	}
	/*-----------------------------------------------------------
	    Toggles tabs - Closes any open tabs, and then opens current tab
	    Input:     1.The number of the current tab
			    2.The number of tabs
			    3.(optional)The number of the tab to leave open
			    4.(optional)Pass in true or false whether or not to animate the open/close of the tabs
	    Output: none 
	    ---------------------------------------------------------*/
	function toggleTab(num,numelems,opennum,animate) {
	    if ($('tabContent'+num).style.display == 'none'){
		for (var i=1;i<=numelems;i++){
		    if ((opennum == null) || (opennum != i)){
			var temph = 'tabHeader'+i;
			var h = $(temph);
			if (!h){
			    var h = $('tabHeaderActive');
			    h.id = temph;
			}
			var tempc = 'tabContent'+i;
			var c = $(tempc);
			if(c.style.display != 'none'){
			    if (animate || typeof animate == 'undefined')
				Effect.toggle(tempc,'blind',{duration:0.5, queue:{scope:'menus', limit: 3}});
			    else 
				toggleDisp(tempc);
			
			    //Element.toggle(tempc);
			}
		    }
		}
		var h = $('tabHeader'+num);
		if (h)
		    h.id = 'tabHeaderActive';
		h.blur();
		var c = $('tabContent'+num);
		c.style.marginTop = '2px';
		
		if (animate || typeof animate == 'undefined'){
		    Effect.toggle('tabContent'+num,'blind',{duration:0.5, queue:{scope:'menus', position:'end', limit: 3}});
		}else{
		    toggleDisp('tabContent'+num);
		} 
		//Element.toggle('tabContent'+num);
	    }
	}
	
// variables
	imageDir = '/images/social/'
	theURL = encodeURIComponent(document.location.href)
	theTitle = encodeURIComponent(document.title)
	
	// preload
	var myImages = new Array (	);
	var myPreload = new Array ();
	for (var i = 0; i < myImages.length; i++ )
	{
		myPreload[ i ]= new Image();
		myPreload[ i ].src = myImages[ i ];
	}
	
	// rollovers
	function imageOver(theImage,imageName) {
		theImage.src = imageDir + imageName
	}
	function imageOut(theImage,imageName) {
		theImage.src = imageDir + "bw/" + imageName
	}
	
	// bookmark
	 function CreateBookmarkLink() {
		
			if (window.sidebar) { // Mozilla Firefox Bookmark
				window.sidebar.addPanel(document.title, document.location.href,"");
			} else if( window.external ) { // IE Favorite
				window.external.AddFavorite( document.location.href, document.title); }
			else if(window.opera && window.print) { // Opera Hotlist
				return true; 
			} else {
				alert("Bookmark our site using one of the many featured online social tools.");
			}
	 }

function addToMyFavorites(objectID) {	
		$('favorite').innerHTML = "<a href=\"#\" id=\"loading\">&nbsp;</a>";
		var aj = new Ajax.Request("/actions/add_to_favorites.php", { method: 'post', parameters: "ajax=1&objectID=" + objectID,
			onSuccess: function (response) { $('favorite').innerHTML = response.responseText; }
		});
		return false;
}
function removeFromMyFavorites(objectID) {
		$('favorite').innerHTML = "<a href=\"#\" id=\"loading\">&nbsp;</a>";
		var aj = new Ajax.Request("/actions/remove_from_favorites.php", {method: 'post', parameters: "ajax=1&objectID=" + objectID,
			onSuccess: function (response) { $('favorite').innerHTML = response.responseText; }
		});
		return false;
}

function clickclear(thisfield, defaulttext) {
	if (thisfield.value == defaulttext) {
		thisfield.value = "";
	}
}

function clickrecall(thisfield, defaulttext) {
	if (thisfield.value == "") {
		thisfield.value = defaulttext;
	}
}
	
function submitComment() {
	$('addcommentspin').innerHTML = "<a href=\"#\" id=\"loading\">&nbsp;&nbsp;&nbsp;&nbsp;</a>";
	
	if($('comment_form_title').value == "Title") {
		$('addcommentspin').innerHTML = "Please enter a title.";
		return false;
	}
	
	if($('comment_form_text').value == "") {
		$('addcommentspin').innerHTML = "Please enter a comment.";
		return false;
	}
	
	var aj = new Ajax.Request(
					"/actions/add_comment.php",
					{
						method: 'post',
						parameters: "ajax=1&"+$('commentform').serialize(),
						onSuccess: function (response) { $('ajaxcomment').innerHTML = response.responseText; $('addcommentspin').innerHTML = ""; $('comment_form_title').value = "Title"; $('comment_form_text').value=""; matchColumns(); }
					});
	 
	return false;
}


// Runs the columns script when page loads
window.onload=function(){
     if(document.getElementsByTagName){
          matchColumns();            
     }
}