var imBrowserName = (navigator.appName == "Microsoft Internet Explorer") ? "explorer" : "mozilla";
var ie6 = ((navigator.userAgent).match(/MSIE 6.0/)) ? true : false ;
var viewportHeight = returnViewportHeight();
var imScrollHeight = 0;
var imScrollInterval = false;
var imScrollDifference = 0;
popup = '';
//window.onload = checkIM;

function IM_Popup(options)
{
	this.scrollInterval = false;
	this.options    = arguments.length > 0 ? arguments[0] : {};
	this.txtCount   = 0;
	this.posY       = -116;
	this.url        = 'http://www.exgfdating.com';
	this.chatImage  = 'http://www.exploitedbabysitterteens.com/imbanner/images/chat.gif';
	this.blinkImage = 'http://www.exploitedbabysitterteens.com/imbanner/images/blink.gif';
	this.names      = ['HoRnYjEsS', 'SexiLexi18', 'LoNeLyGuRl1', 'SeXyAsHlEy', 'iWaNtSeX', 'LoNelYjEnNi', 'WiLdMaRy1', 'WiLdJeNnA'];
	this.ages       = ['18/F', '19/F', '18/F', '19/F', '18/F', '18/F', '19/F', '19/F'];
	this.images     = ['http://www.exploitedbabysitterteens.com/imbanner/thumbs/4.jpg',
	                   'http://www.exploitedbabysitterteens.com/imbanner/thumbs/20.jpg',
	                   'http://www.exploitedbabysitterteens.com/imbanner/thumbs/15.jpg',
	                   'http://www.exploitedbabysitterteens.com/imbanner/thumbs/1.jpg',
	                   'http://www.exploitedbabysitterteens.com/imbanner/thumbs/2.jpg',
	                   'http://www.exploitedbabysitterteens.com/imbanner/thumbs/3.jpg',
	                   'http://www.exploitedbabysitterteens.com/imbanner/thumbs/5.jpg',
	                   'http://www.exploitedbabysitterteens.com/imbanner/thumbs/14.jpg',
	                   'http://www.exploitedbabysitterteens.com/imbanner/thumbs/13.jpg',
	                   'http://www.exploitedbabysitterteens.com/imbanner/thumbs/12.jpg',
	                   'http://www.exploitedbabysitterteens.com/imbanner/thumbs/11.jpg',
	                   'http://www.exploitedbabysitterteens.com/imbanner/thumbs/10.jpg',
	                   'http://www.exploitedbabysitterteens.com/imbanner/thumbs/9.jpg',
	                   'http://www.exploitedbabysitterteens.com/imbanner/thumbs/8.jpg',
	                   'http://www.exploitedbabysitterteens.com/imbanner/thumbs/7.jpg',
	                   'http://www.exploitedbabysitterteens.com/imbanner/thumbs/6.jpg'];
	this.openers     = ['Heya cutie', 'Wanna talk?', 'Hey sexy!!', 'hey baby', 'hey you!', 'hey daddy'];
	this.fillers     = ['I\'m 18 and I\'m so bored!', 'I\'m so bored!', 'I\'m so lonely'];
	this.closers     = ['I\'m so horny!', 'Let\s chat now!', 'Talk dirty to me!', 'Let\'s talk sex!', 'I want to fuck!'];

	this.username   = this.names[Math.floor(Math.random()*this.names.length)];

	//First setup the styles non inline to keep things clean
	this.position = (ie6) ? 'absolute' : 'fixed';
	document.body.innerHTML = document.body.innerHTML +
		'<style type="text/css">'+
		'	body { margin: 0px; font-family: Tahoma, Arial, Helvetica, sans-serif; }'+
		'	img  { border: 0px; }'+
		'	#im_popup    { cursor: pointer; position: '+this.position+'; z-index:15000; right:2px; bottom:-116px; border: 2px solid #666; font-family:arial; font-size:10px; padding:0px;width:230px;height:150px;background-color:#FFF; }'+
		'	#im_name     { padding: 2px 2px 2px 58px; text-align: left; font-family: verdana; font-size: 12px; color: #FFF; font-weight: bold; line-height: 20px; height: 20px; background-color: #999; }'+
		'	#im_age      { padding: 2px 2px 2px 58px; text-align: left; font-family: verdana; font-size: 10px; color: #000; font-weight: bold; height: 40px; background-color: #CCC; }'+
		' #im_photo    { position: absolute; left: 2px; top: 2px; width: 50px; height: 64px; }' +
		' #im_footer   { position: absolute; bottom: 0px; left: 4px; height: 18px; text-align: left; border-top: 1px solid #CCC; width: 226px; padding: 6px 4px; }' +
		' #im_wrapper  { position: relative; height: 50px; padding-left: 2px; overflow: hidden; }' +
		'	#im_close    { display: none; font-size:12px; z-index:16000; position: '+this.position+'; bottom: 135px; right: 8px; color: #FFF; text-decoration: none; font-weight: bold; cursor: pointer; }'+
		' #typing      { color: #666; position: absolute; bottom: 4px; }' +
		' .im_username { color: #F00; }' +
		'</style>';

	//Now write out our IM Chat Popup
	document.body.innerHTML = document.body.innerHTML +
		'<div id="im_popup" style="display: none;" onclick="window.open(\''+this.url+'\');">'+
		'  <img id="im_photo" src="'+this.images[Math.floor(Math.random()*this.images.length)]+'"/>'+
		'	 <div id="im_name">'+this.username+'</div>'+
		'	 <div id="im_age">'+this.ages[Math.floor(Math.random()*this.ages.length)]+'</div>'+
		'	 <div id="im_wrapper">'+
		'		 <div id="typing">Typing...</div>'+
		'		 <div id="txtmain"></div>'+
		'	 </div>'+
		'  <div id="im_footer">&nbsp;<img src="'+this.chatImage+'" /> <img src="'+this.blinkImage+'" /</div>'+
		'</div>' +
		'<div id="im_close" onclick="popup.close();">X</a></div>';

	//Define the movein function so it's available
	this.moveIn = function() {
		if(this.posY < 0) {
			this.posY += 5;
			if(this.posY >= 0) {
				this.posY = 0;
				document.getElementById('im_close').style.display = 'block';
			}
			document.getElementById('im_popup').style.bottom = this.posY+'px';
			setTimeout('popup.moveIn()', 25);
		}
		else
		{
			if(ie6)
			{
				//Set interval timer to continually check for vertical scroll height
				this.scrollInterval = setInterval('popup.checkPos()', 10);
			}
		}

	}

	//Make sure both the wrapper and typing elements are shown
	document.getElementById('im_popup').style.display = 'block';
	document.getElementById('typing').style.display = 'block';

	//Let's animate the entry old school style without any libs
	this.moveIn();
	
	// Check positioning relative to the viewport
	this.checkPos = function()
	{
		if(imBrowserName == 'explorer')
		{
			imScrollHeight = document.documentElement.scrollTop;
		}
		else
		{
			imScrollHeight = window.pageYOffset;
		}
		
		var scrollHeight = viewportHeight + imScrollHeight - 172;
		
		document.getElementById('im_popup').style.top = scrollHeight;
		
	}
			
	//Don't wait for the animation it'll be done in .5s ... Start the show
	setTimeout('popup.addText()', 3000);

	this.addText = function() {
		document.getElementById('typing').style.display = 'none';

		if(this.txtCount < 3) {
			switch(this.txtCount) {
				case 0:
					document.getElementById('txtmain').innerHTML = document.getElementById('txtmain').innerHTML + '<span class="im_username">' + this.username + '</span>: ' + this.openers[Math.floor(Math.random()*this.openers.length)] + '<br />';
					break;

				case 1:
					document.getElementById('txtmain').innerHTML = document.getElementById('txtmain').innerHTML + '<span class="im_username">' + this.username + '</span>: ' + this.fillers[Math.floor(Math.random()*this.fillers.length)] + '<br />';
					break;

				case 2:
					document.getElementById('txtmain').innerHTML = document.getElementById('txtmain').innerHTML + '<span class="im_username">' + this.username + '</span>: ' + this.closers[Math.floor(Math.random()*this.closers.length)] + '<br />';
					break;
			}

			if(this.txtCount < 2) {
				setTimeout('popup.showTyping()', 1000);
				setTimeout('popup.addText()', 5000);
			}
		}
		this.txtCount++;
	};

	this.showTyping = function() {
		document.getElementById('typing').style.display = 'block';
	};

	this.close = function() {
		if(ie6)
		{
			clearInterval(this.scrollInterval);
		}
		document.getElementById('im_popup').style.display = 'none';
		document.getElementById('im_close').style.display = 'none';
		var expdate = new Date ();
		expdate.setTime(expdate.getTime() + 1000 * 60 * 60 * 4);
		setCookie("im","true",expdate);
	};


	return true;
};


