function preview_resource_center(id){
	
	var width  = 1020;
	var height = 600;
	var left   = (screen.width  - width) / 2;
	var top    = ((screen.height - height) / 2) * .5;
	window.open(webroot + '/media/video/id/' + id, 'riswindow', 'status=no, directories=no, menubar=no, resizable=yes, scrollbars=yes, toolbar=no, location=no, width=' + width + ', height=' + height + ', top=' + top + ', left=' + left);	

	return false;
}

function stripe()
{
    $$('table.stripe tbody > tr:nth-child(even)').invoke('addClassName', 'oddrow');
}

function toggleHelp(event)
{
    $('help').toggle();

    new Ajax.Request(webroot + '/help/toggle');

    if ($('help').visible()) {
        new Ajax.Updater(
            'help',
            webroot + '/help/show/' + controller + '/' + action,
            {
                method: 'get'
            }
        );

        $('help-link').update('Turn Help Off');
    } else {
        $('help-link').update('Turn Help On');
    }

    event.stop();
}

function toggleNewsletterInfo(event)
{
    var element = $('info-' + id);

    if (!element) {
        var infoRow = new Element('tr', { 'class': 'newsletter_info', 'id': 'info-' + id });
        var infoLine = new Element('td', { 'class': 'line' }).update();
        var infoCell = new Element('td', { 'colspan': 5 }).update('ya ta');
        infoRow.insert({bottom: infoLine});
        infoRow.insert({bottom: infoCell});
        $('row-' + id).insert({after: infoRow});

        $('link-' + id).getElementsBySelector('img')[0].src=webroot + '/img/icons/contract.png';
    } else {
        $('link-' + id).getElementsBySelector('img')[0].src=webroot + '/img/icons/expand.png';
        element.remove();
    }

    event.stop();
}

function openMediaCenter(event)
{
    var userId = event.element().id;
    var url = 'http://www.top5inrealestate.com/media/index/id/' + currentUserID;
    var width  = 1020;
	var height = 600;
	var left   = (screen.width  - width) / 2;
 	var top    = ((screen.height - height) / 2) * .5;
 	window.open(url, 'top5window', 'status=no, directories=no, menubar=no, resizable=yes, scrollbars=yes, toolbar=no, location=no, width=' + width + ', height=' + height + ', top=' + top + ', left=' + left);	
	if (window.focus) {top5window.focus()}

    event.stop();
}

function adminOpenMediaCenter(event)
{    
	var width  = 1020;
	var height = 600;
	var left   = (screen.width  - width) / 2;
 	var top    = ((screen.height - height) / 2) * .5;
    window.open(this.href, 'top5window', 'status=no, directories=no, menubar=no, resizable=yes, scrollbars=yes, toolbar=no, location=no, width=' + width + ', height=' + height + ', top=' + top + ', left=' + left);	
    event.stop();
}


function chooseMediaCenterImage(event) {
  //alert(event.id);
  new Ajax.Request('/users/choose_image/' + event.id,
  {
    method:'post',
    onSuccess: function(transport){
      var response = transport.responseText || "no response text";
      alert(response);
    },
    onFailure: function(){ alert('Unable to update image...') }
  }); 
}

function selectLogo(id){

  new Ajax.Request('/users/choose_image/brokerage_logo_media_center/' + id,
  {
    method:'post',
    onSuccess: function(transport){
      var response = transport.responseText || "no response text";
      alert(response);
    },
    onFailure: function(){ alert('Unable to update image...') }
  }); 
  
}

function selectAgentLogo(id){
  new Ajax.Request('/users/choose_image/agent_logo_media_center/' + id,
  {
    method:'post',
    onSuccess: function(transport){
      var response = transport.responseText || "no response text";
      alert(response);
    },
    onFailure: function(){ alert('Unable to update image...') }
  }); 
}
function swap_icon(dom_id){
	$(dom_id).src = "http://www.top5inrealestate.com/img/ajax-loading.gif"; 
}
//preload images
var image = new Image();
image.src = 'http://www.top5inrealestate.com/img/ajax-loading.gif';
