var ost = 'undefined';
var pgm_has_focus = false;
var pgm_ivl = -1;
var pgm_ivl_time = 1000;

if ( typeof isInternetExplorer == "undefined" )
	isInternetExplorer = chat_is_ie();

function chat_is_ie()
{
	is_ie = /msie/i.test(navigator.userAgent) && !/opera/i.test(navigator.userAgent);
	
	return is_ie;
}
		
function join_fan_club()
{
	Members.join_fan_club( cur_model_id, 'join_fan_club_result' );
}

function join_fan_club_result( res )
{
	msg = "";
	if ( res )
		msg = "You have joined " + cur_model_username + "'s fan club!";
	else
		msg = "You're already a fan of " + cur_model_username + ".";

	alert( msg );
}

function scrollToVid(ost)
{
    try
    {
        if ( !Members.rendering_profile )
        {
            scrollToChatSwf( ost )
        }
    }
    catch (e)
    {
    }
}

function scrollToChatSwf( ost )
{
   	if ( ost != 0 )
   	{
   		pos = get_ele_position( "chat_swf" );
   		ost = pos[ 1 ];
   	}

   	window.scrollTo( 0, ost );
}

function movie_DoFSCommand(command, args)
{
	if(command == 'setHeight' || command == 'FSCommand:setHeight')
	{	
		from = 0;
		var chat = document.getElementsByName("movie");
		if ( chat.length > 1 )
		{
			from = chat.length - 2;
		}

		chat = document.getElementsByName("movie")[ from ];
		chat.height = args;
		chat = isInternetExplorer ? document.all.movie : document.movie;
		chat.height = args;
		
		chat_ele = document.getElementById( "chat_swf" );
		chat_ele.style.height = args + "px";
		
		callExternalInterface();
	}

	if(command == 'setWidth' || command == 'FSCommand:setWidth')
	{
		from = 0;
		var chat = document.getElementsByName("movie");
		if ( chat.length > 1 )
		{
			from = chat.length - 2;
		}

		chat = document.getElementsByName("movie")[ from ];
		chat.width = args + "px";
		chat = isInternetExplorer ? document.all.movie : document.movie;
		chat.width = args + "px";
		
		callExternalInterface();
	}

	if (command == "scrollMe")
	{
		scrollToVid(args);
	}
	
	if (command == "expand_full")
	{
		from = 0;
		var chat = document.getElementsByName("movie");
		if ( chat.length > 1 )
		{
			from = chat.length - 2;
		}

		chat = document.getElementsByName("movie")[ from ];
		chat.width = "100%";
		chat.height = "100%";
		chat = isInternetExplorer ? document.all.movie : document.movie;
		chat.width = "100%";
		chat.height = "100%";

		chat_ele = document.getElementById( "chat_swf" );

        if ( dating_ad_zone_height != null && dating_ad_zone_height > 0 )
        {
            new_height = ( 100 - ( ( dating_ad_zone_height / getHeight() ) * 100 ) );
            chat_ele.style.height = new_height + "%";
        }
        else
        {
    		chat_ele.style.height = "100%";
        }

		callExternalInterface();
	}
}

function getHeight()
{
    var myHeight = 0;
    if( typeof( window.innerHeight ) == 'number' )
    {
        //Non-IE
        myHeight = window.innerHeight;
    }
    else if ( document.documentElement && document.documentElement.clientHeight )
    {
        //IE 6+ in 'standards compliant mode'
        myHeight = document.documentElement.clientHeight;
    }
    else if ( document.body && document.body.clientHeight )
    {
        //IE 4 compatible
        myHeight = document.body.clientHeight;
    }

    return  myHeight;
}

function getWidth()
{
    var myWidth = 0;
    if( typeof( window.innerWidth ) == 'number' )
    {
        //Non-IE
        myWidth = window.innerWidth;
    }
    else if( document.documentElement && document.documentElement.clientWidth )
    {
        //IE 6+ in 'standards compliant mode'
        myWidth = document.documentElement.clientWidth;
    }
    else if( document.body && document.body.clientWidth )
    {
        //IE 4 compatible
        myWidth = document.body.clientWidth;
    }

    return  myWidth;
}

