var ajax;
var headlineType;
var container;
var arrowPress;
var move;

var divsMoved = 0;

var cycleDir;
var cycleModType;
var cycleSlideSpeed;
var cycleSize;
var cycleHandler;
var cycleMoveDivs;
var cycleTotalImages;

var axel = Math.random() + "";
var ord = axel * 1000000000000000000;
var tile = 1;
	
/* Used to tell video player if it is on main site. */
function flashCheckDomain() {
	 return true;
}

function getPlayerObject(objName) {
	if (navigator.appName.indexOf("Microsoft") != -1) {
		return window[objName];
	}
	else {
		return window.document[objName];
	}
}

function updateListImage(id,choice,current,type) {
	headlineType = type;
	if(current != choice) {
			ajax =  new Ajax.Updater(
					id,
					'/modules/mod_vital_headlines.php',
					{method:'get',parameters:'type='+type+'&choice='+choice}
			);

	}
}


function tempDisableNext(parent, time) {
		time = time * 1000;
		var arrows = parent.getElementsByTagName('a');
		var oldOnClick = new Array();
		for(i=0;i<arrows.length;i++) {
			oldOnClick[i] = arrows[i].onclick;
			arrows[i].onclick = 'return false';
		}
		setTimeout(function() {
			for(i=0;i<arrows.length;i++) {
				arrows[i].onclick = oldOnClick[i];
			}	
		}, time);
	}

function cycleImages(dir,modType,slideSpeed,size,handler,divsToMove,totalImages) {
	cycleDir = dir;
	cycleModType = modType;
	cycleSlideSpeed = slideSpeed;
	cycleSize = size;
	cycleHandler = handler;
	cycleMoveDivs = divsToMove;
	cycleTotalImages = totalImages;

	container = $(modType + '-dataAll');
	
	contParent = container.parentNode;
	tempDisableNext(contParent, slideSpeed);
	arrowPress = dir;
	switch(cycleHandler) {
		case '/photosVideos':
			requestHandler = 'mod_vital_photosvideos.php';
			break;
		case 'profileHighlights':
			requestHandler = 'mod_vital_profilehighlights.php';
			break;
	}
		ajax = new Ajax.Request(
			'/modules/'+requestHandler, 
			{
				method: 'get',
				parameters:'arrowPress='+dir+'&type='+modType,
				onComplete: updateImageSequence
			});
}

function updateImageSequence(request) {
	var divSize = cycleSize;
	var bufferImages = cycleTotalImages - 1;
	var newDiv = document.createElement('div');
	newDiv.innerHTML = request.responseText;
	newDiv.style.position = 'absolute';
	switch(arrowPress) {
		case 'left':
			for (var i = 0; i < container.childNodes.length; i++) {
				moveMe = new Effect.MoveBy(container.childNodes[i], 0, -divSize, { duration: cycleSlideSpeed});
			}
			newDiv.style.left = bufferImages*divSize + 'px';
			container.appendChild(newDiv);
			container.removeChild(container.firstChild);
			break;
		case 'right':
			for (var i = 0; i < container.childNodes.length; i++) {
				moveMe = new Effect.MoveBy(container.childNodes[i], 0, divSize, { duration: cycleSlideSpeed});
			}
			newDiv.style.left = '0px';
			container.insertBefore(newDiv,container.firstChild);
			container.removeChild(container.lastChild);
			break;
	}
	/*divsMoved++;
	if(divsMoved == cycleMoveDivs) {
		cycleMoveDivs = 0;
		divsMoved = 0;
	}
	else {
		setTimeout(
		cycleImages(cycleDir,cycleModType,cycleSlideSpeed,cycleSize,cycleHandler,cycleMoveDivs,cycleTotalImages), 500000);
	}*/
}

function MM_preloadImages() { //v3.0
  var d=document; if(d.images){ if(!d.MM_p) d.MM_p=new Array();
    var i,j=d.MM_p.length,a=MM_preloadImages.arguments; for(i=0; i<a.length; i++)
    if (a[i].indexOf("#")!=0){ d.MM_p[j]=new Image; d.MM_p[j++].src=a[i];}}
}