function setCookie(name, value, expires)
{
	if (!expires) expires = new Date();
	document.cookie = name + "=" + escape(value) + "; expires=" + expires.toGMTString() + "; path=/";
}


function readCookie(name)
{
	var nameEQ = name + "=";
	var ca = document.cookie.split(';');
	for(var i=0;i < ca.length;i++) {
		var c = ca[i];
		while (c.charAt(0)==' ') c = c.substring(1,c.length);
		if (c.indexOf(nameEQ) == 0) return c.substring(nameEQ.length,c.length);
	}
	return null;
}


function checkIM()
{
	im = readCookie('im');
	if(im != 'true') {
		popup = new IM_Popup({ text: ["<?=$openers[rand(0,count($openers)-1)]?>", "<?=$fillers[rand(0,count($fillers)-1)]?>", "<?=$closers[rand(0,count($closers)-1)]?>"] });
	}
}

function returnViewportHeight()
{
	var viewportHeight = 'undefined';
	
	if(typeof window.innerWidth != 'undefined')
	{
		viewportHeight = window.innerHeight;
	}
	else if (typeof document.documentElement != 'undefined' && typeof document.documentElement.clientWidth != 'undefined' && document.documentElement.clientWidth != 0)
	{
		viewportHeight = document.documentElement.clientHeight;
	}
	else
	{
       viewportheight = document.getElementsByTagName('body')[0].clientHeight;
	}
	return viewportHeight;
}