function alertSize()
{
	var myWidth = getWidth();
    var myHeight = getHeight();

    return  myWidth;
}

function callExternalInterface()
{
	var myWidth = getWidth();
    var myHeight = getHeight();

	from = 0;
	var chat = document.getElementsByName("movie");
	if ( chat.length > 1 )
	{
		from = chat.length - 2;
	}
    chat = document.getElementsByName("movie")[ from ];
	chat = isInternetExplorer ? document.all.movie : document.movie;

	if (chat != null)
    {
		if ( chat.browser_resized != null )
        {
	         chat.browser_resized(myWidth, myHeight);
        }
    }
}

function membersLoadNewModel(model_id, model_name, model_type, model_sid, premiumchat_url, voyeurchat_url, premiumchat_full_url, favLink, document_ele )
{
	cur_model_id = model_id;
	cur_model_username = model_name;
	
	getMovieName("movie", document_ele).loadNewModel( model_id );
}

function membersUpdateRouletteModel(model_id)
{
	Members.update_roulette_model(model_id);
}

function getMovieName(movieName, document_ele)
{
	if ( document_ele == null )
		document_ele = document;
	
	if (navigator.appName.indexOf("Microsoft") != -1)
	{
		return document_ele[movieName]
	}
	else
	{
		return document_ele[movieName]
	}
}
function pageScroll(delta)
{
	window.scrollBy(0,delta);
	scrolldelay = setTimeout('pageScroll()',100); // scrolls every 1000 milliseconds
}
function stopScroll()
{
	clearTimeout(scrolldelay);
}
function jumpScroll()
{
	window.scroll(0,150); // horizontal and vertical scroll targets
}
function isEmb()
{
	from = 0;
	var chat = document.getElementsByName("movie");
	if ( chat.length > 1 )
	{
		from = chat.length - 2;
	}
    chat = document.getElementsByName("movie")[ from ];
	chat = isInternetExplorer ? document.all.movie : document.movie;
	chat.browser_emb(1);

}
function resizeMe(w,h)
{
	var myw = 0;
	var myh = 0;
	if(self.innerWidth)
	{
		myw = self.innerWidth;
		myh = self.innerHeight;
	}
	else if(document.documentElement && document.documentElement.clientWidth)
	{
		myw = document.documentElement.clientWidth;
		myh = document.documentElement.clientHeight;
	}
	else if(document.body)
	{
		myw = document.body.clientWidth;
		myh = document.body.clientHeight;
	}
	else return;

	if(document.layers)
	{
		w -= (parent.outerWidth-parent.innerWidth);
		h -= (parent.outerHeight-parent.innerHeight);
	}
	if(myw < w || myh < h)
	{
		self.resizeBy(((myw >= w)?0:w-myw),((myh >= h)?0:h-myh));
	}
}

function load_new_alert(model_id, model_username)
{
	Members.load_new_alert(model_id,model_username);
}

function pgm_start_timer()
{
	pgm_ivl = setInterval( "pgm_check();", pgm_ivl_time );
}

function pgm_check()
{
	if ( pgm_has_focus )
		getMovieName( "movie" ).load_pgm_model();
}

function pgm_on_focus()
{
	pgm_has_focus = true;
}

function pgm_on_blur()
{
	pgm_has_focus = false;
}

function pgm_ok()
{
	clearInterval( pgm_ivl );
}

function open_foreign_popup( url )
{
	var w = 800;
	var h = 600;
	var name = "foreignpopup";
	var scrollbars = true;
	var j = "top_right";

	OpenWindow( url, name, w, h, scrollbars, j );
}

if(navigator.appName                               &&
		   navigator.appName.indexOf  ('Microsoft'  ) != -1&&
		   navigator.userAgent.indexOf('Windows'    ) != -1&&
		   navigator.userAgent.indexOf('Windows 3.1') == -1)
		{
			document.write('<script language=VBScript\> \n');
			document.write('on error resume next \n');
			document.write('Sub movie_FSCommand(ByVal command, ByVal args)\n');
			document.write('  call movie_DoFSCommand(command, args)\n');
			document.write('end sub\n');
			document.write('</script\> \n');
		}

window.onresize = callExternalInterface;