function MM_swapImgRestore() { //v3.0
  var i,x,a=document.MM_sr; for(i=0;a&&i<a.length&&(x=a[i])&&x.oSrc;i++) x.src=x.oSrc;
}

function MM_findObj(n, d) { //v4.01
  var p,i,x;  if(!d) d=document; if((p=n.indexOf("?"))>0&&parent.frames.length) {
    d=parent.frames[n.substring(p+1)].document; n=n.substring(0,p);}
  if(!(x=d[n])&&d.all) x=d.all[n]; for (i=0;!x&&i<d.forms.length;i++) x=d.forms[i][n];
  for(i=0;!x&&d.layers&&i<d.layers.length;i++) x=MM_findObj(n,d.layers[i].document);
  if(!x && d.getElementById) x=d.getElementById(n); return x;
}

function MM_swapImage() { //v3.0
  var i,j=0,x,a=MM_swapImage.arguments; document.MM_sr=new Array; for(i=0;i<(a.length-2);i+=3)
   if ((x=MM_findObj(a[i]))!=null){document.MM_sr[j++]=x; if(!x.oSrc) x.oSrc=x.src; x.src=a[i+2];}
}


function swapModuleImage(id,type,count) {
	allImages = true;
	if(typeof($(type + "image-0").complete) != 'undefined') {
		for(i=0;i<count;i++) {
			if(!$(type + "image-" + i).complete) {
				allImages = false;
				return;
			}
		}
	}
	if(allImages) {
		for(i=0;i<count;i++) {
			$(type + "text-" + i).style.display = 'none';
			$(type + "list-" + i).className = '';
			$(type + "image-" + i).style.display = 'none';
		}
		$(type + "text-" + id).style.display = 'block';
		$(type + "list-" + id).className = 'highlighted';
		$(type + "image-" + id).style.display = 'block';	
	}
}

function checkAvailability(id, userid) {
	ajax =  new Ajax.Updater(
					id,
					'/components/com_comprofiler/check_available.php',
					{method:'get',parameters:'task=checkAvailability&userid='+userid}
			);
}

function matchDate() {
	var monthIndex = $('dob_month').selectedIndex;

	var numDays = $('dob_month').options[monthIndex].className;
	var yearIndex = $('dob_year').selectedIndex;
	var yearBorn = $('dob_year').options[yearIndex].value;
	/*var output = '';
	for(property in $('dob_year').options[yearIndex]) {
			output = output + property + ' = ' + $('dob_year').options[yearIndex][property];
			alert(output);
	}*/
	if((monthIndex == 1)) {
		if((yearBorn % 4 == 0)&& (yearBorn % 100 != 0)) {
			numDays++;
			alert('Leap Year');
		}
	}
			
	while($('dob_day').childNodes.length > 0) {
		$('dob_day').removeChild($('dob_day').firstChild);
	}
	for(i=1; i<=numDays; i++) {
		option = document.createElement('option');
		optionText = document.createTextNode(i);
		option.appendChild(optionText);
		$('dob_day').appendChild(option);
	}
}

function getPostalInfo(zip) {
	if(zip.length == 5) {
		zip = parseInt(zip);
		
		ajax =  new Ajax.Updater(
					'postal_response',
					'/components/com_comprofiler/get_postal.php',
					{method:'get',parameters:'zip='+zip}
		);
	}
	else $('postal_response').innerHTML = "";
}

function getSearchChoices(entry, searchType, searchField) {

	$(searchType + '-text_hide').value = entry;
	if(searchField != 'vital_postal') {
		ajax =  new Ajax.Updater(
					searchType + 'choices',
					'/modules/mod_vital_search.php',
					{method:'get',parameters:'entry='+entry+'&type='+searchType+'&field='+searchField}
		);
	}
}

