var showTeamPopupOnLoad = false;
var showShowreelPopupOnLoad = false;
var currentTeamInfo = 1;

function specialitySearch( val ) {
	if ( val != '' ) {
		document.location = '/casting/profiles/ Speciality::' + val;
	} else {
		document.location = '/casting/profiles';
	}
}

function correctPNG( imageId ) // correctly handle PNG transparency in Win IE 5.5 , 6 & 7.
{
	var arVersion = navigator.appVersion.split("MSIE")
	var version = parseFloat(arVersion[1])
	if ((version >= 5.5) && (version < 7) && (document.body.filters)) 
	{
		var img = document.getElementById( imageId );
		var imgName = img.src.toUpperCase()
		var imgID = (img.id) ? "id='" + img.id + "' " : "";
		var imgClass = (img.className) ? "class='" + img.className + "' " : ""
		var imgTitle = (img.title) ? "title='" + img.title + "' " : "title='" + img.alt + "' "
		var imgStyle = "display:inline-block;" + img.style.cssText 
		if (img.align == "left") imgStyle = "float:left;" + imgStyle
		if (img.align == "right") imgStyle = "float:right;" + imgStyle
		if (img.parentElement.href) imgStyle = "cursor:hand;" + imgStyle
		var strNewHTML = "<span " + imgID + imgClass + imgTitle
		+ " style=\"" + "width:" + img.width + "px; height:" + img.height + "px;" + imgStyle + ";overflow: hidden;"
		+ "filter:progid:DXImageTransform.Microsoft.AlphaImageLoader"
		+ "(src=\'" + img.src + "\', sizingMethod='scale');\"></span>" 
		img.outerHTML = strNewHTML
	}
}

function correctPNGBackground( divId, imgURL, sizingMethod ) // correctly handle PNG transparency in Win IE 5.5 , 6 & 7.
{
	sizingMethod = ( typeof sizingMethod == 'undefined' ) ? 'scale' : sizingMethod;
	var arVersion = navigator.appVersion.split("MSIE")
	var version = parseFloat(arVersion[1])
	if ((version >= 5.5) && (version < 7) && (document.body.filters)) 
	{
		var div = document.getElementById( divId );
		div.style.filter = "progid:DXImageTransform.Microsoft.AlphaImageLoader(src='"+imgURL+"', sizingMethod='" + sizingMethod + "')";
		div.style.background = '';
	}    
}

function correctMenuLink( id ) {
	correctPNGBackground( 'menuSpan_' + id, '/custom/images/menulinkoverred.png' );
}
function menuLinkOff( id ) {
	document.getElementById( 'menuSpan_' + id ).style.filter = '';
}

function mouseOverPortfolioItem( id ) {
	document.getElementById('portfolioHilite' + id).style.display = '';
	if ( currentPortfolioButton != id ) {
		document.getElementById('portfolioHilite' + currentPortfolioButton ).style.display = 'none';
	}
	currentPortfolioButton = id;
}


function setTall() {
	if ( document.getElementById('lhs') && document.getElementById('rhs') && document.getElementById('newsBoxContent') ) {
		var lhsHeight = parseInt( document.getElementById('lhs').offsetHeight );
		var rhsHeight = parseInt( document.getElementById('rhs').offsetHeight );
		var newsBox = document.getElementById('newsBoxContent');
		var newsHeight = parseInt( newsBox.offsetHeight );
		
		if ( lhsHeight > rhsHeight ) {
			var diff = lhsHeight - rhsHeight;
		} else {
			var diff = rhsHeight - lhsHeight;
		}
		
		if ( newsHeight > 120 ) {	// don't wanna make the news box too small
			newsHeight += diff;
			newsBox.style.height = newsHeight + 'px';
			newsBox.style.minHeight = newsHeight + 'px';
		}
	}
}

function initTeamPopup() {
	document.getElementById('teamPopup').style.display = '';
	correctPNGBackground('teamPopupBackground', '/custom/images/teamoverlay.png' );
	teamBox = 
			new YAHOO.widget.Panel("teamPopup",  
											{ width:"578px", 
											  height:"407px", 
											  fixedcenter:true, 
											  close:false, 
											  draggable:false, 
											  modal:true,
											  visible:false,
											  underlay:"none",
											  effect:{effect:YAHOO.widget.ContainerEffect.FADE, duration:0.5} 
											} 
										);

	teamBox.render(document.body);
	if( showTeamPopupOnLoad )
		teamBox.show();
}

function hideTeamPopup() {
	if( typeof teamBox != "undefined" )
		teamBox.hide();
}

function showTeamPopup( num ) {
	document.getElementById('teamInfo'+currentTeamInfo).style.display = 'none';
	document.getElementById('teamInfoImage'+currentTeamInfo).style.display = 'none';
	document.getElementById('teamInfo'+num).style.display = '';
	document.getElementById('teamInfoImage'+num).style.display = '';
	currentTeamInfo = num;
	if( typeof teamBox != "undefined" ) {
		teamBox.show();
	} else {
		showTeamPopupOnLoad = true
	}
}

function initShowreelPopup() {
	document.getElementById('showreelPopup').style.display = '';
	correctPNGBackground('showreelPopupBg', '/custom/images/showreelpanel.png' );
	showreelBox = 
			new YAHOO.widget.Panel("showreelPopup",  
											{ width:"578px", 
											  height:"407px", 
											  fixedcenter:true, 
											  close:false, 
											  draggable:false, 
											  modal:true,
											  visible:false,
											  underlay:"none",
											  effect:{effect:YAHOO.widget.ContainerEffect.FADE, duration:0.5} 
											} 
										);

	showreelBox.render(document.body);
	if( showShowreelPopupOnLoad )
		showreelBox.show();
}

function hideShowreelPopup() {
	if( typeof showreelBox != "undefined" )
		showreelBox.hide();
}

function showShowreelPopup( num ) {
	if( typeof showreelBox != "undefined" ) {
		showreelBox.show();
	} else {
		showShowreelPopupOnLoad = true
	}
}

function handleSliderChange(e, ui)
{
  var maxScroll = $("#homePortfolioItemDescriptionHolder").attr("scrollHeight") -
                  $("#homePortfolioItemDescriptionHolder").height();
  $("#homePortfolioItemDescriptionHolder").animate({scrollTop: (100-ui.value) * (maxScroll / 100) }, 1000);
}
function handleSliderSlide(e, ui)
{
  var maxScroll = $("#homePortfolioItemDescriptionHolder").attr("scrollHeight") -
                  $("#homePortfolioItemDescriptionHolder").height();
  $("#homePortfolioItemDescriptionHolder").attr({scrollTop: (100-ui.value) * (maxScroll / 100) });
}

YAHOO.util.Event.addListener(window, "load", setTall);