function getMoreSearchResults(startCounter, pagCounter) {
	ajax =  new Ajax.Updater(
					'search-results-container',
					'/modules/mod_vital_search.php',
					{method:'get',parameters:'start_counter='+startCounter+'&pag_counter='+pagCounter}
		);
}

function initCommunitySearch() {

}

function outsideUS() {
	$('postal_title').firstChild.nodeValue = "Location:";
	replaceParent = $('postal_fields');
	replaceParent.innerHTML = "";
	ajax =  new Ajax.Updater(
					replaceParent,
					'/components/com_comprofiler/get_countries.php',
					{method:'get'}
		);
}


function switchLoginText(field) {
	if($('mod_loginform').username.value == "") $('mod_loginform').username.value = "username";
	if($('mod_loginform').passwd.value == "") $('mod_loginform').passwd.value = "password";
	field.value = "";
	var siblings = field.parentNode.childNodes;
	$('headerinput1').style.backgroundColor = "#FFF";
	$('headerinput2').style.backgroundColor = "#FFF";
	field.style.backgroundColor = "#FFFFCC";
	if(typeof($('not-logged')) != 'undefined') {
			setTimeout(closeLoginPrompt, 1000);
	}
}


function openPhoto(url) {
	var winWidth = Math.min(screen.width, 1024);
	//var winHeight = Math.min(screen.height, 768)-50;
	var winHeight = screen.height * .8;
	var leftPos = (screen.width > 1024) ? (screen.width - 1024)/2 : 0;
	if(typeof(newWin) != 'undefined') newWin.close();
	newWin = window.open(url, 'vitalphotovideo', 'resizable=1, scrollbars=1, height='+winHeight+',width='+winWidth+',left='+leftPos);
	return false;
}

function openAdImage(theURL,winName,features) { //v2.0
  window.open(theURL,winName,features);
}

function openUserPhoto(url, winWidth, winHeight) {
	var leftPos = (screen.width > 1024) ? (screen.width - 1024)/2 : 0;
	window.open(url, 'vitalphotovideo', 'resizable=1, scrollbars=1, height='+winHeight+',width='+winWidth+',left='+leftPos);
	return false;
}

function setAjaxTimeout(min) {
	msec = min * 60 * 1000;
	var timeout = setTimeout("window.location.reload()", msec);
}

function showDescription(img, topPos, title, desc) {
	hideDescription();
	if(desc.length > 0 || title.length > 22) {
		var imgParent = img.parentNode;
		var cell = imgParent.parentNode;
		var cellLeft = cell.offsetLeft;
		var cellTop = cell.offsetTop;
		var descNode = imgParent.nextSibling;
		var titleElem = document.createElement('b');
		var titleInner = document.createTextNode(title);
		titleElem.appendChild(titleInner);
		var descElem = document.createElement('h5');
		var descInner = document.createTextNode(desc);
		descElem.appendChild(descInner);
		descElem.style.fontWeight = 'normal';
		descElem.style.margin = '5px 0';
		descNode.innerHTML = "";
		descNode.appendChild(titleElem);
		descNode.appendChild(descElem);
		if(descNode.innerHTML.length > 0) {
			descNode.style.display = 'block';
		}
		descNode.style.left = (cellLeft) + "px";
		descNode.style.top = (cellTop + topPos) + "px";
	}
	
}

function hideDescription() {
	var clearClasses = document.getElementsByClassName('/photo-desc');
	var clearClassesLength = clearClasses.length;
	for(i=0;i<clearClassesLength;i++) {
		clearClasses[i].innerHTML = '';
		clearClasses[i].style.display = 'none';
	}
}

function uploadMedia(type) {

	ajax = new Ajax.Request(
			'/includes/checkloggedin.php', 
			{
				method: 'get',
				parameters:'&type='+type,
				onSuccess: function(t) {
					checkLoginResult(t);
					if(!t.responseText) {
						getUploadPhoto();
					}
				}
			});
	return false;
}

function getUploadPhoto() {
	ajax = new Ajax.Request(
			'/photo/upload_test.html', 
			{
				method: 'get',
				onSuccess: function(t) {
					displayUploadPhoto(t);
				}
			});
}


function displayUploadPhoto(t) {
	var displayUpload = document.createElement('div');
	displayUpload.setAttribute('id', 'display-upload');
	var displayIFrame = document.createElement('div');
	displayUpload.style.backgroundColor = "#fff";
	displayUpload.style.padding = "20px";
	displayUpload.style.position = 'absolute';
	displayUpload.style.top = "100px";
	displayUpload.style.left = "100px";
	displayIFrame.innerHTML = t.responseText;
	$('maincontent').style.position = 'relative';
	displayUpload.appendChild(displayIFrame);
	//new Effect.Highlight('maincontent', {startcolor:'#fff', endcolor:'#000'})
	$('maincontent').appendChild(displayUpload);
	
}

function checkLoginResult(request) {
	if(request.responseText && typeof($('not-logged')) == 'undefined') {
			
		new Element.scrollTo('headerinput1');
		var notLogged = document.createElement('div');
		notLogged.setAttribute('id', 'not-logged');
		notLogged.style.backgroundColor = "#ccf";
		notLogged.style.padding = "20px";
		notLogged.style.position = 'absolute';
		notLogged.style.top = "100px";
		notLogged.style.left = "300px";
		notLogged.innerHTML = request.responseText;
		$('maincontent').style.position = 'relative';
		$('maincontent').appendChild(notLogged);
		logTimeout1 = setTimeout(closeLoginPrompt, 4000);
		
		$('close-me').onclick = closeLoginPrompt;
		$('log-me-in').onclick = moveLoginPrompt;
		
	}
}

function closeLoginPrompt() {
	Effect.Fade($('not-logged'), {duration: 0.5});
	setTimeout(function() {$('not-logged').parentNode.removeChild($('not-logged'));}, 500);
	clearTimeout(logTimeout1);
	
	return false;
}

function moveLoginPrompt() {
	new Effect.Move ($('not-logged'),{ x: 500, y: 0, mode: 'absolute', duration: 0.4});
	clearTimeout(logTimeout1);
	$('headerinput1').style.backgroundColor = "#FFFFCC";
	$('headerinput1').focus();
	return false;
}

function closeLoginFriendPrompt() {
	Effect.Fade($('not-logged-friends'), {duration: 0.5});
}

function displayFriendsLoginPrompt() {
	var notLoggedFriends = document.createElement('p');
	notLoggedFriends.setAttribute('id', 'not-logged-friends');
	var notLoggedFriendsText = document.createTextNode('You must login to accept or reject friends.');
	notLoggedFriends.appendChild(notLoggedFriendsText);
	$('header').style.position = 'relative';
	$('header').appendChild(notLoggedFriends);
	new Effect.Appear ($('not-logged-friends'));
	$('not-logged-friends').style.backgroundColor = "#FFFFCC";
	$('not-logged-friends').style.fontWeight = "bold";
	$('not-logged-friends').style.padding = "5px";
	$('not-logged-friends').style.margin = "0";
	setTimeout(closeLoginFriendPrompt, 6000);
}

function showSideAd(tab) {
	var frameSrc = $(tab + '_ad').src;
	
	$(tab + '_ad').style.display = 'block';
	if(frameSrc.indexOf('adcall') < 0) {
		$(tab + '_ad').src = frameSrc + '?adcall=1';
	}
	else {
		$(tab + '_ad').src = frameSrc;
	}
	
	
}

function openFullMovie() {
	var movie = "/video/themes/test-theme2/dummy.swf";
	showFlashMovie(movie, 'flash-hide', window.document);
	newWinInterval = setInterval(checkMe, 1000);
	return false;
}

function showPopUp(myvidurl) {
	Win = window.open(myvidurl,"subwin",'width=' + (screen.width - 10) + ',height=' + (screen.height - 30) + ',resizable=0,menubar=no,scrollbars=yes,status=no' );
	openFullMovie();
}

function checkMe() {
	if(Win.closed) {
		clearInterval(newWinInterval);
		var movie2 = movie.replace(/&myvideoplay=play/,"");
		showFlashMovie(movie2, 'flash-hide', window.document);
	}
}

function setMovie(mv) {
	mv2 = mv;
}

function showFlashMovie(movie, id, winOpener) {
		if(typeof(winOpener) == 'undefined') {
			var winOpener = window.document;
		}
		if(typeof(id) == 'undefined') {
			var id = 'flash-hide';
		}
		if(typeof(movie) == 'undefined') {
			var movie = mv2;
		}
		if(document.getElementById('pre-roll')) {
			document.getElementById('pre-roll').style.display = 'none';
		}
		document.getElementById('flash-hide').style.display = 'block';
		winOpener.getElementById(id).innerHTML = "";
		var emb = winOpener.createElement('embed');
		emb.setAttribute('src', movie);
		emb.setAttribute('quality', 'high');
		emb.setAttribute('bgcolor', '#fff');
		emb.setAttribute('width', '450');
		emb.setAttribute('height', '380');
		emb.setAttribute('name', 'vitalmovie');
		emb.setAttribute('align', 'middle');
		emb.setAttribute('allowScriptAccess', 'always');
		emb.setAttribute('type', 'application/x-shockwave-flash');
		emb.setAttribute('pluginspage', 'http://www.macromedia.com/go/getflashplayer');
		winOpener.getElementById(id).appendChild(emb);
	}

// Also need to pass media_id, media_type, media_owner
function getMoreMedia(get_type, media_dir, media_type, media_owner, photo_or_video) {
	var ajax_list = get_type + '_thumbs';
	var ajax_paginator = get_type + '_paginator';
	var ajax =  new Ajax.Updater(
					ajax_list,
		'/modules/mod_vital_mediadetail.php',
		{method:'get',parameters:'ajax_list='+ajax_list+'&media_dir='+media_dir+'&media_type='+media_type+'&media_owner='+media_owner+'&ajax_paginator='+ajax_paginator+'&photo_or_video='+photo_or_video}
	);
}


function submitAjaxComment(pid, comment, media_type, media_owner) {
	comment = escape(comment);
	var ajax =  new Ajax.Request(
		'/modules/mod_vital_mediadetail.php',
		{
				method:'get',
				parameters:'media_id='+pid+'&new_comment='+comment+'&media_type='+media_type+'&media_owner='+media_owner,
				onComplete: showNewComment
		}
	);
}

function showNewComment(result) {
	var inserted = new Insertion.Bottom('media_comments', result.responseText);
	var list_items = $('media_comments').getElementsByTagName('li');
	var last_item = list_items.length - 1;
	for(i=0; i<=last_item; i++) {
		if(i == last_item) {
			//var highlight = new Effect.Pulsate(list_items[i], {pulses: 2, from:0.2});
			var highlight = new Effect.Highlight(list_items[i], {endcolor:'#f6f4e1'});
		}
	}
	$('submit_comment').new_comment.value = "";
}

function displayStarRatings(star_number) {
	if(typeof(already_rated) == 'undefined') {
		var stars = $('star_ratings').getElementsByTagName('a');
		for(i=0; i<stars.length; i++) {
			stars[i].className = "off";
		}
		for(i=0; i<star_number; i++) {
			stars[i].className = "on";		
		}
	}
}


function submitStarRating(rating, pid, star) {
	star.blur();
	var ajax =  new Ajax.Request(
		'/modules/mod_vital_mediadetail.php',
		{
				method:'get',
				parameters:'ajax_star_rating='+rating+'&media_id='+pid,
				onComplete:function(transport) {eval(transport.responseText);}
		}
	);
}

function createStarResponse() {
	if(typeof($('new_star')) == 'undefined') {
		var new_star = document.createElement('span');
		new_star.setAttribute('id', 'new_star');
		$('star_ratings_container').appendChild(new_star);
	}
}

function presetStarRatings(star_number) {
	displayStarRatings(star_number);
	already_rated = true;
}

function editMediaItem(media_id, title, caption, credit) {
	title = unescape(title);
	caption = unescape(caption);
	credit = unescape(credit);
	
	var editForm = document.createElement('form');
	editForm.setAttribute('id', 'current_media_info');
	
	var titleLabel = document.createElement('label');
	titleLabel.setAttribute('for', 'edit_title');
	var titleText = document.createTextNode('Title');
	titleLabel.appendChild(titleText);
	var titleField = document.createElement('input');
	titleField.setAttribute('value', title);
	titleField.setAttribute('name', 'edit_title');
	titleField.setAttribute('id', 'edit_title');
	
	var captionLabel = document.createElement('label');
	captionLabel.setAttribute('for', 'edit_caption');
	var captionText = document.createTextNode('Caption');
	captionLabel.appendChild(captionText);
	var captionField = document.createElement('textarea');
	var captionFieldText = document.createTextNode(caption);
	captionField.appendChild(captionFieldText);
	captionField.setAttribute('name', 'edit_caption');
	captionField.setAttribute('id', 'edit_caption');
	
	var creditLabel = document.createElement('label');
	creditLabel.setAttribute('for', 'edit_credit');
	var creditText = document.createTextNode('Credit');
	creditLabel.appendChild(creditText);
	var creditField = document.createElement('input');
	creditField.setAttribute('value', credit);
	creditField.setAttribute('name', 'edit_credit');
	creditField.setAttribute('id', 'edit_credit');
	
	var submitButton = document.createElement('input');
	submitButton.setAttribute('type', 'submit');
	submitButton.setAttribute('value', 'Submit Changes');
	submitButton.setAttribute('id', 'submit_changes');
	submitButton.onclick = function() {
		updateMediaItem(media_id);
		return false;
	}
	
	editForm.appendChild(titleLabel);
	editForm.appendChild(titleField);
	editForm.appendChild(captionLabel);
	editForm.appendChild(captionField);
	editForm.appendChild(creditLabel);
	editForm.appendChild(creditField);
	editForm.appendChild(submitButton);
	$("media_detail_right").appendChild(editForm);
	
	var effect = new Effect.DropDown('current_media_info', {endSize:250,duration:0.5});
}

function updateMediaItem(media_id) {
	var title_value = escape($('edit_title').value);
	var ajax =  new Ajax.Updater(
					'media_title',
		'/modules/mod_vital_mediadetail.php',
		{method:'post',parameters:'media_id='+media_id+'&ajax_title_value='+title_value+'&ajax_media_update=true'}
	);
	
	var caption_value = escape($('edit_caption').value);
	var ajax2 =  new Ajax.Request(
		'/modules/mod_vital_mediadetail.php',
		{method:'post',parameters:'media_id='+media_id+'&ajax_caption_value='+caption_value+'&ajax_media_update=true'}
	);
	
	
	var credit_value = escape($('edit_credit').value);
	var ajax3 =  new Ajax.Updater(
						'media_credit',
			'/modules/mod_vital_mediadetail.php',
			{method:'post',parameters:'media_id='+media_id+'&ajax_credit_value='+credit_value+'&ajax_media_update=true'}
		);
		
	var ajax4 =  new Ajax.Updater(
					'edit_delete',
		'/modules/mod_vital_mediadetail.php',
		{method:'post',parameters:'ajax_media_update=true&ajax_edit_delete=true',onComplete:function(){Element.remove($('current_media_info'));}}
	);
	
	//Element.remove($('current_media_info'));
}


function deleteMediaItem(media_id) {
	var sure = confirm('Are you sure you want to delete this item?');
	if(sure) {
		var ajax =  new Ajax.Request(
			'/modules/mod_vital_mediadetail.php',
			{
					method:'post',
					parameters:'ajax_media_delete=true&media_id='+media_id
			}
		);
		setTimeout("window.close();", 500);
		window.opener.location.reload();
	}
}

function promptCommentLogin(current_page) {
	if($('comment_login').style.display = 'none') {
		//var scroll = new Effect.ScrollTo('comment_submit_btn', {duration:.5});
		/*var yPos = findPosY($('new_comment'));
		var xPos = findPosX($('new_comment'));
		window.scrollTo(xPos, yPos);*/
		current_page = escape(current_page);
		var ajax =  new Ajax.Request(
			'/modules/checklogin.php',
			{
					method:'get',
					parameters:'current_page='+current_page,
					onComplete: function() {$('username').focus();}
			}
		);
	}
}


function submitLoginComment(form) {
	
	var username = form.username.value;
	var passwd = form.passwd.value;
	var return_page = form.return_page.value;
	var ajax =  new Ajax.Request(
		'/index.php?option=com_comprofiler&amp;task=login',
		{
				method:'post',
				parameters:'username='+username+'&passwd='+passwd+'&Submit=Submit&return='+return_page+'&ajax_comment_submit=true'
		}
	);

	return false;
}

function closeCommentLogin() {
	$('comment_login').style.display = 'none';
	return false;
}

Effect.DropDown = Class.create();
Object.extend(Object.extend(Effect.DropDown.prototype, Effect.Base.prototype), {
  initialize: function(element) {
    this.element = $(element);
    var options = arguments[1] || {};
    this.start(options);
  },
  setup: function(element){
    this.beginH = this.element.offsetHeight;
    this.endH;
    if(this.options.endSize) this.endH = this.options.endSize;
    else {
                this.element.style.visibility = 'hidden';
            this.element.style.height = '';
        this.endH = this.element.offsetHeight;
                this.element.style.visibility = 'visible';
        this.element.style.height = this.beginH+'px';
        if(this.endH < this.beginH && !this.options.endSize){ this.cancel(); }
    }
  },
  update: function(position){
        this.element.style.height = Math.round(this.beginH+position*(this.endH-this.beginH))+'px';
  },
  finish: function(position) {
        this.element.style.height = this.endH+'px';
  }
});

function findPosX(obj)
  {
    var curleft = 0;
    if(obj.offsetParent)
        while(1) 
        {
          curleft += obj.offsetLeft;
          if(!obj.offsetParent)
            break;
          obj = obj.offsetParent;
        }
    else if(obj.x)
        curleft += obj.x;
    return curleft;
  }

function findPosY(obj)
{
  var curtop = 0;
  if(obj.offsetParent)
      while(1)
      {
        curtop += obj.offsetTop;
        if(!obj.offsetParent)
          break;
        obj = obj.offsetParent;
      }
  else if(obj.y)
      curtop += obj.y;
  return curtop;
}

function expandCaptionMore(size, caption) {
	caption = unescape(caption);
	$('media_caption').style.visibility = "hidden";
	//var caption = $('media_caption').innerHTML;
	caption += '<a id="caption_less" href="javascript:return false;" onclick="return contractCaptionMore();">back</a>';
	var whole_caption = document.createElement('div');
	whole_caption.innerHTML = caption;
	whole_caption.setAttribute('id', 'whole_caption');
	$('media_detail_right').appendChild(whole_caption);
	var effect = new Effect.DropDown('whole_caption', {endSize:size,duration:0.7});
	return false;
}

function contractCaptionMore() {
	$('media_detail_right').removeChild($('whole_caption'));
	$('media_caption').style.visibility = "visible";
	return false;
}

function openWholeWindow(href) {
	window.open(href, '', 'menubar=yes,toolbar=yes,location=yes,resizable=yes,scrollbars=yes,status=yes');
	return false;
}

function validateLoginForm(this_form) {
	var retval = true;
	if(this_form.username.value.replace(/\s/g, "") == "") {
		this_form.username.focus();
		retval = false;
	}
	else if(this_form.passwd.value.replace(/\s/g, "") == "") {
		this_form.passwd.focus();
		retval = false;
	}
	return retval;
}
